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

Commitb0e3dd7

Browse files
committed
Adjust Windows autovacuum service to retry for up to 5 minutes waiting
for the postmaster to start. Dave Page
1 parentbf7737a commitb0e3dd7

File tree

1 file changed

+50
-23
lines changed

1 file changed

+50
-23
lines changed

‎contrib/pg_autovacuum/pg_autovacuum.c

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Revisions by Christopher B. Browne, Liberty RMS
55
* Win32 Service code added by Dave Page
66
*
7-
* $PostgreSQL: pgsql/contrib/pg_autovacuum/pg_autovacuum.c,v 1.28 2005/01/24 00:13:38 neilc Exp $
7+
* $PostgreSQL: pgsql/contrib/pg_autovacuum/pg_autovacuum.c,v 1.29 2005/01/26 22:25:13 tgl Exp $
88
*/
99

1010
#include"postgres_fe.h"
@@ -90,7 +90,7 @@ log_entry(const char *logentry, int level)
9090
{
9191
/*
9292
* Note: Under Windows we dump the log entries to the normal
93-
* stderr/logfile as well, otherwise it can be a pain to debug
93+
* stderr/logfile as well, otherwise it can be a pain to debug
9494
* service install failures etc.
9595
*/
9696

@@ -556,6 +556,9 @@ init_db_list(void)
556556
Dllist*db_list=DLNewList();
557557
db_info*dbs=NULL;
558558
PGresult*res=NULL;
559+
#ifdefWIN32
560+
intk=0;
561+
#endif
559562

560563
DLAddHead(db_list,DLNewElem(init_dbinfo((char*)"template1",0,0)));
561564
if (DLGetHead(db_list)==NULL)
@@ -572,6 +575,30 @@ init_db_list(void)
572575
dbs= ((db_info*)DLE_VAL(DLGetHead(db_list)));
573576
dbs->conn=db_connect(dbs);
574577

578+
#ifdefWIN32
579+
while (dbs->conn==NULL&& !appMode&&k<10)
580+
{
581+
intj;
582+
583+
/* Pause for 30 seconds to allow the database to start up */
584+
log_entry("Pausing 30 seconds to allow the database to startup completely",LVL_INFO);
585+
fflush(LOGOUTPUT);
586+
ServiceStatus.dwWaitHint=10;
587+
for (j=0;j<6;j++)
588+
{
589+
pg_usleep(5000000);
590+
ServiceStatus.dwCheckPoint++;
591+
SetServiceStatus(hStatus,&ServiceStatus);
592+
fflush(LOGOUTPUT);
593+
}
594+
595+
/* now try again */
596+
log_entry("Attempting to connect again.",LVL_INFO);
597+
dbs->conn=db_connect(dbs);
598+
k++;
599+
}
600+
#endif
601+
575602
if (dbs->conn!=NULL)
576603
{
577604
res=send_query(FROZENOID_QUERY,dbs);
@@ -904,7 +931,7 @@ db_connect(db_info * dbi)
904931
PQfinish(db_conn);
905932
db_conn=NULL;
906933
}
907-
934+
908935
returndb_conn;
909936
}/* end of db_connect() */
910937

