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

Commit50e5470

Browse files
committed
Add GUC to enable WAL-logging of hint bits, even with checksums disabled.
WAL records of hint bit updates is useful to tools that want to examinewhich pages have been modified. In particular, this is required to makethe pg_rewind tool safe (without checksums).This can also be used to test how much extra WAL-logging would occur ifyou enabled checksums, without actually enabling them (which you can'tcurrently do without re-initdb'ing).Sawada Masahiko, docs by Samrat Revagade. Reviewed by Dilip Kumar, withfurther changes by me.
1 parent56afe85 commit50e5470

File tree

13 files changed

+70
-9
lines changed

13 files changed

+70
-9
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,6 +1944,32 @@ include 'filename'
19441944
</listitem>
19451945
</varlistentry>
19461946

1947+
<varlistentry id="guc-wal-log-hintbits" xreflabel="wal_log_hintbits">
1948+
<term><varname>wal_log_hintbits</varname> (<type>boolean</type>)</term>
1949+
<indexterm>
1950+
<primary><varname>wal_log_hintbits</> configuration parameter</primary>
1951+
</indexterm>
1952+
<listitem>
1953+
<para>
1954+
When this parameter is <literal>on</>, the <productname>PostgreSQL</>
1955+
server writes the entire content of each disk page to WAL during the
1956+
first modification of that page after a checkpoint, even for
1957+
non-critical modifications of so-called hint bits.
1958+
</para>
1959+
1960+
<para>
1961+
If data checksums are enabled, hint bit updates are always WAL-logged
1962+
and this setting is ignored. You can use this setting to test how much
1963+
extra WAL-logging would occur if your database had data checksums
1964+
enabled.
1965+
</para>
1966+
1967+
<para>
1968+
This parameter can only be set at server start. The default value is <literal>off</>.
1969+
</para>
1970+
</listitem>
1971+
</varlistentry>
1972+
19471973
<varlistentry id="guc-wal-buffers" xreflabel="wal_buffers">
19481974
<term><varname>wal_buffers</varname> (<type>integer</type>)</term>
19491975
<indexterm>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6271,7 +6271,7 @@ log_heap_visible(RelFileNode rnode, Buffer heap_buffer, Buffer vm_buffer,
62716271
rdata[1].buffer_std= false;
62726272
rdata[1].next=NULL;
62736273

6274-
if (DataChecksumsEnabled())
6274+
if (XLogHintBitIsNeeded())
62756275
{
62766276
rdata[1].next=&(rdata[2]);
62776277

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,10 @@ visibilitymap_set(Relation rel, BlockNumber heapBlk, Buffer heapBuf,
287287
cutoff_xid);
288288

289289
/*
290-
* If data checksums are enabled, we need to protect the heap
291-
* page from being torn.
290+
* If data checksums are enabled (or wal_log_hintbits=on), we
291+
*need to protect the heappage from being torn.
292292
*/
293-
if (DataChecksumsEnabled())
293+
if (XLogHintBitIsNeeded())
294294
{
295295
PageheapPage=BufferGetPage(heapBuf);
296296

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ boolXLogArchiveMode = false;
7979
char*XLogArchiveCommand=NULL;
8080
boolEnableHotStandby= false;
8181
boolfullPageWrites= true;
82+
boolwalLogHintbits= false;
8283
boollog_checkpoints= false;
8384
intsync_method=DEFAULT_SYNC_METHOD;
8485
intwal_level=WAL_LEVEL_MINIMAL;
@@ -5270,6 +5271,7 @@ BootStrapXLOG(void)
52705271
ControlFile->max_prepared_xacts=max_prepared_xacts;
52715272
ControlFile->max_locks_per_xact=max_locks_per_xact;
52725273
ControlFile->wal_level=wal_level;
5274+
ControlFile->wal_log_hintbits=walLogHintbits;
52735275
ControlFile->data_checksum_version=bootstrap_data_checksum_version;
52745276

52755277
/* some additional ControlFile fields are set in WriteControlFile() */
@@ -9058,6 +9060,7 @@ static void
90589060
XLogReportParameters(void)
90599061
{
90609062
if (wal_level!=ControlFile->wal_level||
9063+
walLogHintbits!=ControlFile->wal_log_hintbits||
90619064
MaxConnections!=ControlFile->MaxConnections||
90629065
max_worker_processes!=ControlFile->max_worker_processes||
90639066
max_prepared_xacts!=ControlFile->max_prepared_xacts||
@@ -9080,6 +9083,7 @@ XLogReportParameters(void)
90809083
xlrec.max_prepared_xacts=max_prepared_xacts;
90819084
xlrec.max_locks_per_xact=max_locks_per_xact;
90829085
xlrec.wal_level=wal_level;
9086+
xlrec.wal_log_hintbits=walLogHintbits;
90839087

90849088
rdata.buffer=InvalidBuffer;
90859089
rdata.data= (char*)&xlrec;
@@ -9094,6 +9098,7 @@ XLogReportParameters(void)
90949098
ControlFile->max_prepared_xacts=max_prepared_xacts;
90959099
ControlFile->max_locks_per_xact=max_locks_per_xact;
90969100
ControlFile->wal_level=wal_level;
9101+
ControlFile->wal_log_hintbits=walLogHintbits;
90979102
UpdateControlFile();
90989103
}
90999104
}
@@ -9480,6 +9485,7 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record)
94809485
ControlFile->max_prepared_xacts=xlrec.max_prepared_xacts;
94819486
ControlFile->max_locks_per_xact=xlrec.max_locks_per_xact;
94829487
ControlFile->wal_level=xlrec.wal_level;
9488+
ControlFile->wal_log_hintbits=walLogHintbits;
94839489

94849490
/*
94859491
* Update minRecoveryPoint to ensure that if recovery is aborted, we

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,16 +2626,15 @@ MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
26262626
booldelayChkpt= false;
26272627

26282628
/*
2629-
* If checksums are enabled, and the buffer is permanent, then a full
2630-
* page image may be required even for some hint bit updates to
2631-
* protect against torn pages. This full page image is only necessary
2629+
* If we need to protect hint bit updates from torn writes, WAL-log a
2630+
* full page image of the page. This full page image is only necessary
26322631
* if the hint bit update is the first change to the page since the
26332632
* last checkpoint.
26342633
*
26352634
* We don't check full_page_writes here because that logic is included
26362635
* when we call XLogInsert() since the value changes dynamically.
26372636
*/
2638-
if (DataChecksumsEnabled()&& (bufHdr->flags&BM_PERMANENT))
2637+
if (XLogHintBitIsNeeded()&& (bufHdr->flags&BM_PERMANENT))
26392638
{
26402639
/*
26412640
* If we're in recovery we cannot dirty a page because of a hint.

‎src/backend/utils/misc/guc.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,17 @@ static struct config_bool ConfigureNamesBool[] =
866866
true,
867867
NULL,NULL,NULL
868868
},
869+
870+
{
871+
{"wal_log_hintbits",PGC_POSTMASTER,WAL_SETTINGS,
872+
gettext_noop("Writes full pages to WAL when first modified after a checkpoint, even for a non-critical modifications"),
873+
NULL
874+
},
875+
&walLogHintbits,
876+
false,
877+
NULL,NULL,NULL
878+
},
879+
869880
{
870881
{"log_checkpoints",PGC_SIGHUP,LOGGING_WHAT,
871882
gettext_noop("Logs each checkpoint."),

‎src/backend/utils/misc/postgresql.conf.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
# fsync_writethrough
185185
# open_sync
186186
#full_page_writes = on# recover from partial page writes
187+
#wal_log_hintbits = off# also do full pages writes of non-critical updates
187188
#wal_buffers = -1# min 32kB, -1 sets based on shared_buffers
188189
# (change requires restart)
189190
#wal_writer_delay = 200ms# 1-10000 milliseconds

‎src/bin/pg_controldata/pg_controldata.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ main(int argc, char *argv[])
260260
ControlFile.backupEndRequired ?_("yes") :_("no"));
261261
printf(_("Current wal_level setting: %s\n"),
262262
wal_level_str(ControlFile.wal_level));
263+
printf(_("Current wal_log_hintbits setting: %s\n"),
264+
ControlFile.wal_log_hintbits ?_("on") :_("off"));
263265
printf(_("Current max_connections setting: %d\n"),
264266
ControlFile.MaxConnections);
265267
printf(_("Current max_worker_processes setting: %d\n"),

‎src/bin/pg_resetxlog/pg_resetxlog.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ GuessControlValues(void)
525525
/* minRecoveryPoint, backupStartPoint and backupEndPoint can be left zero */
526526

527527
ControlFile.wal_level=WAL_LEVEL_MINIMAL;
528+
ControlFile.wal_log_hintbits= false;
528529
ControlFile.MaxConnections=100;
529530
ControlFile.max_worker_processes=8;
530531
ControlFile.max_prepared_xacts=0;
@@ -721,6 +722,7 @@ RewriteControlFile(void)
721722
* anyway at startup.
722723
*/
723724
ControlFile.wal_level=WAL_LEVEL_MINIMAL;
725+
ControlFile.wal_log_hintbits= false;
724726
ControlFile.MaxConnections=100;
725727
ControlFile.max_worker_processes=8;
726728
ControlFile.max_prepared_xacts=0;

‎src/include/access/xlog.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ extern bool XLogArchiveMode;
189189
externchar*XLogArchiveCommand;
190190
externboolEnableHotStandby;
191191
externboolfullPageWrites;
192+
externboolwalLogHintbits;
192193
externboollog_checkpoints;
193194
externintnum_xloginsert_slots;
194195

@@ -211,6 +212,17 @@ extern intwal_level;
211212
*/
212213
#defineXLogIsNeeded() (wal_level >= WAL_LEVEL_ARCHIVE)
213214

215+
/*
216+
* Is a full-page image needed for hint bit updates?
217+
*
218+
* Normally, we don't WAL-log hint bit updates, but if checksums are enabled,
219+
* we have to protect them against torn page writes. When you only set
220+
* individual bits on a page, it's still consistent no matter what combination
221+
* of the bits make it to disk, but the checksum wouldn't match. Also WAL-log
222+
* them if forced by wal_log_hintbits=on.
223+
*/
224+
#defineXLogHintBitIsNeeded() (DataChecksumsEnabled() || walLogHintbits)
225+
214226
/* Do we need to WAL-log information required only for Hot Standby and logical replication? */
215227
#defineXLogStandbyInfoActive() (wal_level >= WAL_LEVEL_HOT_STANDBY)
216228

‎src/include/access/xlog_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ typedef struct xl_parameter_change
209209
intmax_prepared_xacts;
210210
intmax_locks_per_xact;
211211
intwal_level;
212+
boolwal_log_hintbits;
212213
}xl_parameter_change;
213214

214215
/* logs restore point */

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201311261
56+
#defineCATALOG_VERSION_NO201312131
5757

5858
#endif

‎src/include/catalog/pg_control.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ typedef struct ControlFileData
171171
* or hot standby.
172172
*/
173173
intwal_level;
174+
boolwal_log_hintbits;
174175
intMaxConnections;
175176
intmax_worker_processes;
176177
intmax_prepared_xacts;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp