Add a function pg_stat_clear_snapshot() that discards any statistics snapshot
Tom Lane <tgl@sss.pgh.pa.us>
Add a function pg_stat_clear_snapshot() that discards any statistics snapshot already collected in the current transaction; this allows plpgsql functions to watch for stats updates even though they are confined to a single transaction. Use this instead of the previous kluge involving pg_stat_file() to wait for the stats collector to update in the stats regression test. Internally, decouple storage of stats snapshots from transaction boundaries; they'll now stick around until someone calls pgstat_clear_snapshot --- which xact.c still does at transaction end, to maintain the previous behavior. This makes the logic a lot cleaner, at the price of a couple dozen cycles per transaction exit.
Files
| Path | Change | +/− |
|---|---|---|
| doc/src/sgml/monitoring.sgml | modified | +16 −4 |
| src/backend/access/transam/xact.c | modified | +4 −1 |
| src/backend/postmaster/pgstat.c | modified | +87 −63 |
| src/backend/utils/adt/pgstatfuncs.c | modified | +24 −12 |
| src/include/catalog/catversion.h | modified | +2 −2 |
| src/include/catalog/pg_proc.h | modified | +5 −3 |
| src/include/pgstat.h | modified | +2 −1 |
| src/test/regress/expected/stats.out | modified | +28 −44 |
| src/test/regress/sql/stats.sql | modified | +20 −36 |