tags:

views:

3995

answers:

3

What's the correct way to copy entire database (its structure and data) to a new one in pgAdmin?

+4  A: 

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.

TrayMan
Thanks, I needed to create a dump from another server, and it seems this helps: http://www.postgresql.org/docs/8.3/interactive/backup-dump.html#BACKUP-DUMP-RESTORE
egaga
You can even do `pg_dump -U postgres sourcedb | psql -U postgres newdb` although the efficiency of this technique may be questionable (since you probably end up context switching between reads and writes)
Frank Farmer
+18  A: 

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:

CREATE DATABASE newdb WITH TEMPLATE originaldb;

Bell
Note that originaldb needs to be idle (no write transactions) for this to work.
synecdoche
+1  A: 

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

Isomorph