Index: pg_autovacuum.c
===================================================================
RCS file: /projects/cvsroot/pgsql/contrib/pg_autovacuum/pg_autovacuum.c,v
retrieving revision 1.28
diff -u -r1.28 pg_autovacuum.c
--- pg_autovacuum.c	24 Jan 2005 00:13:38 -0000	1.28
+++ pg_autovacuum.c	25 Jan 2005 11:46:44 -0000
@@ -556,6 +556,7 @@
 	Dllist	   *db_list = DLNewList();
 	db_info    *dbs = NULL;
 	PGresult   *res = NULL;
+    int        j = 0, k = 0;
 
 	DLAddHead(db_list, DLNewElem(init_dbinfo((char *) "template1", 0, 0)));
 	if (DLGetHead(db_list) == NULL)
@@ -571,6 +572,28 @@
 	 */
 	dbs = ((db_info *) DLE_VAL(DLGetHead(db_list)));
 	dbs->conn = db_connect(dbs);
+    
+#ifdef WIN32
+    while (dbs->conn == NULL && !appMode && k < 10)
+    {
+        /* Pause for 30 seconds to allow the database to start up */
+        log_entry("Pausing 30 seconds to allow the database to startup completely", LVL_INFO);
+        fflush(LOGOUTPUT);
+        ServiceStatus.dwWaitHint = 10;
+        for (j=0; j<6; j++) 
+        {
+            pg_usleep(5000000);
+            ServiceStatus.dwCheckPoint++;
+            SetServiceStatus(hStatus, &ServiceStatus);
+            fflush(LOGOUTPUT);
+        }
+        
+        /* now try again */
+        log_entry("Attempting to connect again.", LVL_INFO);
+        dbs->conn = db_connect(dbs);
+        k++;
+    }
+#endif
 
 	if (dbs->conn != NULL)
 	{
