]> granicus.if.org Git - postgresql/commitdiff
Make the walwriter close it's handle to an old xlog segment if it's no longer
authorMagnus Hagander <magnus@hagander.net>
Wed, 9 Jun 2010 10:54:50 +0000 (10:54 +0000)
committerMagnus Hagander <magnus@hagander.net>
Wed, 9 Jun 2010 10:54:50 +0000 (10:54 +0000)
the current one. Not doing this would leave the walwriter with a handle to a
deleted file if there was nothing for it to do for a long period of time,
preventing the file from  being completely removed.

Reported by Tollef Fog Heen, and thanks to Heikki for some hand-holding with
the patch.

src/backend/access/transam/xlog.c

index 1ff0a3d397eb7bdc06ebcffc64a8c36ad3bf67d4..6f44dcaf9da8eaabe627d3343f88c9b01f38c5b7 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.292.2.10 2010/02/19 01:06:51 itagaki Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.292.2.11 2010/06/09 10:54:50 mha Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1821,9 +1821,21 @@ XLogBackgroundFlush(void)
                flexible = false;               /* ensure it all gets written */
        }
 
-       /* Done if already known flushed */
+       /*
+        * If already known flushed, we're done. Just need to check if we
+        * are holding an open file handle to a logfile that's no longer
+        * in use, preventing the file from being deleted.
+        */
        if (XLByteLE(WriteRqstPtr, LogwrtResult.Flush))
+       {
+               if (openLogFile >= 0) {
+                       if (!XLByteInPrevSeg(LogwrtResult.Write, openLogId, openLogSeg))
+                       {
+                               XLogFileClose();
+                       }
+               }
                return;
+       }
 
 #ifdef WAL_DEBUG
        if (XLOG_DEBUG)