1

I am using PostgreSQL for CentOS. And i changed the data directory to store PostgreSQL data on a different disk.

nano /usr/lib/systemd/system/postgresql.service

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

However, after installing the package update, the contents of the configuration file were changed back to the default settings.

Do I need to check the configuration file every time I install a package update later? Or is there a way to preserve the config file?

1

1 Answer 1

3

There are two ways to deal with this:

  1. the old way:

    You create a file /etc/systemd/system/postgresql.service that contains

     .include /usr/lib/systemd/system/postgresql.service
    
     [Service]
     Environment=PGDATA=/data/pgsql/data
    
  2. the new way:

    You create a directory /etc/systemd/system/postgresql.service.d that contains a file named (for example) pgdata.conf with the contents

     [Service]
     Environment=PGDATA=/data/pgsql/data
    

Then notify systemd with

systemctl daemon-reload

This configuration change will override the corresponding value from /usr/lib/systemd/system/postgresql.service, so the change will survive an upgrade.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.