Reputation: 1
The disk size increases periodically, even though the dead tuple count is reduced by increasing the performance of Autovacuum. The amount of inserts is less than the number of dead tuples.
Test Environment:
Centos 7. postgesql 10.7 , memory 128G, ssd :600G,cpu : 16core
More than 40 million insert a day.
There are about 120 million dead tuples due to periodic updates.
I save data for a month and delete it once a week.
saved data is about 1.2 billion.
I checked disk size and dead tuple status periodically. Disk size:
SELECT nspname || '.' || relname AS "relation",
pg_total_relation_size(C.oid) AS "total_size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind <> 'i'
AND nspname !~ '^pg_toast'
ORDER BY pg_total_relation_size(C.oid) DESC
LIMIT 3;
Dead tuples:
SELECT relname, n_live_tup, n_dead_tup,
n_dead_tup / (n_live_tup::float) as ratio
FROM pg_stat_user_tables
WHERE n_live_tup > 0
AND n_dead_tup > 1000
ORDER BY ratio DESC;
It takes more than 3 days for Autovacuum. I changed it to run within 30 minutes with this setting like this:
ALTER SYSTEM SET maintenance_work_mem ='1GB';
select pg_reload_conf();
alter table pm_reporthour set (autovacuum_vacuum_cost_limit = 1000);
ALTER TABLE PM_REPORTHOUR SET (autovacuum_vacuum_cost_delay =0);
Please advise which one to review.
Upvotes: 0
Views: 183
Reputation: 246338
If you have large deletes, you will always get bloat. The king's way in this case is partitioning: partition by range so that you can run DROP TABLE
on a partition instead of a massive DELETE
. Apart from better performance, that will avoid all bloat.
Upvotes: 1