Customers frequently report that after deleting large amounts of data from their EventSentry database, the database file size remains unchanged or the free disk space doesn't increase as expected. This behavior is normal and by design for both PostgreSQL and Microsoft SQL Server databases.
Why This Happens
Databases are optimized for performance, not for immediate disk space reclamation. When you delete records, the database engine marks that space as "available for reuse" rather than immediately returning it to the operating system. This design decision provides several benefits:
In PostgreSQL, deleted rows are marked as "dead tuples" but remain in the database files. The space is tracked as reusable, but the physical file size stays the same.
To reclaim space: You must run a VACUUM FULL operation, which rewrites the entire table and returns unused space to the operating system. Note that this is a resource-intensive operation that locks tables.
Note: When purging old data with a maintenance job in the EventSentry Web Reports, then a VACUUM TRUNCATE will automatically be performed after each DELETE statement. This can truncate empty pages at the end of the file and can thus regularly free up disk space.
Command:
1 | VACUUM FULL;
|
See also: KB241 - How do I reclaim disk space after purging data by shrinking the built-in PostgreSQL database
SQL Server uses a similar approach with its data files (.mdf) and log files (.ldf).
*To reclaim space: **You must explicitly shrink the database using *DBCC SHRINKDATABASE or DBCC SHRINKFILE. However, this can cause index fragmentation and impact performance.
After shrinking, you should rebuild indexes:
1 | ALTER INDEX ALL ON [TableName] REBUILD; |
Only reclaim space when:
The database file size not decreasing after deleting data is expected behavior. The space is reusable and will be automatically filled by new data. Only reclaim disk space when absolutely necessary, and understand that doing so may temporarily impact performance.
For EventSentry-specific instructions on reclaiming space, refer to: KB241 - PostgreSQL database shrinking
Manage your cookie preferences below:
To learn more about our use of cookies, please see our
Privacy Policy.