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

Commite8ea69e

Browse files
committed
Patch reverted because of random buildfarm failures:
---------------------------------------------------------------------------Delay write of pg_stats file to once every five minutes, duringshutdown, or when requested by a backend:It changes so the file is only written once every 5 minutes (changeableof course, I just picked something) instead of once every half second.It's still written when the stats collector shuts down, just as before.And it is now also written on backend request. A backend requests arewrite by simply sending a special stats message. It operates on theassumption that the backends aren't actually going to read thestatistics file very often, compared to how frequent it's written today.Magnus Hagander
1 parent63cb35c commite8ea69e

File tree

2 files changed

+14
-121
lines changed

2 files changed

+14
-121
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 12 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*Copyright (c) 2001-2006, PostgreSQL Global Development Group
1515
*
16-
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.126 2006/05/19 19:08:26 alvherre Exp $
16+
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.127 2006/05/30 02:35:39 momjian Exp $
1717
* ----------
1818
*/
1919
#include"postgres.h"
@@ -28,7 +28,6 @@
2828
#include<arpa/inet.h>
2929
#include<signal.h>
3030
#include<time.h>
31-
#include<sys/stat.h>
3231

3332
#include"pgstat.h"
3433

@@ -67,15 +66,12 @@
6766
* Timer definitions.
6867
* ----------
6968
*/
69+
#definePGSTAT_STAT_INTERVAL500/* How often to write the status file;
70+
* in milliseconds. */
7071

71-
/* How often to write the status file, in milliseconds. */
72-
#definePGSTAT_STAT_INTERVAL(5*60*1000)
73-
74-
/*
75-
*How often to attempt to restart a failed statistics collector; in ms.
76-
*Must be at least PGSTAT_STAT_INTERVAL.
77-
*/
78-
#definePGSTAT_RESTART_INTERVAL (5*60*1000)
72+
#definePGSTAT_RESTART_INTERVAL 60/* How often to attempt to restart a
73+
* failed statistics collector; in
74+
* seconds. */
7975

8076
/* ----------
8177
* Amount of space reserved in pgstat_recvbuffer().
@@ -176,12 +172,11 @@ static void pgstat_drop_database(Oid databaseid);
176172
staticvoidpgstat_write_statsfile(void);
177173
staticvoidpgstat_read_statsfile(HTAB**dbhash,Oidonlydb,
178174
PgStat_StatBeEntry**betab,
179-
int*numbackends,boolrewrite);
175+
int*numbackends);
180176
staticvoidbackend_read_statsfile(void);
181177

182178
staticvoidpgstat_setheader(PgStat_MsgHdr*hdr,StatMsgTypemtype);
183179
staticvoidpgstat_send(void*msg,intlen);
184-
staticvoidpgstat_send_rewrite(void);
185180

186181
staticvoidpgstat_recv_bestart(PgStat_MsgBestart*msg,intlen);
187182
staticvoidpgstat_recv_beterm(PgStat_MsgBeterm*msg,intlen);
@@ -1458,24 +1453,6 @@ pgstat_send(void *msg, int len)
14581453
#endif
14591454
}
14601455

1461-
/*
1462-
* pgstat_send_rewrite() -
1463-
*
1464-
*Send a command to the collector to rewrite the stats file.
1465-
* ----------
1466-
*/
1467-
staticvoid
1468-
pgstat_send_rewrite(void)
1469-
{
1470-
PgStat_MsgRewritemsg;
1471-
1472-
if (pgStatSock<0)
1473-
return;
1474-
1475-
pgstat_setheader(&msg.m_hdr,PGSTAT_MTYPE_REWRITE);
1476-
pgstat_send(&msg,sizeof(msg));
1477-
}
1478-
14791456

14801457
/* ----------
14811458
* PgstatBufferMain() -
@@ -1576,7 +1553,7 @@ PgstatCollectorMain(int argc, char *argv[])
15761553
fd_setrfds;
15771554
intreadPipe;
15781555
intlen=0;
1579-
structitimervaltimeout,canceltimeout;
1556+
structitimervaltimeout;
15801557
boolneed_timer= false;
15811558

15821559
MyProcPid=getpid();/* reset MyProcPid */
@@ -1631,15 +1608,12 @@ PgstatCollectorMain(int argc, char *argv[])
16311608
timeout.it_value.tv_sec=PGSTAT_STAT_INTERVAL /1000;
16321609
timeout.it_value.tv_usec=PGSTAT_STAT_INTERVAL %1000;
16331610

1634-
/* Values set to zero will cancel the active timer */
1635-
MemSet(&canceltimeout,0,sizeof(structitimerval));
1636-
16371611
/*
16381612
* Read in an existing statistics stats file or initialize the stats to
16391613
* zero.
16401614
*/
16411615
pgStatRunningInCollector= true;
1642-
pgstat_read_statsfile(&pgStatDBHash,InvalidOid,NULL,NULL, false);
1616+
pgstat_read_statsfile(&pgStatDBHash,InvalidOid,NULL,NULL);
16431617

