`psql` command to view all existing tablespaces?
Asked Answered
S

4

10

What's the psql command to view all existing tablespaces?

\l+ displays all existing databases with their configured tablespace, but it won't display tablespaces which have been created but don't yet contain a database.

Sisal answered 14/2, 2020 at 12:28 Comment(4)
Tablespaces don't "contain databases". They contain tablesHydrastinine
Ah right, so when you CREATE DATABASE db1 TABLESPACE tp1;, the only purpose this serves is to configure the default tablespace for any table or index created in the database?Sisal
That's correct, yes.Hydrastinine
\? to get help for backslash commands.Gymnasiarch
H
8

As documented in the manual, the command to list tablespaces is \db

If you are looking for a command, just enter \? in the psql command line and it will show you all available commands including a short description.

Hydrastinine answered 14/2, 2020 at 12:31 Comment(0)
S
6

PSQL meta-command

\db+

SQL

SELECT * FROM pg_tablespace;
Sarcous answered 16/6, 2021 at 12:53 Comment(1)
a call for SELECT * FROM pg_tables; (its a "VIEW") might return much more data.Catanddog
G
4

Here is the psql command that you can use:

postgres=# \db+
                                      List of tablespaces
        Name    |  Owner   | Location | Access privileges | Options |  Size  | Description 
    ------------+----------+----------+-------------------+---------+--------+-------------
     pg_default | postgres |          |                   |         | 448 MB | 
     pg_global  | postgres |          |                   |         | 631 kB | 
    (2 rows)
Gwenngwenneth answered 14/2, 2020 at 12:34 Comment(0)
A
0

You can use below query to view all existing tablespaces as well as the location of non default tablespace using psql.

postgres=# select spcname ,pg_tablespace_location(oid) from pg_tablespace;

spcname   |      pg_tablespace_location
-------------+----------------------------------
pg_default  |
pg_global   |
devdefault  | /pgdata/devdata_tbs/devdefault
temp        | /pgdata/devdata_tbs/temporary
Anonym answered 8/12, 2023 at 7:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.