def __init__(self): time_check_query="""SELECT CASE WHEN (SELECT TRUE FROM log_time WHERE hour_truncate=date_trunc('hour',now())) THEN NULl ELSE LOCALTIMESTAMP END AS actual_time,date_trunc('hour',LOCALTIMESTAMP) AS hour_truncate""" self.cursor.execute(time_check_query) time_data=self.cursor.fetchone() if not time_data[0]: logger.critical('Appropriate record for "{0}" already exists'.format(time_data[1])) self.cursor.close() db_handler.close() exit() logger.debug('Log time obtained. Actual Time: {0}\tHour Truncate: {1}'.format(time_data[0],time_data[1])) self.actual_time=time_data[0] self.hour_truncate=time_data[1] self.cursor.execute("INSERT INTO log_time (hour_truncate,actual_time) VALUES ('{0}','{1}') RETURNING id".format(time_data[1],time_data[0])) self.id=self.cursor.fetchone()[0] db_handler.commit()
self_cursor.execute("INSERT INTO schema_name VALUES (1,1,'t','t','public')") sn=SchemaName() sn.discover_tables() for tn_id in sn.get_tables(): tn=TableName(tn_id) tn.discover_indexes() tn.discover_toast() toast_id=tn.get_toast_id() if toast_id: ttn=TableToastName(toast_id) ttn.discover_index() sn.discover_functions() try: prod_cursor.execute("SELECT current_setting('track_functions') AS track_functions") except Exception as e: logger.error("Cannot get 'track_functions' configuraion param: {0}".format(e.pgerror)) pass else: track_changes=prod_cursor.fetchone()[0] if track_changes != 'none': self_cursor.execute("UPDATE host_cluster SET track_functions ='{0}'".format(track_changes)) prod_cursor.close() self_cursor.close() db_handler.close() prod_handler.close()