dbTalk Databases Forums  

how knowing on which tablespace is located a table ?

comp.databases.postgresql comp.databases.postgresql


Discuss how knowing on which tablespace is located a table ? in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Patrox
 
Posts: n/a

Default how knowing on which tablespace is located a table ? - 09-12-2007 , 02:43 AM






hi !
I would like to know how can I know on which tablespace belong a table ?
In "information_schema.tables", nothing about a table's tablespace ...
any idea ?
thx !
P.

Reply With Quote
  #2  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: how knowing on which tablespace is located a table ? - 09-12-2007 , 03:23 AM






Patrox <nospam (AT) nospammmmmmm (DOT) org> wrote:
Quote:
I would like to know how can I know on which tablespace belong a table ?
In "information_schema.tables", nothing about a table's tablespace ...
You'll have to query the catalogs for that, something like:

SELECT COALESCE(tbs.spcname, '*default tablespace*') AS tbsname
FROM pg_catalog.pg_class AS t
JOIN pg_catalog.pg_namespace AS s
ON (s.oid = t.relnamespace)
LEFT OUTER JOIN pg_catalog.pg_tablespace AS tbs
ON (tbs.oid = t.reltablespace)
WHERE t.relname = 'tablename' AND s.nspname = 'schemaname';

Yours,
Laurenz Albe


Reply With Quote
  #3  
Old   
Patrox
 
Posts: n/a

Default Re: how knowing on which tablespace is located a table ? - 09-12-2007 , 04:44 AM



thx a lot Laurenz but something must be missing somewhere as it
retrieves no rows so far :

tbsname
---------
(0 rows)

by the way I found "pg_tables" which tells amongst other things on which
tablespace is located a table; therefore it suits my needs.

Nevertheless as I'm busy discevering Postgres I'm interested to know a
bit more about what you used : pg_class, pg_namespace, pg_tablespace

Laurenz Albe a écrit :
Quote:
Patrox <nospam (AT) nospammmmmmm (DOT) org> wrote:
I would like to know how can I know on which tablespace belong a table ?
In "information_schema.tables", nothing about a table's tablespace ...

You'll have to query the catalogs for that, something like:

SELECT COALESCE(tbs.spcname, '*default tablespace*') AS tbsname
FROM pg_catalog.pg_class AS t
JOIN pg_catalog.pg_namespace AS s
ON (s.oid = t.relnamespace)
LEFT OUTER JOIN pg_catalog.pg_tablespace AS tbs
ON (tbs.oid = t.reltablespace)
WHERE t.relname = 'tablename' AND s.nspname = 'schemaname';

Yours,
Laurenz Albe

Reply With Quote
  #4  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: how knowing on which tablespace is located a table ? - 09-12-2007 , 05:41 AM



Please don't top-post!

Patrox <nospam (AT) nospammmmmmm (DOT) org> wrote:
Quote:
I would like to know how can I know on which tablespace belong a table ?
In "information_schema.tables", nothing about a table's tablespace ...

You'll have to query the catalogs for that, something like:

SELECT COALESCE(tbs.spcname, '*default tablespace*') AS tbsname
FROM pg_catalog.pg_class AS t
JOIN pg_catalog.pg_namespace AS s
ON (s.oid = t.relnamespace)
LEFT OUTER JOIN pg_catalog.pg_tablespace AS tbs
ON (tbs.oid = t.reltablespace)
WHERE t.relname = 'tablename' AND s.nspname = 'schemaname';

thx a lot Laurenz but something must be missing somewhere as it
retrieves no rows so far :

tbsname
---------
(0 rows)
Maybe your table is not called 'tablename' or does not live in schema
'schemaname'?

Maybe you don't run 8.2? You never said which version you use.

Quote:
by the way I found "pg_tables" which tells amongst other things on which
tablespace is located a table; therefore it suits my needs.
I didn't know pg_tables. A useful view!

Quote:
Nevertheless as I'm busy discevering Postgres I'm interested to know a
bit more about what you used : pg_class, pg_namespace, pg_tablespace
That can be easily done:

http://www.postgresql.org/docs/curre.../catalogs.html

Yours,
Laurenz Albe


Reply With Quote
  #5  
Old   
Patrox
 
Posts: n/a

Default Re: how knowing on which tablespace is located a table ? - 09-13-2007 , 03:48 AM



Laurenz Albe a écrit :
Quote:
Please don't top-post!

Patrox <nospam (AT) nospammmmmmm (DOT) org> wrote:
I would like to know how can I know on which tablespace belong a table ?
In "information_schema.tables", nothing about a table's tablespace ...
You'll have to query the catalogs for that, something like:

SELECT COALESCE(tbs.spcname, '*default tablespace*') AS tbsname
FROM pg_catalog.pg_class AS t
JOIN pg_catalog.pg_namespace AS s
ON (s.oid = t.relnamespace)
LEFT OUTER JOIN pg_catalog.pg_tablespace AS tbs
ON (tbs.oid = t.reltablespace)
WHERE t.relname = 'tablename' AND s.nspname = 'schemaname';
thx a lot Laurenz but something must be missing somewhere as it
retrieves no rows so far :

tbsname
---------
(0 rows)

Maybe your table is not called 'tablename' or does not live in schema
'schemaname'?
.... silly of me, ur right ... ;-)

Quote:
Maybe you don't run 8.2? You never said which version you use.

by the way I found "pg_tables" which tells amongst other things on which
tablespace is located a table; therefore it suits my needs.

I didn't know pg_tables. A useful view!

Nevertheless as I'm busy discevering Postgres I'm interested to know a
bit more about what you used : pg_class, pg_namespace, pg_tablespace

That can be easily done:

http://www.postgresql.org/docs/curre.../catalogs.html
great ! thx !

Quote:
Yours,
Laurenz Albe

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.