I’m looking to copy a PostgreSQL Server to Another server.
- I want to migrate entire server which might contain multiple databases
- I am trying to do it with cloud databases (e.g. AWS which doesn’t provide super user privileges for RDS) so it would be better to provide a solution with Users of attribute Create role, Create DB
Password valid until infinity
I want something like (This query doesn’t exists just an example)
pg_dumpall -C -h localhost -U localuser | psql -h remotehost -U remoteuser
I know that below query exists but it is does not work same for pg_dumpall
pg_dump -C -h localhost -U localuser dbname | psql -h remotehost -U remoteuser dbname
2
Answers
-c for clean databases before recreating.
also you should have superuser privilege for this user.
If your goal is to move all databases from cluster A to cluster B, except for one specific database on cluster A, you can add the
--exclude-database=pattern
parameter topg_dumpall
:As mentioned in the comments,
-C
doesn’t exist for this command because it’s unnecessary. The--clean
is optional and not really advised as a default – if you misdirect your command and target the wrong cluster, it’s better for it to warn you than to quietly wipe it clean.Your edits fundamentally change the question and the latest comment doesn’t really align with the latest revision – multi-db dump&restore is what you initially asked about, and that’s exactly what
pg_dumpall
is meant to do.I suspect your problem isn’t really about PostgreSQL
psql
,pg_dump
orpg_dumpall
, it’s about how these things are done on AWS RDS. Here’s the official manual.