pg_tablespace_size() 是一个系统函数,它返回指定 表空间 的大小(以字节为单位)。
pg_tablespace_size() 在 PostgreSQL 8.1 中被添加。
用法
pg_tablespace_size ( name ) → bigint pg_tablespace_size ( oid ) → bigint
pg_tablespace_size() 可以使用表空间的 OID 或名称进行调用,并以字节为单位返回表空间的大小。
变更历史
- PostgreSQL 8.1
- 添加(提交 358a897f)
pg_tablespace_size() 最初是在 PostgreSQL 8.0 中被添加到(已废弃的) dbsize contrib 模块 中的。
示例
psql 的 \db+ 命令使用的查询
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)
参考资料
- PostgreSQL文档: 数据库对象大小函数
