What's the correct way to copy entire database (its structure and data) to a new one in pgAdmin?
Postgres allows the use of any existing database on the server as a template when creating a new database. I'm not sure whether pgAdmin gives you the option on the create database dialog but you should be able to execute the following in a query window if it doesn't:
Still, you may get:
| |||||||||||||||||||||
|
A command-line version of Bell's answer:
This should be run under the privileges of the database master, usually postgres. | |||||||||
|
Don't know about pgAdmin, but pgdump gives you a dump of the database in SQL. You only need to create a database by the same name and do 'psql mydatabase < mydump' to restore all of the tables and their data and all access privileges. | |||||||||||||
|
In pgAdmin you can make a backup from your original database, and then just create a new database and restore from the backup just created. Regards | |||||
|
PostgreSQL 9.1.2:
| |||||
|
For those still interested, I have come up with a bash script that does (more or less) what the author wanted. I had to make a daily business database copy on a production system, this script seems to do the trick. Remember to change the database name/user/pw values.
| |||
|
What's the correct way to copy entire database (its structure and data) to a new one in pgAdmin? Answer:
Tried and tested. | |||||
|
If the database has open connections, this script may help. I use this to create a test database from a backup of the live-production database every night. This assumes that you have an .SQL backup file from the production db (I do this within webmin).
| |||
|
Using pgAdmin, disconnect the database that you want to use as a template. Then you select it as the template to create the new database, this avoids getting the already in use error. | |||
|