如何检查在 PostgreSQL 中存储表需要多少页/块?

发布于 2025-01-15 06:16:16 字数 66 浏览 2 评论 0原文

假设我们有一个表 PEOPLE。如何检查将其存储在 PostgreSQL 中需要多少页/块?

Let's suppose we have a table PEOPLE. How can I check how many pages/blocks are required for storing it in PostgreSQL?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情空心 2025-01-22 06:16:16

从系统目录中获取当前使用的实际块数 pg_class

SELECT oid::regclass AS tbl, relpages
FROM   pg_class
WHERE  relname = 'people'; -- or "PEOPLE"?

这只是主要关系。而且这个计数可能有些过时了。不包括 TOAST、辅助关系或索引。但它包含任何数量的膨胀,可以使用 VACUUM FULL 或类似工具来消除。更多:

使用 oid::regclass 的表述可以防止与 search_path 发生任何混淆。如果该表不可见(search_path 中的第一个表),则输出是架构限定的。

Get the actual number of blocks currently used from the system catalog pg_class:

SELECT oid::regclass AS tbl, relpages
FROM   pg_class
WHERE  relname = 'people'; -- or "PEOPLE"?

That's only the main relation. And the count may be somewhat outdated. Not including TOAST, auxiliary relations or indexes. But it includes any amount of bloat, that might be removed with VACUUM FULL or similar tools. More:

The formulation with oid::regclass defends against any confusion with the search_path. If the table is not visible (first one in the search_path), then the output is schema-qualified.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文