Update tablecopy tool: Add --disable-triggers option.
authorRadek Brich <brich.radek@ifortuna.cz>
Mon, 14 Apr 2014 22:28:12 +0200
changeset 96 acf63df539b7
parent 95 6adcb7ee4517
child 97 a4af93e72e2b
Update tablecopy tool: Add --disable-triggers option.
tablecopy.py
--- a/tablecopy.py	Thu Mar 20 16:33:34 2014 +0100
+++ b/tablecopy.py	Mon Apr 14 22:28:12 2014 +0200
@@ -23,6 +23,8 @@
             help="Do nothing, just print tables to be copied. Useful in combination with --regex.")
         self.parser.add_argument('--no-sort', dest='nosort', action='store_true',
             help="Do not sort. By default, tables are sorted by foreign key references.")
+        self.parser.add_argument('--disable-triggers', dest='notriggers', action='store_true',
+            help="Disable all triggers for the session.")
 
         self.init()
 
@@ -30,6 +32,12 @@
         self.srcconn = self.pgm.get_conn('src')
         self.dstconn = self.pgm.get_conn('dst')
 
+        if self.args.notriggers:
+            curs = self.dstconn.cursor()
+            curs.execute('SET session_replication_role = replica;')
+            curs.close()
+            self.dstconn.commit()
+
         dc = pgdatacopy.PgDataCopy(self.srcconn, self.dstconn)
 
         if self.args.nosort: