todb = psycopg2.connect('dbname=to_db')
r_fd, w_fd = os.pipe()

def copy_from():
    cur = todb.cursor()
cur.copy_from(os.fdopen(r_fd), 'table')
cur.close()
todb.commit()
to_thread = threading.Thread(target=copy_from)
to_thread.start()
cur = fromdb.cursor()
write_f = os.fdopen(w_fd, 'w')
cur.copy_to(write_f, 'table')
write_f.close()
to_thread.join()
скопировать postgres в python с помощью psycopg2