RE: Moving the data directory for systemd service startup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, 
Here is how I setup PGDATA in a non-default location on RHEL 7 for PostgreSQL 9.6, installed with postgres.org RPMs, leaving the /usr/lib/systemd/system/postgresql-9.6.service file unchanged:

[root@pgs-p01 ~]# mkdir /data/postgres/pgdata
[root@pgs-p01 ~]# chown -R postgres:postgres /data/postgres

[postgres@pgs-p01 ~]$ pg_ctl  -D  /data/postgres/pgdata  initdb

[root@pgs-p01 ~]# vi /etc/systemd/system/postgresql-9.6.service
[root@pgs-p01 ~]# cat /etc/systemd/system/postgresql-9.6.service
.include /lib/systemd/system/postgresql-9.6.service

[Service]
Environment=PGDATA=/data/postgres/pgdata
[root@pgs-p01 ~]# systemctl daemon-reload
[root@pgs-p01 ~]# systemctl enable postgresql-9.6
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-9.6.service to /etc/systemd/system/postgresql-9.6.service.
[root@pgs-p01 ~]# systemctl start postgresql-9.6
[root@pgs-p01 ~]# systemctl status postgresql-9.6
â postgresql-9.6.service - PostgreSQL 9.6 database server
   Loaded: loaded (/etc/systemd/system/postgresql-9.6.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2018-04-04 13:29:26 PDT; 12s ago
     Docs: https://urldefense.proofpoint.com/v2/url?u=https-3A__www.postgresql.org_docs_9.6_static_&d=DwIGaQ&c=n6-cguzQvX_tUIrZOS_4Og&r=qmukiPJHYhgc3gzUy0nJGagHTl7faSE78XBWd5BdKPA&m=ir5ygAgBNo2KraRXN9JazrYzNEpYQ_9GBIkoZbKhkbM&s=ESUfZHAfPnY5S0O672sO_m1Jmjzaj5rxbeD8K5_Bpr4&e=
  Process: 23865 ExecStartPre=/usr/pgsql-9.6/bin/postgresql96-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 23871 (postmaster)
   CGroup: /system.slice/postgresql-9.6.service
           ââ23871 /usr/pgsql-9.6/bin/postmaster -D /data/postgres/pgdata
           ââ23873 postgres: logger process
           ââ23875 postgres: checkpointer process
           ââ23876 postgres: writer process
           ââ23877 postgres: wal writer process
           ââ23878 postgres: autovacuum launcher process
           ââ23879 postgres: stats collector process
Apr 04 13:29:26 pgs-p01.xxx.com systemd[1]: Starting PostgreSQL 9.6 database server...
Apr 04 13:29:26 pgs-p01.xxx.com postmaster[23871]: < 2018-04-04 13:29:26.297 PDT > LOG:  redirecting log output ...cess
Apr 04 13:29:26 pgs-p01.xxx.com postmaster[23871]: < 2018-04-04 13:29:26.297 PDT > HINT:  Future log output will...og".
Apr 04 13:29:26 pgs-p01.xxx.com systemd[1]: Started PostgreSQL 9.6 database server.
[root@pgs-p01 ~]#

[postgres@pgs-p01 ~]$ grep PGDATA= /usr/lib/systemd/system/postgresql-9.6.service
Environment=PGDATA=/var/lib/pgsql/9.6/data/
[postgres@pgs-p01 ~]$


-----Original Message-----
From: Evan Rempel [mailto:erempel@xxxxxxx] 
Sent: Monday, July 23, 2018 10:20 AM
To: pgsql-admin@xxxxxxxxxxxxxxxxxxxx
Subject: Moving the data directory for systemd service startup

I am using the official RPMs for RHEL-7 and am having difficulty in using a different database directory than the default of

/var/lib/pgsql/9.6/data/
or
/var/lib/pgsql/10/data/


It is easy to modify the service file

/usr/lib/systemd/system/postgresql-9.6.service

with the line

Environment=PGDATA=/var/lib/pgsql/9.6/data/

to point to the location I want, but an RPM update will replace this file and break database startup.

I was hoping that there would be a line

EnvironmentFile=-/etc/sysconfig/pgsql/postgresql-9.6

or

EnvironmentFile=-/etc/sysconfig/pgsql/postgresql-10

to allow for customization of the environment variables, similar to the init.d startup, but I don't see one.


Am I missing something, or is the configuration of the systemd unit file an oversight?

Any information would be helpful.

Evan.










[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux