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:
|
|||||||||||||||||||||
|
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.
|
|||
|
PostgreSQL 9.1.2:
|
|||
|
What's the correct way to copy entire database (its structure and data) to a new one in pgAdmin? Ans. CREATE DATABASE newdb WITH TEMPLATE originaldb; Tried and tested. |
|||||
|
A command-line version of Bell's answer:
This should be run under the privileges of the database master, usually postgres. |
|||||||||
|
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 |
|||
|
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. |
|||||||||||
|