elif cnt.missing:
# seems there is no active copy thread, launch new
t = self.get_table_by_state(TABLE_MISSING)
+
+ # drop all foreign keys to and from this table
+ self.drop_fkeys(dst_db, t.name)
+
+ # change state after fkeys are dropped thus allowing
+ # failure inbetween
self.change_table_state(dst_db, t, TABLE_IN_COPY)
# the copy _may_ happen immidiately
q2 = "select londiste.subscriber_restore_table_fkey(%(from_table)s, %(fkey_name)s)"
dst_curs.execute(q2, row)
dst_db.commit()
+
+ def drop_fkeys(self, dst_db, table_name):
+ # drop all foreign keys to and from this table
+ # they need to be dropped one at a time to avoid deadlocks with user code
+ dst_curs = dst_db.cursor()
+ q = "select * from londiste.find_table_fkeys(%s)"
+ dst_curs.execute(q, [table_name])
+ list = dst_curs.dictfetchall()
+ for row in list:
+ self.log.info('Dropping fkey: %s' % row['fkey_name'])
+ q2 = "select londiste.subscriber_drop_table_fkey(%(from_table)s, %(fkey_name)s)"
+ dst_curs.execute(q2, row)
+ dst_db.commit()
if __name__ == '__main__':
script = Replicator(sys.argv[1:])
for c in src_struct.get_column_list():
if c not in dlist:
raise Exception('Column %s does not exist on dest side' % c)
-
- # drop all foreign keys to and from this table
- self.drop_fkeys(dst_db, tbl_stat.name)
# drop unnecessary stuff
objs = T_CONSTRAINT | T_INDEX | T_TRIGGER | T_RULE
self.log.info("%s: copy finished: %d bytes, %d rows" % (
tablename, stats[0], stats[1]))
- def drop_fkeys(self, dst_db, table_name):
- # drop all foreign keys to and from this table
- # they need to be dropped one at a time to avoid deadlocks with user code
- dst_curs = dst_db.cursor()
- q = "select * from londiste.find_table_fkeys(%s)"
- dst_curs.execute(q, [table_name])
- list = dst_curs.dictfetchall()
- for row in list:
- self.log.info('Dropping fkey: %s' % row['fkey_name'])
- q2 = "select londiste.subscriber_drop_table_fkey(%(from_table)s, %(fkey_name)s)"
- dst_curs.execute(q2, row)
- dst_db.commit()
-
if __name__ == '__main__':
script = CopyTable(sys.argv[1:])
script.start()