Forrest logo
tool overview
On this page you find all important commands for the CLI tool pg_dump. If the command you are looking for is missing please ask our AI.

pg_dump

pg_dump is a command line tool that comes with PostgreSQL, a powerful open-source relational database management system. It is primarily used to create backups of PostgreSQL databases in a portable SQL format.

With pg_dump, you can effectively dump a database into a plain-text file, making it easy to transport or restore on another system. It generates a SQL script containing a series of SQL statements that can recreate the structure of the database, along with all the data.

This tool offers various options to customize the backup process according to your needs. You can choose to dump a single database or multiple databases at once, specify specific tables or schemas to include/exclude, and even dump only the schema without the data or vice versa.

pg_dump is also capable of generating output in other formats like binary, custom, or directory. These formats provide faster backup/restoration, smaller file size, or more extensible backup options, respectively.

It supports parallel dumping by utilizing multiple sessions, which can significantly speed up the backup process for large databases. Additionally, you can compress the output file using various compression algorithms, reducing the storage space required.

The tool also allows you to capture and restore specific snapshots of the database at different points in time, ensuring proper version control and recovery options.

pg_dump integrates well with other PostgreSQL tools, such as pg_restore, which is used to restore the dumped data into a database. It also works seamlessly with various third-party backup and recovery solutions.

Overall, pg_dump is a versatile and essential command line tool for conveniently creating backups of PostgreSQL databases, providing reliability, flexibility, and options for efficient and secure data preservation.

List of commands for pg_dump:

  • pg_dump:tldr:4119a pg_dump: Dump a database into a custom-format archive file.
    $ pg_dump -Fc ${db_name} > ${output_file-dump}
    try on your machine
    explain this command
  • pg_dump:tldr:4a411 pg_dump: Same as above, customize host and port.
    $ pg_dump -h ${host} -p ${port} ${db_name} > ${output_file-sql}
    try on your machine
    explain this command
  • pg_dump:tldr:cd40f pg_dump: Dump database into an SQL-script file.
    $ pg_dump ${db_name} > ${output_file-sql}
    try on your machine
    explain this command
  • pg_dump:tldr:e06f3 pg_dump: Dump only database data into an SQL-script file.
    $ pg_dump -a ${db_name} > ${path-to-output_file-sql}
    try on your machine
    explain this command
  • pg_dump:tldr:f6d1d pg_dump: Dump only schema (data definitions) into an SQL-script file.
    $ pg_dump -s ${db_name} > ${path-to-output_file-sql}
    try on your machine
    explain this command
  • pg_dump:tldr:fd1a3 pg_dump: Same as above, customize username.
    $ pg_dump -U ${username} ${db_name} > ${output_file-sql}
    try on your machine
    explain this command
tool overview