postgresql pg_dump的输出去哪里

时间:2022-06-01 12:55:53

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

我正在尝试备份postgresql的db,我想使用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

但我不知道输出文件的位置。任何帮助将不胜感激

3 个解决方案

#1


10  

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

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

Example

c:\Program files\postgresql\9.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.sql file

在上面的命令之后输入User“postgres”密码并检查D:\ drive for backup.sql文件

#2


2  

If you are not specifying fully qualified paths, like:

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

pg_dump your_db_name > dbdump

pg_dump your_db_name> dbdump

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

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

C:\Users\username

C:\ Users \用户名

#3


1  

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 dists,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:

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

find / -name 'my_database.sql'

EDIT: I tried to run the analogous command in Ubuntu 12.04:

编辑:我试图在Ubuntu 12.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中,具体取决于您正在使用的具体设备

#1


10  

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

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

Example

c:\Program files\postgresql\9.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.sql file

在上面的命令之后输入User“postgres”密码并检查D:\ drive for backup.sql文件

#2


2  

If you are not specifying fully qualified paths, like:

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

pg_dump your_db_name > dbdump

pg_dump your_db_name> dbdump

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

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

C:\Users\username

C:\ Users \用户名

#3


1  

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 dists,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:

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

find / -name 'my_database.sql'

EDIT: I tried to run the analogous command in Ubuntu 12.04:

编辑:我试图在Ubuntu 12.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中,具体取决于您正在使用的具体设备