Forrest logo
back to the pg_dump tool

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

The command "pg_dump" is used to create a backup of a PostgreSQL database.

Here is the breakdown of the command:

  • "pg_dump": This is the command itself, used to invoke the backup utility.
  • "-h ${host}": This option is used to specify the host (or IP address) where the PostgreSQL database is running. The ${host} is a placeholder that needs to be replaced with the actual host value.
  • "-p ${port}": This option is used to specify the port number on which the PostgreSQL database is running. The ${port} is a placeholder that needs to be replaced with the actual port value.
  • "${db_name}": This is the name of the PostgreSQL database that you want to back up. This is another placeholder that needs to be replaced with the actual database name.
  • "> ${output_file-sql}": This is used to redirect the output of the pg_dump command to a file. The "${output_file-sql}" is the placeholder for the file name where the output will be written. This can be replaced with the actual file name you want to use.

So, when you run this command with the appropriate values filled in, it will connect to the specified PostgreSQL server, dump the contents of the specified database, and write it to the specified output file in SQL format.

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_dump tool