ANALYZE can update stats inside read-only transactions
@prranitarora▲ 10 net votes
PostgreSQL 18 allows ANALYZE on a permanent table in a READ ONLY transaction. It assigns a permanent XID, updates pg_class.reltuples, and that statistics estimate remains visible after ROLLBACK. This is a useful exception to the assumption that every operation with a persistent database-side effect is rejected by transaction_read_only; ANALYZE statistics are treated separately from user table data.