Beispiel #1
0
    def stat(self,in_time_id):
	if not super(TableName,self).stat(in_time_id):
	    logger.error("Return from TN.stat False from super.stat()")
	    return False
	idx_sets=self.get_dependants(False)
	if not idx_sets:
	    logger.info("TN.stat no ids_sets returned. Maybe no indexes present. Tabe {0}".format(self.db_fields['tbl_name']))
	    return True
	else:
	    for idx_set in idx_sets:
		idn=IndexName(self.db_conn,self.prod_dsn,idx_set)
		idn.set_prod_conn(self.prod_conn)
		if not idn.stat(in_time_id):
		    logger.error("TN.stat False from idn.stat")
	ttn_id=self.get_toast_id()
	if ttn_id:
	    ttn=TableToastName(self.db_conn,self.prod_dsn,ttn_id)
	    ttn.set_prod_conn(self.prod_conn)
	    if not ttn.stat(in_time_id):
		logger.error("TN.stat False from ttn.stat")
	    tin_id=ttn.get_tindex_id()
	    tin=IndexToastName(self.db_conn,self.prod_dsn,tin_id)
	    tin.set_prod_conn(self.prod_conn)
	    if not tin.stat(in_time_id):
		logger.error("TN.stat False from tin.stat")
	return True
Beispiel #2
0
	    for sn_id in dn.get_dependants(obs=True):
		sn=SchemaName(sn_id)
		sn.discover_tables(db_cursor)
		sn.discover_functions(db_cursor)
		for tbl_id in sn.get_tables():
		    tn=TableName(tbl_id)
		    tn.stat(lt.id,db_cursor)
		    tn.va_stat(lt.id,db_cursor)
		    tn.discover_indexes(db_cursor)
		    for ind_id in tn.get_dependants():
			ind=IndexName(ind_id)
			ind.stat(lt.id,db_cursor)
		    tn.discover_toast(db_cursor)
		    toast_id=tn.get_toast_id()
		    if toast_id:
			ttn=TableToastName(toast_id)
			ttn.stat(lt.id,db_cursor)
			ttn.discover_index(db_cursor)
			tin=IndexToastName(ttn.get_tindex_id())
			tin.stat(lt.id,db_cursor)
		if hc.get_track_function():
		    for fnc_id in sn.get_functions():
			func=FunctionName(fnc_id)
			func.stat(lt.id,db_cursor)
	if not db_cursor.closed:
	    db_cursor.close()

work_cursor.close()
database.db_conn.close()

    def discover_index(self):
	p_cur=self._get_p_cursor()
	if not p_cur:
	    logger.error("Return from TTN.discover_index No p_cur obtained")
	    return False
	try:
	    p_cur.execute("""SELECT i.oid,i.relname
FROM pg_class t
INNER JOIN pg_class i ON t.reltoastidxid=i.oid
WHERE t.relkind='t'
AND t.oid={0}""".format(self.db_fields['obj_oid']))
	except Exception as e:
	    logger.error("Canot execute toast index discovery query on Prod: {0}".format(e.pgerror))
	    p_cur.close()
	    return False
	p_idx=p_cur.fetchone()
	p_cur.close()
	cur=self._get_cursor()
	if not cur:
	    logger.error("Return from TTN.discover_index No cur obtained")
	    return False
	try:
	    cur.execute("SELECT obj_oid,tidx_name,id FROM index_toast_name WHERE ttn_id={0} AND alive".format(self.id))
	except Exception as e:
	    logger.error("Canot execute toast index discovery query on Local: {0}".format(e.pgerror))
	    return False
	l_idx=cur.fetchone()
	cur.close()
	if l_idx and p_idx:
	    if not (l_idx[0]==p_idx[0] and l_idx[1]==p_idx[1]):
		logger.info("Retired TOAST index {0} for table {1}".format(l_idx[1],self.db_fields['ttbl_name']))
		old_tidx=IndexToastName(l_idx[2])
		if not old_tidx.retire():
		    logger.error("TTN.discover_index Cannot retire old I place")
		logger.info("Create new TOAST index {0} in table {1}".format(p_idx[1],self.db_fields['ttbl_name']))
		new_tidx=IndexToastName(self.db_conn,self.prod_conn)
		new_tidx.set_fields(ttn_id=self.id,obj_oid=p_idx[0],tidx_name=p_idx[1])
		if not new_tidx._create():
		    logger.error("TTN.discover_index Cannot create new I place")
		self.toast_idx_id=new_tidx.get_id()
	elif l_idx and not p_idx:
	    self.toast_idx_id=None
	    logger.info("Retired TOAST index {0} for table {1}".format(l_idx[1],self.db_fields['ttbl_name']))
	    old_tidx=IndexToastName(self.db_conn,self.prod_conn,l_idx[2])
	    if not old_tidx.retire():
		logger.error("TTN.discover_index Cannot retire old II place")
	elif not l_idx and p_idx:
	    logger.info("Create new TOAST index {0} in table {1}".format(p_idx[1],self.db_fields['ttbl_name']))
	    new_tidx=IndexToastName(self.db_conn,self.prod_conn)
	    new_tidx.set_fields(ttn_id=self.id,obj_oid=p_idx[0],tidx_name=p_idx[1])
	    self.toast_idx_id=new_tidx.get_id()
	    if not new_tidx._create():
		logger.error("TTN.discover_index Cannot create new III place")
	return True