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

Commitad8753a

Browse files
committed
Fix pg_stat_reset_single_table_counters() for shared relations
This commit fixes the function of $subject for shared relations. Thisfeature has been added bye042678. Unfortunately, this new behavior gotremoved by5891c7a when moving statistics to shared memory.Reported-by: Mitsuru HinataAuthor: Masahiro IkedaReviewed-by: Kyotaro Horiguchi, Masahiko SawadaDiscussion:https://postgr.es/m/7cc69f863d9b1bc677544e3accd0e4b4@oss.nttdata.comBackpatch-through: 15
1 parent62017cb commitad8753a

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include"access/htup_details.h"
1818
#include"access/xlog.h"
1919
#include"access/xlogprefetcher.h"
20+
#include"catalog/catalog.h"
2021
#include"catalog/pg_authid.h"
2122
#include"catalog/pg_type.h"
2223
#include"common/ip.h"
@@ -2117,13 +2118,17 @@ pg_stat_reset_shared(PG_FUNCTION_ARGS)
21172118
PG_RETURN_VOID();
21182119
}
21192120

2120-
/* Reset a single counter in the current database */
2121+
/*
2122+
* Reset a statistics for a single object, which may be of current
2123+
* database or shared across all databases in the cluster.
2124+
*/
21212125
Datum
21222126
pg_stat_reset_single_table_counters(PG_FUNCTION_ARGS)
21232127
{
21242128
Oidtaboid=PG_GETARG_OID(0);
2129+
Oiddboid= (IsSharedRelation(taboid) ?InvalidOid :MyDatabaseId);
21252130

2126-
pgstat_reset(PGSTAT_KIND_RELATION,MyDatabaseId,taboid);
2131+
pgstat_reset(PGSTAT_KIND_RELATION,dboid,taboid);
21272132

21282133
PG_RETURN_VOID();
21292134
}

‎src/test/regress/expected/stats.out

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,52 @@ SELECT pg_stat_get_live_tuples(:drop_stats_test_subxact_oid);
557557
DROP TABLE trunc_stats_test, trunc_stats_test1, trunc_stats_test2, trunc_stats_test3, trunc_stats_test4;
558558
DROP TABLE prevstats;
559559
-----
560+
-- Test reset of some stats for shared table
561+
-----
562+
-- This updates the comment of the database currently in use in
563+
-- pg_shdescription with a fake value, then sets it back to its
564+
-- original value.
565+
SELECT shobj_description(d.oid, 'pg_database') as description_before
566+
FROM pg_database d WHERE datname = current_database() \gset
567+
-- force some stats in pg_shdescription.
568+
BEGIN;
569+
SELECT current_database() as datname \gset
570+
COMMENT ON DATABASE :"datname" IS 'This is a test comment';
571+
SELECT pg_stat_force_next_flush();
572+
pg_stat_force_next_flush
573+
--------------------------
574+
575+
(1 row)
576+
577+
COMMIT;
578+
-- check that the stats are reset.
579+
SELECT (n_tup_ins + n_tup_upd) > 0 AS has_data FROM pg_stat_all_tables
580+
WHERE relid = 'pg_shdescription'::regclass;
581+
has_data
582+
----------
583+
t
584+
(1 row)
585+
586+
SELECT pg_stat_reset_single_table_counters('pg_shdescription'::regclass);
587+
pg_stat_reset_single_table_counters
588+
-------------------------------------
589+
590+
(1 row)
591+
592+
SELECT (n_tup_ins + n_tup_upd) > 0 AS has_data FROM pg_stat_all_tables
593+
WHERE relid = 'pg_shdescription'::regclass;
594+
has_data
595+
----------
596+
f
597+
(1 row)
598+
599+
-- set back comment
600+
\if :{?description_before}
601+
COMMENT ON DATABASE :"datname" IS :'description_before';
602+
\else
603+
COMMENT ON DATABASE :"datname" IS NULL;
604+
\endif
605+
-----
560606
-- Test that various stats views are being properly populated
561607
-----
562608
-- Test that sessions is incremented when a new session is started in pg_stat_database

‎src/test/regress/sql/stats.sql

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,36 @@ SELECT pg_stat_get_live_tuples(:drop_stats_test_subxact_oid);
289289
DROPTABLE trunc_stats_test, trunc_stats_test1, trunc_stats_test2, trunc_stats_test3, trunc_stats_test4;
290290
DROPTABLE prevstats;
291291

292+
-----
293+
-- Test reset of some stats for shared table
294+
-----
295+
296+
-- This updates the comment of the database currently in use in
297+
-- pg_shdescription with a fake value, then sets it back to its
298+
-- original value.
299+
SELECT shobj_description(d.oid,'pg_database')as description_before
300+
FROM pg_database dWHERE datname= current_database() \gset
301+
302+
-- force some stats in pg_shdescription.
303+
BEGIN;
304+
SELECT current_database()as datname \gset
305+
COMMENT ON DATABASE :"datname" IS'This is a test comment';
306+
SELECT pg_stat_force_next_flush();
307+
COMMIT;
308+
309+
-- check that the stats are reset.
310+
SELECT (n_tup_ins+ n_tup_upd)>0AS has_dataFROM pg_stat_all_tables
311+
WHERE relid='pg_shdescription'::regclass;
312+
SELECT pg_stat_reset_single_table_counters('pg_shdescription'::regclass);
313+
SELECT (n_tup_ins+ n_tup_upd)>0AS has_dataFROM pg_stat_all_tables
314+
WHERE relid='pg_shdescription'::regclass;
315+
316+
-- set back comment
317+
\if :{?description_before}
318+
COMMENT ON DATABASE :"datname" IS:'description_before';
319+
\else
320+
COMMENT ON DATABASE :"datname" ISNULL;
321+
\endif
292322

293323
-----
294324
-- Test that various stats views are being properly populated

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp