简体   繁体   English

为什么我的postgres数据库这么大?

[英]why is my postgres database so big?

i'm running PostgreSQL 9.4.6 and I have a database that's 78GB found by running 我正在运行PostgreSQL 9.4.6,并且我通过运行找到了一个78GB的数据库

SELECT pg_size_pretty(pg_database_size('<db name>')) As fulldbsize;

In order to track down why my database is so big I've tried the following:- 为了跟踪为什么我的数据库这么大,我尝试了以下操作:

SELECT relname as "Table",      
       pg_size_pretty(pg_total_relation_size(relid)) As "Size",
       pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as "External Size" 
FROM pg_catalog.pg_statio_user_tables 
ORDER BY pg_total_relation_size(relid) DESC;

But when adding up the resulting tables I get to about 15GB. 但是,当将结果表加起来时,我的容量约为15GB。

What's using my up the space in my database? 我的数据库空间用完了什么? What further commands can I run? 我还能运行什么命令?

you can also get information about all objects and their respective sizes 您还可以获得有关所有对象及其各自大小的信息

 SELECT
 relname AS objectname,
 relkind AS objecttype,
 reltuples AS "#entries", pg_size_pretty(relpages::bigint*8*1024) AS size
 FROM pg_class
 WHERE relpages >= 8
 ORDER BY relpages DESC;

This should detail: 这应该详细说明:

  • objectname – The name of the object objectname –对象的名称
  • objecttype – r for the table, i for an index, t for toast data, ... 对象类型– r代表表格,i代表索引,t代表吐司数据,...
  • entries – The estimated number of entries in the object (eg rows) 个条目–对象中的估计条目数(例如,行)
  • size – The size of the object size –对象的大小

This will list all objects an their size: 这将列出所有对象及其大小:

SELECT relname, pg_total_relation_size(oid)
FROM pg_class
ORDER BY 2 DESC;

That should help you account for the database size. 这应该可以帮助您说明数据库的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM