pg_dump
databaseLinux/Unix
The pg_dump command is one of the most frequently used commands in Linux/Unix-like operating systems. pg_dump Extract a PostgreSQL database into a script file or other archive file
Quick Reference
Command Name:
pg_dump
Category:
database
Platform:
Linux/Unix
Basic Usage:
pg_dump [options] [arguments]
Common Use Cases
Syntax
pg_dump [connection-option...] [option...] [dbname]
Options
Option | Description |
---|---|
-a, --data-only |
Dump only the data, not the schema |
-b, --blobs |
Include large objects in dump |
-c, --clean |
Clean (drop) database objects before recreating |
-C, --create |
Include commands to create database in dump |
-E, --encoding=ENCODING |
Dump the data in encoding ENCODING |
-f, --file=FILENAME |
Output file or directory name |
-F, --format=c|d|t|p |
Output file format (custom, directory, tar, plain text) |
-n, --schema=SCHEMA |
Dump the named schema(s) only |
-N, --exclude-schema=SCHEMA |
Do NOT dump the named schema(s) |
-o, --oids |
Include OIDs in dump |
-O, --no-owner |
Skip restoration of object ownership |
-s, --schema-only |
Dump only the schema, no data |
-S, --superuser=NAME |
Superuser user name to use in the dump |
-t, --table=TABLE |
Dump the named table(s) only |
-T, --exclude-table=TABLE |
Do NOT dump the named table(s) |
-v, --verbose |
Verbose mode |
-x, --no-privileges |
Do not dump privileges (grant/revoke) |
-Z, --compress=0-9 |
Compression level for compressed formats |
--binary-upgrade |
For use by upgrade utilities only |
--column-inserts |
Dump data as INSERT commands with column names |
--disable-dollar-quoting |
Disable dollar quoting, use SQL standard quoting |
--disable-triggers |
Disable triggers during data-only restore |
--inserts |
Dump data as INSERT commands, rather than COPY |
--no-security-labels |
Do not dump security label assignments |
--no-synchronized-snapshots |
Do not use synchronized snapshots in parallel jobs |
Connection Options:
Option | Description |
---|---|
-d, --dbname=DBNAME |
Database to dump |
-h, --host=HOSTNAME |
Database server host or socket directory |
-p, --port=PORT |
Database server port number |
-U, --username=NAME |
Connect as specified database user |
-w, --no-password |
Never prompt for password |
-W, --password |
Force password prompt |
--role=ROLENAME |
Do SET ROLE before dump |
Examples
How to Use These Examples
The examples below show common ways to use the pg_dump
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
# Basic Examples Basic
pg_dump mydb > mydb.sql