16441618
/*
16451619
* Create the known backends table
@@ -1794,12 +1768,6 @@ PgstatCollectorMain(int argc, char *argv[])
17941768
pgstat_recv_analyze((PgStat_MsgAnalyze*)&msg,nread);
17951769
break;
17961770

1797-
casePGSTAT_MTYPE_REWRITE:
1798-
need_statwrite= true;
1799-
/* Disable the timer - it will be restarted on next data update */
1800-
setitimer(ITIMER_REAL,&canceltimeout,NULL);
1801-
break;
1802-
18031771
default:
18041772
break;
18051773
}
@@ -2380,7 +2348,7 @@ comparePids(const void *v1, const void *v2)
23802348
*/
23812349
staticvoid
23822350
pgstat_read_statsfile(HTAB**dbhash,Oidonlydb,
2383-
PgStat_StatBeEntry**betab,int*numbackends,boolrewrite)
2351+
PgStat_StatBeEntry**betab,int*numbackends)
23842352
{
23852353
PgStat_StatDBEntry*dbentry;
23862354
PgStat_StatDBEntrydbbuf;
@@ -2399,71 +2367,6 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
23992367
MemoryContextuse_mcxt;
24002368
intmcxt_flags;
24012369

2402-
2403-
if (rewrite)
2404-
{
2405-
/*
2406-
* To force a rewrite of the stats file from the collector, send
2407-
* a REWRITE message to the stats collector. Then wait for the file
2408-
* to change. On Unix, we wait for the inode to change (as the file
2409-
* is renamed into place from a different file). Win32 has no concept
2410-
* of inodes, so we wait for the date on the file to change instead.
2411-
* We can do this on win32 because we have high-res timing on the
2412-
* file dates, but we can't on unix, because it has 1sec resolution
2413-
* on the fields in struct stat.
2414-
*/
2415-
inti;
2416-
#ifndefWIN32
2417-
structstatst1,st2;
2418-
2419-
if (stat(PGSTAT_STAT_FILENAME,&st1))
2420-
{
2421-
/* Assume no file there yet */
2422-
st1.st_ino=0;
2423-
}
2424-
st2.st_ino=0;
2425-
#else
2426-
WIN32_FILE_ATTRIBUTE_DATAfd1,fd2;
2427-
2428-
if (!GetFileAttributesEx(PGSTAT_STAT_FILENAME,GetFileExInfoStandard,&fd1))
2429-
{
2430-
fd1.ftLastWriteTime.dwLowDateTime=0;
2431-
fd1.ftLastWriteTime.dwHighDateTime=0;
2432-
}
2433-
fd2.ftLastWriteTime.dwLowDateTime=0;
2434-
fd2.ftLastWriteTime.dwHighDateTime=0;
2435-
#endif
2436-
2437-
2438-
/* Send rewrite message */
2439-
pgstat_send_rewrite();
2440-
2441-
/* Now wait for the file to change */
2442-
for (i=0;i<50;i++)
2443-
{
2444-
#ifndefWIN32
2445-
if (!stat(PGSTAT_STAT_FILENAME,&st2))
2446-
{
2447-
if (st2.st_ino!=st1.st_ino)
2448-
break;
2449-
}
2450-
#else
2451-
if (GetFileAttributesEx(PGSTAT_STAT_FILENAME,GetFileExInfoStandard,&fd2))
2452-
{
2453-
if (fd1.ftLastWriteTime.dwLowDateTime!=fd2.ftLastWriteTime.dwLowDateTime||
2454-
fd1.ftLastWriteTime.dwHighDateTime!=fd2.ftLastWriteTime.dwHighDateTime)
2455-
break;
2456-
}
2457-
#endif
2458-
2459-
pg_usleep(50000);
2460-
}
2461-
if (i >=50)
2462-
ereport(WARNING,
2463-
(errmsg("pgstat update timeout")));
2464-
/* Fallthrough and read the old file anyway - old data better than no data */
2465-
}
2466-
24672370
/*
24682371
* If running in the collector or the autovacuum process, we use the
24692372
* DynaHashCxt memory context.If running in a backend, we use the
@@ -2782,7 +2685,7 @@ backend_read_statsfile(void)
27822685
return;
27832686
Assert(!pgStatRunningInCollector);
27842687
pgstat_read_statsfile(&pgStatDBHash,InvalidOid,
2785-
&pgStatBeTable,&pgStatNumBackends, true);
2688+
&pgStatBeTable,&pgStatNumBackends);
27862689
}
27872690
else
27882691
{
@@ -2792,7 +2695,7 @@ backend_read_statsfile(void)
27922695
{
27932696
Assert(!pgStatRunningInCollector);
27942697
pgstat_read_statsfile(&pgStatDBHash,MyDatabaseId,
2795-
&pgStatBeTable,&pgStatNumBackends, true);
2698+
&pgStatBeTable,&pgStatNumBackends);
27962699
pgStatDBHashXact=topXid;
27972700
}
27982701
}

‎src/include/pgstat.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*Copyright (c) 2001-2006, PostgreSQL Global Development Group
77
*
8-
*$PostgreSQL: pgsql/src/include/pgstat.h,v 1.45 2006/05/19 19:08:26 alvherre Exp $
8+
*$PostgreSQL: pgsql/src/include/pgstat.h,v 1.46 2006/05/30 02:35:39 momjian Exp $
99
* ----------
1010
*/
1111
#ifndefPGSTAT_H
@@ -32,8 +32,7 @@ typedef enum StatMsgType
3232
PGSTAT_MTYPE_RESETCOUNTER,
3333
PGSTAT_MTYPE_AUTOVAC_START,
3434
PGSTAT_MTYPE_VACUUM,
35-
PGSTAT_MTYPE_ANALYZE,
36-
PGSTAT_MTYPE_REWRITE
35+
PGSTAT_MTYPE_ANALYZE
3736
}StatMsgType;
3837

3938
/* ----------
@@ -108,15 +107,6 @@ typedef struct PgStat_MsgDummy
108107
charm_dummy[512];
109108
}PgStat_MsgDummy;
110109

111-
/* ----------
112-
* PgStat_MsgRewrite Sent by backends to cause a rewrite of the stats file
113-
* ----------
114-
*/
115-
typedefstructPgstat_MsgRewrite
116-
{
117-
PgStat_MsgHdrm_hdr;
118-
}PgStat_MsgRewrite;
119-
120110
/* ----------
121111
* PgStat_MsgBestartSent by the backend on startup
122112
* ----------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp