Links

   Quran Explorer - Interactive Audio Recitations & Translations

Wednesday, September 1, 2010

PostgreSQL - Dump and Restore

#pg_dump -Fc imlu > imlu.sql

1. My Dump - explicit column names
#pg_dump -c -D -v sacco>dump.sacco.sql
-c drops db objects b4 recreating them
-C starts with command to create the db and reconnect to it
-D dump with explicit column names (slow)

2. Simplest dump
# pg_dump -d sacco > simplestdump.sacco.sql
-d Dump data as INSERT commands

3. single table dump
#pg_dump -d -t periods sacco >dump.periods.sacco.sql

RESTORE
#createdb sacco (after dropping) - or createdb -T template0 sacco
#psql -f dump.sacco.sql sacco - or psql dbname < infile

23.1.2. Using pg_dumpall
The above mechanism is cumbersome and inappropriate when backing up an entire database cluster. For this reason the pg_dumpall program is provided. pg_dumpall backs up each database in a given cluster, and also preserves cluster-wide data such as users and groups. The basic usage of this command is:

pg_dumpall > outfile

The resulting dump can be restored with psql:
psql -f infile postgres

(Actually, you can specify any existing database name to start from, but if you are reloading in an empty cluster then postgres should generally be used.) It is always necessary to have database superuser access when restoring a pg_dumpall dump, as that is required to restore the user and group information.

List All Databases
\l
Alternatively, you can list the databases from the command line using:
psql -l

No comments:

Post a Comment

Feel free to leave a comment