2000-12-25
pg_dump
1
Application
pg_dump
Extract a Postgres database into a script file or other archive file
2000-11-22
pg_dump [ dbname ]
pg_dump [ -h host ]
[ -p port ]
[ -t table ]
[ -a ] [ -b ] [ -c ] [-C] [ -d ] [ -D ]
[-f file]
[-F format]
[ -i ] [ -n ] [ -N ] [ -o ] [ -O ] [-R]
[ -s ] [ -S ] [ -u ] [ -v ] [ -x ] [ -Z 0..9 ]
[ dbname ]
2000-11-22
Inputs
pg_dump accepts the following command
line arguments:
dbname
Specifies the name of the database to be extracted.
dbname
defaults to the value of the
USER
environment variable.
-a
Dump out only the data, no schema (definitions).
-b
Dump BLOB data.
-c
Clean (drop) schema prior to create.
-C
For plain text (script) output, include SQL to create the database itself.
-d
Dump data as proper insert strings. This is not recommended for large databases
for performance reasons.
-D
Dump data as inserts with attribute names. This is not recommended for large databases
for performance reasons.
-f file
Send output to the specified file.
-F format
Format can be one of the following:
p
output a plain text SQL script file (default)
t
output a TAR archive suitable for input into
pg_restore. Using this archive format
allows reordering and/or exclusion of schema elements
at the time the database is restored. It is also possible to limit
which data is reloaded at restore time.
c
output a custom archive suitable for input into
pg_restore. This is the most flexible
format in that it allows reordering of data load as well
as schema elements. This format is also compressed by default.
-i
Ignore version mismatch between pg_dump
and the database server. Since pg_dump
knows a great deal about system catalogs, any given version of
pg_dump is only intended to work with
the corresponding release of the database server. Use this option
if you need to override the version check (and if
pg_dump then fails, don't
say you weren't warned).
-n
Suppress double quotes around identifiers unless absolutely necessary.
This may cause trouble loading this dumped data if there are reserved words
used for identifiers.
This was the default behavior for
pg_dump prior to v6.4.
-N
Include double quotes around identifiers.
This is the default.
-o
Dump object identifiers (OIDs) for every table.
-O
In plain text output mode, don't set object ownership to match the
original database. Typically, pg_dump
issues \connect statments to set
ownership of schema elements.
-R
In plain text output mode, prohibit pg_dump
from issuing any \connect statements.
-s
Dump out only the schema (definitions), no data.
-S username
Specify the superuser username to use when disabling triggers and/or
setting ownership of schema elements.
-t table
Dump data for table only.
-u
Use password authentication. Prompts for username and password.
-v
Specifies verbose mode.
-x
Prevent dumping of ACLs (grant/revoke commands) and table ownership information.
-Z 0..9
Specify the compression level to use in archive formats that support
compression (currently only the custom archive format supports compression).
pg_dump also accepts
the following command line arguments for connection parameters:
-h host
Specifies the hostname of the machine on which the
postmaster
is running. If host begins with a slash, it is used
as the directory for the unix domain socket.
-p port
Specifies the Internet TCP/IP port or local Unix domain socket file
extension on which the postmaster
is listening for connections. The port number defaults to 5432,
or the value of the PGPORT
environment variable (if set).
-u
Use password authentication.
Prompts for
username
and password.
1998-11-05
Outputs
pg_dump will create a file or
write to stdout.
Connection to database 'template1' failed.
connectDBStart() -- connect() failed: No such file or directory
Is the postmaster running locally
and accepting connections on Unix socket '/tmp/.s.PGSQL.5432'?
pg_dump could not attach to the
postmaster
process on the specified host and port. If you see this message,
ensure that the postmaster
is running on the proper host and that you have specified the proper
port. If your site uses an authentication system, ensure that you
have obtained the required authentication credentials.
Connection to database 'dbname' failed.
FATAL 1: SetUserId: user 'username' is not in 'pg_shadow'
You do not have a valid entry in the relation pg_shadow
and and will not be allowed to access Postgres.
Contact your Postgres administrator.
dumpSequence(table): SELECT failed
You do not have permission to read the database.
Contact your Postgres site administrator.
pg_dump internally executes
SELECT statements. If you have problems running
pg_dump,
make sure you are able to select information from the database using, for
example, psql.
2000-
Description
pg_dump is a utility for dumping out a
Postgres database into a script or archive
file containing query commands. The script files are in text format
and can be used to reconstruct the database, even on other machines
and other architectures.
The archive files, new with version 7.1, contain enough information for
pg_restore to rebuild the database, but also
allow pg_restore to be selective about what is restored, or even to
reorder the items prior to being restored. The archive files should
also be portable across architectures.
pg_dump
will produce the queries necessary to re-generate all
user-defined types, functions, tables, indices, aggregates, and
operators. In addition, all the data is copied out in text format so
that it can be readily copied in again, as well as imported into tools
for editing.
pg_dump
is useful for dumping out the contents of a database to move from one
Postgres installation to another. After running
pg_dump,
one should examine the output for any warnings, especially
in light of the limitations listed below.
When used with one of the alternate file formats and combined with
pg_restore, it provides a flexible archival
and trasfer mechanism. pg_dump can be used
to backup an entire database, then pg_restore
can be used to examine the archive and/or select which parts of the
database are to be restored.
See the pg_restore documentation for details.
2000-11-21
Notes
pg_dump has a few limitations.
The limitations mostly stem from
difficulty in extracting certain meta-information from the system
catalogs.
pg_dump
does not understand partial indices. The reason is
the same as above; partial index predicates are stored as plans.
When dumping a single table or as plain text, pg_dump
does not handle large objects. Large objects must be dumped in their
entirity using one of the binary archive formats.
When doing a data only dump, pg_dump emits queries
to disable triggers on user tables before inserting the data and queries to
re-enable them after the data has been inserted. If the restore is stopped
in the middle, the system catalogs may be left in the wrong state.
2000-11-21
Usage
To dump a database of the same name as the user:
$ pg_dump > db.out
To reload this database:
$ psql -e database < db.out
To dump a database called mydb that contains BLOBs to a TAR file:
$ pg_dump -Ft --blobs mydb > db.tar
To reload this database (with BLOBs) to an existing db called newdb:
$ pg_restore db.tar --db=newdb