Problem
When migrating to PostgreSQL 15, an error occurs: the archive database location is incorrect:
ERROR: invalid tablespace location: /var/lib/postgresql/11/archive_2023 (name=archive_2023, owner=postgres)
Cause
The symlink to the archive databases was created according to outdated instructions and is located in the paths of the old cluster /var/lib/postgresql/11/.
Find out the location of the database:
Run SQL:
ibaytr sql
In the psql console, run the SQL query:
SELECT spcname AS "Name", pg_catalog.pg_get_userbyid(spcowner) AS "Owner", pg_catalog.pg_tablespace_location(oid) AS "Location" FROM pg_catalog.pg_tablespace ORDER BY 1;
Example output:
Name | Owner | Location --------------+----------+------------------------------------- archive_2023 | postgres | /var/lib/postgresql/11/archive_2023 pg_default | postgres | pg_global | postgres | (3 строки) ibatyrr=>The archive_2023 database is located in the old cluster /var/lib/postgresql/11/.
Solution
Recreate the symlink to the mounted volume.
Stop PostgreSQL:
sudo systemctl stop postgresql@11-main
Find out the name of the current symlink to the archive database, in our case archive_2023:
sudo ls -l /var/lib/postgresql/11/main/pg_tblspc total 0 lrwxrwxrwx 1 postgres postgres 35 июн 3 22:18 24939407 -> /var/lib/postgresql/11/archive_2023
Remove the symlink:
sudo rm /var/lib/postgresql/11/main/pg_tblspc/24939407
Check that everything has been deleted:
sudo ls -l /var/lib/postgresql/11/main/pg_tblspc
Create a new symlink:
sudo ln -sf /mnt/archive_2023/ /var/lib/postgresql/11/main/pg_tblspc/24939407
Make sure that the symlink is created and points to the desired directory:
sudo ls -l /var/lib/postgresql/11/main/pg_tblspc total 0 lrwxrwxrwx 1 root root 18 июл 1 18:41 24939407 -> /mnt/archive_2023/
Resume PostgreSQL:
sudo systemctl start postgresql@11-main
Log into the psql console again and check all tablespaces:
ibatyr sql ibatyr sql psql (11.20 (Ubuntu 11.20-1.pgdg18.04+1))
Get help:
helpExample output:
ibatyr=> SELECT spcname AS "Name", pg_catalog.pg_get_userbyid(spcowner) AS "Owner", pg_catalog.pg_tablespace_location(oid) AS "Location" FROM pg_catalog.pg_tablespace ORDER BY 1; Name | Owner | Location --------------+----------+-------------------- archive_2023 | postgres | /mnt/archive_2023/ pg_default | postgres | pg_global | postgres | (3 строки) ibatyr=>
Now the database is located in the correct directory - /mnt/archive_2023/.