My current process for copying my database to the new server is to pg_dump with --no-owner --no-privileges
Then on the new server, I
- create the database
- create the two users
- create all the necessary permissions for both users
- run
pg_restoreas one user - change ownership of the objects that should be owned by the second user
This is a very tedious and error-prone process. Just a few minutes ago, for example, I have created all the objects in the postgres database, instead of mydatabase.
Is there a way to make it simpler? Can the dump contain all the users I need, all the permissions, and database name?
Is is possible to do it all with one pg_dump line on the main server, then scp, and the one pg_restore line on the new server?
Should I be using pg_dumpall instead? I have only one database on the server.
You can use
pg_dumpall -rto dump the users (roles).Apart from that, I would say that scripting is a solution. Write a script that does all the right moves, so you don't have to do them by hand.