PostgreSQL 磁碟使用大小監控

來源:互聯網
上載者:User

標籤:

表大小資訊

postgres=# SELECT *, pg_size_pretty(total_bytes) AS total
postgres-# , pg_size_pretty(index_bytes) AS INDEX
postgres-# , pg_size_pretty(toast_bytes) AS toast
postgres-# , pg_size_pretty(table_bytes) AS TABLE
postgres-# FROM (
postgres(# SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes FROM (
postgres(# SELECT c.oid,nspname AS table_schema, relname AS TABLE_NAME
postgres(# , c.reltuples AS row_estimate
postgres(# , pg_total_relation_size(c.oid) AS total_bytes
postgres(# , pg_indexes_size(c.oid) AS index_bytes
postgres(# , pg_total_relation_size(reltoastrelid) AS toast_bytes
postgres(# FROM pg_class c
postgres(# LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
postgres(# WHERE relkind = ‘r‘
postgres(# ) a
postgres(# ) a;
oid | table_schema | table_name | row_estimate | total_bytes | index_bytes | toast_bytes | table_bytes | total
| index | toast | table
-------+--------------------+-------------------------+--------------+-------------+-------------+-------------+-------------+--------
----+------------+------------+------------
24933 | public | pgbench_tellers | 1280 | 237568 | 73728 | | 163840 | 232 kB
| 72 kB | | 160 kB
24939 | public | pgbench_branches | 128 | 65536 | 16384 | | 49152 | 64 kB
| 16 kB | | 48 kB
24936 | public | pgbench_accounts | 1.28e+07 | 2009858048 | 287531008 | | 1722327040 | 1917 MB
| 274 MB | | 1643 MB
24930 | public | pgbench_history | 20826 | 1261568 | 0 | | 1261568 | 1232 kB
| 0 bytes | | 1232 kB
2619 | pg_catalog | pg_statistic | 402 | 286720 | 32768 | 73728 | 180224 | 280 kB
| 32 kB | 72 kB | 176 kB
1247 | pg_catalog | pg_type | 354 | 163840 | 57344 | | 106496 | 160 kB
| 56 kB | | 104 kB
1260 | pg_catalog | pg_authid | 1 | 73728 | 32768 | | 40960 | 72 kB
| 32 kB | | 40 kB
1418 | pg_catalog | pg_user_mapping | 0 | 16384 | 16384 | | 0 | 16 kB
| 16 kB | | 0 bytes
2613 | pg_catalog | pg_largeobject | 0 | 8192 | 8192 | | 0 | 8192 by
tes | 8192 bytes | | 0 bytes
1249 | pg_catalog | pg_attribute | 2399 | 598016 | 188416 | | 409600 | 584 kB
| 184 kB | | 400 kB
1255 | pg_catalog | pg_proc | 2821 | 958464 | 327680 | 8192 | 622592 | 936 kB

最大的資料庫

postgres=# SELECT d.datname AS Name, pg_catalog.pg_get_userbyid(d.datdba) AS Owner,
postgres-# CASE WHEN pg_catalog.has_database_privilege(d.datname, ‘CONNECT‘)
postgres-# THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))
postgres-# ELSE ‘No Access‘
postgres-# END AS SIZE
postgres-# FROM pg_catalog.pg_database d
postgres-# ORDER BY
postgres-# CASE WHEN pg_catalog.has_database_privilege(d.datname, ‘CONNECT‘)
postgres-# THEN pg_catalog.pg_database_size(d.datname)
postgres-# ELSE NULL
postgres-# END DESC -- nulls first
postgres-# LIMIT 20
postgres-# ;
name | owner | size
--------------+--------------+---------
benchmarksql | benchmarksql | 10 GB
postgres | postgres | 1925 MB
pg_monitor | postgres | 7816 kB
scott | scott | 7632 kB
cott | cott | 7496 kB
template1 | postgres | 7496 kB
mgt | mgt | 7496 kB
template0 | postgres | 7129 kB
(8 rows)

最大的表

postgres=# SELECT nspname || ‘.‘ || relname AS "relation",
postgres-# pg_size_pretty(pg_relation_size(C.oid)) AS "size"
postgres-# FROM pg_class C
postgres-# LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
postgres-# WHERE nspname NOT IN (‘pg_catalog‘, ‘information_schema‘)
postgres-# ORDER BY pg_relation_size(C.oid) DESC
postgres-# LIMIT 20;
relation | size
------------------------------+------------
public.pgbench_accounts | 1642 MB
public.pgbench_accounts_pkey | 274 MB
public.pgbench_history | 1208 kB
pg_toast.pg_toast_2618 | 376 kB
public.pgbench_tellers | 128 kB
public.pgbench_tellers_pkey | 72 kB
pg_toast.pg_toast_2619 | 24 kB
pg_toast.pg_toast_2618_index | 16 kB
public.pgbench_branches_pkey | 16 kB
public.pgbench_branches | 16 kB
pg_toast.pg_toast_2619_index | 16 kB
pg_toast.pg_toast_2396_index | 8192 bytes
pg_toast.pg_toast_2606_index | 8192 bytes
pg_toast.pg_toast_2609_index | 8192 bytes
pg_toast.pg_toast_2964_index | 8192 bytes
pg_toast.pg_toast_2620_index | 8192 bytes
pg_toast.pg_toast_2604_index | 8192 bytes
pg_toast.pg_toast_1255_index | 8192 bytes
pg_toast.pg_toast_3596_index | 8192 bytes
pg_toast.pg_toast_3592_index | 8192 bytes
(20 rows)

表的總大小

postgres=# SELECT nspname || ‘.‘ || relname AS "relation",
postgres-# pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
postgres-# FROM pg_class C
postgres-# LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
postgres-# WHERE nspname NOT IN (‘pg_catalog‘, ‘information_schema‘)
postgres-# AND C.relkind <> ‘i‘
postgres-# AND nspname !~ ‘^pg_toast‘
postgres-# ORDER BY pg_total_relation_size(C.oid) DESC
postgres-# LIMIT 20;
relation | total_size
---------------------------+------------
public.pgbench_accounts | 1917 MB
public.pgbench_history | 1232 kB
public.pgbench_tellers | 232 kB
public.pgbench_branches | 64 kB
public.pg_stat_statements | 0 bytes
public.pg_buffercache | 0 bytes
(6 rows)

ref:https://wiki.postgresql.org/wiki/Disk_Usage

PostgreSQL 磁碟使用大小監控

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.