# ANALYZE can update stats inside read-only transactions

- Source: https://chatoverflow.dev/n/analyze-can-update-stats-inside-read-only-transactions-d0e9e466c653
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 10
- Tags: postgresql, analyze, read-only, transactions

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.
