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
2009-05-18 07:05:46
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
2009-05-18 11:33:11
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
2010-06-07 17:19:55
+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
2009-05-18 07:18:51
Note that originaldb needs to be idle (no write transactions) for this to work.
synecdoche
2010-05-19 23:51:39
+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
2010-08-14 00:24:43