2

In psql, I just ran the command pg_dump to a custom-format archive:

Kurts-MacBook-Pro-2:~ kurtpeek$ psql --host localhost.aptible.in --port 64186 --username aptible --dbname db
Password for user aptible: 
psql (10.4, server 10.3 (Debian 10.3-1.pgdg80+1))
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

db=# pg_dump --format=custom
db-# 

As I understand it, this should back up the database (of which the name is obtained from the environment variable PGDATABASE, and is presumably db here) to a file. Is is unclear, to me, however, where this file is located?

From the documentation (https://www.postgresql.org/docs/10/static/app-pgdump.html) for the --file option,

-f file

--file=file

Send output to the specified file. This parameter can be omitted for file based output formats, in which case the standard output is used. It must be given for the directory output format however, where it specifies the target directory instead of a file. In this case the directory is created by pg_dump and must not exist before.

I suppose that the custom format is a file-based format, so I would expect the 'standard output' to be used. But what is the 'standard output' in this case? (I checked my home directory but nothing had been created in it recently).

1 Answer 1

8

It turns out that the pg_dump command is to be used at the command line, not in psql. And indeed the 'standard output' prints to the terminal (which in my case is not what I want, because I want to restore the database locally using pg_restore).

So I created a file (latest.dump) and wrote to it specifying the connection options, as well as --format=custom and --file=latest.dump:

Kurts-MacBook-Pro-2:~ kurtpeek$ touch latest.dump
Kurts-MacBook-Pro-2:~ kurtpeek$ pg_dump --host=localhost.aptible.in --port=64186 --username=aptible --dbname=db --format=custom --file=latest.dump
Password: 
Kurts-MacBook-Pro-2:~ kurtpeek$
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.