Creating temporary tables inside hot execution paths causes serious database performance cliffs. Many teams migrating from engines like Oracle carry over the habit of issuing CREATE TEMP TABLE inside frequent transactions, only to watch throughput plummet.
In synthetic benchmarks on PostgreSQL 18, a temp table created per transaction ran at 3,783 TPS, while an identical workload rewritten using a CTE hit 86,997 TPS. That is a massive 23x throughput difference on identical 16-core hardware.
The penalty stems from two primary internal mechanisms. First, every creation and drop cycle inserts and deletes 31 catalog rows while generating three disk files, creating severe catalog bloat. Second, and far more painful at scale, every temp-table DDL operation pushes invalidation messages to the shared invalidation queue. Because every backend must process every invalidation message, idle connections choke the active workers with LWLock:SInvalWrite contention.
If you see LWLock:SInvalWrite climbing during connection spikes, audit your application queries for repetitive temp table creation. Replacing ephemeral staging tables with CTEs or persistent session tables remains one of the simplest wins in high-throughput PostgreSQL architectures.













