查找 postgresql 表及其索引的磁盘大小
本文将讨论如何找到 postgresql 表及其索引的磁盘大小。
使用 psql 查找 postgresql 表和数据库的磁盘大小
你可以使用 \l
查看数据库大小,使用 \d
显示表大小。但在此之前,你需要登录数据库执行查询。
以下是在 postgres 中显示表和数据库大小的命令和输出:
postgres=#\l
输出:
postgres-#\dlistofrelationsschema|name|type|owner|persistence|accessmethod|size|description-------- ------------------ ---------- ---------- ------------- --------------- ------------ -------------
public|book_lends|table|postgres|permanent|heap|16kb|public|books|table|postgres|permanent|heap|16kb|public|employee|table|postgres|permanent|heap|16kb|public|employee_id_seq|sequence|postgres|permanent||8192bytes|public|events|table|postgres|permanent|heap|16kb|public|mock_data|table|postgres|permanent|heap|48kb|public|product|table|postgres|permanent|heap|16kb|public|product_id_seq|sequence|postgres|permanent||8192bytes|public|products|table|postgres|permanent|heap|16kb|public|products_id_seq|sequence|postgres|permanent||8192bytes|public|prroducts|table|postgres|permanent|heap|8192bytes|public|prroducts_id_seq|sequence|postgres|permanent||8192bytes|public|stores|table|postgres|permanent|heap|16kb|public|stores_id_seq|sequence|postgres|permanent||8192bytes|public|users|table|postgres|permanent|heap|16kb|(15rows)
这里它显示了我们在 postgres 数据库中的所有表及其名称、类型、所有者、大小、访问方法等。
查找数据库中最大表的大小
这是 postgres 官方编写的代码片段,用于按降序显示表格大小。
selectnspname||'.'||relnameas"relation",pg_size_pretty(pg_total_relation_size(c.oid))as"total_size"frompg_classcleftjoinpg_namespacenon(n.oid=c.relnamespace)wherenspnamenotin('pg_catalog','information_schema')andc.relkind<>'i'andnspname!~'^pg_toast'orderbypg_total_relation_size(c.oid)desclimit10;
输出:
relation | total_size
------------------- ------------
public.mock_data | 48 kb
public.product | 32 kb
public.products | 32 kb
public.books | 32 kb
public.book_lends | 32 kb
public.employee | 32 kb
public.stores | 32 kb
public.users | 32 kb
public.events | 16 kb
public.prroducts | 16 kb
(10 rows)
我们在数据库中的 postgres
下搜索了 10 个最大的表。
你可以点击以下 了解更多关于 postgres 中磁盘大小的查询。你将找到用于查找最大集群、最大关系、分区表等的 sql 查询。
更多关于数据库大小的函数。
转载请发邮件至 1244347461@qq.com 进行申请,经作者同意之后,转载请以链接形式注明出处
本文地址:
相关文章
在一个 postgresql 查询中使用多个 with 语句
发布时间:2023/03/20 浏览次数:337 分类:postgresql
-
在本教程中,我们将学习如何使用多个 with 语句在 postgresql 中使用两个临时表执行查询。
发布时间:2023/03/20 浏览次数:185 分类:postgresql
-
本文介绍如何在 ubuntu 上找到 postgresql 数据库的配置文件。
发布时间:2023/03/20 浏览次数:409 分类:数据库
-
本文解释了如何直接从终端/命令行或 psql shell 运行 sql 文件。为此,你需要指定主机名、端口、用户名和数据库名称。
发布时间:2023/03/20 浏览次数:89 分类:postgresql
-
本文展示了如何列出 postgresql 上的活动连接。
发布时间:2023/03/20 浏览次数:966 分类:postgresql
-
在 pl/sql 中,你可能需要在 postgres 中使用循环。我们可以使用 for 和 while 语句来创建循环。
发布时间:2023/03/20 浏览次数:141 分类:postgresql
-
本文介绍如何在 postgresql 中仅使用单个查询来重命名列以及更改其类型。
发布时间:2023/03/20 浏览次数:233 分类:postgresql
-
本文介绍如何在 postgresql 中使用 select 方法连接列。
发布时间:2023/03/20 浏览次数:281 分类:postgresql
-
本文展示了如何使用 case 语句并给出了 postgresql 中的示例。