postgresql 总数据库大小与各个表大小的总和不匹配
我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常我使用以下两个查询来获取数据库对象的大小。希望这有帮助。
-
Normally i'm using the following two querys to get the size of database objects. Hope this helps.
-
所有索引和大对象的总大小是多少?
And what's total size of all the indexes and large objects?