select sum(t.size) from (
SELECT table_schema || '.' || table_name AS table_full_name, pg_total_relation_size('"' || table_schema || '"."' || table_name || '"' )AS size
FROM information_schema.tables
ORDER BY
pg_total_relation_size('"' || table_schema || '"."' || table_name || '"' ) DESC
) t
SELECT table_schema || '.' || table_name AS table_full_name, pg_total_relation_size('"' || table_schema || '"."' || table_name || '"' )AS size
FROM information_schema.tables
ORDER BY
pg_total_relation_size('"' || table_schema || '"."' || table_name || '"' ) DESC
playboy= > \l / / \加上字母l,相当于mysql的,mysql> show databases;
List of databases
Name | Owner | Encoding
playboy | postgres | UTF8
postgres | postgres | UTF8
template0 | postgres | UTF8
template1 | postgres | UTF8
playboy= > select pg_database_size('playboy' ); / / 查看playboy数据库的大小
pg_database_size
3637896
(1 row )
playboy= > select pg_database.datname, pg_database_size(pg_database.datname) AS size from pg_database; / / 查看所有数据库的大小
datname | size
postgres | 3621512
playboy | 3637896
template1 | 3563524
template0 | 3563524
(4 rows )
playboy= > select pg_size_pretty(pg_database_size('playboy' )); / / 以KB,MB,GB的方式来查看数据库大小
pg_size_pretty
3553 kB
(1 row )
playboy= > \d test; / / 相当于mysql的,mysql> desc test;
Table "public.test"
Column | Type | Modifiers
id | integer | not null
name | character varying (32 ) |
Indexes: "playboy_id_pk" PRIMARY KEY, btree (id)
playboy= > select pg_relation_size('test' ); / / 查看表大小
pg_relation_size
0
(1 row )
playboy= > select pg_size_pretty(pg_relation_size('test' )); / / 以KB,MB,GB的方式来查看表大小
pg_size_pretty
0 bytes
(1 row )
playboy= > select pg_size_pretty(pg_total_relation_size('test' )); / / 查看表的总大小,包括索引大小
pg_size_pretty
8192 bytes
(1 row )
playboy= > \di / / 相当于mysql的,mysql> show index from test;
List of relations
Schema | Name | Type | Owner | Table
public | playboy_id_pk | index | playboy | test
(1 row )
playboy= > select pg_size_pretty(pg_relation_size('playboy_id_pk' )); / / 查看索大小
pg_size_pretty
8192 bytes
(1 row )
playboy=> select spcname from pg_tablespace;
spcname
------------
pg_default
pg_global
(2 rows )
playboy => select pg_size_pretty (pg_tablespace_size('pg_default' )) ;
pg_size_pretty
----------------
14 MB
(1 row)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构