简体   繁体   English

Postgres服务的Centos 7环境变量

[英]Centos 7 environment variables for Postgres service

Recently I had the problem of starting a postgresql service with custom PGDATA path. 最近我遇到了使用自定义PGDATA路径启动postgresql服务的问题。 It tried to look in the default data directory (/var/lib/pgsql/9.3/data/) which was not initialized and therefore triggered these errors. 它试图查看未初始化的默认数据目录(/var/lib/pgsql/9.3/data/),因此触发了这些错误。 It appears the problem is that the service starter on Centos 7 strips all the environment variables, including PGDATA. 似乎问题是Centos 7上的服务启动器剥离了所有环境变量,包括PGDATA。

Interesting thread on the issue 关于这个问题的有趣线索

Is there a way to configure 有没有办法配置

service postgresql-9.3 start

to use custom environment variables? 使用自定义环境变量? Are there configuration files for services where these variables have to be defined? 是否有必须定义这些变量的服务的配置文件?

Thank you in advance! 先感谢您!

Thanks for the above answer, we just ran into this change today. 感谢上面的回答,我们今天刚刚遇到了这个变化。 You can also keep the default settings and only override the PGDATA variable by putting the following in /etc/systemd/system/postgresql-9.3.service : 您还可以保留默认设置,并通过将以下内容放在/etc/systemd/system/postgresql-9.3.service中来覆盖PGDATA变量:

# Include the default config:
.include /lib/systemd/system/postgresql-9.3.service

[Service]
Environment=PGDATA=<your path here>/pgsql/9.3/data

This removes the need to reintegrate changes in /usr/lib/systemd/system/postgresql-9.3.service back to your local copy. 这样就无需将/usr/lib/systemd/system/postgresql-9.3.service中的更改重新集成回本地副本。

OK, I got a solution that worked for me. 好的,我得到了一个适合我的解决方案。

nano /etc/systemd/system/postgresql-9.3.service 

with the contents copied over from /usr/lib/systemd/system/postgresql-9.3.service and PGDATA variable changed. 从/usr/lib/systemd/system/postgresql-9.3.service和PGDATA变量复制的内容已更改。 Then 然后

systemctl daemon-reload

And then I started the service normally and it worked fine. 然后我正常启动服务,它工作正常。 The trick was making changes to this service configuration file. 诀窍是更改此服务配置文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM