postgresql Postgres 服务的 Centos 7 环境变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26848495/
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
Centos 7 environment variables for Postgres service
提问by Vitaly Stanchits
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.
最近我遇到了使用自定义 PGDATA 路径启动 postgresql 服务的问题。它试图查看未初始化的默认数据目录 (/var/lib/pgsql/9.3/data/),因此触发了这些错误。问题似乎是 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!
先感谢您!
采纳答案by Vitaly Stanchits
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
从 /usr/lib/systemd/system/postgresql-9.3.service 复制的内容和 PGDATA 变量已更改。然后
systemctl daemon-reload
And then I started the service normally and it worked fine. The trick was making changes to this service configuration file.
然后我正常启动了服务,它运行良好。诀窍是更改此服务配置文件。
回答by mvermaes
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.serviceback to your local copy.
这消除了将/usr/lib/systemd/system/postgresql-9.3.service 中的更改重新集成到本地副本的需要。