Skip to content

Postgres failed to start with custom PGDATA dir on redhat family #128

@shaunrampersad

Description

@shaunrampersad

I'm using a custom value for PGDATA. The rpm packages install but the service fails to start in systemd.

Setup:

OS : Centos 7
PG Version : Initially started with pg12 from software collections. Removed this to use the role default which is 9.2
Role version: 2.2.0

How to reproduce:

Run the role with postgresql_data_dir set to any directory. E.g: /opt/pgdata
The role will fail here.

    TASK [geerlingguy.postgresql : Ensure PostgreSQL is started and enabled on boot.] ***
    fatal: [postgresql]: FAILED! => {"changed": false, "msg": "Unable to start service postgresql: Job for postgresql.service failed because the control process exited with error code. See \"systemctl status postgresql.service\" and \"journalctl -xe\" for details.\n"}

The data dir contains an initialised DB.

[root@postgresql /]# ls /opt/pgdata/
base    pg_clog      pg_ident.conf  pg_notify  pg_snapshots  pg_subtrans  pg_twophase  pg_xlog
global  pg_hba.conf  pg_multixact   pg_serial  pg_stat_tmp   pg_tblspc    PG_VERSION   postgresql.conf

Expected outcome:

Postgres installed and db initialises in /opt/pgdata. Service managed by systemd.

Workaround:

create an override for systemd and add the PGDATA environment variable.

NB: This is a manual work around. Not ideal, but will get you running. you can then run ansible again.

[root@postgresql /]# systemctl edit postgresql.service

Add the following

[Service]
Environment="PGDATA=/opt/pgdata"

reload systemd and start

[root@postgresql /]# systemctl daemon-reload
[root@postgresql /]# systemctl start postgresql.service
[root@postgresql /]# systemctl status postgresql.service
● postgresql.service - PostgreSQL database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/postgresql.service.d
           └─override.conf
   Active: active (running) since Sat 2020-05-09 13:25:26 UTC; 7s ago

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions