Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centos 7 environment variables for Postgres service

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!

like image 423
Vitaly Stanchits Avatar asked Nov 10 '14 16:11

Vitaly Stanchits


1 Answers

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.

like image 128
mvermaes Avatar answered Sep 24 '22 10:09

mvermaes