database postgresql pg_dump 的输出在哪里

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24930923/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 09:16:59  来源:igfitidea点击:

postgresql where does the output of pg_dump go

databasepostgresqlcommand-linebackuppg-dump

提问by Dariush Jafari

I am trying to backup a db of postgresql and I want to use pg_dumpcommand.
I tried :

我正在尝试备份 postgresql 的数据库并且我想使用pg_dump命令。
我试过 :

psql -U postgres
postgres-# pg_dump test > backup.sql

But I don't know where the output file goes.
Any help will be appreciated

但我不知道输出文件去哪里了。
任何帮助将不胜感激

采纳答案by Meem

Go to command prompt and directory postgresql\9.3\bin.

转到命令提示符和目录 postgresql\9.3\bin。

Example

例子

.

.

..
    c:\Program files\postgresql.3\bin> pg_dump -h localhost -p 5432 -U postgres test > D:\backup.sql
...

After above command enter User "postgres" password and check D:\drive for backup.sqlfile

在上述命令后输入用户“postgres”密码并检查D:\驱动器中的backup.sql文件

回答by mivk

I'm late to this party, but I feel that none of the answers are really correct. Most seem to imply that pg_dumpwrites a file somewhere. It doesn't. Youare sending the output to a file, and youtold the shell where to write that file.

我参加这个聚会迟到了,但我觉得没有一个答案是真正正确的。大多数似乎暗示在pg_dump某处写入文件。它没有。要发送的输出到一个文件,告诉壳在哪里写的文件。

In your example pg_dump test > backup.sql, which uses the plainor SQL format, the pg_dumpcommand does not storeany file anywhere. It just sends the output to STDOUT, which is usually your screen, and it's done.

在您pg_dump test > backup.sql使用plainor SQL 格式的示例中,该pg_dump命令不会在任何地方存储任何文件。它只是将输出发送到STDOUT,这通常是您的屏幕,然后就完成了。

But in your command, you also told your shell (Terminal, Command prompt, whatever) to redirect STDOUT to a file. This has nothing to do with pg_dumpbut is a standard feature of shells like Bash or cmd.exe.

但是在您的命令中,您还告诉您的 shell(终端、命令提示符等)将 STDOUT 重定向到一个文件。这与pg_dumpBash 或 cmd.exe 等 shell 的标准功能无关,但它是标准功能。

You used >to redirect STDOUT to a file instead of the screen. And you gave the file name: "backup.sql". Since you didn't specify any path, the file will be in your current directory. This is probably your home directory, unless you have done a cd ...into some other directory.

您曾经>将 STDOUT 重定向到文件而不是屏幕。你给了文件名:“backup.sql”。由于您没有指定任何路径,该文件将在您的当前目录中。这可能是您的主目录,除非您已cd ...进入其他目录。

In the particular case of pg_dump, you could also have used an alternative to the > /path/to/some_fileshell redirection, by using the -f some_fileoption:

在 的特殊情况下pg_dump,您还可以> /path/to/some_file通过使用-f some_file选项来使用 shell 重定向的替代方法:

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

-f 文件
--file=文件

将输出发送到指定的文件。对于基于文件的输出格式,可以省略此参数,在这种情况下使用标准输出。

So your command could have been pg_dump test -f backup.sql, asking pg_dump to write directly to that file.

所以你的命令可能是pg_dump test -f backup.sql,要求 pg_dump 直接写入该文件。

But in any case, you give the file name, and if you don't specify a path, the file is created in your current directory. If your prompt doesn't already display your current directory, you can have it shown with the pwdcommand on Unix, and cdin Windows.

但无论如何,您提供文件名,如果您不指定路径,则会在您的当前目录中创建该文件。如果您的提示尚未显示您的当前目录,您可以pwd在 Unix 和cdWindows中使用命令显示它。

回答by Brian Hellekin

In my situation (PostgreSQL 9.1.21, Centos 6.7), the command

在我的情况下(PostgreSQL 9.1.21,Centos 6.7),命令

runuser -l postgres -c 'pg_dump my_database > my_database.sql'

saved the file here:

将文件保存在这里:

/var/lib/pgsql/my_database.sql

Not sure if that is true for other Linux dists, CentOS and/or pgl versions. According to the answer post by the asker of this question, this is true, but other users said the backup file was in the current directory (a situation different of most people reading this thread, for obvious reasons). Well, I hope this can help other users with the same problem.

不确定其他 Linux 发行版、CentOS 和/或 pgl 版本是否如此。根据这个问题的提问者的回答,这是真的,但其他用户说备份文件在当前目录中(大多数人阅读这个帖子的情况不同,原因很明显)。好吧,我希望这可以帮助其他有同样问题的用户。

P.s.: if that's not the path for your situation, you can try (in Linux) to find it using the below command (as stated by @Bohemian in the comments of this question), but this can take a while:

Ps:如果这不是您的情况的路径,您可以尝试(在 Linux 中)使用以下命令找到它(如@Bohemian 在此问题的评论中所述),但这可能需要一段时间:

find / -name 'my_database.sql'

EDIT:I tried to run the analogous command in Ubuntu 12.04 (it works on Ubuntu 18.04):

编辑:我尝试在 Ubuntu 12.04 中运行类似的命令(它适用于 Ubuntu 18.04):

sudo -u postgres pg_dump my_database > my_database.sql

And in this case the file was saved in the current directory where I ran the command! So both cases can happen in Linux, depending of the specific dist you are working

在这种情况下,文件保存在我运行命令的当前目录中!因此,这两种情况都可能发生在 Linux 中,具体取决于您正在使用的特定发行版

回答by WelcomeTo

If you are not specifying fully qualified paths, like:

如果您没有指定完全限定的路径,例如:

pg_dump your_db_name > dbdump

pg_dump your_db_name > dbdump

then in Windowsit stores dumps in current user's home directory. I.e.:

然后在Windows 中,它将转储存储在当前用户的主目录中。IE:

C:\Users\username

C:\Users\username

回答by IvanM

In Linux default path is:

在 Linux 中默认路径是:

/var/lib/postgresql/

/var/lib/postgresql/

回答by faisal12

In pgadmin 4 for a Mac, assuming dump is successful you can click on "More Details" you will see a box that says "Running command:" in that box you will see /Applications/pgAdmin 4.app/Contents/SharedSupport/pg_dump --file "path/to/file" where path to file is the destination of storage.

在 Mac 的 pgadmin 4 中,假设转储成功,您可以单击“更多详细信息”,您将看到一个显示“运行命令:”的框,在该框中您将看到 /Applications/pgAdmin 4.app/Contents/SharedSupport/pg_dump --file "path/to/file" 其中文件的路径是存储的目的地。

回答by Shiju S S

In the server (Ubundu/Centos) the path of backup file will be /var/lib/pgadmin/storage/

在服务器(Ubundu/Centos)中备份文件的路径是 /var/lib/pgadmin/storage/