diff options
Diffstat (limited to 'python')
-rw-r--r-- | python/londiste/playback.py | 20 | ||||
-rw-r--r-- | python/londiste/table_copy.py | 2 |
2 files changed, 22 insertions, 0 deletions
diff --git a/python/londiste/playback.py b/python/londiste/playback.py index 7a3fd0fb..70617a90 100644 --- a/python/londiste/playback.py +++ b/python/londiste/playback.py @@ -253,6 +253,8 @@ class Replicator(pgq.SerialConsumer): # and the transaction must be kept open so that # the SerialConsumer can save last tick and commit. + self.sync_database_encodings(src_db, dst_db) + self.handle_seqs(dst_curs) self.handle_events(dst_curs, ev_list) self.save_table_state(dst_curs) @@ -559,6 +561,24 @@ class Replicator(pgq.SerialConsumer): res = os.system(cmd) self.log.debug("Launch result: "+repr(res)) + def sync_database_encodings(self, src_db, dst_db): + """Make sure client_encoding is same on both side.""" + + try: + # psycopg2 + if src_db.encoding != dst_db.encoding: + dst_db.set_client_encoding(src_db.encoding) + except AttributeError: + # psycopg1 + src_curs = src_db.cursor() + dst_curs = dst_db.cursor() + src_curs.execute("show client_encoding") + src_enc = src_curs.fetchone()[0] + dst_curs.execute("show client_encoding") + dst_enc = dst_curs.fetchone()[0] + if src_enc != dst_enc: + dst_curs.execute("set client_encoding = %s", [src_enc]) + if __name__ == '__main__': script = Replicator(sys.argv[1:]) script.start() diff --git a/python/londiste/table_copy.py b/python/londiste/table_copy.py index f3e21376..edbcbbde 100644 --- a/python/londiste/table_copy.py +++ b/python/londiste/table_copy.py @@ -33,6 +33,8 @@ class CopyTable(Replicator): src_db.set_isolation_level(skytools.I_SERIALIZABLE) src_db.commit() + self.sync_database_encodings(src_db, dst_db) + # initial sync copy src_curs = src_db.cursor() dst_curs = dst_db.cursor() |