Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where in the DB is the Location of a postgres tablespace stored

I am using postgres 9.2 on redhat 6

this should be simple but I can't find it anywhere. I am looking for the database table and column which stores the Location for a postgres tablespace, I thought it would be in PG_TABLESPACE, but

select * from pg_tablespace

shows...

postgres=# select * from pg_tablespace;
     spcname     | spcowner | spcacl | spcoptions
-----------------+----------+--------+------------
 pg_default      |       10 |        |
 pg_global       |       10 |        |
 C_TBL_DB91SABIR |       10 |        |
(3 rows)

but no location, any ideas where the location is kept?

thanks

like image 964
davegreen100 Avatar asked Feb 05 '16 10:02

davegreen100


People also ask

Do we have tablespace in PostgreSQL?

PostgreSQL comes with two default tablespaces: pg_default tablespace stores user data. pg_global tablespace stores global data.

What is the tablespace in Postgres?

Tablespaces in PostgreSQL allow database administrators to define locations in the file system where the files representing database objects can be stored. Once created, a tablespace can be referred to by name when creating database objects.


2 Answers

Use pg_tablespace_location(tablespace_oid)(PostgreSQL 9.2+) to get the path in the file system where the tablespace is located.

You'll get oid of tablespace from pg_tablespace, so the query should be

select spcname
      ,pg_tablespace_location(oid) 
from   pg_tablespace;
like image 143
Vivek S. Avatar answered Nov 02 '22 18:11

Vivek S.


Another super easy command to list all table spaces

\db+

This will provide you all table space details very quick

like image 21
Jerry Avatar answered Nov 02 '22 19:11

Jerry