pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Daulat Ram <Daulat.Ram@exponential.com>
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: how to find a tablespace for the table?
Date: Sat, 22 Feb 2020 10:45:39 -0800
Message-ID: <4dc3920a-264c-a33d-15a4-dba5ad60b98a@aklaver.com> (raw)
In-Reply-To: <MN2PR01MB585454502962534049DD06C89BEE0@MN2PR01MB5854.prod.exchangelabs.com>
References: <MN2PR01MB585454502962534049DD06C89BEE0@MN2PR01MB5854.prod.exchangelabs.com>

On 2/22/20 10:34 AM, Daulat Ram wrote:
> Hi team,
> 
> how to find a tablespace for the table?
> 
> See my comments below:
> 
> I have created a database with default tablespace like below:
> 
> edb=# CREATE DATABASE conndb WITH TABLESPACE = conn_s_tables;
> 
> After that I have created a table
> 
> CREATE TABLE COMPANY_new(
> 
>     ID INT PRIMARY KEY     NOT NULL,
> 
>     NAME           TEXT    NOT NULL,
> 
>     AGE            INT     NOT NULL,
> 
>     ADDRESS        CHAR(50),
> 
>     SALARY         REAL,
> 
>     JOIN_DATE        DATE
> 
> ) ,
> 
> CREATE TABLE COMPANY_new(
> 
>     ID INT PRIMARY KEY     NOT NULL,
> 
>     NAME           TEXT    NOT NULL,
> 
>     AGE            INT     NOT NULL,
> 
>     ADDRESS        CHAR(50),
> 
>     SALARY         REAL,
> 
>     JOIN_DATE        DATE
> 
> )
> 
> tablespace conn_s_tables ;
> 
> But I am unable to search the tablespace name where tablespace exist , 
> tablespace column is blank.

https://www.postgresql.org/docs/12/view-pg-tables.html

tablespace 	name 	pg_tablespace.spcname 	Name of tablespace containing 
table (null if default for database)

https://www.postgresql.org/docs/12/sql-createdatabase.html

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.

So conn_s_tables is default for conndb, therefore it will not show up in 
queries below.


If you want to find the default tablespace:

https://www.postgresql.org/docs/12/catalog-pg-database.html

dattablespace 	oid 	pg_tablespace.oid 	The default tablespace for the 
database. Within this database, all tables for which 
pg_class.reltablespace is zero will be stored in this tablespace; in 
particular, all the non-shared system catalogs will be there.

> 
> conndb=# select schemaname,tablename,tableowner,tablespace from 
> pg_tables where tablename='company';
> 
> schemaname | tablename |  tableowner  | tablespace
> 
> ------------+-----------+--------------+------------
> 
> conndb     | company   | enterprisedb |
> 
> (1 row)
> 
> conndb=# select schemaname,tablename,tableowner,tablespace from 
> pg_tables where tablename='company_new';
> 
> schemaname |  tablename  |  tableowner  | tablespace
> 
> ------------+-------------+--------------+------------
> 
> conndb     | company_new | enterprisedb |
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (16+ messages)

Message-ID: <4dc3920a-264c-a33d-15a4-dba5ad60b98a@aklaver.com>
Permalink:  ../4dc3920a-264c-a33d-15a4-dba5ad60b98a@aklaver.com/
Also on:    postgresql.org/message-id/4dc3920a-264c-a33d-15a4-dba5ad60b98a@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, Daulat.Ram@exponential.com
  Subject: Re: how to find a tablespace for the table?
  In-Reply-To: <4dc3920a-264c-a33d-15a4-dba5ad60b98a@aklaver.com>
  References: <MN2PR01MB585454502962534049DD06C89BEE0@MN2PR01MB5854.prod.exchangelabs.com> <4dc3920a-264c-a33d-15a4-dba5ad60b98a@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox