Postgresql 9.3 on Centos 7 with custom PGDATA

I am trying to configure a Postgresql 9.3 server on Centos 7 (installation via yum) inside a custom directory, which in my case is an encrypted partition (/ custom_container / database) that mounts at startup. For some reason, Postgresql does not behave as it should in the manual, and makes a mistake when starting the service.

Note. He doesn’t want to accept the PGDATA environment variable that I set, and at startup

su - postgres -c '/usr/pgsql-9.3/bin/initdb' 

(given that the PGDATA directory belongs to postgres: postgres), the cluster is initialized inside the default directory / var / lib / pgsql / 9.3 / data / The only way to change this is to use

 su - postgres -c '/usr/pgsql-9.3/bin/initdb --pgdata=$PGDATA' 

Initializes the directory inside the custom container that I use. This is something I could not understand, as the docs say that the PGDATA variable is taken by default.

Problem: at startup

 service postgresql-9.3 start 

I get an error with a log

 postgresql-9.3.service - PostgreSQL 9.3 database server Loaded: loaded (/usr/lib/systemd/system/postgresql-9.3.service; disabled) Active: failed (Result: exit-code) since Mon 2014-11-10 15:24:15 CET; 1s ago Process: 2785 ExecStartPre=/usr/pgsql-9.3/bin/postgresql93-check-db-dir ${PGDATA} (code=exited, status=1/FAILURE) Nov 10 15:24:15 CentOS-70-64-minimal systemd[1]: Starting PostgreSQL 9.3 database server... Nov 10 15:24:15 CentOS-70-64-minimal postgresql93-check-db-dir[2785]: "/var/lib/pgsql/9.3/data/" is missing or empty. Nov 10 15:24:15 CentOS-70-64-minimal postgresql93-check-db-dir[2785]: Use "/usr/pgsql-9.3/bin/postgresql93-setup initdb" to initialize t...ster. Nov 10 15:24:15 CentOS-70-64-minimal postgresql93-check-db-dir[2785]: See %{_pkgdocdir}/README.rpm-dist for more information. Nov 10 15:24:15 CentOS-70-64-minimal systemd[1]: postgresql-9.3.service: control process exited, code=exited status=1 Nov 10 15:24:15 CentOS-70-64-minimal systemd[1]: Failed to start PostgreSQL 9.3 database server. Nov 10 15:24:15 CentOS-70-64-minimal systemd[1]: Unit postgresql-9.3.service entered failed state. 

This means that Postgresql, even if the cluster is initialized in the new $ PGDATA directory (/ custom_container / database), is still looking for the cluster in / var / lib / pgsql / 9.3 / data /

Has anyone experienced this behavior of Postgresql before? Maybe I forgot some configuration options or the problem arose from the Postgresql installation?

Thank you in advance!

+6
source share
4 answers

It seems that the real problem was setting the environment variables that I worked in the following thread: Centos 7 environment variables for the Postgres service The problem is the PGDATA variable set inside the user / etc / systemd / system / postgresql -9.3.service that needs to be created from the contents of / usr / lib / systemd / system / postgresql -9.3.service, which uses the standard PGDATA var.

+4
source

try the following:

  ## Login with postgres user su - postgres export PGDATA=/your_path/data pg_ctl -D $PGDATA start & 
+3
source

I think for most "CentOS 7 way" this needs to copy the service file:

 sudo cp /usr/lib/systemd/system/postgresql-9.6.service /etc/systemd/system/postgresql-9.6.service 

Then edit the file / etc / systemd / system / postgresql -9.6.service:

 # Location of database directory Environment=PGDATA=/mnt/volume/var/lib/pgsql/9.6/data/ 

Then run it sudo systemctl start postgresql-9.6 and check:

 # sudo ps -ax | grep postmaster 32100 ? Ss 0:00 /usr/pgsql-9.6/bin/postmaster -D /mnt/volume/var/lib/pgsql/9.6/data/ 
+1
source

Try editing the file /etc/init.d/postgresql-9.3: PGDATA = / your / user / path

0
source

Source: https://habr.com/ru/post/977983/


All Articles