HiveBrain v1.2.0
Get Started
← Back to all entries
debugsqlMinor

Tablespace symlink error after changing data_directory location in PSQL 9.4

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
aftererrortablespacepsqldata_directorychangingsymlinklocation

Problem

Problem: After changing the 'data_directory' location in PSQL 9.4 (Windows Server 2012 R2) an error is thrown to the user when: (a) trying to connect to the PSQL server using PgAdmin or (b) when trying to list the tablespaces \db using the SQL Shell. In both cases the error is the following:


ERROR: could not read symbolic link "pg_tblspc/53605151": Invalid Argument.

Although the error message persists even after restarting the PSQL server it does not seem to affect the users' ability to ETL using the database.

Background: I followed the instructions suggested at the following link https://stackoverflow.com/questions/22596301/how-to-change-postgresql-data-directory to change the 'data_directory'.

Actions taken: I tried to remove the symbolic link using the following command using my system administrator account.:

rmdir ...\pg_tblspc\53605151


After the symlink is removed the error thrown changes slightly to the following:


ERROR: could not read symbolic link "pg_tblspc/53605151": No such file or directory

Any insights would be more than welcome on how to fix this.

Solution

Postgres tablespaces are a symbolic link in the pg_tblspc directory. That link must point to a valid place for the tablespace files.

Please, make a link again, pointing to the right place.

You can see the tablespaces locations on psql client with the \db command or running the query bellow:

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;


See the documentation for more details.

Code Snippets

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;

Context

StackExchange Database Administrators Q#145519, answer score: 4

Revisions (0)

No revisions yet.