mirror of
https://github.com/postgres/postgres.git
synced 2025-06-29 10:41:53 +03:00
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.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.37 2007/01/05 22:19:41 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.38 2007/02/07 23:11:29 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -39,7 +39,6 @@ extern Datum pg_stat_get_last_autoanalyze_time(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum pg_stat_get_backend_idset(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_backend_pid(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_stat_reset(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_stat_get_backend_pid(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_stat_get_backend_dbid(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_stat_get_backend_userid(PG_FUNCTION_ARGS);
|
||||
@ -57,6 +56,9 @@ extern Datum pg_stat_get_db_xact_rollback(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_stat_get_db_blocks_fetched(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_stat_get_db_blocks_hit(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum pg_stat_clear_snapshot(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_stat_reset(PG_FUNCTION_ARGS);
|
||||
|
||||
|
||||
Datum
|
||||
pg_stat_get_numscans(PG_FUNCTION_ARGS)
|
||||
@ -336,16 +338,6 @@ pg_backend_pid(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_INT32(MyProcPid);
|
||||
}
|
||||
|
||||
/*
|
||||
* Built-in function for resetting the counters
|
||||
*/
|
||||
Datum
|
||||
pg_stat_reset(PG_FUNCTION_ARGS)
|
||||
{
|
||||
pgstat_reset_counters();
|
||||
|
||||
PG_RETURN_BOOL(true);
|
||||
}
|
||||
|
||||
Datum
|
||||
pg_stat_get_backend_pid(PG_FUNCTION_ARGS)
|
||||
@ -678,3 +670,23 @@ pg_stat_get_db_blocks_hit(PG_FUNCTION_ARGS)
|
||||
|
||||
PG_RETURN_INT64(result);
|
||||
}
|
||||
|
||||
|
||||
/* Discard the active statistics snapshot */
|
||||
Datum
|
||||
pg_stat_clear_snapshot(PG_FUNCTION_ARGS)
|
||||
{
|
||||
pgstat_clear_snapshot();
|
||||
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
|
||||
/* Reset all counters for the current database */
|
||||
Datum
|
||||
pg_stat_reset(PG_FUNCTION_ARGS)
|
||||
{
|
||||
pgstat_reset_counters();
|
||||
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
Reference in New Issue
Block a user