How do I dump a database in PostgreSQL?

How do I dump a database in PostgreSQL?

Dump Your PostgreSQL Database

  1. SSH to the staging/production server.
  2. Dump the desired database: pg_dump database_name > database_name_20160527.sql.
  3. Leave SSH and download your new SQL file using SCP.
  4. Restore Your PostgreSQL Dump.
  5. If you want to use the current localhost database, you must drop it first:

What is PostgreSQL database dump?

pg_dump is a utility for backing up a PostgreSQL database. It makes consistent backups even if the database is being used concurrently. pg_dump does not block other users accessing the database (readers or writers). pg_dump only dumps a single database. Dumps can be output in script or archive file formats.

How to do a SQL dump in PostgreSQL?

The idea behind this dump method is to generate a file with SQL commands that, when fed back to the server, will recreate the database in the same state as it was at the time of the dump. PostgreSQL provides the utility program pg_dump for this purpose. The basic usage of this command is: pg_dump dbname > dumpfile

Which is internally consistent in PostgreSQL SQL dump?

Dumps created by pg_dump are internally consistent, meaning, the dump represents a snapshot of the database at the time pg_dump began running. pg_dump does not block other operations on the database while it is working. (Exceptions are those operations that need to operate with an exclusive lock, such as most forms of ALTER TABLE .) 25.1.1.

How to dump Oids in PostgreSQL documentation 9.1?

Important: If your database schema relies on OIDs (for instance, as foreign keys) you must instruct pg_dump to dump the OIDs as well. To do this, use the -o command-line option. 24.1.1. Restoring the Dump

Which is relative to template0 in PostgreSQL SQL dump?

The dumps produced by pg_dump are relative to template0. This means that any languages, procedures, etc. added via template1 will also be dumped by pg_dump. As a result, when restoring, if you are using a customized template1, you must create the empty database from template0, as in the example above.