Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 64cb889

Browse files
committed
Ensure that the remainder of the current pg_clog page is zeroed during
startup, just to be sure that there's no leftover junk there.
1 parent 9cf4eaa commit 64cb889

File tree

1 file changed

+33
-2
lines changed
  • src/backend/access/transam

1 file changed

+33
-2
lines changed

src/backend/access/transam/clog.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
2525
* Portions Copyright (c) 1994, Regents of the University of California
2626
*
27-
* $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.25 2004/08/29 05:06:40 momjian Exp $
27+
* $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.26 2004/08/30 19:00:42 tgl Exp $
2828
*
2929
*-------------------------------------------------------------------------
3030
*/
@@ -210,10 +210,41 @@ ZeroCLOGPage(int pageno, bool writeXlog)
210210
void
211211
StartupCLOG(void)
212212
{
213+
TransactionId xid = ShmemVariableCache->nextXid;
214+
int pageno = TransactionIdToPage(xid);
215+
int byteno = TransactionIdToByte(xid);
216+
int bshift = TransactionIdToBIndex(xid) * CLOG_BITS_PER_XACT;
217+
int slotno;
218+
char *byteptr;
219+
220+
LWLockAcquire(CLogControlLock, LW_EXCLUSIVE);
221+
213222
/*
214223
* Initialize our idea of the latest page number.
215224
*/
216-
ClogCtl->shared->latest_page_number = TransactionIdToPage(ShmemVariableCache->nextXid);
225+
ClogCtl->shared->latest_page_number = pageno;
226+
227+
/*
228+
* Zero out the remainder of the current clog page. Under normal
229+
* circumstances it should be zeroes already, but it seems at least
230+
* theoretically possible that XLOG replay will have settled on a
231+
* nextXID value that is less than the last XID actually used and
232+
* marked by the previous database lifecycle (since subtransaction
233+
* commit writes clog but makes no WAL entry). Let's just be safe.
234+
* (We need not worry about pages beyond the current one, since those
235+
* will be zeroed when first used.)
236+
*/
237+
slotno = SimpleLruReadPage(ClogCtl, pageno, xid);
238+
byteptr = ClogCtl->shared->page_buffer[slotno] + byteno;
239+
240+
/* Zero so-far-unused positions in the current byte */
241+
*byteptr &= (1 << bshift) - 1;
242+
/* Zero the rest of the page */
243+
MemSet(byteptr + 1, 0, BLCKSZ - byteno - 1);
244+
245+
ClogCtl->shared->page_status[slotno] = SLRU_PAGE_DIRTY;
246+
247+
LWLockRelease(CLogControlLock);
217248
}
218249

219250
/*

0 commit comments

Comments
 (0)