3

Is there a way to copy table of one database to table of another database within the same cluster?

I have a cluster with multiple database. I have a master Database and multiple slave databases .

I will change one table in master and i want to copy to remaining database.

Is there a way to do it via postgresql console?

I use the following from the bash.

pg_dump -h localhost -U myuser -C -t my_table -d first_db>/tmp/table_dump 
psql -U myuser -d second_db</tmp/table_dump

I have to create a temporary dump file.

I use psycopg adapter to manage databases. Here I am looking forward for some solution.

asked Dec 20, 2016 at 10:21
1

1 Answer 1

2

Inspired by https://stackoverflow.com/a/19697098/450812, you can create a pipe.

pg_dump -h localhost -U myuser -C -t my_table -d first_db | psql -U myuser -d second_db

If you need to enter passwords, you can:

PGPASSWORD=password1 pg_dump -h localhost -U myuser -C -t my_table -d first_db | PGPASSWORD=password2 psql -U myuser -d second_db
answered Feb 22, 2022 at 13:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.