POSTGRESQL-ESSENTIALS practice question 8 of 15

Which pg_dump option allows you to dump only the data without schema definitions?

Full set: 71 questions
Answer options
A: -d
B: --data-only Correct answer
C: -D
D: --no-schema
Correct Answer:
B. --data-only
Explanation

The pgdump utility is used for creating backups of a PostgreSQL database. To create a dump that contains only the data and excludes the schema definitions (like CREATE TABLE statements), the --data-only option is used. Its short-form equivalent is -a. This is particularly useful when the target database already has the required schema structure, and only the data needs to be restored or transferred. The resulting dump file will primarily contain COPY statements to load the data into the existing tables.

Why Incorrect

A. -d: This option, or its long form --dbname, is used to specify the name of the database to connect to, not to control the dump content.
C. -D: This is not a valid option for the pgdump utility. It is used by other PostgreSQL tools like initdb to specify the data directory location.
D. --no-schema: This is not a valid pgdump option. The correct and officially supported option to achieve this outcome is --data-only.

References

1. PostgreSQL 16 Documentation, pgdump:

Section: Options -> Options Controlling the Output Content

Reference: The documentation explicitly states: "--data-only / -a Dump only the data, not the schema (data definitions). Table data, large objects, and sequence values are dumped."

Reference: The documentation also lists: "-d dbname / --dbname=dbname Specifies the name of the database to connect to." This confirms option A's purpose.

2. University of California, Berkeley, CS186: Introduction to Database Systems, Lecture 21: Practicalities: SQL in the Real World:

Section: Backup and Recovery

Reference: Course materials discuss database administration utilities, noting that pgdump provides flags to separate schema and data. The --data-only flag is cited as the standard method for extracting only table data for migration or archival purposes, distinct from schema-only dumps (-s).

Scroll to Top