Running pg_dump

The first thing we want to do is to create a simple textual dump:

[hs@linuxpc ~]$ pg_dump test > /tmp/dump.sql  

This is the most simplistic backup you can imagine. pg_dump logs in to the local database instance, connects to a database test, and starts to extract all the data, which will be sent to stdout and redirected to the file. The beauty is that standard output gives you all the flexibility of a Unix system. You can easily compress the data using a pipe or do whatever you want.

In some cases, you might want to run pg_dump as a different user. All PostgreSQL client programs support a consistent set of command-line parameters to pass user information. If you just want to set the user, use the -U flag:

[hs@linuxpc ~]$ pg_dump ...

Get Mastering PostgreSQL 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.