在 MacOS 上 pg_dump 的文件输出去哪儿了? [英] Where does the file output of pg_dump go on MacOS?

查看:82
本文介绍了在 MacOS 上 pg_dump 的文件输出去哪儿了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

psql 中,我只是将命令 pg_dump 运行到自定义格式的存档中:

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-# 

据我所知,这应该将数据库(其名称从环境变量 PGDATABASE 中获得,这里大概是 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?

来自文档(https://www.postgresql.org/docs/10/static/app-pgdump.html) 用于 --file 选项,

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

-f 文件

--file=file

将输出发送到指定的文件.对于基于文件的输出格式,可以省略此参数,在这种情况下使用标准输出.但是,必须为目录输出格式提供它,它指定目标目录而不是文件.在这种情况下,目录是由 pg_dump 创建的,之前不能存在.

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.

我认为 custom 格式是一种基于文件的格式,因此我希望使用标准输出".但在这种情况下,标准输出"是什么?(我检查了我的主目录,但最近没有在其中创建任何内容).

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).

推荐答案

原来 pg_dump 命令是在命令行中使用的,而不是在 psql.事实上,标准输出"会打印到终端(在我的情况下,这不是我想要的,因为我想使用 pg_restore 在本地恢复数据库).

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).

所以我创建了一个文件 (latest.dump) 并写入其中指定连接选项,以及 --format=custom--file=latest.dump:

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$

这篇关于在 MacOS 上 pg_dump 的文件输出去哪儿了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