Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit09b115f

Browse files
committed
Write a WAL record whenever we perform an operation without WAL-logging
that would've been WAL-logged if archiving was enabled. If we encountersuch records in archive recovery anyway, we know that some data ismissing from the log. A WARNING is emitted in that case.Original patch by Fujii Masao, with changes by me.
1 parent47ce95a commit09b115f

File tree

7 files changed

+100
-7
lines changed

7 files changed

+100
-7
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 7 additions & 1 deletion
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.282 2010/01/14 11:08:00 sriggs Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.283 2010/01/20 19:43:40 heikki Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -5074,10 +5074,16 @@ heap2_desc(StringInfo buf, uint8 xl_info, char *rec)
50745074
void
50755075
heap_sync(Relationrel)
50765076
{
5077+
charreason[NAMEDATALEN+30];
5078+
50775079
/* temp tables never need fsync */
50785080
if (rel->rd_istemp)
50795081
return;
50805082

5083+
snprintf(reason,sizeof(reason),"heap inserts on \"%s\"",
5084+
RelationGetRelationName(rel));
5085+
XLogReportUnloggedStatement(reason);
5086+
50815087
/* main heap */
50825088
FlushRelationBuffers(rel);
50835089
/* FlushRelationBuffers will have opened rd_smgr */

‎src/backend/access/nbtree/nbtsort.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
* Portions Copyright (c) 1994, Regents of the University of California
6060
*
6161
* IDENTIFICATION
62-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.122 2010/01/15 09:19:00 heikki Exp $
62+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.123 2010/01/2019:43:40 heikki Exp $
6363
*
6464
*-------------------------------------------------------------------------
6565
*/
@@ -215,6 +215,18 @@ _bt_leafbuild(BTSpool *btspool, BTSpool *btspool2)
215215
*/
216216
wstate.btws_use_wal=XLogIsNeeded()&& !wstate.index->rd_istemp;
217217

218+
/*
219+
* Write an XLOG UNLOGGED record if WAL-logging was skipped because
220+
* WAL archiving is not enabled.
221+
*/
222+
if (!wstate.btws_use_wal&& !wstate.index->rd_istemp)
223+
{
224+
charreason[NAMEDATALEN+20];
225+
snprintf(reason,sizeof(reason),"b-tree build on \"%s\"",
226+
RelationGetRelationName(wstate.index));
227+
XLogReportUnloggedStatement(reason);
228+
}
229+
218230
/* reserve the metapage */
219231
wstate.btws_pages_alloced=BTREE_METAPAGE+1;
220232
wstate.btws_pages_written=0;

‎src/backend/access/transam/xlog.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.358 2010/01/15 09:19:00 heikki Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.359 2010/01/2019:43:40 heikki Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -7561,6 +7561,31 @@ RequestXLogSwitch(void)
75617561
returnRecPtr;
75627562
}
75637563

7564+
/*
7565+
* Write an XLOG UNLOGGED record, indicating that some operation was
7566+
* performed on data that we fsync()'d directly to disk, skipping
7567+
* WAL-logging.
7568+
*
7569+
* Such operations screw up archive recovery, so we complain if we see
7570+
* these records during archive recovery. That shouldn't happen in a
7571+
* correctly configured server, but you can induce it by temporarily
7572+
* disabling archiving and restarting, so it's good to at least get a
7573+
* warning of silent data loss in such cases. These records serve no
7574+
* other purpose and are simply ignored during crash recovery.
7575+
*/
7576+
void
7577+
XLogReportUnloggedStatement(char*reason)
7578+
{
7579+
XLogRecDatardata;
7580+
7581+
rdata.buffer=InvalidBuffer;
7582+
rdata.data=reason;
7583+
rdata.len=strlen(reason)+1;
7584+
rdata.next=NULL;
7585+
7586+
XLogInsert(RM_XLOG_ID,XLOG_UNLOGGED,&rdata);
7587+
}
7588+
75647589
/*
75657590
* XLOG resource manager's routines
75667591
*
@@ -7703,6 +7728,19 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record)
77037728
LWLockRelease(ControlFileLock);
77047729
}
77057730
}
7731+
elseif (info==XLOG_UNLOGGED)
7732+
{
7733+
if (InArchiveRecovery)
7734+
{
7735+
/*
7736+
* Note: We don't print the reason string from the record,
7737+
* because that gets added as a line using xlog_desc()
7738+
*/
7739+
ereport(WARNING,
7740+
(errmsg("unlogged operation performed, data may be missing"),
7741+
errhint("This can happen if you temporarily disable archive_mode without taking a new base backup.")));
7742+
}
7743+
}
77067744
}
77077745

77087746
void
@@ -7752,6 +7790,12 @@ xlog_desc(StringInfo buf, uint8 xl_info, char *rec)
77527790
appendStringInfo(buf,"backup end: %X/%X",
77537791
startpoint.xlogid,startpoint.xrecoff);
77547792
}
7793+
elseif (info==XLOG_UNLOGGED)
7794+
{
7795+
char*reason=rec;
7796+
7797+
appendStringInfo(buf,"unlogged operation: %s",reason);
7798+
}
77557799
else
77567800
appendStringInfo(buf,"UNKNOWN");
77577801
}

‎src/backend/commands/cluster.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.193 2010/01/15 09:19:01 heikki Exp $
14+
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.194 2010/01/2019:43:40 heikki Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -821,6 +821,18 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex,
821821
*/
822822
use_wal=XLogIsNeeded()&& !NewHeap->rd_istemp;
823823

824+
/*
825+
* Write an XLOG UNLOGGED record if WAL-logging was skipped because
826+
* WAL archiving is not enabled.
827+
*/
828+
if (!use_wal&& !NewHeap->rd_istemp)
829+
{
830+
charreason[NAMEDATALEN+20];
831+
snprintf(reason,sizeof(reason),"CLUSTER on \"%s\"",
832+
RelationGetRelationName(NewHeap));
833+
XLogReportUnloggedStatement(reason);
834+
}
835+
824836
/* use_wal off requires rd_targblock be initially invalid */
825837
Assert(NewHeap->rd_targblock==InvalidBlockNumber);
826838

‎src/backend/commands/tablecmds.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.316 2010/01/17 22:56:21 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.317 2010/01/20 19:43:40 heikki Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -7015,6 +7015,19 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace)
70157015

70167016
heap_close(pg_class,RowExclusiveLock);
70177017

7018+
/*
7019+
* Write an XLOG UNLOGGED record if WAL-logging was skipped because
7020+
* WAL archiving is not enabled.
7021+
*/
7022+
if (!XLogIsNeeded()&& !rel->rd_istemp)
7023+
{
7024+
charreason[NAMEDATALEN+40];
7025+
snprintf(reason,sizeof(reason),"ALTER TABLE SET TABLESPACE on \"%s\"",
7026+
RelationGetRelationName(rel));
7027+
7028+
XLogReportUnloggedStatement(reason);
7029+
}
7030+
70187031
relation_close(rel,NoLock);
70197032

70207033
/* Make sure the reltablespace change is visible */
@@ -7043,6 +7056,10 @@ copy_relation_data(SMgrRelation src, SMgrRelation dst,
70437056
/*
70447057
* We need to log the copied data in WAL iff WAL archiving/streaming is
70457058
* enabled AND it's not a temp rel.
7059+
*
7060+
* Note: If you change the conditions here, update the conditions in
7061+
* ATExecSetTableSpace() for when an XLOG UNLOGGED record is written
7062+
* to match.
70467063
*/
70477064
use_wal=XLogIsNeeded()&& !istemp;
70487065

‎src/include/access/xlog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.97 2010/01/16 00:04:41 tgl Exp $
9+
* $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.98 2010/01/20 19:43:40 heikki Exp $
1010
*/
1111
#ifndefXLOG_H
1212
#defineXLOG_H
@@ -278,6 +278,7 @@ extern void InitXLOGAccess(void);
278278
externvoidCreateCheckPoint(intflags);
279279
externboolCreateRestartPoint(intflags);
280280
externvoidXLogPutNextOid(OidnextOid);
281+
externvoidXLogReportUnloggedStatement(char*reason);
281282
externXLogRecPtrGetRedoRecPtr(void);
282283
externXLogRecPtrGetInsertRecPtr(void);
283284
externXLogRecPtrGetWriteRecPtr(void);

‎src/include/catalog/pg_control.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_control.h,v 1.48 2010/01/04 12:50:50 heikki Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_control.h,v 1.49 2010/01/20 19:43:40 heikki Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -63,6 +63,7 @@ typedef struct CheckPoint
6363
#defineXLOG_NEXTOID0x30
6464
#defineXLOG_SWITCH0x40
6565
#defineXLOG_BACKUP_END0x50
66+
#defineXLOG_UNLOGGED0x60
6667

6768

6869
/* System status indicator */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp