如何访问 PostgreSQL pg_log 文件夹而不是 postgres 用户并遇到权限问题?

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

How to access PostgreSQL pg_log folder without being the postgres user and running into permission issues?

macospostgresql

提问by ams

On my mac os x development machine, I have postgres 9.1 installed to /Library/PostgreSQL/9.1and the data directory for PostgreSQL is in /Library/PostgreSQL/9.1/dataI have configured logging so I get good logs out of postgres about what sql queries are executing on the server .... etc such that these are written to /Library/PostgreSQL/9.1/data/pg_logI am using the enterprise db pre packaged postgres binary.

在我的 mac os x 开发机器上,我安装了 postgres 9.1/Library/PostgreSQL/9.1并且 PostgreSQL 的数据目录在/Library/PostgreSQL/9.1/data我已经配置了日志记录,所以我从 postgres 中获得了关于服务器上正在执行的 sql 查询的良好日志......等等这些是写给/Library/PostgreSQL/9.1/data/pg_log我使用企业数据库预打包的 postgres 二进制文件的。

The problem is that $PGDATA is owned by the postgres user which is running the postgres processes. When I changed the permissions on the data directory with chmod o+xr datapostgres refused to start and tells me that it can not start with the postgres directory having permissions to anything but the postgres user.

问题是 $PGDATA 归运行 postgres 进程的 postgres 用户所有。当我更改数据目录的权限时,chmod o+xr datapostgres 拒绝启动并告诉我它不能从 postgres 目录开始,该目录对 postgres 用户以外的任何人都具有权限。

FATAL:  data directory "/Library/PostgreSQL/9.1/data" has group or world access
DETAIL:  Permissions should be u=rwx (0700)

Having to sudo in and out of the postgres dir just to get at the log files is annoying.

为了获取日志文件而不得不在 postgres 目录中进出 sudo 很烦人。

What is a good way to configure postgres logging on Mac OS X so that it is easy to access the log files from any user that is logged in, rather than having to use sudo or be the postgres user?

在 Mac OS X 上配置 postgres 日志记录的好方法是什么,以便可以轻松地从任何登录用户访问日志文件,而不必使用 sudo 或成为 postgres 用户?

UPDATESee my answer below, for the exact recipe I used to make it work.

更新请参阅下面的答案,了解我用来使其工作的确切配方。

回答by Chris Travers

The simple fact is that PostgreSQL won't let you do this. However, there is a better solution, which is to make sure the following are set in the postgresql.conf:

一个简单的事实是 PostgreSQL 不会让你这样做。但是,有一个更好的解决方案,那就是确保在 postgresql.conf 中设置以下内容:

This one is the default. If it is commented out and not otherwise set, that's ok:

这是默认设置。如果它被注释掉并且没有另外设置,那没关系:

log_destination = 'stderr' 

This needs to be set on:

这需要设置为:

logging_collector = on  

You can then point this somewhere else:

然后您可以将其指向其他地方:

log_directory = 'pg_log'  

You could point this somewhere you can access it. For example, give postgres appropriate access and point to:

你可以把它指向你可以访问的地方。例如,为 postgres 提供适当的访问权限并指向:

log_directory = '/var/log/postgresql'

Then as long as it isn't in the data directory you can set whatever permissions you want.

然后只要它不在数据目录中,您就可以设置您想要的任何权限。

回答by ams

Steps I used to make it work.

我用来使它工作的步骤。

  • Create a directory /var/pg_logand make it world readable and writable chmod o+wxr
  • Set the following values in postgresql.conf file

    log_directory = '/var/pg_log'

    log_file_mode = 0506

  • restart postgres

  • /var/pg_logshould have postgres .log files that you can monitor with the mac os x, console utility. no sudo required to see what is going on in there.
  • 创建一个目录/var/pg_log并使其世界可读和可写chmod o+wxr
  • 在 postgresql.conf 文件中设置以下值

    log_directory = '/var/pg_log'

    log_file_mode = 0506

  • 重启 postgres

  • /var/pg_log应该有 postgres .log 文件,您可以使用 mac os x 控制台实用程序监视这些文件。不需要 sudo 来查看那里发生了什么。

Note Postgres refused to allow any permission above 511 on the log file.

注意 Postgres 拒绝在日志文件上允许超过 511 的任何权限。