When using pg_dump
to back up a PostgreSQL database, here are some important flags and options to consider:
-
-d, --dbname=NAME: Specifies the name of the database to dump.
-
-f, --file=FILENAME: Directs the output to the specified file or directory.
-
-F, --format=c|t|p: Specifies the format of the output file (
c
for custom,t
for tar,p
for plain text SQL). -
-h, --host=HOSTNAME: Specifies the host name of the machine on which the server is running.
-
-p, --port=PORT: Specifies the TCP port or local Unix socket file extension on which the server is listening for connections.
-
-U, --username=NAME: Connect as the specified PostgreSQL user.
-
-w, --no-password: Never issue a password prompt. Useful for scripting.
-
-W, --password: Force password prompt (should be avoided in scripts for security reasons).
-
-c, --clean: Clean (drop) database objects before recreating them.
-
-j, --jobs=NUM: Use this many parallel jobs to dump large objects. This can speed up the dump process.
-
--data-only: Dump only the data, not the schema.
-
--schema-only: Dump only the schema, not the data.
-
--inserts: Dump data as INSERT commands rather than COPY.
-
--column-inserts: Dump data as INSERT commands with column names.
To back up everything including records, the default behavior of pg_dump
is to include both schema (table definitions, functions, etc.) and data (records within tables). This ensures a complete backup of the database. If you want to include only data or only schema, you can use the --data-only
or --schema-only
options respectively.
For a basic backup of an entire database to a file named backup.sql
, you might use a command like this:
pg_dump -U your_username -d your_database -f backup.sql
Adjust your_username
and your_database
with your actual PostgreSQL username and database name.