不允许“root”执行 PostgreSQL 服务器

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

"root" execution of the PostgreSQL server is not permitted

postgresqlsudoprivileges

提问by chopper draw lion4

When I try to start postgresql I get an error:

当我尝试启动 postgresql 时,出现错误:

postgres

postgres does not know where to find the server configuration file.
You must specify the --config-file or -D invocation option or set the PGDATA environment variable.

postgres 不知道在哪里可以找到服务器配置文件。
您必须指定 --config-file 或 -D 调用选项或设置 PGDATA 环境变量。

So then I try to set my config file:

那么我尝试设置我的配置文件:

postgres -D /usr/local/var/postgres

And I get the following error:

我收到以下错误:

postgres cannot access the server configuration file "/usr/local/var/postgres/postgresql.conf": Permission denied

postgres 无法访问服务器配置文件“/usr/local/var/postgres/postgresql.conf”:权限被拒绝

Hmm okay. Next, I try to perform that same action as an admin:

嗯好吧。接下来,我尝试以管理员身份执行相同的操作:

 sudo postgres -D /usr/local/var/postgres

And I receive the following error:

我收到以下错误:

"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent possible system security compromise. See the documentation for more information on how to properly start the server.

不允许 PostgreSQL 服务器的“root”执行。
服务器必须在非特权用户 ID 下启动,以防止可能的系统安全危害。有关如何正确启动服务器的更多信息,请参阅文档。

I googled around for that error message but cannot find a solution.
Can anyone provide some insight into this?

我搜索了该错误消息,但找不到解决方案。
任何人都可以对此提供一些见解吗?

回答by Muthukumar

For those trying to run custom command using the official docker image, use the following command. docker-entrypoint.shhandles switching the user and handling other permissions.

对于那些尝试使用官方 docker 镜像运行自定义命令的人,请使用以下命令。docker-entrypoint.sh处理切换用户和处理其他权限。

docker-entrypoint.sh -c 'shared_buffers=256MB' -c 'max_connections=200'

回答by Erwin Brandstetter

Your command does not do what you think it does. To run something as system userpostgres:

您的命令不会执行您认为的操作。以系统用户身份运行postgres

 sudo -u postgres command

To run the command(also named postgres!):

要运行命令(也称为postgres!):

sudo -u postgres postgres -D /usr/local/var/postgres

Your command does the opposite:

你的命令正好相反:

sudo postgres -D /usr/local/var/postgres

It runs the program postgresas the superuser root(sudowithout -uswitch), and Postgres does not allow to be run with superuser privileges for security reasons. Hence the error message.

postgres以超级用户身份运行程序rootsudo不带-u开关),出于安全原因,Postgres 不允许以超级用户权限运行。因此出现错误消息。

If you are going to run a couple of commands as system user postgres, change the user with:

如果您打算以 system user 身份运行几个命令,请使用以下命令postgres更改用户:

sudo -u postgres -i

... and exitwhen you are done.

......exit当你完成时。

If you see this error message while operating as system user postgres, then something is wrong with permissions on the file or one of the containing directories.

如果您在以 system user 身份操作时看到此错误消息postgres,则说明文件或包含目录之一的权限有问题。

postgres cannot access the server configuration file "/usr/local/var/postgres/postgresql.conf": Permission denied /usr/local/var/postgres/postgresql.conf

postgres 无法访问服务器配置文件“/usr/local/var/postgres/postgresql.conf”:权限被拒绝 /usr/local/var/postgres/postgresql.conf

In closing:

最后: