This thread here shows how to copy a table from one database to another, where a similar table already exists:
pg_dump -a -t my_table my_db | psql target_db
However, this pg_dump
only works on either non-partitioned table or a partition itself. I have many partitions in the two databases:
table_1_part_1
table_1_part_2
...
table_1_part_n
...
table_k_part_m
So, using pg_dump
, I have to do that for each partition.
What is a good solution for efficient copying in this case? Assuming that all partitions exist in both databases. If there is SQL query, I can use it in a Python script.