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

Commitfbcbc5d

Browse files
committed
Force a checkpoint before committing a CREATE DATABASE command. This
should fix the recent reports of "index is not a btree" failures,as well as preventing a more obscure race condition involving changesto a template database just after copying it with CREATE DATABASE.
1 parent3acca18 commitfbcbc5d

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

‎doc/src/sgml/backup.sgml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/backup.sgml,v 2.68 2005/06/21 20:45:43 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/backup.sgml,v 2.69 2005/06/25 22:47:28 tgl Exp $
33
-->
44
<chapter id="backup">
55
<title>Backup and Restore</title>
@@ -1119,6 +1119,18 @@ restore_command = 'copy /mnt/server/archivedir/%f "%p"' # Windows
11191119
</para>
11201120
</listitem>
11211121

1122+
<listitem>
1123+
<para>
1124+
If a <command>CREATE DATABASE</> command is executed while a base
1125+
backup is being taken, and then the template database that the
1126+
<command>CREATE DATABASE</> copied is modified while the base backup
1127+
is still in progress, it is possible that recovery will cause those
1128+
modifications to be propagated into the created database as well.
1129+
This is of course undesirable. To avoid this risk, it is best not to
1130+
modify any template databases while taking a base backup.
1131+
</para>
1132+
</listitem>
1133+
11221134
<listitem>
11231135
<para>
11241136
<command>CREATE TABLESPACE</> commands are WAL-logged with the literal

‎src/backend/commands/dbcommands.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.160 2005/06/21 04:02:31 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.161 2005/06/25 22:47:29 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -514,6 +514,36 @@ createdb(const CreatedbStmt *stmt)
514514
/* Close pg_database, but keep exclusive lock till commit */
515515
heap_close(pg_database_rel,NoLock);
516516

517+
/*
518+
* We force a checkpoint before committing. This effectively means
519+
* that committed XLOG_DBASE_CREATE operations will never need to be
520+
* replayed (at least not in ordinary crash recovery; we still have
521+
* to make the XLOG entry for the benefit of PITR operations).
522+
* This avoids two nasty scenarios:
523+
*
524+
* #1: When PITR is off, we don't XLOG the contents of newly created
525+
* indexes; therefore the drop-and-recreate-whole-directory behavior
526+
* of DBASE_CREATE replay would lose such indexes.
527+
*
528+
* #2: Since we have to recopy the source database during DBASE_CREATE
529+
* replay, we run the risk of copying changes in it that were committed
530+
* after the original CREATE DATABASE command but before the system
531+
* crash that led to the replay. This is at least unexpected and at
532+
* worst could lead to inconsistencies, eg duplicate table names.
533+
*
534+
* (Both of these were real bugs in releases 8.0 through 8.0.3.)
535+
*
536+
* In PITR replay, the first of these isn't an issue, and the second
537+
* is only a risk if the CREATE DATABASE and subsequent template
538+
* database change both occur while a base backup is being taken.
539+
* There doesn't seem to be much we can do about that except document
540+
* it as a limitation.
541+
*
542+
* Perhaps if we ever implement CREATE DATABASE in a less cheesy
543+
* way, we can avoid this.
544+
*/
545+
RequestCheckpoint(true);
546+
517547
/*
518548
* Set flag to update flat database file at commit.
519549
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp