Skip to content

Instantly share code, notes, and snippets.

@chocobn69
Created March 29, 2016 12:46
Show Gist options
  • Save chocobn69/eeeb370255180279cb0a to your computer and use it in GitHub Desktop.
Save chocobn69/eeeb370255180279cb0a to your computer and use it in GitHub Desktop.
# -*- coding: utf8 -*-
from django.core.management.base import BaseCommand
from django.db import connection
from django.core import mail
import logging
logger = logging.getLogger(__name__)
class Command(BaseCommand):
args = ''
help = "Verifie l'etat des tables dans postgresql"
def handle(self, *args, **options):
"""
:param args:
:param options:
:return:
"""
cursor = connection.cursor()
try:
cursor.execute("""
select reltuples, relpages, pg_relation_size(oid),oid::regclass
from pg_class
where reltuples=0 and relpages > 0 and relkind = 'r'
""")
problems = cursor.fetchall()
if problems:
logger.error(problems)
try:
mail.send_mail(subject='database probleme',
message="""
we have some problems :
%s""" % problems,
from_email='',
recipient_list=['YOURMAIL'],
fail_silently=False)
except Exception as e:
logger.exception(e)
except Exception as e:
raise e
finally:
cursor.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment