欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PostgreSQL如何查詢表大小(單獨查詢和批量查詢)

 更新時間:2024年02月03日 09:05:58   作者:阿福Chris  
PostgreSQL提供了多個系統(tǒng)管理函數(shù)來查看表,索引表空間及數(shù)據(jù)庫的大小,這篇文章主要給大家介紹了關(guān)于PostgreSQL如何查詢表大小的相關(guān)資料,文中介紹的方法包括單獨查詢和批量查詢,需要的朋友可以參考下

前言

查詢 PG 表的大小通常需要使用函數(shù)/視圖來實現(xiàn),分為單獨查詢和批量查詢的場景,下面簡單列一下:

1. 單表大小查詢

如果要查詢單個表的大小,可以使用常用的函數(shù),參考語句如下:

select pg_size_pretty(pg_relation_size('表名'));

注意:這個查詢結(jié)果不包括索引大小,如果要查詢索引大小,可以通過查詢 information_schema.tables 來獲取

2.所有數(shù)據(jù)庫表大小批量查詢

如果要查詢所有表的大小,包括索引,那么最方便的就是直接查詢 information_schema.tables 表了,可以參考如下查詢語句:

select
	table_name,
	pg_size_pretty(table_size) as table_size,
	pg_size_pretty(indexes_size) as indexes_size,
	pg_size_pretty(total_size) as total_size
from
	(
	select
		table_name,
		pg_table_size(table_name) as table_size,
		pg_indexes_size(table_name) as indexes_size,
		pg_total_relation_size(table_name) as total_size
	from
		(
		select
			('"' || table_schema || '"."' || table_name || '"') as table_name
		from
			information_schema.tables
) as all_tables
	order by
		total_size desc
) as pretty_sizes;

附:查詢數(shù)據(jù)庫大小

-- 查詢單個數(shù)據(jù)庫大小
select pg_size_pretty(pg_database_size('postgres')) as size;
 
-- 查詢所有數(shù)據(jù)庫大小
select datname, pg_size_pretty (pg_database_size(datname)) AS size from pg_database;

總結(jié) 

到此這篇關(guān)于PostgreSQL如何查詢表大小的文章就介紹到這了,更多相關(guān)PostgreSQL查詢表大小內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論