On Wed, Dec 19, 2007 at 04:44:12PM +0100, Magnus Hagander wrote:
> On Wed, Dec 19, 2007 at 04:20:23PM +0100, Zeugswetter Andreas ADI SD wrote:
> >
> > > > Yeah, I think it would be useful to log one message if after (say) 5
> > > > seconds we still haven't been able to open the file.
> > >
> > > Either that, or on the first run.
> >
> > Imho 1-5s is better, so that would be after the 10-50th try.
>
> Ok, so I'll put in a warning after 50 tries.
Updated version attached. Comments on the wording of the messages are also
welcome ;-)
//Magnus
Index: src/port/open.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/port/open.c,v
retrieving revision 1.22
diff -c -r1.22 open.c
*** src/port/open.c 30 Nov 2007 11:16:43 -0000 1.22
--- src/port/open.c 19 Dec 2007 15:50:06 -0000
***************
*** 13,19 ****
#ifdef WIN32
! #include "c.h"
#include <windows.h>
#include <fcntl.h>
--- 13,23 ----
#ifdef WIN32
! #ifndef FRONTEND
! #include "postgres.h"
! #else
! #include "postgres_fe.h"
! #endif
#include <windows.h>
#include <fcntl.h>
***************
*** 58,65 ****
pgwin32_open(const char *fileName, int fileFlags,...)
{
int fd;
! HANDLE h;
SECURITY_ATTRIBUTES sa;
/* Check that we can handle the request */
assert((fileFlags & ((O_RDONLY | O_WRONLY | O_RDWR) | O_APPEND |
--- 62,70 ----
pgwin32_open(const char *fileName, int fileFlags,...)
{
int fd;
! HANDLE h = INVALID_HANDLE_VALUE;
SECURITY_ATTRIBUTES sa;
+ int loops = 0;
/* Check that we can handle the request */
assert((fileFlags & ((O_RDONLY | O_WRONLY | O_RDWR) | O_APPEND |
***************
*** 71,77 ****
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
! if ((h = CreateFile(fileName,
/* cannot use O_RDONLY, as it == 0 */
(fileFlags & O_RDWR) ? (GENERIC_WRITE
| GENERIC_READ) :
((fileFlags & O_WRONLY) ?
GENERIC_WRITE : GENERIC_READ),
--- 76,82 ----
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
! while ((h = CreateFile(fileName,
/* cannot use O_RDONLY, as it == 0 */
(fileFlags & O_RDWR) ? (GENERIC_WRITE
| GENERIC_READ) :
((fileFlags & O_WRONLY) ?
GENERIC_WRITE : GENERIC_READ),
***************
*** 88,93 ****
--- 93,121 ----
((fileFlags & O_DSYNC) ?
FILE_FLAG_WRITE_THROUGH : 0),
NULL)) == INVALID_HANDLE_VALUE)
{
+ /*
+ * Sharing violation or locking error can indicate antivirus,
backup
+ * or similar software that's locking the file. Try again for
30 seconds
+ * before giving up.
+ */
+ if (GetLastError() == ERROR_SHARING_VIOLATION ||
+ GetLastError() == ERROR_LOCK_VIOLATION)
+ {
+ pg_usleep(100000);
+ loops++;
+
+ #ifndef FRONTEND
+ if (loops == 50)
+ ereport(WARNING,
+ (errmsg("could not open file \"%s\" due
to sharing violation. Will retry for 30 seconds.",
+ fileName,
+ errhint("You may have antivirus,
backup or similar software interfering with the database."))));
+ #endif
+
+ if (loops < 300)
+ continue;
+ }
+
_dosmaperr(GetLastError());
return -1;
}
---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?
http://archives.postgresql.org