QA
Senior LevelPostgreSQL

Why can excessive Subtransactions (SAVEPOINTs) degrade PostgreSQL performance by 10x?

❓ Interview Prompt: Explain Subtransactions (`SAVEPOINT`), subtransaction cache limit (64 XIDs), `pg_subtrans` SLRU cache overflow, and severe lock contention.

PostgreSQL implements 'SAVEPOINT' using Subtransactions:

The 10x Performance Degradation Trap:

Each backend process caches up to 64 active subtransaction IDs in CPU RAM. If a transaction executes more than 64 'SAVEPOINT' operations:

•
Subtransaction state overflows out of CPU RAM into disk-backed 'pg_subtrans' SLRU files!
•
Triggers severe SLRU lock contention across all backend processes, degrading cluster throughput by 10x!

Code Implementation Example

sql
-- Avoid excessive SAVEPOINT calls inside loops!
BEGIN;
SAVEPOINT sp1; -- Okay
-- Executing 100+ SAVEPOINTs causes pg_subtrans SLRU overflow!
COMMIT;
💡Avoiding subtransaction savepoint loops to prevent SLRU cache degradation.
🎯 Interview Key Takeaway

Avoid executing excessive SAVEPOINT statements inside loops to prevent pg_subtrans SLRU disk overflow.

#SAVEPOINT#Subtransactions#SLRU Overflow#Performance#Senior
Back to all PostgreSQL Questions→

More PostgreSQL Interview Questions

Beginner LevelPostgreSQL

How to use pgvector in PostgreSQL for vector similarity search with HNSW indexes?

Beginner LevelPostgreSQL

What is PostgreSQL architecture and how do client backends connect via process fork model?

Beginner LevelPostgreSQL

What special built-in data types exist in PostgreSQL (JSONB, UUID, ARRAY, INET, TEXT)?