Skip site navigation (1) Skip section navigation (2)

Kludge in pg_standby.c

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: pgsql-hackers list <pgsql-hackers(at)postgresql(dot)org>
Subject: Kludge in pg_standby.c
Date: 2007-12-03 17:41:50
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
There's a suspicious ifdef in pg_standby for WIN32 which smells like a kludge
added to work around a Windows problem which makes it work but at great

#ifdef WIN32
                 * Windows reports that the file has the right number of bytes
                 * even though the file is still being copied and cannot be
                 * opened by pg_standby yet. So we wait for sleeptime secs
                 * before attempting to restore. If that is not enough, we
                 * will rely on the retry/holdoff mechanism.
                pg_usleep(sleeptime * 1000000L);

This happens before we return *any* WAL file to be processed. That means it
slows down the processing of any file by 1s. On a server which has fallen
behind this means it can't process files as quickly as it can copy them, it's
limited to at most 1/s.

I think it wouldn't be hard to do this properly. We can try to open the file,
handle the expected Windows error by sleeping for 1s and repeating until we
can successfully open it. Something like (untested):

		bool success = false;
                int fd, tries = 10;
		while (--tries) {
                   fd = open(WALFilePath, O_RDONLY);
                   if (fd >= 0) {
                       success = true;
                   } else if (errno == EWINDOWSBLOWS) {
                   } else {
                       perror("pg_standby open:");
               if (!success) {
                   fprintf(stderr, "pg_standby: couldn't open file \"%s\" due to \"%s\", 
                           WALFilePath, strerror(EWINDOWSBLOWS));

  Gregory Stark
  Ask me about EnterpriseDB's RemoteDBA services!


pgsql-hackers by date

Next:From: Jeff DavisDate: 2007-12-03 18:32:29
Subject: Re: Sorting Improvements for 8.4
Previous:From: Filip WuytackDate: 2007-12-03 17:27:42
Subject: Re: 8.3 beta 4 crash on windows 2003 64-bit

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group