|PostgreSQL Reference Manual - Volume 3 - Server Administration Guide|
by The PostgreSQL Global Development Group
Paperback (6"x9"), 204 pages
RRP £13.95 ($24.95)
Sales of this book support the PostgreSQL project! Get a printed copy>>>
10.1 SQL Dump
The idea behind this dump method is to generate a text file with SQL
commands that, when fed back to the server, will recreate the
database in the same state as it was at the time of the dump.
PostgreSQL provides the utility program
pg_dump for this purpose. The basic usage of this
pg_dump dbname > outfile
As you see, pg_dump writes its results to the standard output. We will see below how this can be useful.
pg_dump is a regular PostgreSQL client application (albeit a particularly clever one). This means that you can do this backup procedure from any remote host that has access to the database. But remember that pg_dump does not operate with special permissions. In particular, it must have read access to all tables that you want to back up, so in practice you almost always have to run it as a database superuser.
To specify which database server pg_dump should
contact, use the command line options
-p port. The
default host is the local host or whatever your
PGHOST environment variable specifies. Similarly,
the default port is indicated by the
environment variable or, failing that, by the compiled-in default.
(Conveniently, the server will normally have the same compiled-in
As any other PostgreSQL client application,
pg_dump will by default connect with the database
user name that is equal to the current operating system user name. To override
this, either specify the
-U option or set the
PGUSER. Remember that
pg_dump connections are subject to the normal
client authentication mechanisms (which are described in section 7 Client Authentication).
Dumps created by pg_dump are internally consistent,
that is, updates to the database while pg_dump is
running will not be in the dump. pg_dump does not
block other operations on the database while it is working.
(Exceptions are those operations that need to operate with an
exclusive lock, such as
Important: If your database schema relies on OIDs (for instance as foreign keys) you must instruct pg_dump to dump the OIDs as well. To do this, use the
-ocommand line option.
|ISBN 0954612043||PostgreSQL Reference Manual - Volume 3 - Server Administration Guide||See the print edition|