Обсуждение: 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.
Hi Evan, On Mon, Jul 23, 2018 at 10:19:31AM -0700, Evan Rempel wrote: > [...] > Am I missing something, or is the configuration of the systemd unit file an oversight? That's not really a question related to PostgreSQL, but to systemd, and how to "override" (parts of) your systems' unit files. Since you appear to be on EL7, you best check out the docs your distro provides on the matter: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/sect-managing_services_with_systemd-unit_files#sect-Managing_Services_with_systemd-Unit_File_Modify (Spoiler alert: All systemd-using distros are pretty much the same in these regards, which is one of the benefits of converging towards this service manager in the GNU/Linux ecosystem.) Hth. -- with best regards: - Johannes Truschnigg ( johannes@truschnigg.info ) www: https://johannes.truschnigg.info/ phone: +43 650 2 133337 xmpp: johannes@truschnigg.info Please do not bother me with HTML-email or attachments. Thank you.
Вложения
Except that the systemd file comes from the postgresql10-server RPM produced by the PostgreSQL community. I was trying to figure out how the PostgreSQL systemd service file authors intended users to configure a different data directory than the default. On 07/23/2018 10:26 AM, Johannes Truschnigg wrote: > Hi Evan, > > On Mon, Jul 23, 2018 at 10:19:31AM -0700, Evan Rempel wrote: >> [...] >> Am I missing something, or is the configuration of the systemd unit file an oversight? > That's not really a question related to PostgreSQL, but to systemd, and how to > "override" (parts of) your systems' unit files. > > Since you appear to be on EL7, you best check out the docs your distro > provides on the matter: > > https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/sect-managing_services_with_systemd-unit_files#sect-Managing_Services_with_systemd-Unit_File_Modify > > (Spoiler alert: All systemd-using distros are pretty much the same in these > regards, which is one of the benefits of converging towards this service > manager in the GNU/Linux ecosystem.) > > Hth. > -- Evan Rempel erempel@uvic.ca Senior Systems Administrator 250.721.7691 Data Centre Services, University Systems, University of Victoria
Sorry for the quick reply (without reading it completely). The document you refer to does address by question on how to augment/extend the configuration of the system unit file. Thanks, On 07/23/2018 10:29 AM, Evan Rempel wrote: > Except that the systemd file comes from the postgresql10-server RPM produced by the PostgreSQL community. > > I was trying to figure out how the PostgreSQL systemd service file authors intended users to configure a different > data directory than the default. > > On 07/23/2018 10:26 AM, Johannes Truschnigg wrote: >> Hi Evan, >> >> On Mon, Jul 23, 2018 at 10:19:31AM -0700, Evan Rempel wrote: >>> [...] >>> Am I missing something, or is the configuration of the systemd unit file an oversight? >> That's not really a question related to PostgreSQL, but to systemd, and how to >> "override" (parts of) your systems' unit files. >> >> Since you appear to be on EL7, you best check out the docs your distro >> provides on the matter: >> >> https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/sect-managing_services_with_systemd-unit_files#sect-Managing_Services_with_systemd-Unit_File_Modify >> >> (Spoiler alert: All systemd-using distros are pretty much the same in these >> regards, which is one of the benefits of converging towards this service >> manager in the GNU/Linux ecosystem.) >> >> Hth. >> > -- Evan
Hi Evan, On Mon, Jul 23, 2018 at 10:29:52AM -0700, Evan Rempel wrote: > Except that the systemd file comes from the postgresql10-server RPM produced by the PostgreSQL community. The origin of your unit file doesn't matter to systemd on your EL7 host. You can run # systemctl edit <yourunitfilename> and (recent releases of) systemd will drop you into your $EDITOR in an appropriately created drop-in unit extension file, or you can run # mkdir /etc/systemd/system/<yourunitfilename>.service.d/ # $EDITOR /etc/systemd/system/<yourunitfilename>.service.d/environment.conf and put your "Environment=PGDATA=/var/lib/pgsql/9.6/data/" stanza (take care to get the INI-style section right!) into the resulting editor buffer. Once you save that and `systemctl daemon-reload` your unit configuration, you can use # systemctl cat <yourunitfilename> to see what systemd makes of your changes, and then restart the service with the changes applied. The delta you introduced that way will survive package upgrades (but you'll have to re-apply these changes to postgres service units with new/different unit names, i. e. different major versions, in the same manner). -- with best regards: - Johannes Truschnigg ( johannes@truschnigg.info ) www: https://johannes.truschnigg.info/ phone: +43 650 2 133337 xmpp: johannes@truschnigg.info Please do not bother me with HTML-email or attachments. Thank you.
Вложения
Hi, Here is how I setup PGDATA in a non-default location on RHEL 7 for PostgreSQL 9.6, installed with postgres.org RPMs, leavingthe /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@uvic.ca] Sent: Monday, July 23, 2018 10:20 AM To: pgsql-admin@lists.postgresql.org 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 defaultof /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.