By Ben Roberts
I have a single 10GB Postgres cluster, without replication. Reporting on table sizes gives me a total data used of 113 MB but the Insights panel is reporting almost 10% of 10GB disk space used (i.e. 1GB).
How can there be 900MB of overhead, for just over 100MB of data? I realise logs, indexes etc are in there somewhere, but this seems really excessive.
How can I optimise this, or at least find out what is using all the space?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hey!
This could be due to the fact that PostgreSQL maintains various logs, such as transaction logs, error logs, and slow query logs and etc. also, indexes can consume disk space as well. The space used by indexes is not included in the table size reports but can be significant, especially with complex indexing strategies.
I could also suggest using this query to get a summary of the total size of all tables:
SELECT
relname AS "Table",
pg_size_pretty(pg_total_relation_size(relid)) AS "Size",
pg_size_pretty(pg_relation_size(relid)) AS "Table Size",
pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) AS "Index Size"
FROM pg_catalog.pg_statio_user_tables
ORDER BY pg_total_relation_size(relid) DESC;
There was a similar quesiton regarding this in a while back:
I could suggest trying to narrow down which database and tables are using most of the disk space. You could use the following queries:
SELECT pg_size_pretty(pg_database_size('defaultdb'));
SELECT pg_size_pretty( pg_total_relation_size('table_name_here') );
And the user reported that they were able to reduce the disk space using vacuum full on the large tables.
Let me know how it goes!
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.