Re: pg_tables bug?

From: Gaetano Mendola <mendola(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_tables bug?
Date: 2015-12-18 22:18:44
Message-ID: CAJycT5qhJUMi2ua47vyyUGpTRpdV-ERLQiUT_3MxxnDjkQK_zQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

From documentation about "CREATE DATABASE name WITH TABLESAPCE =
tablespace_name":

tablespace_name
The name of the tablespace that will be associated with the new database,
or DEFAULT to
use the template database's tablespace. This tablespace will be the default
tablespace used
for objects created in this database. See CREATE TABLESPACE for more
information.

I'm sure that my tables are created in the name space but those are not
reported either in
pg_tables, either in pg_dump or by \d.

Look as this:

kalman(at)kalman-VirtualBox:~$ mkdir tablespace_XXX
kalman(at)kalman-VirtualBox:~$ sudo chown postgres.postgres tablespace_XXX
kalman(at)kalman-VirtualBox:~$ psql template1
psql (9.4.5)
Type "help" for help.

template1=# create tablespace XXX LOCATION '/home/kalman/tablespace_XXX';
CREATE TABLESPACE
template1=# create database db_test with tablespace = XXX;
CREATE DATABASE
template1=# \q

kalman(at)kalman-VirtualBox:~$ psql db_test
psql (9.4.5)
Type "help" for help.

db_test=# create table t_test ( a integer, b numeric);
CREATE TABLE
db_test=# \d+ t_test
Table "public.t_test"
Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+-----------+---------+--------------+-------------
a | integer | | plain | |
b | numeric | | main | |

db_test=# select * from pg_tables where tablename = 't_test';
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules |
hastriggers
------------+-----------+------------+------------+------------+----------+-------------
public | t_test | kalman | | f | f |
f
(1 row)

db_test=# select oid from pg_database where datname = 'db_test';
oid
-------
80335

db_test=# select relfilenode from pg_class where relname = 't_test';
relfilenode
-------------
80336
(1 row)

Unfortunately contrary to what postgres is showing me the table test is in
/home/kalman/tablespace_XXXX:

root(at)kalman-VirtualBox:~# file
/home/kalman/tablespace_XXX/PG_9.4_201409291/80335/80336
/home/kalman/tablespace_XXX/PG_9.4_201409291/80335/80336: empty

as you can see the CREATE DATABASE documentation is honored but the system
is failing to give me the right tablespace location for that table.

Regards

On Thu, 17 Dec 2015 at 15:36 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Gaetano Mendola <mendola(at)gmail(dot)com> writes:
> > I'm playing around with tablespace (postgresq 9.4) and I found out what I
> > believe is a bug in pg_tables.
> > Basically if you create a database in a table space X and then you
> create a
> > table on the database the table is created correctly on the tablespace X
> (
> > I did a check on the filesystem) however if you do a select on pg_tables
> > the column tablespace for that table is empty and even worst if you dump
> > the DB there is no reporting about the the database or table being on
> that
> > tablespace.
> > Even \d doesn't report that the table is in the tablespace X.
>
> An empty entry in that column means that the table is in the default
> tablespace for the database. Which it sounds like is what you have
> here. I think it's operating as designed, though you might quibble
> with the decision that showing default tablespaces explicitly would
> have been clutter.
>
> regards, tom lane
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Gaetano Mendola 2015-12-18 22:55:26 Re: pg_tables bug?
Previous Message Fabien COELHO 2015-12-18 21:56:24 Re: extend pgbench expressions with functions