@@ -980,44 +1007,44 @@ static void
9801007
perform_maintenance_command(db_info*dbi,tbl_info*tbl,intoperation)
9811008
{
9821009
charbuf[256];
983-
984-
/*
1010+
1011+
/*
9851012
* Set the vacuum_cost variables if supplied on command line
986-
*/
1013+
*/
9871014
if (args->av_vacuum_cost_delay!=-1)
988-
{
1015+
{
9891016
snprintf(buf,sizeof(buf),"set vacuum_cost_delay = %d",
9901017
args->av_vacuum_cost_delay);
9911018
send_query(buf,dbi);
9921019
}
9931020
if (args->av_vacuum_cost_page_hit!=-1)
994-
{
1021+
{
9951022
snprintf(buf,sizeof(buf),"set vacuum_cost_page_hit = %d",
9961023
args->av_vacuum_cost_page_hit);
9971024
send_query(buf,dbi);
9981025
}
9991026
if (args->av_vacuum_cost_page_miss!=-1)
1000-
{
1027+
{
10011028
snprintf(buf,sizeof(buf),"set vacuum_cost_page_miss = %d",
10021029
args->av_vacuum_cost_page_miss);
10031030
send_query(buf,dbi);
10041031
}
10051032
if (args->av_vacuum_cost_page_dirty!=-1)
1006-
{
1033+
{
10071034
snprintf(buf,sizeof(buf),"set vacuum_cost_page_dirty = %d",
10081035
args->av_vacuum_cost_page_dirty);
10091036
send_query(buf,dbi);
10101037
}
10111038
if (args->av_vacuum_cost_limit!=-1)
1012-
{
1039+
{
10131040
snprintf(buf,sizeof(buf),"set vacuum_cost_limit = %d",
10141041
args->av_vacuum_cost_limit);
10151042
send_query(buf,dbi);
10161043
}
1017-
1044+
10181045
/*
1019-
* if ((relisshared = t and database != template1) or
1020-
* if operation = ANALYZE_ONLY)
1046+
* if ((relisshared = t and database != template1) or
1047+
* if operation = ANALYZE_ONLY)
10211048
* then only do an analyze
10221049
*/
10231050
if ((tbl->relisshared>0&&strcmp("template1",dbi->dbname)!=0)||
@@ -1027,14 +1054,14 @@ perform_maintenance_command(db_info * dbi, tbl_info * tbl, int operation)
10271054
snprintf(buf,sizeof(buf),"VACUUM ANALYZE %s",tbl->table_name);
10281055
else
10291056
return;
1030-
1057+
10311058
if (args->debug >=1)
10321059
{
10331060
sprintf(logbuffer,"Performing: %s",buf);
10341061
log_entry(logbuffer,LVL_DEBUG);
10351062
fflush(LOGOUTPUT);
10361063
}
1037-
1064+
10381065
send_query(buf,dbi);
10391066

10401067
update_table_thresholds(dbi,tbl,operation);
@@ -1085,7 +1112,7 @@ get_cmd_args(int argc, char *argv[])
10851112
args->port=0;
10861113

10871114
/*
1088-
* Cost-Based Vacuum Delay Settings for pg_autovacuum
1115+
* Cost-Based Vacuum Delay Settings for pg_autovacuum
10891116
*/
10901117
args->av_vacuum_cost_delay=-1;
10911118
args->av_vacuum_cost_page_hit=-1;
@@ -1255,7 +1282,7 @@ usage(void)
12551282
fprintf(stderr," [-m] vacuum_cost_page_miss (default=none)\n");
12561283
fprintf(stderr," [-n] vacuum_cost_page_dirty (default=none)\n");
12571284
fprintf(stderr," [-l] vacuum_cost_limit (default=none)\n");
1258-
1285+
12591286
fprintf(stderr," [-U] username (libpq default)\n");
12601287
fprintf(stderr," [-P] password (libpq default)\n");
12611288
fprintf(stderr," [-H] host (libpq default)\n");
@@ -1307,10 +1334,10 @@ print_cmd_args(void)
13071334
log_entry(logbuffer,LVL_INFO);
13081335
sprintf(logbuffer," args->analyze_scaling_factor=%f",args->analyze_scaling_factor);
13091336
log_entry(logbuffer,LVL_INFO);
1310-
1337+
13111338
if (args->av_vacuum_cost_delay!=-1)
13121339
sprintf(logbuffer," args->av_vacuum_cost_delay=%d",args->av_vacuum_cost_delay);
1313-
else
1340+
else
13141341
sprintf(logbuffer," args->av_vacuum_cost_delay=(default)");
13151342
log_entry(logbuffer,LVL_INFO);
13161343
if (args->av_vacuum_cost_page_hit!=-1)
@@ -1333,7 +1360,7 @@ print_cmd_args(void)
13331360
else
13341361
sprintf(logbuffer," args->av_vacuum_cost_limit=(default)");
13351362
log_entry(logbuffer,LVL_INFO);
1336-
1363+
13371364
sprintf(logbuffer," args->debug=%d",args->debug);
13381365
log_entry(logbuffer,LVL_INFO);
13391366

@@ -1450,8 +1477,8 @@ InstallService(void)
14501477
if (args->av_vacuum_cost_page_dirty!=-1)
14511478
sprintf(szCommand,"%s -d %d",szCommand,args->av_vacuum_cost_page_dirty);
14521479
if (args->av_vacuum_cost_limit!=-1)
1453-
sprintf(szCommand,"%s -d %d",szCommand,args->av_vacuum_cost_limit);
1454-
1480+
sprintf(szCommand,"%s -d %d",szCommand,args->av_vacuum_cost_limit);
1481+
14551482
/* And write the new value */
14561483
if (RegSetValueEx(hk,"ImagePath",0,REG_EXPAND_SZ, (LPBYTE)szCommand, (DWORD)strlen(szCommand)+1))
14571484
return-4;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp