Question

I would like to copy two tables from database A to database B, in postgres how can I do it using pg_dump without losing the previous tables and data in database B ?

I read some answers in Stack Overflow suggesting using pg_dump but in the documentation page I read?

The idea behind this dump method is to generate a text file with SQL commands that, when fed back to the server, will recreate the database in the same state as it was at the time of the dump

Doesn't that mean it will delete the previous data in database B?

If someone could tell me step by step solution to move two tables in database A to database B without losing any previous data in Database B, it would be helpful.

Was it helpful?

Solution

I found the answer to my question :

sudo -u OWNER_USER pg_dump -t users databasename1 | sudo -u OWNER_USER psql databasename2

OTHER TIPS

  1. if you pg_restore a database into b database, of course a will replace b. instead pick specific table you would like to restore using pg_restore -t
  2. you could pg_restore to different schema, by using -O (no_owner)

so let say

pg_dump -Fc -f dump.dmp -v -h host -U user_login -n schema_to_dump

you can

pg_restore -v -h host -U user_login -n schema_to_import -a --disable-triggers dump.dmp
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top