postgresql Postgres 数据库文件在 ubuntu 中保存在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3467167/
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-20 00:15:17  来源:igfitidea点击:

Where Postgres database files are saved in ubuntu?

postgresqlubuntu

提问by Mithun Sreedharan

How can I find where Postgres 8.x database files are saved in Ubuntu 10.04 file system?

如何在 Ubuntu 10.04 文件系统中找到 Postgres 8.x 数据库文件的保存位置?

回答by Frank Heikens

In the postgres prompt, just execute this query:

在 postgres 提示中,只需执行以下查询:

SHOW data_directory;

Check also the Ubuntu manual: https://help.ubuntu.com/10.04/serverguide/C/postgresql.html

另请查看 Ubuntu 手册:https: //help.ubuntu.com/10.04/serverguide/C/postgresql.html

回答by Promise Preston

Here's how I located the directory of my Postgres database files in Ubuntu:

以下是我在 Ubuntu 中定位 Postgres 数据库文件目录的方法:

Run the command below in your terminal to switch user to postgresuser:

在终端中运行以下命令以将用户切换为postgres用户:

su - postgres

It will request for the postgresuser passwordwhich you set up when you were setting up PostgreSQL on your machine.

它会要求您输入您在机器上设置 PostgreSQL 时设置的postgres用户密码

Next, you will need to login into the psqlterminal/prompt. This can be accomplished by running the code below:

接下来,您需要登录psql终端/提示。这可以通过运行以下代码来完成:

psql

It will also request for the postgrespasswordwhich you set up when you were setting up PostgreSQL on your machine.

它还会请求您在机器上设置 PostgreSQL 时设置的postgres密码

If you are successfully logged in, you will see a prompt similar to this:

如果登录成功,会看到类似这样的提示:

psql (11.5 (Ubuntu 11.5-3.pgdg18.04+1), server 10.10 (Ubuntu 10.10-1.pgdg18.04+1))
Type "help" for help.

postgres=#

At this point you will execute the query below to display the directory where Postgres Database files are stored on your Linux macchine:

此时,您将执行以下查询以显示 Linux 机器上存储 Postgres 数据库文件的目录:

SHOW data_directory;

This should display an output similar to this:

这应该显示与此类似的输出:

data_directory        
-----------------------------
/var/lib/postgresql/10/main
(1 row)

You can now locate the Postgres Database files by navigating the directory that was displayed.

您现在可以通过导航显示的目录来定位 Postgres 数据库文件。

However, the PostgreSQL configuration directory in Ubuntu is located in /etc/postgresql/10/main. Take note that 10is the version of my PostgreSQL installation on my server. Your version might be 9.5, 11or 12or any other version. Run the command psql --versionto confirm your PostgreSQL version.

但是,Ubuntu 中的 PostgreSQL 配置目录位于/etc/postgresql/10/main. 请注意,这10是我在服务器上安装的 PostgreSQL 版本。您的版本可能是9.51112或任何其他版本。运行命令psql --version以确认您的 PostgreSQL 版本。

Run the command below to navigate to the directory:

运行以下命令以导航到目录:

cd ~
cd /etc/postgresql/10/main

That's all.

就这样。

I hope this helps

我希望这有帮助