Running a PostgreSQL-database in an user defined data directory /mnt/Daten/Technik//PostgreSQL, I experienced different issues over the time in regards to major updates for PostgreSQL and / or MANJARO-updates:
PostgreSQL 18 / Manjaro UPdate 2025-12-08
now seems to be mandatory, to have this declaration in /usr/lib/systemd/system/postgresql.service to Environment=PGROOT=/mnt/Daten/Technik/PostgreSQL
04.04.2023 AND 05.02.2025 Override-File
File etc/systemd/system/ [Service] Environment=PGROOT=/mnt/Daten/Technik/PostgreSQL
PostgreSQL 18 / Manjaro UPdate 2026-02-01
Manjaro UPdate broke this and I had again Environment=PGROOT=/var/lib/postgres
11.01.2021
File /var/lib/postgres having data_directory = '/mnt/Daten/Technik/PostgreSQL/data'
My questions:
Is this in relation running PostgreSQL as systemd-service (which would be my preferred option)? How to check this?
How to define the data directory to be update-proof?
Thank you @Phemisters. I’m sorry, but don’t understand
If I understand you correctly, part of your question was that a change to /usr/lib/systemd/system/postgresql.service was removed when you updated. And that you wanted to prevent that. A way to do that is to have a custom change which is not updated, which is what the linked doc was explaining.
So one approach (from the linked doc) would be to use this command:
sudo systemctl edit postgresql.service
This opens an editor, and you can add your custom line (read the notes in the opened file - lines with a # at the start are comments which do not affect anything but tell you what to do and show existing lines from the main service file):
Environment=PGROOT=/mnt/Daten/Technik/PostgreSQL
and then close the editor, to save the changes. This creates a custom file to override the old setting, and should be unaffected by any later updates.
By the way, I have never done this, but that’s what the docs say.
Everything in this file is commented. Firstly with a hash, and secondly on the wrong place. So you basically have an empty file now.
It should probably look like this
It should probably look like this
### Anything between here and the comment below will become the contents of the drop-in file COMM1
Environment=PGROOT=/mnt/Daten/Technik/PostgreSQL
### Edits below this comment will be discarded
I will apply this.But besides that, actually I have
/usr/lib/systemd/system/postgresql.service with
Environment=PGROOT=/mnt/Daten/Technik/PostgreSQL
would you agree that I DROP thhis line?
/var/lib/postgres/data/postgresql.conf with
data_directory = ‘/mnt/Daten/Technik/PostgreSQL/data’
I think the goal is to have your custom path in a custom systemd file, not in the installed /usr/lib/systemd/system/postgresql.service (to allow the installed one to change, if necessary, when you next update).
Using the suggested sudo systemctl edit postgresql.service command will result in a custom file, which is where you want your custom data path. At least, that is what I think is wanted.
The real problem is not having a custom data folder - but rather keeping PostgreSQL at a specific version.
When postgresql is updated from one major to the next, there is update procedures that must be run to ensure the database structure matches the new major version.
While I have little experience with PostgreSQL - I know that systemd overrides created to change the default behavior of a service will always survive an update - suffice your overrides are created in /etc/systemd/system and this is important - **never touch the files in /usr tree - your change will be overwritten with an update.
If you want to ensure a postgresql production database is never touched by an update, add postgresql to the list of IgnorePkg in the [options] section of /etc/pacman.conf.