Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
7e40cdc0
Commit
7e40cdc0
authored
Jan 19, 2010
by
Magnus Hagander
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add pg_stat_reset_shared('bgwriter') to reset the cluster-wide shared
statistics of the bgwriter. Greg Smith
parent
4f15699d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
111 additions
and
7 deletions
+111
-7
doc/src/sgml/monitoring.sgml
doc/src/sgml/monitoring.sgml
+12
-1
src/backend/postmaster/pgstat.c
src/backend/postmaster/pgstat.c
+61
-1
src/backend/utils/adt/pgstatfuncs.c
src/backend/utils/adt/pgstatfuncs.c
+13
-1
src/include/catalog/catversion.h
src/include/catalog/catversion.h
+2
-2
src/include/catalog/pg_proc.h
src/include/catalog/pg_proc.h
+3
-1
src/include/pgstat.h
src/include/pgstat.h
+20
-1
No files found.
doc/src/sgml/monitoring.sgml
View file @
7e40cdc0
<!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.7
3 2009/11/29 18:14:30 tgl
Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.7
4 2010/01/19 14:11:30 mha
Exp $ -->
<chapter id="monitoring">
<chapter id="monitoring">
<title>Monitoring Database Activity</title>
<title>Monitoring Database Activity</title>
...
@@ -918,6 +918,17 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
...
@@ -918,6 +918,17 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
(requires superuser privileges)
(requires superuser privileges)
</entry>
</entry>
</row>
</row>
<row>
<entry><literal><function>pg_stat_reset_shared</function>(text)</literal></entry>
<entry><type>void</type></entry>
<entry>
Reset some of the shared statistics counters for the database cluster to
zero (requires superuser privileges). Calling
<literal>pg_stat_reset_shared('bgwriter')</> will zero all the values shown by
<structname>pg_stat_bgwriter</>.
</entry>
</row>
</tbody>
</tbody>
</tgroup>
</tgroup>
</table>
</table>
...
...
src/backend/postmaster/pgstat.c
View file @
7e40cdc0
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
*
*
* Copyright (c) 2001-2010, PostgreSQL Global Development Group
* Copyright (c) 2001-2010, PostgreSQL Global Development Group
*
*
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.19
7 2010/01/10 14:16:07
mha Exp $
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.19
8 2010/01/19 14:11:30
mha Exp $
* ----------
* ----------
*/
*/
#include "postgres.h"
#include "postgres.h"
...
@@ -270,6 +270,7 @@ static void pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len);
...
@@ -270,6 +270,7 @@ static void pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len);
static
void
pgstat_recv_tabpurge
(
PgStat_MsgTabpurge
*
msg
,
int
len
);
static
void
pgstat_recv_tabpurge
(
PgStat_MsgTabpurge
*
msg
,
int
len
);
static
void
pgstat_recv_dropdb
(
PgStat_MsgDropdb
*
msg
,
int
len
);
static
void
pgstat_recv_dropdb
(
PgStat_MsgDropdb
*
msg
,
int
len
);
static
void
pgstat_recv_resetcounter
(
PgStat_MsgResetcounter
*
msg
,
int
len
);
static
void
pgstat_recv_resetcounter
(
PgStat_MsgResetcounter
*
msg
,
int
len
);
static
void
pgstat_recv_resetsharedcounter
(
PgStat_MsgResetsharedcounter
*
msg
,
int
len
);
static
void
pgstat_recv_autovac
(
PgStat_MsgAutovacStart
*
msg
,
int
len
);
static
void
pgstat_recv_autovac
(
PgStat_MsgAutovacStart
*
msg
,
int
len
);
static
void
pgstat_recv_vacuum
(
PgStat_MsgVacuum
*
msg
,
int
len
);
static
void
pgstat_recv_vacuum
(
PgStat_MsgVacuum
*
msg
,
int
len
);
static
void
pgstat_recv_analyze
(
PgStat_MsgAnalyze
*
msg
,
int
len
);
static
void
pgstat_recv_analyze
(
PgStat_MsgAnalyze
*
msg
,
int
len
);
...
@@ -1153,6 +1154,38 @@ pgstat_reset_counters(void)
...
@@ -1153,6 +1154,38 @@ pgstat_reset_counters(void)
pgstat_send
(
&
msg
,
sizeof
(
msg
));
pgstat_send
(
&
msg
,
sizeof
(
msg
));
}
}
/* ----------
* pgstat_reset_shared_counters() -
*
* Tell the statistics collector to reset cluster-wide shared counters.
* ----------
*/
void
pgstat_reset_shared_counters
(
const
char
*
target
)
{
PgStat_MsgResetsharedcounter
msg
;
if
(
pgStatSock
<
0
)
return
;
if
(
!
superuser
())
ereport
(
ERROR
,
(
errcode
(
ERRCODE_INSUFFICIENT_PRIVILEGE
),
errmsg
(
"must be superuser to reset statistics counters"
)));
if
(
strcmp
(
target
,
"bgwriter"
)
==
0
)
msg
.
m_resettarget
=
RESET_BGWRITER
;
else
{
ereport
(
ERROR
,
(
errcode
(
ERRCODE_SYNTAX_ERROR
),
errmsg
(
"unrecognized reset target: '%s'"
,
target
),
errhint
(
"allowed targets are 'bgwriter'."
)));
}
pgstat_setheader
(
&
msg
.
m_hdr
,
PGSTAT_MTYPE_RESETSHAREDCOUNTER
);
pgstat_send
(
&
msg
,
sizeof
(
msg
));
}
/* ----------
/* ----------
* pgstat_report_autovac() -
* pgstat_report_autovac() -
...
@@ -2915,6 +2948,12 @@ PgstatCollectorMain(int argc, char *argv[])
...
@@ -2915,6 +2948,12 @@ PgstatCollectorMain(int argc, char *argv[])
len
);
len
);
break
;
break
;
case
PGSTAT_MTYPE_RESETSHAREDCOUNTER
:
pgstat_recv_resetsharedcounter
(
(
PgStat_MsgResetsharedcounter
*
)
&
msg
,
len
);
break
;
case
PGSTAT_MTYPE_AUTOVAC_START
:
case
PGSTAT_MTYPE_AUTOVAC_START
:
pgstat_recv_autovac
((
PgStat_MsgAutovacStart
*
)
&
msg
,
len
);
pgstat_recv_autovac
((
PgStat_MsgAutovacStart
*
)
&
msg
,
len
);
break
;
break
;
...
@@ -3868,6 +3907,27 @@ pgstat_recv_resetcounter(PgStat_MsgResetcounter *msg, int len)
...
@@ -3868,6 +3907,27 @@ pgstat_recv_resetcounter(PgStat_MsgResetcounter *msg, int len)
HASH_ELEM
|
HASH_FUNCTION
);
HASH_ELEM
|
HASH_FUNCTION
);
}
}
/* ----------
* pgstat_recv_resetshared() -
*
* Reset some shared statistics of the cluster.
* ----------
*/
static
void
pgstat_recv_resetsharedcounter
(
PgStat_MsgResetsharedcounter
*
msg
,
int
len
)
{
if
(
msg
->
m_resettarget
==
RESET_BGWRITER
)
{
/* Reset the global background writer statistics for the cluster. */
memset
(
&
globalStats
,
0
,
sizeof
(
globalStats
));
}
/*
* Presumably the sender of this message validated the target, don't
* complain here if it's not valid
*/
}
/* ----------
/* ----------
* pgstat_recv_autovac() -
* pgstat_recv_autovac() -
*
*
...
...
src/backend/utils/adt/pgstatfuncs.c
View file @
7e40cdc0
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.5
7 2010/01/02 16:57:54 momjian
Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.5
8 2010/01/19 14:11:31 mha
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -78,6 +78,7 @@ extern Datum pg_stat_get_buf_alloc(PG_FUNCTION_ARGS);
...
@@ -78,6 +78,7 @@ extern Datum pg_stat_get_buf_alloc(PG_FUNCTION_ARGS);
extern
Datum
pg_stat_clear_snapshot
(
PG_FUNCTION_ARGS
);
extern
Datum
pg_stat_clear_snapshot
(
PG_FUNCTION_ARGS
);
extern
Datum
pg_stat_reset
(
PG_FUNCTION_ARGS
);
extern
Datum
pg_stat_reset
(
PG_FUNCTION_ARGS
);
extern
Datum
pg_stat_reset_shared
(
PG_FUNCTION_ARGS
);
/* Global bgwriter statistics, from bgwriter.c */
/* Global bgwriter statistics, from bgwriter.c */
extern
PgStat_MsgBgWriter
bgwriterStats
;
extern
PgStat_MsgBgWriter
bgwriterStats
;
...
@@ -1108,3 +1109,14 @@ pg_stat_reset(PG_FUNCTION_ARGS)
...
@@ -1108,3 +1109,14 @@ pg_stat_reset(PG_FUNCTION_ARGS)
PG_RETURN_VOID
();
PG_RETURN_VOID
();
}
}
/* Reset some shared cluster-wide counters */
Datum
pg_stat_reset_shared
(
PG_FUNCTION_ARGS
)
{
char
*
target
=
text_to_cstring
(
PG_GETARG_TEXT_PP
(
0
));
pgstat_reset_shared_counters
(
target
);
PG_RETURN_VOID
();
}
src/include/catalog/catversion.h
View file @
7e40cdc0
...
@@ -37,7 +37,7 @@
...
@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.57
5 2010/01/19 05:50:18 tgl
Exp $
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.57
6 2010/01/19 14:11:32 mha
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -53,6 +53,6 @@
...
@@ -53,6 +53,6 @@
*/
*/
/* yyyymmddN */
/* yyyymmddN */
#define CATALOG_VERSION_NO 2010011
8
1
#define CATALOG_VERSION_NO 2010011
9
1
#endif
#endif
src/include/catalog/pg_proc.h
View file @
7e40cdc0
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.56
3 2010/01/19 05:50:18 tgl
Exp $
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.56
4 2010/01/19 14:11:32 mha
Exp $
*
*
* NOTES
* NOTES
* The script catalog/genbki.pl reads this file and generates .bki
* The script catalog/genbki.pl reads this file and generates .bki
...
@@ -3073,6 +3073,8 @@ DATA(insert OID = 2230 ( pg_stat_clear_snapshot PGNSP PGUID 12 1 0 0 f f f f f
...
@@ -3073,6 +3073,8 @@ DATA(insert OID = 2230 ( pg_stat_clear_snapshot PGNSP PGUID 12 1 0 0 f f f f f
DESCR
(
"statistics: discard current transaction's statistics snapshot"
);
DESCR
(
"statistics: discard current transaction's statistics snapshot"
);
DATA
(
insert
OID
=
2274
(
pg_stat_reset
PGNSP
PGUID
12
1
0
0
f
f
f
f
f
v
0
0
2278
""
_null_
_null_
_null_
_null_
pg_stat_reset
_null_
_null_
_null_
));
DATA
(
insert
OID
=
2274
(
pg_stat_reset
PGNSP
PGUID
12
1
0
0
f
f
f
f
f
v
0
0
2278
""
_null_
_null_
_null_
_null_
pg_stat_reset
_null_
_null_
_null_
));
DESCR
(
"statistics: reset collected statistics for current database"
);
DESCR
(
"statistics: reset collected statistics for current database"
);
DATA
(
insert
OID
=
3775
(
pg_stat_reset_shared
PGNSP
PGUID
12
1
0
0
f
f
f
f
f
v
1
0
2278
"25"
_null_
_null_
_null_
_null_
pg_stat_reset_shared
_null_
_null_
_null_
));
DESCR
(
"statistics: reset collected statistics shared across the cluster"
);
DATA
(
insert
OID
=
1946
(
encode
PGNSP
PGUID
12
1
0
0
f
f
f
t
f
i
2
0
25
"17 25"
_null_
_null_
_null_
_null_
binary_encode
_null_
_null_
_null_
));
DATA
(
insert
OID
=
1946
(
encode
PGNSP
PGUID
12
1
0
0
f
f
f
t
f
i
2
0
25
"17 25"
_null_
_null_
_null_
_null_
binary_encode
_null_
_null_
_null_
));
DESCR
(
"convert bytea value into some ascii-only text string"
);
DESCR
(
"convert bytea value into some ascii-only text string"
);
...
...
src/include/pgstat.h
View file @
7e40cdc0
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
*
*
* Copyright (c) 2001-2010, PostgreSQL Global Development Group
* Copyright (c) 2001-2010, PostgreSQL Global Development Group
*
*
* $PostgreSQL: pgsql/src/include/pgstat.h,v 1.8
6 2010/01/02 16:58:00 momjian
Exp $
* $PostgreSQL: pgsql/src/include/pgstat.h,v 1.8
7 2010/01/19 14:11:31 mha
Exp $
* ----------
* ----------
*/
*/
#ifndef PGSTAT_H
#ifndef PGSTAT_H
...
@@ -38,6 +38,7 @@ typedef enum StatMsgType
...
@@ -38,6 +38,7 @@ typedef enum StatMsgType
PGSTAT_MTYPE_TABPURGE
,
PGSTAT_MTYPE_TABPURGE
,
PGSTAT_MTYPE_DROPDB
,
PGSTAT_MTYPE_DROPDB
,
PGSTAT_MTYPE_RESETCOUNTER
,
PGSTAT_MTYPE_RESETCOUNTER
,
PGSTAT_MTYPE_RESETSHAREDCOUNTER
,
PGSTAT_MTYPE_AUTOVAC_START
,
PGSTAT_MTYPE_AUTOVAC_START
,
PGSTAT_MTYPE_VACUUM
,
PGSTAT_MTYPE_VACUUM
,
PGSTAT_MTYPE_ANALYZE
,
PGSTAT_MTYPE_ANALYZE
,
...
@@ -93,6 +94,12 @@ typedef struct PgStat_TableCounts
...
@@ -93,6 +94,12 @@ typedef struct PgStat_TableCounts
PgStat_Counter
t_blocks_hit
;
PgStat_Counter
t_blocks_hit
;
}
PgStat_TableCounts
;
}
PgStat_TableCounts
;
/* Possible targets for resetting cluster-wide shared values */
typedef
enum
PgStat_Shared_Reset_Target
{
RESET_BGWRITER
}
PgStat_Shared_Reset_Target
;
/* ------------------------------------------------------------
/* ------------------------------------------------------------
* Structures kept in backend local memory while accumulating counts
* Structures kept in backend local memory while accumulating counts
...
@@ -260,6 +267,16 @@ typedef struct PgStat_MsgResetcounter
...
@@ -260,6 +267,16 @@ typedef struct PgStat_MsgResetcounter
Oid
m_databaseid
;
Oid
m_databaseid
;
}
PgStat_MsgResetcounter
;
}
PgStat_MsgResetcounter
;
/* ----------
* PgStat_MsgResetsharedcounter Sent by the backend to tell the collector
* to reset a shared counter
* ----------
*/
typedef
struct
PgStat_MsgResetsharedcounter
{
PgStat_MsgHdr
m_hdr
;
PgStat_Shared_Reset_Target
m_resettarget
;
}
PgStat_MsgResetsharedcounter
;
/* ----------
/* ----------
* PgStat_MsgAutovacStart Sent by the autovacuum daemon to signal
* PgStat_MsgAutovacStart Sent by the autovacuum daemon to signal
...
@@ -414,6 +431,7 @@ typedef union PgStat_Msg
...
@@ -414,6 +431,7 @@ typedef union PgStat_Msg
PgStat_MsgTabpurge
msg_tabpurge
;
PgStat_MsgTabpurge
msg_tabpurge
;
PgStat_MsgDropdb
msg_dropdb
;
PgStat_MsgDropdb
msg_dropdb
;
PgStat_MsgResetcounter
msg_resetcounter
;
PgStat_MsgResetcounter
msg_resetcounter
;
PgStat_MsgResetsharedcounter
msg_resetsharedcounter
;
PgStat_MsgAutovacStart
msg_autovacuum
;
PgStat_MsgAutovacStart
msg_autovacuum
;
PgStat_MsgVacuum
msg_vacuum
;
PgStat_MsgVacuum
msg_vacuum
;
PgStat_MsgAnalyze
msg_analyze
;
PgStat_MsgAnalyze
msg_analyze
;
...
@@ -635,6 +653,7 @@ extern void pgstat_drop_database(Oid databaseid);
...
@@ -635,6 +653,7 @@ extern void pgstat_drop_database(Oid databaseid);
extern
void
pgstat_clear_snapshot
(
void
);
extern
void
pgstat_clear_snapshot
(
void
);
extern
void
pgstat_reset_counters
(
void
);
extern
void
pgstat_reset_counters
(
void
);
extern
void
pgstat_reset_shared_counters
(
const
char
*
);
extern
void
pgstat_report_autovac
(
Oid
dboid
);
extern
void
pgstat_report_autovac
(
Oid
dboid
);
extern
void
pgstat_report_vacuum
(
Oid
tableoid
,
bool
shared
,
bool
adopt_counts
,
extern
void
pgstat_report_vacuum
(
Oid
tableoid
,
bool
shared
,
bool
adopt_counts
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment