Skip to content

Commit 2042b34

Browse files
committed
Invent WAL timelines, as per recent discussion, to make point-in-time
recovery more manageable. Also, undo recent change to add FILE_HEADER and WASTED_SPACE records to XLOG; instead make the XLOG page header variable-size with extra fields in the first page of an XLOG file. This should fix the boundary-case bugs observed by Mark Kirkwood. initdb forced due to change of XLOG representation.
1 parent 8d3517d commit 2042b34

File tree

26 files changed

+1331
-991
lines changed

26 files changed

+1331
-991
lines changed

doc/src/sgml/page.sgml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/page.sgml,v 1.17 2003/12/14 00:10:32 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/page.sgml,v 1.18 2004/07/21 22:31:18 tgl Exp $
33
-->
44

55
<chapter id="page">
@@ -114,37 +114,38 @@ data. Empty in ordinary tables.</entry>
114114
<entry>pd_lsn</entry>
115115
<entry>XLogRecPtr</entry>
116116
<entry>8 bytes</entry>
117-
<entry>LSN: next byte after last byte of xlog</entry>
117+
<entry>LSN: next byte after last byte of xlog record for last change
118+
to this page</entry>
118119
</row>
119120
<row>
120-
<entry>pd_sui</entry>
121-
<entry>StartUpID</entry>
121+
<entry>pd_tli</entry>
122+
<entry>TimeLineID</entry>
122123
<entry>4 bytes</entry>
123-
<entry>SUI of last changes (currently it's used by heap AM only)</entry>
124+
<entry>TLI of last change</entry>
124125
</row>
125126
<row>
126127
<entry>pd_lower</entry>
127128
<entry>LocationIndex</entry>
128129
<entry>2 bytes</entry>
129-
<entry>Offset to start of free space.</entry>
130+
<entry>Offset to start of free space</entry>
130131
</row>
131132
<row>
132133
<entry>pd_upper</entry>
133134
<entry>LocationIndex</entry>
134135
<entry>2 bytes</entry>
135-
<entry>Offset to end of free space.</entry>
136+
<entry>Offset to end of free space</entry>
136137
</row>
137138
<row>
138139
<entry>pd_special</entry>
139140
<entry>LocationIndex</entry>
140141
<entry>2 bytes</entry>
141-
<entry>Offset to start of special space.</entry>
142+
<entry>Offset to start of special space</entry>
142143
</row>
143144
<row>
144145
<entry>pd_pagesize_version</entry>
145146
<entry>uint16</entry>
146147
<entry>2 bytes</entry>
147-
<entry>Page size and layout version number information.</entry>
148+
<entry>Page size and layout version number information</entry>
148149
</row>
149150
</tbody>
150151
</tgroup>

src/backend/access/heap/heapam.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.170 2004/07/11 18:01:44 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.171 2004/07/21 22:31:19 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1214,7 +1214,7 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid)
12141214
recptr = XLogInsert(RM_HEAP_ID, info, rdata);
12151215

12161216
PageSetLSN(page, recptr);
1217-
PageSetSUI(page, ThisStartUpID);
1217+
PageSetTLI(page, ThisTimeLineID);
12181218
}
12191219
else
12201220
{
@@ -1390,7 +1390,7 @@ heap_delete(Relation relation, ItemPointer tid,
13901390
recptr = XLogInsert(RM_HEAP_ID, XLOG_HEAP_DELETE, rdata);
13911391

13921392
PageSetLSN(dp, recptr);
1393-
PageSetSUI(dp, ThisStartUpID);
1393+
PageSetTLI(dp, ThisTimeLineID);
13941394
}
13951395
else
13961396
{
@@ -1748,10 +1748,10 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
17481748
if (newbuf != buffer)
17491749
{
17501750
PageSetLSN(BufferGetPage(newbuf), recptr);
1751-
PageSetSUI(BufferGetPage(newbuf), ThisStartUpID);
1751+
PageSetTLI(BufferGetPage(newbuf), ThisTimeLineID);
17521752
}
17531753
PageSetLSN(BufferGetPage(buffer), recptr);
1754-
PageSetSUI(BufferGetPage(buffer), ThisStartUpID);
1754+
PageSetTLI(BufferGetPage(buffer), ThisTimeLineID);
17551755
}
17561756
else
17571757
{
@@ -1902,7 +1902,7 @@ heap_mark4update(Relation relation, HeapTuple tuple, Buffer *buffer,
19021902
* XLOG stuff: no logging is required as long as we have no
19031903
* savepoints. For savepoints private log could be used...
19041904
*/
1905-
PageSetSUI(BufferGetPage(*buffer), ThisStartUpID);
1905+
PageSetTLI(BufferGetPage(*buffer), ThisTimeLineID);
19061906

19071907
/* store transaction information of xact marking the tuple */
19081908
tuple->t_data->t_infomask &= ~(HEAP_XMAX_COMMITTED |
@@ -2184,7 +2184,7 @@ heap_xlog_clean(bool redo, XLogRecPtr lsn, XLogRecord *record)
21842184
PageRepairFragmentation(page, NULL);
21852185

21862186
PageSetLSN(page, lsn);
2187-
PageSetSUI(page, ThisStartUpID); /* prev sui */
2187+
PageSetTLI(page, ThisTimeLineID);
21882188
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
21892189
WriteBuffer(buffer);
21902190
}
@@ -2217,7 +2217,7 @@ heap_xlog_newpage(bool redo, XLogRecPtr lsn, XLogRecord *record)
22172217
memcpy(page, (char *) xlrec + SizeOfHeapNewpage, BLCKSZ);
22182218

22192219
PageSetLSN(page, lsn);
2220-
PageSetSUI(page, ThisStartUpID);
2220+
PageSetTLI(page, ThisTimeLineID);
22212221
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
22222222
WriteBuffer(buffer);
22232223
}
@@ -2283,7 +2283,7 @@ heap_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record)
22832283
/* Make sure there is no forward chain link in t_ctid */
22842284
htup->t_ctid = xlrec->target.tid;
22852285
PageSetLSN(page, lsn);
2286-
PageSetSUI(page, ThisStartUpID);
2286+
PageSetTLI(page, ThisTimeLineID);
22872287
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
22882288
WriteBuffer(buffer);
22892289
return;
@@ -2368,7 +2368,7 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
23682368
if (offnum == InvalidOffsetNumber)
23692369
elog(PANIC, "heap_insert_redo: failed to add tuple");
23702370
PageSetLSN(page, lsn);
2371-
PageSetSUI(page, ThisStartUpID); /* prev sui */
2371+
PageSetTLI(page, ThisTimeLineID);
23722372
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
23732373
WriteBuffer(buffer);
23742374
return;
@@ -2466,7 +2466,7 @@ heap_xlog_update(bool redo, XLogRecPtr lsn, XLogRecord *record, bool move)
24662466
if (samepage)
24672467
goto newsame;
24682468
PageSetLSN(page, lsn);
2469-
PageSetSUI(page, ThisStartUpID);
2469+
PageSetTLI(page, ThisTimeLineID);
24702470
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
24712471
WriteBuffer(buffer);
24722472
goto newt;
@@ -2564,7 +2564,7 @@ newsame:;
25642564
if (offnum == InvalidOffsetNumber)
25652565
elog(PANIC, "heap_update_redo: failed to add tuple");
25662566
PageSetLSN(page, lsn);
2567-
PageSetSUI(page, ThisStartUpID); /* prev sui */
2567+
PageSetTLI(page, ThisTimeLineID);
25682568
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
25692569
WriteBuffer(buffer);
25702570
return;

src/backend/access/nbtree/nbtinsert.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.112 2004/04/21 18:24:25 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.113 2004/07/21 22:31:19 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -621,11 +621,11 @@ _bt_insertonpg(Relation rel,
621621
if (BufferIsValid(metabuf))
622622
{
623623
PageSetLSN(metapg, recptr);
624-
PageSetSUI(metapg, ThisStartUpID);
624+
PageSetTLI(metapg, ThisTimeLineID);
625625
}
626626

627627
PageSetLSN(page, recptr);
628-
PageSetSUI(page, ThisStartUpID);
628+
PageSetTLI(page, ThisTimeLineID);
629629
}
630630

631631
END_CRIT_SECTION();
@@ -903,13 +903,13 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
903903
recptr = XLogInsert(RM_BTREE_ID, xlinfo, rdata);
904904

905905
PageSetLSN(leftpage, recptr);
906-
PageSetSUI(leftpage, ThisStartUpID);
906+
PageSetTLI(leftpage, ThisTimeLineID);
907907
PageSetLSN(rightpage, recptr);
908-
PageSetSUI(rightpage, ThisStartUpID);
908+
PageSetTLI(rightpage, ThisTimeLineID);
909909
if (!P_RIGHTMOST(ropaque))
910910
{
911911
PageSetLSN(spage, recptr);
912-
PageSetSUI(spage, ThisStartUpID);
912+
PageSetTLI(spage, ThisTimeLineID);
913913
}
914914
}
915915

@@ -1494,13 +1494,13 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
14941494
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_NEWROOT, rdata);
14951495

14961496
PageSetLSN(rootpage, recptr);
1497-
PageSetSUI(rootpage, ThisStartUpID);
1497+
PageSetTLI(rootpage, ThisTimeLineID);
14981498
PageSetLSN(metapg, recptr);
1499-
PageSetSUI(metapg, ThisStartUpID);
1499+
PageSetTLI(metapg, ThisTimeLineID);
15001500
PageSetLSN(lpage, recptr);
1501-
PageSetSUI(lpage, ThisStartUpID);
1501+
PageSetTLI(lpage, ThisTimeLineID);
15021502
PageSetLSN(rpage, recptr);
1503-
PageSetSUI(rpage, ThisStartUpID);
1503+
PageSetTLI(rpage, ThisTimeLineID);
15041504
}
15051505

15061506
END_CRIT_SECTION();

src/backend/access/nbtree/nbtpage.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.76 2004/06/02 17:28:17 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.77 2004/07/21 22:31:20 tgl Exp $
1313
*
1414
* NOTES
1515
* Postgres btree pages look like ordinary relation pages. The opaque
@@ -84,7 +84,7 @@ _bt_metapinit(Relation rel)
8484
rdata);
8585

8686
PageSetLSN(pg, recptr);
87-
PageSetSUI(pg, ThisStartUpID);
87+
PageSetTLI(pg, ThisTimeLineID);
8888
}
8989

9090
END_CRIT_SECTION();
@@ -249,9 +249,9 @@ _bt_getroot(Relation rel, int access)
249249
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_NEWROOT, &rdata);
250250

251251
PageSetLSN(rootpage, recptr);
252-
PageSetSUI(rootpage, ThisStartUpID);
252+
PageSetTLI(rootpage, ThisTimeLineID);
253253
PageSetLSN(metapg, recptr);
254-
PageSetSUI(metapg, ThisStartUpID);
254+
PageSetTLI(metapg, ThisTimeLineID);
255255
}
256256

257257
END_CRIT_SECTION();
@@ -686,7 +686,7 @@ _bt_delitems(Relation rel, Buffer buf,
686686
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_DELETE, rdata);
687687

688688
PageSetLSN(page, recptr);
689-
PageSetSUI(page, ThisStartUpID);
689+
PageSetTLI(page, ThisTimeLineID);
690690
}
691691

692692
END_CRIT_SECTION();
@@ -1080,22 +1080,22 @@ _bt_pagedel(Relation rel, Buffer buf, bool vacuum_full)
10801080
if (BufferIsValid(metabuf))
10811081
{
10821082
PageSetLSN(metapg, recptr);
1083-
PageSetSUI(metapg, ThisStartUpID);
1083+
PageSetTLI(metapg, ThisTimeLineID);
10841084
}
10851085
page = BufferGetPage(pbuf);
10861086
PageSetLSN(page, recptr);
1087-
PageSetSUI(page, ThisStartUpID);
1087+
PageSetTLI(page, ThisTimeLineID);
10881088
page = BufferGetPage(rbuf);
10891089
PageSetLSN(page, recptr);
1090-
PageSetSUI(page, ThisStartUpID);
1090+
PageSetTLI(page, ThisTimeLineID);
10911091
page = BufferGetPage(buf);
10921092
PageSetLSN(page, recptr);
1093-
PageSetSUI(page, ThisStartUpID);
1093+
PageSetTLI(page, ThisTimeLineID);
10941094
if (BufferIsValid(lbuf))
10951095
{
10961096
page = BufferGetPage(lbuf);
10971097
PageSetLSN(page, recptr);
1098-
PageSetSUI(page, ThisStartUpID);
1098+
PageSetTLI(page, ThisTimeLineID);
10991099
}
11001100
}
11011101

src/backend/access/nbtree/nbtsort.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
* Portions Copyright (c) 1994, Regents of the University of California
5757
*
5858
* IDENTIFICATION
59-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.84 2004/07/19 02:47:03 tgl Exp $
59+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.85 2004/07/21 22:31:20 tgl Exp $
6060
*
6161
*-------------------------------------------------------------------------
6262
*/
@@ -299,14 +299,14 @@ _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno)
299299
recptr = XLogInsert(RM_HEAP_ID, XLOG_HEAP_NEWPAGE, rdata);
300300

301301
PageSetLSN(page, recptr);
302-
PageSetSUI(page, ThisStartUpID);
302+
PageSetTLI(page, ThisTimeLineID);
303303

304304
END_CRIT_SECTION();
305305
}
306306
else
307307
{
308-
/* Leave the page LSN zero if not WAL-logged, but set SUI anyway */
309-
PageSetSUI(page, ThisStartUpID);
308+
/* Leave the page LSN zero if not WAL-logged, but set TLI anyway */
309+
PageSetTLI(page, ThisTimeLineID);
310310
}
311311

312312
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy