Centos 7 environment variables for Postgres service

99封情书 提交于 2020-01-13 10:06:15

问题


Recently I had the problem of starting a postgresql service with custom PGDATA path. It tried to look in the default data directory (/var/lib/pgsql/9.3/data/) which was not initialized and therefore triggered these errors. It appears the problem is that the service starter on Centos 7 strips all the environment variables, including 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!


回答1:


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:

# 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.




回答2:


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. 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.



来源:https://stackoverflow.com/questions/26848495/centos-7-environment-variables-for-postgres-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!