Master in Oracle DBA | Join us for the demo session on 19th November 2025 at 7:00 PM IST

PostgreSQL Free Space Management

Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
  • User AvatarPradip
  • 20 Nov, 2025
  • 0 Comments
  • 3 Mins Read

PostgreSQL Free Space Management

PostgreSQL Free Space Management: How PostgreSQL Reclaims & Tracks Storage Internally

PostgreSQL is known for its robust storage architecture, MVCC implementation, and strong performance. However, one area many DBAs and developers overlook is free space management—how PostgreSQL identifies, tracks, and reuses space created by updates/deletes.

Since PostgreSQL doesn’t overwrite row data in place (due to MVCC), deleted and updated tuples become dead tuples, generating internal fragmentation. Efficient free space management ensures that PostgreSQL reuses this space instead of endlessly consuming disk storage.

Let’s dive into how PostgreSQL handles this.


Why Free Space Becomes a Concern in PostgreSQL?

PostgreSQL uses MVCC (Multi-Version Concurrency Control), meaning:

  • An UPDATE creates a new version of a row

  • The old version remains until vacuum removes it

  • DELETE marks rows as dead, not removed instantly

Over time this creates:

Process Effect
Frequent UPDATE/DELETE Dead tuples accumulate
No VACUUM Table grows on disk unnecessarily
Fragmentation Query performance degrades

Thus, PostgreSQL must track where reusable space exists—this is where FSM comes in.


What is FSM (Free Space Map)?

The Free Space Map (FSM) is a PostgreSQL internal data structure that tracks how much free space exists on each data page of a table or index.

FSM helps PostgreSQL:

✔ Decide where to insert new tuples
✔ Avoid creating unnecessary new pages
✔ Reuse empty space efficiently
✔ Reduce table bloat

FSM improves performance by preventing excessive disk writes.


Where is FSM Stored?

Each table and index has a separate FSM file:

<relfilenode>_fsm

For example, if a table’s relfilenode is 16384, its FSM file is:

16384_fsm

Use oid or relfilenode queries to find it:

SELECT relname, relfilenode FROM pg_class WHERE relname = 'customers';

How PostgreSQL Updates FSM

FSM is updated automatically during:

  • Vacuum

  • Page splits

  • Tuple removal

  • Bulk deletes

You can also manually trigger FSM updates by running:

VACUUM customers;
VACUUM FULL customers;

VACUUM FULL physically rewrites the table, while normal VACUUM only marks space as reusable.


FSM vs Visibility Map (VM)

Many confuse FSM with Visibility Map. They track different information:

Feature FSM VM
Stores Free space on pages Whether pages need vacuum
Focus Reuse of storage Skipping unnecessary vacuum scans
File type _fsm _vm
Helps With Inserts, reducing bloat Faster VACUUM, index-only scans

Both work together to maintain healthy storage.


Monitoring Free Space & Bloat

Check table bloat using extension:

CREATE EXTENSION pgstattuple;
SELECT * FROM pgstattuple('customers');

Useful columns:

Column Meaning
dead_tuple_percent How much space is wasted
free_percent Free space in table
live_tuple_percent Space actually used

Best Practices for Free Space Management

Practice Purpose
Enable autovacuum Continuous space reclamation
Tune autovacuum thresholds Avoid delayed vacuuming
Use pg_repack instead of VACUUM FULL for production Non-blocking table compaction
Partition high-churn tables Reduces bloat impact
Monitor dead tuples via pg_stat_all_tables Detect early fragmentation

Example tuning:

ALTER TABLE customers SET (autovacuum_vacuum_scale_factor = 0.1);
ALTER TABLE customers SET (autovacuum_analyze_scale_factor = 0.05);

Summary

Concept Description
FSM Tracks free space for efficient inserts
Dead Tuples Created from MVCC updates/deletes
VACUUM Removes dead tuples and updates FSM
VM Tracks visibility, reduces vacuum overhead
Goal Minimize bloat & optimize storage usage

Effective Free Space Management ensures your PostgreSQL instance performs efficiently and controls unnecessary storage growth—especially in transactional databases with heavy updates.

📺 Want to see how we teach? Head over to our YouTube channel for insights, tutorials, and tech breakdowns: 👉 www.youtube.com/@learnomate

🌐 To know more about our courses, offerings, and team: Visit our official website: 👉 www.learnomate.org

💼 Let’s connect and talk tech! Follow me on LinkedIn for more updates, thoughts, and learning resources: 👉 https://www.linkedin.com/in/ankushthavali/

📝 If you want to read more about different technologies, Check out our detailed blog posts here: 👉 https://learnomate.org/blogs/

Let’s keep learning, exploring, and growing together. Because staying curious is the first step to staying ahead.

Happy learning!

ANKUSH😎

Let's Talk

Find your desired career path with us!