postgresql 总数据库大小与各个表大小的总和不匹配

发布于 2024-10-18 22:11:09 字数 804 浏览 0 评论 0原文

我的 postgres 数据库(版本 8.2.3)显示大小为 24 GB。

为了得到这个数字,我执行这个查询:

SELECT
  oid, datname, pg_database_size(datname) as actualsize, 
  pg_size_pretty(pg_database_size(datname)) as size 
FROM pg_database 
ORDER BY datname  

然而,当我执行这个查询时,同一数据库中各个表的大小并没有增加 24 GB:

SELECT 
  schemaname, tablename, pg_size_pretty(size) AS size_pretty, 
  pg_size_pretty(total_size) AS total_size_pretty 
FROM
  (SELECT *, pg_relation_size(schemaname||'.'||tablename) AS size, 
   pg_total_relation_size(schemaname||'.'||tablename) AS total_size 
   FROM pg_tables where schemaname = 'public') AS TABLES 
ORDER BY total_size DESC;

我已经用相当大小和total_size总结了各个表的大小,但是值不匹配:

我得到的大小为 3.5 GB,

total_size_pretty 为 5.2 GB。

我在哪里可以找到剩余的总空间的用途?

My postgres database (version 8.2.3) is showing a size of 24 GB.

To get this figure I execute this query:

SELECT
  oid, datname, pg_database_size(datname) as actualsize, 
  pg_size_pretty(pg_database_size(datname)) as size 
FROM pg_database 
ORDER BY datname  

However, the sizes of the individual tables in the same database are not adding 24 GB when I execute this query:

SELECT 
  schemaname, tablename, pg_size_pretty(size) AS size_pretty, 
  pg_size_pretty(total_size) AS total_size_pretty 
FROM
  (SELECT *, pg_relation_size(schemaname||'.'||tablename) AS size, 
   pg_total_relation_size(schemaname||'.'||tablename) AS total_size 
   FROM pg_tables where schemaname = 'public') AS TABLES 
ORDER BY total_size DESC;

I've done sum up the individual tables size with pretty size and total_size, but the value does not match:

I am getting a pretty size of 3.5 GB

I am getting a total_size_pretty of 5.2 GB.

Where do I find out what the rest of the total space is being used for?

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

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

发布评论

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

评论(2

杀お生予夺 2024-10-25 22:11:09

通常我使用以下两个查询来获取数据库对象的大小。希望这有帮助。

SELECT pg_size_pretty(sum(pg_relation_size(pg_class.oid))::bigint), nspname,
CASE pg_class.relkind WHEN 'r' THEN 'table' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 'v' THEN 'view' WHEN 't' THEN 'toast' ELSE pg_class.relkind::text END
FROM pg_class
LEFT OUTER JOIN pg_namespace ON (pg_namespace.oid = pg_class.relnamespace)
GROUP BY pg_class.relkind, nspname
ORDER BY sum(pg_relation_size(pg_class.oid)) DESC;

-

SELECT pg_size_pretty(pg_relation_size(pg_class.oid)), pg_class.relname, pg_namespace.nspname,
CASE pg_class.relkind WHEN 'r' THEN 'table' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 'v' THEN 'view' WHEN 't' THEN 'TOAST' ELSE pg_class.relkind::text END
FROM pg_class 
LEFT OUTER JOIN pg_namespace ON (pg_namespace.oid = pg_class.relnamespace)
ORDER BY pg_relation_size(pg_class.oid) DESC;

Normally i'm using the following two querys to get the size of database objects. Hope this helps.

SELECT pg_size_pretty(sum(pg_relation_size(pg_class.oid))::bigint), nspname,
CASE pg_class.relkind WHEN 'r' THEN 'table' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 'v' THEN 'view' WHEN 't' THEN 'toast' ELSE pg_class.relkind::text END
FROM pg_class
LEFT OUTER JOIN pg_namespace ON (pg_namespace.oid = pg_class.relnamespace)
GROUP BY pg_class.relkind, nspname
ORDER BY sum(pg_relation_size(pg_class.oid)) DESC;

-

SELECT pg_size_pretty(pg_relation_size(pg_class.oid)), pg_class.relname, pg_namespace.nspname,
CASE pg_class.relkind WHEN 'r' THEN 'table' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 'v' THEN 'view' WHEN 't' THEN 'TOAST' ELSE pg_class.relkind::text END
FROM pg_class 
LEFT OUTER JOIN pg_namespace ON (pg_namespace.oid = pg_class.relnamespace)
ORDER BY pg_relation_size(pg_class.oid) DESC;
留蓝 2024-10-25 22:11:09

所有索引和大对象的总大小是多少?

And what's total size of all the indexes and large objects?

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