0

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.

1
  • Have you read the man for pg_dump? Commented Jul 22, 2013 at 5:24

2 Answers 2

3

I found the answer to my question :

sudo -u OWNER_USER pg_dump -t users databasename1 | sudo -u OWNER_USER psql databasename2
Sign up to request clarification or add additional context in comments.

Comments

0
  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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.