0

Many webs (as StackOverFlow: Copying PostgreSQL database to another server ) talk about that, but maybe something is wrong in my command.

pg_dump -C -h localhost -U postgres BD.to.move | psql -h server.destiny -U postgres BD.to.move

I have password root + password postgres on S1

I have password root + password postgres on S2

however after of run my command over server1, in server2 NO'T exist the BD.to.move.

My command is wrong?

How I can copy/transfer {BD.to.move + ROLES + SCHEMAS + users, + password, etc...} ?

(in others words, the BD complet to use directly in production over server.destiny)

VyR
  • 201
  • 1
  • 2
  • 13
  • First check that `pg_dump` is working, that you're getting proper SQL output. – tadman Apr 01 '21 at 05:09
  • yes, ``pg_dump`` work fine, I can get BD in file. But now I want use the option to send BD+SCHEMAS+ROLES to server.destiny without file intermediate – VyR Apr 01 '21 at 05:18

1 Answers1

0

Don't specify the argument BD.to.move to psql, since that database does not exist at the destination. Use postgres, which exists.

If you create your dump with -C, it will contain a CREATE DATABASE statement. In order to restore such a dump, you must connect to an existing database other than the one you want to restore, then psql will first create the database, then connect to it and restore the data.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263