postgresql 通过 YUM 存储库作为默认守护程序用户安装时如何在 centos 上运行 postgres
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12940943/
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
How to run postgres on centos when installed via YUM repo as default daemon user
提问by AndrewPK
With a freshly installed version of Postgres 9.2 via yum repository on Centos 6, how do you run postgres as a different user when it is configured to run as 'postgres:postgres' (u:g) out of the box?
通过 Centos 6 上的 yum 存储库新安装的 Postgres 9.2 版本,当 postgres 配置为开箱即用的“postgres:postgres”(u:g)运行时,如何以不同的用户身份运行它?
采纳答案by AndrewPK
This is only for a fresh installation (as it pertained to my situation) as it involves blowing away the data dir.
这仅适用于全新安装(因为它与我的情况有关),因为它涉及清除数据目录。
The steps I took to resolve this issue while utilizing the packaged startup scripts for a fresh installation:
我在使用打包的启动脚本进行全新安装时解决此问题的步骤:
- Remove the postgres data dir
/var/lib/pgsql/9.2/data
if you've already gone through the initdb process with the postgres user:group configured as default. - Modify the startup script (
/etc/init.d/postgresql-9.2
) to replace all instances ofpostgres:postgres
withNEWUSER:NEWGROUP
. - Modify the startup script to replace all instances of
postgres
in any$SU -l postgres
lines with theNEWUSER
. - run
/etc/init.d/postgres initdb
to regenerate the cluster using the new username - Make sure any logs created are owned by the new user or remove old logs if error on initdb (the configuration file in my case was found in
/var/lib/pgsql/9.2/data/postgresql.conf
). - Startup postgres and it should now be running under the new user/group.
/var/lib/pgsql/9.2/data
如果您已经使用默认配置的 postgres user:group 完成了 initdb 进程,请删除 postgres 数据目录。- 修改启动脚本(
/etc/init.d/postgresql-9.2
),以取代的所有实例postgres:postgres
用NEWUSER:NEWGROUP
。 - 修改启动脚本以将
postgres
任何$SU -l postgres
行中的所有实例替换为NEWUSER
. - 运行
/etc/init.d/postgres initdb
以使用新用户名重新生成集群 - 确保创建的所有日志归新用户所有,或者如果 initdb 出错(我的配置文件在 中找到
/var/lib/pgsql/9.2/data/postgresql.conf
),则删除旧日志。 - 启动 postgres,它现在应该在新用户/组下运行。
I understand this might not be what other people are looking for if they have existing postgres db's and want to restart the server to run as a different user/group combo - this was not my case, and I didn't see an answer posted anywhere for a 'fresh' install utilizing the pre-packaged startup scripts.
我知道如果其他人拥有现有的 postgres db 并且想要重新启动服务器以作为不同的用户/组组合运行,这可能不是他们正在寻找的东西 - 这不是我的情况,我没有看到任何地方发布的答案使用预先打包的启动脚本进行“全新”安装。
回答by Craig Ringer
In addition to AndrewPK's explanation, I'd like to note that you can also start new PostgreSQL instances as any user by stopping and disabling the system Pg service, then using:
除了 AndrewPK 的解释之外,我还想指出,您还可以通过停止和禁用系统 Pg 服务来以任何用户身份启动新的 PostgreSQL 实例,然后使用:
initdb -D /path/to/data/directory
pg_ctl start -D /path/to/data/directory
This won't auto-start the server on boot, though. For that you must integrate into your init system. On CentOS 6 a simple System V-style init script in /etc/init.d/ and a suitable symlink into /etc/rc3.d/ or /etc/rc3.d/ (depending on default runlevel) is sufficient.
但是,这不会在启动时自动启动服务器。为此,您必须集成到您的 init 系统中。在 CentOS 6 上,/etc/init.d/ 中一个简单的 System V 风格的 init 脚本和一个合适的符号链接到 /etc/rc3.d/ 或 /etc/rc3.d/(取决于默认运行级别)就足够了。
If running more than one instance at a time they must be on different ports. Change the port
directive in postgresql.conf
in the datadir or set it on startup with pg_ctl -o "-p 5433" ...
. You may also need to override the unix_socket_directories
if your user doesn't have write permission to the default socket directory.
如果一次运行多个实例,它们必须位于不同的端口上。更改datadir 中的port
指令postgresql.conf
或在启动时使用pg_ctl -o "-p 5433" ...
. unix_socket_directories
如果您的用户没有对默认套接字目录的写权限,您可能还需要覆盖。