Thread: pg_castalog.pg_tables does not show the real tablespace for tables

pg_castalog.pg_tables does not show the real tablespace for tables

From
"J. Carlos Muro"
Date:
Hi!
I have created a tablespace and a database in that tablespace:

create tablespace tb_user location '/data/tb_user';
create database mydatabase tablespace "tb_user";
\c mydatabase;
create table a_table (id bigint, name text);

I supposed that "a_table" should be in the tablespace "tb_user" as the database was created to use it by default. But I doesnt seem like that when i state the next:

mydatabase=# select tablename,tablespace from pg_catalog.pg_tables where tablename='a_table';
 tablename | tablespace
-----------+------------
 a_table   |

Why?
I can imagine that the table was really created in tb_user tablespace, as i realize that there were created new files under the /data/tb_user directory.
The database seems to have been properly created for that tablespace:

    Name    |  Owner   | Encoding | Tablespace |        Description
------------+----------+----------+------------+---------------------------
 mydatabase | postgres | UTF8     | tb_user    |
 postgres   | postgres | UTF8     | pg_default |
 template0  | postgres | UTF8     | pg_default |
 template1  | postgres | UTF8     | pg_default | default template database

Is there a way to see where real tablespace for a given table?
Thanks in advance!!
J. Carlos Muro

Re: pg_castalog.pg_tables does not show the real tablespace for tables

From
Tom Lane
Date:
"J. Carlos Muro" <murojc@gmail.com> writes:
> I have created a tablespace and a database in that tablespace:

> create tablespace tb_user location '/data/tb_user';
> create database mydatabase tablespace "tb_user";
> \c mydatabase;
> create table a_table (id bigint, name text);

> I supposed that "a_table" should be in the tablespace "tb_user" as the
> database was created to use it by default. But I doesnt seem like that when
> i state the next:

The database's default tablespace is never named explicitly in pg_tables
nor in the underlying pg_class catalog.  This is intentional to make it
easier to move a database to a different default tablespace.

            regards, tom lane