I understand space isn't abruptly released (unless one does TRUNCATE
). But this one looks abnormal to me.
What could be the reason for a postgresql (9.3.10) table not releasing space after having 70% of its records removed?
I have a table called user_sessions_session
. As the name implies, it stores sessions data for each user of a web app.
It's original size was:
Table | Size | External Size
----------------------------------+---------+---------------
user_sessions_session | 15 GB | 13 GB
I thereafter deleted all user sessions older than 3 months ago. That was the majority of the rows in the table. This was 3 days ago. I just checked the table size again, here's what I see:
Table | Size | External Size
----------------------------------+---------+---------------
user_sessions_session | 15 GB | 13 GB
Moreover, select * from pg_stat_activity where query like 'autovacuum:%';
reveals no vacuuming is going on at this point.
Btw I've had this same issue with this same sessions table before - it's not a one off.
In case it matters, here's the SQL I used to get table sizes (user_sessions_session showed up as number 1 in the list):
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;