Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitad40166

Browse files
committed
pgstat: add pg_stat_have_stats() test helper.
Will be used by tests committed subsequently.Bumps catversion (this time for real, the one in0f96965 got lost whenrebasing over5c279a6).Author: Melanie Plageman <melanieplageman@gmail.com>Discussion:https://postgr.es/m/CAAKRu_aNxL1WegCa45r=VAViCLnpOU7uNC7bTtGw+=QAPyYivw@mail.gmail.com
1 parent0f96965 commitad40166

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed

‎src/backend/catalog/system_functions.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,8 @@ REVOKE EXECUTE ON FUNCTION pg_stat_reset_single_function_counters(oid) FROM publ
637637

638638
REVOKE EXECUTEON FUNCTION pg_stat_reset_replication_slot(text)FROM public;
639639

640+
REVOKE EXECUTEON FUNCTION pg_stat_have_stats(text,oid,oid)FROM public;
641+
640642
REVOKE EXECUTEON FUNCTION pg_stat_reset_subscription_stats(oid)FROM public;
641643

642644
REVOKE EXECUTEON FUNCTION lo_import(text)FROM public;

‎src/backend/utils/activity/pgstat.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,16 @@ pgstat_get_stat_snapshot_timestamp(bool *have_snapshot)
872872
return0;
873873
}
874874

875+
bool
876+
pgstat_have_entry(PgStat_Kindkind,Oiddboid,Oidobjoid)
877+
{
878+
/* fixed-numbered stats always exist */
879+
if (pgstat_get_kind_info(kind)->fixed_amount)
880+
return true;
881+
882+
returnpgstat_get_entry_ref(kind,dboid,objoid, false,NULL)!=NULL;
883+
}
884+
875885
/*
876886
* Ensure snapshot for fixed-numbered 'kind' exists.
877887
*

‎src/backend/utils/adt/pgstatfuncs.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,3 +2394,21 @@ pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
23942394
/* Returns the record as Datum */
23952395
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc,values,nulls)));
23962396
}
2397+
2398+
/*
2399+
* Checks for presence of stats for object with provided kind, database oid,
2400+
* object oid.
2401+
*
2402+
* This is useful for tests, but not really anything else. Therefore not
2403+
* documented.
2404+
*/
2405+
Datum
2406+
pg_stat_have_stats(PG_FUNCTION_ARGS)
2407+
{
2408+
char*stats_type=text_to_cstring(PG_GETARG_TEXT_P(0));
2409+
Oiddboid=PG_GETARG_OID(1);
2410+
Oidobjoid=PG_GETARG_OID(2);
2411+
PgStat_Kindkind=pgstat_get_kind_from_str(stats_type);
2412+
2413+
PG_RETURN_BOOL(pgstat_have_entry(kind,dboid,objoid));
2414+
}

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO202204072
56+
#defineCATALOG_VERSION_NO202204073
5757

5858
#endif

‎src/include/catalog/pg_proc.dat

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5376,6 +5376,12 @@
53765376
proargmodes => '{i,o,o,o,o,o,o,o,o,o,o}',
53775377
proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,total_txns,total_bytes,stats_reset}',
53785378
prosrc => 'pg_stat_get_replication_slot' },
5379+
5380+
{ oid => '8384', descr => 'statistics: check if a stats object exists',
5381+
proname => 'pg_stat_have_stats', provolatile => 'v', proparallel => 'r',
5382+
prorettype => 'bool', proargtypes => 'text oid oid',
5383+
prosrc => 'pg_stat_have_stats' },
5384+
53795385
{ oid => '8523', descr => 'statistics: information about subscription stats',
53805386
proname => 'pg_stat_get_subscription_stats',
53815387
provolatile => 's', proparallel => 'r',

‎src/include/pgstat.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@ extern TimestampTz pgstat_get_stat_snapshot_timestamp(bool *have_snapshot);
426426

427427
/* helpers */
428428
externPgStat_Kindpgstat_get_kind_from_str(char*kind_str);
429+
externboolpgstat_have_entry(PgStat_Kindkind,Oiddboid,Oidobjoid);
430+
429431

430432
/*
431433
* Functions in pgstat_archiver.c

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp