Where does the file output of pg_dump go on MacOS?

馋奶兔 提交于 2019-12-23 03:23:27

问题


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:


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$


来源:https://stackoverflow.com/questions/50823425/where-does-the-file-output-of-pg-dump-go-on-macos

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!