pg_tablespace_size()

A system function returning the size of the specified tablespace

pg_tablespace_size() is a system function returning the size (in bytes) of the specified tablespace.

pg_tablespace_size() was added in PostgreSQL 8.1.

Usage

pg_tablespace_size() can be called with the tablespace OID or name, and returns the tablespace size in bytes.

Change history

Examples

The query used by psql's \db+ command:

postgres=# \db+
********* QUERY **********
SELECT spcname AS "Name",
  pg_catalog.pg_get_userbyid(spcowner) AS "Owner",
  pg_catalog.pg_tablespace_location(oid) AS "Location",
  pg_catalog.array_to_string(spcacl, E'\n') AS "Access privileges",
  spcoptions AS "Options",
  pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS "Size",
  pg_catalog.shobj_description(oid, 'pg_tablespace') AS "Description"
FROM pg_catalog.pg_tablespace
ORDER BY 1;
**************************

                                          List of tablespaces
    Name    |  Owner   |         Location           | Access privileges | Options |    Size    | Description
------------+----------+----------------------------+-------------------+---------+------------+-------------
 pg_default | postgres |                            |                   |         | 31 MB      |
 pg_global  | postgres |                            |                   |         | 575 kB     |
 tblspace_1 | postgres | /var/lib/pgsql/tblspc_dir1 |                   |         | 8192 bytes |
 tblspace_2 | postgres | /var/lib/pgsql/tblspc_dir2 |                   |         | 0 bytes    |
(4 rows)

Categories

Management / adminstration, Tablespaces

See also

pg_tablespace_databases(), pg_tablespace_location(), tablespace, pg_tablespace