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

Commit89c546c

Browse files
committed
pgstat: split relation, database handling out of pgstat_report_stat().
pgstat_report_stat() handles several types of stats, yet relation stats haveso far been handled directly in pgstat_report_stat().A later commit will move the handling of the different kinds of stats intoseparate files. By splitting out relation handling in this commit that latermove will just move code around without other changes.Author: Andres Freund <andres@anarazel.de>Discussion:https://postgr.es/m/20220303021600.hs34ghqcw6zcokdh@alap3.anarazel.de
1 parenta3a75b9 commit89c546c

File tree

1 file changed

+56
-23
lines changed

1 file changed

+56
-23
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,12 @@ static HTAB *pgStatTabHash = NULL;
222222
*/
223223
staticHTAB*pgStatFunctions=NULL;
224224

225+
/*
226+
* Indicates if backend has some relation stats that it hasn't yet
227+
* sent to the collector.
228+
*/
229+
staticboolhave_relation_stats= false;
230+
225231
/*
226232
* Indicates if backend has some function stats that it hasn't yet
227233
* sent to the collector.
@@ -338,7 +344,9 @@ static bool pgstat_db_requested(Oid databaseid);
338344
staticPgStat_StatReplSlotEntry*pgstat_get_replslot_entry(NameDataname,boolcreate_it);
339345
staticvoidpgstat_reset_replslot(PgStat_StatReplSlotEntry*slotstats,TimestampTzts);
340346

347+
staticvoidpgstat_send_tabstats(TimestampTznow,booldisconnect);
341348
staticvoidpgstat_send_tabstat(PgStat_MsgTabstat*tsmsg,TimestampTznow);
349+
staticvoidpgstat_update_dbstats(PgStat_MsgTabstat*tsmsg,TimestampTznow);
342350
staticvoidpgstat_send_funcstats(void);
343351
staticvoidpgstat_send_slru(void);
344352
staticHTAB*pgstat_collect_oids(Oidcatalogid,AttrNumberanum_oid);
@@ -866,15 +874,9 @@ allow_immediate_pgstat_restart(void)
866874
void
867875
pgstat_report_stat(booldisconnect)
868876
{
869-
/* we assume this inits to all zeroes: */
870-
staticconstPgStat_TableCountsall_zeroes;
871877
staticTimestampTzlast_report=0;
872878

873879
TimestampTznow;
874-
PgStat_MsgTabstatregular_msg;
875-
PgStat_MsgTabstatshared_msg;
876-
TabStatusArray*tsa;
877-
inti;
878880

879881
pgstat_assert_is_up();
880882

@@ -887,7 +889,7 @@ pgstat_report_stat(bool disconnect)
887889
* generates no WAL records can write or sync WAL data when flushing the
888890
* data pages.
889891
*/
890-
if ((pgStatTabList==NULL||pgStatTabList->tsa_used==0)&&
892+
if (!have_relation_stats&&
891893
pgStatXactCommit==0&&pgStatXactRollback==0&&
892894
pgWalUsage.wal_records==prevWalUsage.wal_records&&
893895
WalStats.m_wal_write==0&&WalStats.m_wal_sync==0&&
@@ -908,6 +910,32 @@ pgstat_report_stat(bool disconnect)
908910
if (disconnect)
909911
pgstat_report_disconnect(MyDatabaseId);
910912

913+
/* First, send relation statistics */
914+
pgstat_send_tabstats(now,disconnect);
915+
916+
/* Now, send function statistics */
917+
pgstat_send_funcstats();
918+
919+
/* Send WAL statistics */
920+
pgstat_send_wal(true);
921+
922+
/* Finally send SLRU statistics */
923+
pgstat_send_slru();
924+
}
925+
926+
/*
927+
* Subroutine for pgstat_report_stat: Send relation statistics
928+
*/
929+
staticvoid
930+
pgstat_send_tabstats(TimestampTznow,booldisconnect)
931+
{
932+
/* we assume this inits to all zeroes: */
933+
staticconstPgStat_TableCountsall_zeroes;
934+
PgStat_MsgTabstatregular_msg;
935+
PgStat_MsgTabstatshared_msg;
936+
TabStatusArray*tsa;
937+
inti;
938+
911939
/*
912940
* Destroy pgStatTabHash before we start invalidating PgStat_TableEntry
913941
* entries it points to. (Should we fail partway through the loop below,
@@ -980,18 +1008,11 @@ pgstat_report_stat(bool disconnect)
9801008
if (shared_msg.m_nentries>0)
9811009
pgstat_send_tabstat(&shared_msg,now);
9821010

983-
/* Now, send function statistics */
984-
pgstat_send_funcstats();
985-
986-
/* Send WAL statistics */
987-
pgstat_send_wal(true);
988-
989-
/* Finally send SLRU statistics */
990-
pgstat_send_slru();
1011+
have_relation_stats= false;
9911012
}
9921013

9931014
/*
994-
* Subroutine forpgstat_report_stat: finish and senda tabstat message
1015+
* Subroutine forpgstat_send_tabstats: finish and sendone tabstat message
9951016
*/
9961017
staticvoid
9971018
pgstat_send_tabstat(PgStat_MsgTabstat*tsmsg,TimestampTznow)
@@ -1007,6 +1028,23 @@ pgstat_send_tabstat(PgStat_MsgTabstat *tsmsg, TimestampTz now)
10071028
* Report and reset accumulated xact commit/rollback and I/O timings
10081029
* whenever we send a normal tabstat message
10091030
*/
1031+
pgstat_update_dbstats(tsmsg,now);
1032+
1033+
n=tsmsg->m_nentries;
1034+
len= offsetof(PgStat_MsgTabstat,m_entry[0])+
1035+
n*sizeof(PgStat_TableEntry);
1036+
1037+
pgstat_setheader(&tsmsg->m_hdr,PGSTAT_MTYPE_TABSTAT);
1038+
pgstat_send(tsmsg,len);
1039+
}
1040+
1041+
/*
1042+
* Subroutine for pgstat_send_tabstat: Handle xact commit/rollback and I/O
1043+
* timings.
1044+
*/
1045+
staticvoid
1046+
pgstat_update_dbstats(PgStat_MsgTabstat*tsmsg,TimestampTznow)
1047+
{
10101048
if (OidIsValid(tsmsg->m_databaseid))
10111049
{
10121050
tsmsg->m_xact_commit=pgStatXactCommit;
@@ -1052,13 +1090,6 @@ pgstat_send_tabstat(PgStat_MsgTabstat *tsmsg, TimestampTz now)
10521090
tsmsg->m_active_time=0;
10531091
tsmsg->m_idle_in_xact_time=0;
10541092
}
1055-
1056-
n=tsmsg->m_nentries;
1057-
len= offsetof(PgStat_MsgTabstat,m_entry[0])+
1058-
n*sizeof(PgStat_TableEntry);
1059-
1060-
pgstat_setheader(&tsmsg->m_hdr,PGSTAT_MTYPE_TABSTAT);
1061-
pgstat_send(tsmsg,len);
10621093
}
10631094

10641095
/*
@@ -2179,6 +2210,8 @@ get_tabstat_entry(Oid rel_id, bool isshared)
21792210

21802211
pgstat_assert_is_up();
21812212

2213+
have_relation_stats= true;
2214+
21822215
/*
21832216
* Create hash table if we don't have it already.
21842217
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp