You need to update all packages, with this big update you don’t have the choice to delay the update of postgresql packages. After the complete update, upgrade the database, via the normal steps.
The > at the end of this line suggests it has been truncated. I would expect postgresql-check-db-dir to report why it failed. Can you re-run systemctl status postgresql.service but in a wider terminal window?
In the postgresql.service file it sets PGROOT before running the DB check - you might want to check it is set to /mnt/Daten/Technik/PostgreSQL.
Well i can’t figure out how the data should have been migrated since there seems to be only the dumping part. Anyway, i have a somewhat similar setup and did it like so
# su postgres
[postgres]$ cd /home/postgres
[postgres]$ mv data olddata
[postgres]$ mkdir data
[postgres]$ mkdir tmp
[postgres]$ cd tmp
[postgres]$ initdb -D /home/postgres/data
[postgres]$ pg_upgrade -b /opt/pgsql-PG_VERSION/bin -B /usr/bin -d /home/postgres/olddata -D /home/postgres/data
The differences are creating a temporary working directory and using the single pg_upgrade command (which is said to be the recommended way - notice PG_VERSION stands for the old version). Notice also that as of version 18 the check sums are turned on by default. Unless you had them turned on for the old 17 version already you need the extra step of turning check sums off temporarily for the migration. Notice also that i didn’t turn on the service. This comes only after the pg_upgrade but you tried a different path - but if you dump that is export where is the import?
The postgresql.service file on my system is located here: /usr/lib/systemd/system/postgresql.service. Yours may be at a different location. In my file I see this line (it is just a text file so you can use whatever you want to view it):
Environment=PGROOT=/var/lib/postgres
And it is important it is correct for you database. My database files were initialised with initdb -D /var/lib/postgres/data - note PGDATA does not have the data part.
The postgresql-check-db-dir script (in my system) checks the contents of the PG_VERSION file; for instance on my system that file says 18 (I used sudo because only the postgres users has access - I could have switched user but just used sudo)
~ > sudo cat /var/lib/postgres/data/PG_VERSION
18
Somewhere there is a mismatch on your system - either the check is using the wrong directory, or the initdb used another version, or something else.
Edited to add:
We know there is a mismatch because the status included this:
Dez 16 15:09:10 XYZ postgres[944]: An old version of the database format was found.
The postgresql.service file on my system is located here: /usr/lib/systemd/system/postgresql.service. Yours may be at a different location. In my file I see this line (it is just a text file so you can use whatever you want to view it):
Mine /usr/lib/systemd/system/postgresql.service is the same:
Without knowing the history of you installation I can’t say why.
I can say that you need to make things consistent. You used initdb to set the data directory to /mnt/Daten/Technik/PostgreSQL/data, and that path seemed to be what was being used before. This assumes that this command did actually dump your data:
pg_dumpall -h /tmp -f /tmp/old_backup.sql
I see the destination of your data was set to /tmp/old_backup.sql, and /tmp is generally completely cleared when you re-boot.
I would first check that the dumped data exists and looks right; pg_dumpall dumps the data as a text file so I would check the file looks like it contains you data. If not, I would re-do those steps to ensure you have a valid dump, and I would personally not put it in /tmp in case you need to re-boot at some point.
Once you are sure your data is safe, I would make a backup copy of postgresql.service and then edit the original to have something like this:
Environment=PGROOT=/mnt/Daten/Technik/PostgreSQL
I would then re-start the service and if the status says it is running, you can continue to the next step to import your data.
Secondly, I don’t think you need to clear /mnt/Daten/Technik/PostgreSQL/data - it was initialised by the initdb.
Thirdly, I don’t know what settings you have to restore - depends on what you might have changed. But, yes restore any custom settings before the import of data, I guess.
Fourthly, if the service is running then you can import the data with psql with the name of the file you dumped it to, something like this: