Forrest logo
back to the pg_dumpall tool

pg_dumpall:tldr:dc6c0

pg_dumpall: Same as above, customize host and port.
$ pg_dumpall -h ${host} -p ${port} > ${output_file-sql}
try on your machine

The command pg_dumpall is used to create a SQL script file that contains the SQL commands needed to recreate all of the databases in a PostgreSQL cluster. Let's break down the command:

  • pg_dumpall: This is the command itself, used to dump all the databases in the PostgreSQL cluster.

  • -h ${host}: This is an optional flag that specifies the host (hostname or IP address) where the PostgreSQL server is running. The ${host} placeholder should be replaced with the actual host value.

  • -p ${port}: This is another optional flag that specifies the port number that the PostgreSQL server is listening on. The ${port} placeholder should be replaced with the actual port value.

  • > ${output_file-sql}: This part of the command redirects the output of the pg_dumpall command to a file named ${output_file-sql}. The ${output_file-sql} placeholder should be replaced with the desired name of the output file, which should have a .sql extension.

Here's an example of how the command may look when filled in with actual values:

pg_dumpall -h localhost -p 5432 > backup.sql

In this example, localhost is the hostname or IP address of the PostgreSQL server, 5432 is the port number, and backup.sql is the name of the output file where the SQL script will be saved.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the pg_dumpall tool