Rename "pg_xlog" directory to "pg_wal".

"xlog" is not a particularly clear abbreviation for "write-ahead log",
and it sometimes confuses users into believe that the contents of the
"pg_xlog" directory are not critical data, leading to unpleasant
consequences.  So, rename the directory to "pg_wal".

This patch modifies pg_upgrade and pg_basebackup to understand both
the old and new directory layouts; the former is necessary given the
purpose of the tool, while the latter merely avoids an unnecessary
backward-compatibility break.

We may wish to consider renaming other programs, switches, and
functions which still use the old "xlog" naming to also refer to
"wal".  However, that's still under discussion, so let's do just this
much for now.

Discussion: CAB7nPqTeC-8+zux8_-4ZD46V7YPwooeFxgndfsq5Rg8ibLVm1A@mail.gmail.com

Michael Paquier
This commit is contained in:
Robert Haas 2016-10-20 11:24:37 -04:00
parent ec7db2b483
commit f82ec32ac3
37 changed files with 276 additions and 223 deletions

View File

@ -472,7 +472,7 @@ tar -cf backup.tar /usr/local/pgsql/data
<para>
At all times, <productname>PostgreSQL</> maintains a
<firstterm>write ahead log</> (WAL) in the <filename>pg_xlog/</>
<firstterm>write ahead log</> (WAL) in the <filename>pg_wal/</>
subdirectory of the cluster's data directory. The log records
every change made to the database's data files. This log exists
primarily for crash-safety purposes: if the system crashes, the
@ -616,7 +616,7 @@ archive_command = 'copy "%p" "C:\\server\\archivedir\\%f"' # Windows
<literal>%p</> and <literal>%f</> parameters have been replaced,
the actual command executed might look like this:
<programlisting>
test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_xlog/00000001000000A900000065 /mnt/server/archivedir/00000001000000A900000065
test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_wal/00000001000000A900000065 /mnt/server/archivedir/00000001000000A900000065
</programlisting>
A similar command will be generated for each new file to be archived.
</para>
@ -668,9 +668,9 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_xlog/
fills, nothing further can be archived until the tape is swapped.
You should ensure that any error condition or request to a human operator
is reported appropriately so that the situation can be
resolved reasonably quickly. The <filename>pg_xlog/</> directory will
resolved reasonably quickly. The <filename>pg_wal/</> directory will
continue to fill with WAL segment files until the situation is resolved.
(If the file system containing <filename>pg_xlog/</> fills up,
(If the file system containing <filename>pg_wal/</> fills up,
<productname>PostgreSQL</> will do a PANIC shutdown. No committed
transactions will be lost, but the database will remain offline until
you free some space.)
@ -682,7 +682,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_xlog/
operation continues even if the archiving process falls a little behind.
If archiving falls significantly behind, this will increase the amount of
data that would be lost in the event of a disaster. It will also mean that
the <filename>pg_xlog/</> directory will contain large numbers of
the <filename>pg_wal/</> directory will contain large numbers of
not-yet-archived segment files, which could eventually exceed available
disk space. You are advised to monitor the archiving process to ensure that
it is working as you intend.
@ -743,7 +743,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_xlog/
configuration file reload. If you wish to temporarily stop archiving,
one way to do it is to set <varname>archive_command</> to the empty
string (<literal>''</>).
This will cause WAL files to accumulate in <filename>pg_xlog/</> until a
This will cause WAL files to accumulate in <filename>pg_wal/</> until a
working <varname>archive_command</> is re-established.
</para>
</sect2>
@ -1062,10 +1062,10 @@ SELECT pg_stop_backup();
<para>
You should, however, omit from the backup the files within the
cluster's <filename>pg_xlog/</> subdirectory. This
cluster's <filename>pg_wal/</> subdirectory. This
slight adjustment is worthwhile because it reduces the risk
of mistakes when restoring. This is easy to arrange if
<filename>pg_xlog/</> is a symbolic link pointing to someplace outside
<filename>pg_wal/</> is a symbolic link pointing to someplace outside
the cluster directory, which is a common setup anyway for performance
reasons. You might also want to exclude <filename>postmaster.pid</>
and <filename>postmaster.opts</>, which record information
@ -1149,7 +1149,7 @@ SELECT pg_stop_backup();
location in case you need them later. Note that this precaution will
require that you have enough free space on your system to hold two
copies of your existing database. If you do not have enough space,
you should at least save the contents of the cluster's <filename>pg_xlog</>
you should at least save the contents of the cluster's <filename>pg_wal</>
subdirectory, as it might contain logs which
were not archived before the system went down.
</para>
@ -1172,9 +1172,9 @@ SELECT pg_stop_backup();
</listitem>
<listitem>
<para>
Remove any files present in <filename>pg_xlog/</>; these came from the
Remove any files present in <filename>pg_wal/</>; these came from the
file system backup and are therefore probably obsolete rather than current.
If you didn't archive <filename>pg_xlog/</> at all, then recreate
If you didn't archive <filename>pg_wal/</> at all, then recreate
it with proper permissions,
being careful to ensure that you re-establish it as a symbolic link
if you had it set up that way before.
@ -1183,7 +1183,7 @@ SELECT pg_stop_backup();
<listitem>
<para>
If you have unarchived WAL segment files that you saved in step 2,
copy them into <filename>pg_xlog/</>. (It is best to copy them,
copy them into <filename>pg_wal/</>. (It is best to copy them,
not move them, so you still have the unmodified files if a
problem occurs and you have to start over.)
</para>
@ -1265,9 +1265,9 @@ restore_command = 'cp /mnt/server/archivedir/%f %p'
<para>
WAL segments that cannot be found in the archive will be sought in
<filename>pg_xlog/</>; this allows use of recent un-archived segments.
<filename>pg_wal/</>; this allows use of recent un-archived segments.
However, segments that are available from the archive will be used in
preference to files in <filename>pg_xlog/</>.
preference to files in <filename>pg_wal/</>.
</para>
<para>

View File

@ -2932,7 +2932,7 @@ include_dir 'conf.d'
<listitem>
<para>
Specifies the minimum number of past log file segments kept in the
<filename>pg_xlog</>
<filename>pg_wal</>
directory, in case a standby server needs to fetch them for streaming
replication. Each segment is normally 16 megabytes. If a standby
server connected to the sending server falls behind by more than
@ -2946,7 +2946,7 @@ include_dir 'conf.d'
<para>
This sets only the minimum number of segments retained in
<filename>pg_xlog</>; the system might need to retain more segments
<filename>pg_wal</>; the system might need to retain more segments
for WAL archival or to recover from a checkpoint. If
<varname>wal_keep_segments</> is zero (the default), the system
doesn't keep any extra segments for standby purposes, so the number
@ -3322,7 +3322,7 @@ include_dir 'conf.d'
<para>
Specify how long the standby server should wait when WAL data is not
available from any sources (streaming replication,
local <filename>pg_xlog</> or WAL archive) before retrying to
local <filename>pg_wal</> or WAL archive) before retrying to
retrieve WAL data. This parameter can only be set in the
<filename>postgresql.conf</> file or on the server command line.
The default value is 5 seconds. Units are milliseconds if not specified.

View File

@ -15327,7 +15327,7 @@ SELECT * FROM pg_ls_dir('.') WITH ORDINALITY AS t(ls,n);
pg_snapshots | 13
pg_multixact | 14
PG_VERSION | 15
pg_xlog | 16
pg_wal | 16
pg_hba.conf | 17
pg_stat_tmp | 18
pg_subtrans | 19

View File

@ -594,24 +594,24 @@ protocol to make nodes agree on a serializable transactional order.
(see <xref linkend="restore-command">) or directly from the master
over a TCP connection (streaming replication). The standby server will
also attempt to restore any WAL found in the standby cluster's
<filename>pg_xlog</> directory. That typically happens after a server
<filename>pg_wal</> directory. That typically happens after a server
restart, when the standby replays again WAL that was streamed from the
master before the restart, but you can also manually copy files to
<filename>pg_xlog</> at any time to have them replayed.
<filename>pg_wal</> at any time to have them replayed.
</para>
<para>
At startup, the standby begins by restoring all WAL available in the
archive location, calling <varname>restore_command</>. Once it
reaches the end of WAL available there and <varname>restore_command</>
fails, it tries to restore any WAL available in the <filename>pg_xlog</> directory.
fails, it tries to restore any WAL available in the <filename>pg_wal</> directory.
If that fails, and streaming replication has been configured, the
standby tries to connect to the primary server and start streaming WAL
from the last valid record found in archive or <filename>pg_xlog</>. If that fails
from the last valid record found in archive or <filename>pg_wal</>. If that fails
or streaming replication is not configured, or if the connection is
later disconnected, the standby goes back to step 1 and tries to
restore the file from the archive again. This loop of retries from the
archive, <filename>pg_xlog</>, and via streaming replication goes on until the server
archive, <filename>pg_wal</>, and via streaming replication goes on until the server
is stopped or failover is triggered by a trigger file.
</para>
@ -619,7 +619,7 @@ protocol to make nodes agree on a serializable transactional order.
Standby mode is exited and the server switches to normal operation
when <command>pg_ctl promote</> is run or a trigger file is found
(<varname>trigger_file</>). Before failover,
any WAL immediately available in the archive or in <filename>pg_xlog</> will be
any WAL immediately available in the archive or in <filename>pg_wal</> will be
restored, but no attempt is made to connect to the master.
</para>
</sect2>
@ -895,7 +895,7 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
However, these methods often result in retaining more WAL segments than
required, whereas replication slots retain only the number of segments
known to be needed. An advantage of these methods is that they bound
the space requirement for <literal>pg_xlog</>; there is currently no way
the space requirement for <literal>pg_wal</>; there is currently no way
to do this using replication slots.
</para>
<para>

View File

@ -1612,7 +1612,7 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
Increase <xref linkend="guc-max-wal-size"> and <xref
linkend="guc-checkpoint-timeout"> ; this reduces the frequency
of checkpoints, but increases the storage requirements of
<filename>/pg_xlog</>.
<filename>/pg_wal</>.
</para>
</listitem>

View File

@ -1947,7 +1947,7 @@ The commands accepted in walsender mode are:
<para>
Include the necessary WAL segments in the backup. This will include
all the files between start and stop backup in the
<filename>pg_xlog</filename> directory of the base directory tar
<filename>pg_wal</filename> directory of the base directory tar
file.
</para>
</listitem>
@ -2076,8 +2076,8 @@ The commands accepted in walsender mode are:
</listitem>
<listitem>
<para>
<filename>pg_xlog</>, including subdirectories. If the backup is run
with WAL files included, a synthesized version of <filename>pg_xlog</filename> will be
<filename>pg_wal</>, including subdirectories. If the backup is run
with WAL files included, a synthesized version of <filename>pg_wal</filename> will be
included, but it will only contain the files necessary for the
backup to work, not the rest of the contents.
</para>

View File

@ -173,22 +173,22 @@ PostgreSQL documentation
<para>
The WAL starting address should be
larger than any WAL segment file name currently existing in
the directory <filename>pg_xlog</> under the data directory.
the directory <filename>pg_wal</> under the data directory.
These names are also in hexadecimal and have three parts. The first
part is the <quote>timeline ID</> and should usually be kept the same.
For example, if <filename>00000001000000320000004A</> is the
largest entry in <filename>pg_xlog</>, use <literal>-l 00000001000000320000004B</> or higher.
largest entry in <filename>pg_wal</>, use <literal>-l 00000001000000320000004B</> or higher.
</para>
<note>
<para>
<command>pg_resetxlog</command> itself looks at the files in
<filename>pg_xlog</> and chooses a default <option>-l</> setting
<filename>pg_wal</> and chooses a default <option>-l</> setting
beyond the last existing file name. Therefore, manual adjustment of
<option>-l</> should only be needed if you are aware of WAL segment
files that are not currently present in <filename>pg_xlog</>, such as
files that are not currently present in <filename>pg_wal</>, such as
entries in an offline archive; or if the contents of
<filename>pg_xlog</> have been lost entirely.
<filename>pg_wal</> have been lost entirely.
</para>
</note>
</listitem>

View File

@ -61,14 +61,14 @@ PostgreSQL documentation
<para>
<application>pg_rewind</> examines the timeline histories of the source
and target clusters to determine the point where they diverged, and
expects to find WAL in the target cluster's <filename>pg_xlog</> directory
expects to find WAL in the target cluster's <filename>pg_wal</> directory
reaching all the way back to the point of divergence. The point of divergence
can be found either on the target timeline, the source timeline, or their common
ancestor. In the typical failover scenario where the target cluster was
shut down soon after the divergence, this is not a problem, but if the
target cluster ran for a long time after the divergence, the old WAL
files might no longer be present. In that case, they can be manually
copied from the WAL archive to the <filename>pg_xlog</> directory, or
copied from the WAL archive to the <filename>pg_wal</> directory, or
fetched on startup by configuring <filename>recovery.conf</>. The use of
<application>pg_rewind</> is not limited to failover, e.g. a standby
server can be promoted, run some write transactions, and then rewinded

View File

@ -118,7 +118,7 @@ PostgreSQL documentation
<listitem>
<para>
Directory in which to find log segment files. The default is to search
for them in the <literal>pg_xlog</literal> subdirectory of the current
for them in the <literal>pg_wal</literal> subdirectory of the current
directory.
</para>
</listitem>

View File

@ -57,8 +57,8 @@
<para>
Specifies the file name to write test data in.
This file should be in the same file system that the
<filename>pg_xlog</> directory is or will be placed in.
(<filename>pg_xlog</> contains the <acronym>WAL</> files.)
<filename>pg_wal</> directory is or will be placed in.
(<filename>pg_wal</> contains the <acronym>WAL</> files.)
The default is <filename>pg_test_fsync.out</> in the current
directory.
</para>

View File

@ -345,7 +345,7 @@ NET STOP postgresql-9.0
your old cluster
once you start the new cluster after the upgrade. Link mode also
requires that the old and new cluster data directories be in the
same file system. (Tablespaces and <filename>pg_xlog</> can be on
same file system. (Tablespaces and <filename>pg_wal</> can be on
different file systems.) See <literal>pg_upgrade --help</> for a full
list of options.
</para>
@ -508,7 +508,7 @@ rsync --archive --delete --hard-links --size-only old_pgdata new_pgdata remote_d
<para>
If you have tablespaces, you will need to run a similar
<application>rsync</> command for each tablespace directory. If you
have relocated <filename>pg_xlog</> outside the data directories,
have relocated <filename>pg_wal</> outside the data directories,
<application>rsync</> must be run on those directories too.
</para>
</step>

View File

@ -141,7 +141,7 @@ Item
</row>
<row>
<entry><filename>pg_xlog</></entry>
<entry><filename>pg_wal</></entry>
<entry>Subdirectory containing WAL (Write Ahead Log) files</entry>
</row>

View File

@ -557,7 +557,7 @@
</para>
<para>
The number of WAL segment files in <filename>pg_xlog</> directory depends on
The number of WAL segment files in <filename>pg_wal</> directory depends on
<varname>min_wal_size</>, <varname>max_wal_size</> and
the amount of WAL generated in previous checkpoint cycles. When old log
segment files are no longer needed, they are removed or recycled (that is,
@ -582,7 +582,7 @@
kept at all times. Also, if WAL archiving is used, old segments can not be
removed or recycled until they are archived. If WAL archiving cannot keep up
with the pace that WAL is generated, or if <varname>archive_command</varname>
fails repeatedly, old WAL files will accumulate in <filename>pg_xlog</>
fails repeatedly, old WAL files will accumulate in <filename>pg_wal</>
until the situation is resolved. A slow or failed standby server that
uses a replication slot will have the same effect (see
<xref linkend="streaming-replication-slots">).
@ -594,7 +594,7 @@
which are similar to checkpoints in normal operation: the server forces
all its state to disk, updates the <filename>pg_control</> file to
indicate that the already-processed WAL data need not be scanned again,
and then recycles any old log segment files in the <filename>pg_xlog</>
and then recycles any old log segment files in the <filename>pg_wal</>
directory.
Restartpoints can't be performed more frequently than checkpoints in the
master because restartpoints can only be performed at checkpoint records.
@ -750,7 +750,7 @@
<para>
<acronym>WAL</acronym> logs are stored in the directory
<filename>pg_xlog</filename> under the data directory, as a set of
<filename>pg_wal</filename> under the data directory, as a set of
segment files, normally each 16 MB in size (but the size can be changed
by altering the <option>--with-wal-segsize</> configure option when
building the server). Each segment is divided into pages, normally
@ -767,7 +767,7 @@
<para>
It is advantageous if the log is located on a different disk from the
main database files. This can be achieved by moving the
<filename>pg_xlog</filename> directory to another location (while the server
<filename>pg_wal</filename> directory to another location (while the server
is shut down, of course) and creating a symbolic link from the
original location in the main data directory to the new location.
</para>

View File

@ -43,7 +43,7 @@
/*
* Copies all timeline history files with id's between 'begin' and 'end'
* from archive to pg_xlog.
* from archive to pg_wal.
*/
void
restoreTimeLineHistoryFiles(TimeLineID begin, TimeLineID end)
@ -191,7 +191,7 @@ readTimeLineHistory(TimeLineID targetTLI)
result = lcons(entry, result);
/*
* If the history file was fetched from archive, save it in pg_xlog for
* If the history file was fetched from archive, save it in pg_wal for
* future reference.
*/
if (fromArchive)

View File

@ -235,9 +235,9 @@ static int LocalXLogInsertAllowed = -1;
* valid in the startup process.
*
* When ArchiveRecoveryRequested is true, but InArchiveRecovery is false, we're
* currently performing crash recovery using only XLOG files in pg_xlog, but
* currently performing crash recovery using only XLOG files in pg_wal, but
* will switch to using offline XLOG archives as soon as we reach the end of
* WAL in pg_xlog.
* WAL in pg_wal.
*/
bool ArchiveRecoveryRequested = false;
bool InArchiveRecovery = false;
@ -700,12 +700,12 @@ typedef enum
{
XLOG_FROM_ANY = 0, /* request to read WAL from any source */
XLOG_FROM_ARCHIVE, /* restored using restore_command */
XLOG_FROM_PG_XLOG, /* existing file in pg_xlog */
XLOG_FROM_PG_WAL, /* existing file in pg_wal */
XLOG_FROM_STREAM /* streamed from master */
} XLogSource;
/* human-readable names for XLogSources, for debugging output */
static const char *xlogSourceNames[] = {"any", "archive", "pg_xlog", "stream"};
static const char *xlogSourceNames[] = {"any", "archive", "pg_wal", "stream"};
/*
* openLogFile is -1 or a kernel FD for an open log file segment.
@ -3345,7 +3345,7 @@ XLogFileOpen(XLogSegNo segno)
* Open a logfile segment for reading (during recovery).
*
* If source == XLOG_FROM_ARCHIVE, the segment is retrieved from archive.
* Otherwise, it's assumed to be already available in pg_xlog.
* Otherwise, it's assumed to be already available in pg_wal.
*/
static int
XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli,
@ -3374,7 +3374,7 @@ XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli,
return -1;
break;
case XLOG_FROM_PG_XLOG:
case XLOG_FROM_PG_WAL:
case XLOG_FROM_STREAM:
XLogFilePath(path, tli, segno);
restoredFromArchive = false;
@ -3393,7 +3393,7 @@ XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli,
KeepFileRestoredFromArchive(path, xlogfname);
/*
* Set path to point at the new file in pg_xlog.
* Set path to point at the new file in pg_wal.
*/
snprintf(path, MAXPGPATH, XLOGDIR "/%s", xlogfname);
}
@ -3481,10 +3481,10 @@ XLogFileReadAnyTLI(XLogSegNo segno, int emode, int source)
}
}
if (source == XLOG_FROM_ANY || source == XLOG_FROM_PG_XLOG)
if (source == XLOG_FROM_ANY || source == XLOG_FROM_PG_WAL)
{
fd = XLogFileRead(segno, emode, tli,
XLOG_FROM_PG_XLOG, true);
XLOG_FROM_PG_WAL, true);
if (fd != -1)
{
if (!expectedTLEs)
@ -3693,10 +3693,10 @@ RemoveOldXlogFiles(XLogSegNo segno, XLogRecPtr PriorRedoPtr, XLogRecPtr endptr)
*
* This is called during recovery, whenever we switch to follow a new
* timeline, and at the end of recovery when we create a new timeline. We
* wouldn't otherwise care about extra WAL files lying in pg_xlog, but they
* wouldn't otherwise care about extra WAL files lying in pg_wal, but they
* might be leftover pre-allocated or recycled WAL segments on the old timeline
* that we haven't used yet, and contain garbage. If we just leave them in
* pg_xlog, they will eventually be archived, and we can't let that happen.
* pg_wal, they will eventually be archived, and we can't let that happen.
* Files that belong to our timeline history are valid, because we have
* successfully replayed them, but from others we can't be sure.
*
@ -3853,15 +3853,15 @@ RemoveXlogFile(const char *segname, XLogRecPtr PriorRedoPtr, XLogRecPtr endptr)
}
/*
* Verify whether pg_xlog and pg_xlog/archive_status exist.
* Verify whether pg_wal and pg_wal/archive_status exist.
* If the latter does not exist, recreate it.
*
* It is not the goal of this function to verify the contents of these
* directories, but to help in cases where someone has performed a cluster
* copy for PITR purposes but omitted pg_xlog from the copy.
* copy for PITR purposes but omitted pg_wal from the copy.
*
* We could also recreate pg_xlog if it doesn't exist, but a deliberate
* policy decision was made not to. It is fairly common for pg_xlog to be
* We could also recreate pg_wal if it doesn't exist, but a deliberate
* policy decision was made not to. It is fairly common for pg_wal to be
* a symlink, and if that was the DBA's intent then automatically making a
* plain directory would result in degraded performance with no notice.
*/
@ -3871,7 +3871,7 @@ ValidateXLOGDirectoryStructure(void)
char path[MAXPGPATH];
struct stat stat_buf;
/* Check for pg_xlog; if it doesn't exist, error out */
/* Check for pg_wal; if it doesn't exist, error out */
if (stat(XLOGDIR, &stat_buf) != 0 ||
!S_ISDIR(stat_buf.st_mode))
ereport(FATAL,
@ -4027,11 +4027,11 @@ ReadRecord(XLogReaderState *xlogreader, XLogRecPtr RecPtr, int emode,
* If archive recovery was requested, but we were still doing
* crash recovery, switch to archive recovery and retry using the
* offline archive. We have now replayed all the valid WAL in
* pg_xlog, so we are presumably now consistent.
* pg_wal, so we are presumably now consistent.
*
* We require that there's at least some valid WAL present in
* pg_xlog, however (!fetch_ckpt). We could recover using the WAL
* from the archive, even if pg_xlog is completely empty, but we'd
* pg_wal, however (!fetch_ckpt). We could recover using the WAL
* from the archive, even if pg_wal is completely empty, but we'd
* have no idea how far we'd have to replay to reach consistency.
* So err on the safe side and give up.
*/
@ -4039,7 +4039,7 @@ ReadRecord(XLogReaderState *xlogreader, XLogRecPtr RecPtr, int emode,
!fetching_ckpt)
{
ereport(DEBUG1,
(errmsg_internal("reached end of WAL in pg_xlog, entering archive recovery")));
(errmsg_internal("reached end of WAL in pg_wal, entering archive recovery")));
InArchiveRecovery = true;
if (StandbyModeRequested)
StandbyMode = true;
@ -4156,7 +4156,7 @@ rescanLatestTimeLine(void)
/*
* As in StartupXLOG(), try to ensure we have all the history files
* between the old target and new target in pg_xlog.
* between the old target and new target in pg_wal.
*/
restoreTimeLineHistoryFiles(oldtarget + 1, newtarget);
@ -5189,7 +5189,7 @@ readRecoveryCommandFile(void)
ereport(WARNING,
(errmsg("recovery command file \"%s\" specified neither primary_conninfo nor restore_command",
RECOVERY_COMMAND_FILE),
errhint("The database server will regularly poll the pg_xlog subdirectory to check for files placed there.")));
errhint("The database server will regularly poll the pg_wal subdirectory to check for files placed there.")));
}
else
{
@ -6056,7 +6056,7 @@ StartupXLOG(void)
#endif
/*
* Verify that pg_xlog and pg_xlog/archive_status exist. In cases where
* Verify that pg_wal and pg_wal/archive_status exist. In cases where
* someone has performed a copy for PITR, these directories may have been
* excluded and need to be re-created.
*/
@ -6269,7 +6269,7 @@ StartupXLOG(void)
* and put it into archive recovery by creating a recovery.conf file.
*
* Our strategy in that case is to perform crash recovery first,
* replaying all the WAL present in pg_xlog, and only enter archive
* replaying all the WAL present in pg_wal, and only enter archive
* recovery after that.
*
* But usually we already know how far we need to replay the WAL (up
@ -6473,7 +6473,7 @@ StartupXLOG(void)
/*
* Copy any missing timeline history files between 'now' and the recovery
* target timeline from archive to pg_xlog. While we don't need those
* target timeline from archive to pg_wal. While we don't need those
* files ourselves - the history file of the recovery target timeline
* covers all the previous timelines in the history too - a cascading
* standby server might be interested in them. Or, if you archive the WAL
@ -7094,7 +7094,7 @@ StartupXLOG(void)
/*
* We are now done reading the xlog from stream. Turn off streaming
* recovery to force fetching the files (which would be required at end of
* recovery, e.g., timeline history file) from archive or pg_xlog.
* recovery, e.g., timeline history file) from archive or pg_wal.
*/
StandbyMode = false;
@ -7382,7 +7382,7 @@ StartupXLOG(void)
* As a compromise, we rename the last segment with the .partial
* suffix, and archive it. Archive recovery will never try to read
* .partial segments, so they will normally go unused. But in the odd
* PITR case, the administrator can copy them manually to the pg_xlog
* PITR case, the administrator can copy them manually to the pg_wal
* directory (removing the suffix). They can be useful in debugging,
* too.
*
@ -9958,7 +9958,7 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
* first WAL segment containing the startup checkpoint has pages in
* the beginning with the old timeline ID. That can cause trouble at
* recovery: we won't have a history file covering the old timeline if
* pg_xlog directory was not included in the base backup and the WAL
* pg_wal directory was not included in the base backup and the WAL
* archive was cleared too before starting the backup.
*
* This also ensures that we have emitted a WAL page header that has
@ -10605,7 +10605,7 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p)
* archived before returning. If archiving isn't enabled, the required WAL
* needs to be transported via streaming replication (hopefully with
* wal_keep_segments set high enough), or some more exotic mechanism like
* polling and copying files from pg_xlog with script. We have no
* polling and copying files from pg_wal with script. We have no
* knowledge of those mechanisms, so it's up to the user to ensure that he
* gets all the required WAL.
*
@ -11195,9 +11195,9 @@ next_record_is_invalid:
* Open the WAL segment containing WAL position 'RecPtr'.
*
* The segment can be fetched via restore_command, or via walreceiver having
* streamed the record, or it can already be present in pg_xlog. Checking
* pg_xlog is mainly for crash recovery, but it will be polled in standby mode
* too, in case someone copies a new segment directly to pg_xlog. That is not
* streamed the record, or it can already be present in pg_wal. Checking
* pg_wal is mainly for crash recovery, but it will be polled in standby mode
* too, in case someone copies a new segment directly to pg_wal. That is not
* documented or recommended, though.
*
* If 'fetching_ckpt' is true, we're fetching a checkpoint record, and should
@ -11227,8 +11227,8 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
/*-------
* Standby mode is implemented by a state machine:
*
* 1. Read from either archive or pg_xlog (XLOG_FROM_ARCHIVE), or just
* pg_xlog (XLOG_FROM_XLOG)
* 1. Read from either archive or pg_wal (XLOG_FROM_ARCHIVE), or just
* pg_wal (XLOG_FROM_PG_WAL)
* 2. Check trigger file
* 3. Read from primary server via walreceiver (XLOG_FROM_STREAM)
* 4. Rescan timelines
@ -11244,7 +11244,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
*-------
*/
if (!InArchiveRecovery)
currentSource = XLOG_FROM_PG_XLOG;
currentSource = XLOG_FROM_PG_WAL;
else if (currentSource == 0)
currentSource = XLOG_FROM_ARCHIVE;
@ -11263,13 +11263,13 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
switch (currentSource)
{
case XLOG_FROM_ARCHIVE:
case XLOG_FROM_PG_XLOG:
case XLOG_FROM_PG_WAL:
/*
* Check to see if the trigger file exists. Note that we
* do this only after failure, so when you create the
* trigger file, we still finish replaying as much as we
* can from archive and pg_xlog before failover.
* can from archive and pg_wal before failover.
*/
if (StandbyMode && CheckForStandbyTrigger())
{
@ -11279,7 +11279,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
/*
* Not in standby mode, and we've now tried the archive
* and pg_xlog.
* and pg_wal.
*/
if (!StandbyMode)
return false;
@ -11339,7 +11339,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
* little chance that the problem will just go away, but
* PANIC is not good for availability either, especially
* in hot standby mode. So, we treat that the same as
* disconnection, and retry from archive/pg_xlog again.
* disconnection, and retry from archive/pg_wal again.
* The WAL in the archive should be identical to what was
* streamed, so it's unlikely that it helps, but one can
* hope...
@ -11400,11 +11400,11 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
elog(ERROR, "unexpected WAL source %d", currentSource);
}
}
else if (currentSource == XLOG_FROM_PG_XLOG)
else if (currentSource == XLOG_FROM_PG_WAL)
{
/*
* We just successfully read a file in pg_xlog. We prefer files in
* the archive over ones in pg_xlog, so try the next file again
* We just successfully read a file in pg_wal. We prefer files in
* the archive over ones in pg_wal, so try the next file again
* from the archive first.
*/
if (InArchiveRecovery)
@ -11425,7 +11425,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
switch (currentSource)
{
case XLOG_FROM_ARCHIVE:
case XLOG_FROM_PG_XLOG:
case XLOG_FROM_PG_WAL:
/* Close any old file we might have open. */
if (readFile >= 0)
{
@ -11438,7 +11438,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
/*
* Try to restore the file from archive, or read an existing
* file from pg_xlog.
* file from pg_wal.
*/
readFile = XLogFileReadAnyTLI(readSegNo, DEBUG2,
currentSource == XLOG_FROM_ARCHIVE ? XLOG_FROM_ANY :
@ -11447,7 +11447,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
return true; /* success! */
/*
* Nope, not found in archive or pg_xlog.
* Nope, not found in archive or pg_wal.
*/
lastSourceFailed = true;
break;
@ -11503,7 +11503,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
* not open already. Also read the timeline history
* file if we haven't initialized timeline history
* yet; it should be streamed over and present in
* pg_xlog by now. Use XLOG_FROM_STREAM so that
* pg_wal by now. Use XLOG_FROM_STREAM so that
* source info is set correctly and XLogReceiptTime
* isn't changed.
*/
@ -11535,10 +11535,10 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
/*
* Note that we don't "return false" immediately here.
* After being triggered, we still want to replay all
* the WAL that was already streamed. It's in pg_xlog
* the WAL that was already streamed. It's in pg_wal
* now, so we just treat this as a failure, and the
* state machine will move on to replay the streamed
* WAL from pg_xlog, and then recheck the trigger and
* WAL from pg_wal, and then recheck the trigger and
* exit replay.
*/
lastSourceFailed = true;
@ -11578,7 +11578,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
* or legitimate end-of-WAL situation. Generally, we use it as-is, but if
* we're retrying the exact same record that we've tried previously, only
* complain the first time to keep the noise down. However, we only do when
* reading from pg_xlog, because we don't expect any invalid records in archive
* reading from pg_wal, because we don't expect any invalid records in archive
* or in records streamed from master. Files in the archive should be complete,
* and we should never hit the end of WAL because we stop and wait for more WAL
* to arrive before replaying it.
@ -11593,7 +11593,7 @@ emode_for_corrupt_record(int emode, XLogRecPtr RecPtr)
{
static XLogRecPtr lastComplaint = 0;
if (readSource == XLOG_FROM_PG_XLOG && emode == LOG)
if (readSource == XLOG_FROM_PG_WAL && emode == LOG)
{
if (RecPtr == lastComplaint)
emode = DEBUG1;

View File

@ -421,7 +421,7 @@ ExecuteRecoveryCommand(char *command, char *commandName, bool failOnSignal)
/*
* A file was restored from the archive under a temporary filename (path),
* and now we want to keep it. Rename it under the permanent filename in
* in pg_xlog (xlogfname), replacing any existing file with the same name.
* in pg_wal (xlogfname), replacing any existing file with the same name.
*/
void
KeepFileRestoredFromArchive(char *path, char *xlogfname)

View File

@ -128,7 +128,7 @@ pg_start_backup(PG_FUNCTION_ARGS)
* pg_stop_backup: finish taking an on-line backup dump
*
* We write an end-of-backup WAL record, and remove the backup label file
* created by pg_start_backup, creating a backup history file in pg_xlog
* created by pg_start_backup, creating a backup history file in pg_wal
* instead (whence it will immediately be archived). The backup history file
* contains the same info found in the label file, plus the backup-end time
* and WAL location. Before 9.0, the backup-end time was read from the backup

View File

@ -54,7 +54,7 @@ and WalRcvData->slotname, and initializes the starting point in
WalRcvData->receiveStart.
As walreceiver receives WAL from the master server, and writes and flushes
it to disk (in pg_xlog), it updates WalRcvData->receivedUpto and signals
it to disk (in pg_wal), it updates WalRcvData->receivedUpto and signals
the startup process to know how far WAL replay can advance.
Walreceiver sends information about replication progress to the master server

View File

@ -346,7 +346,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
TimeLineID tli;
/*
* I'd rather not worry about timelines here, so scan pg_xlog and
* I'd rather not worry about timelines here, so scan pg_wal and
* include all WAL files in the range between 'startptr' and 'endptr',
* regardless of the timeline the file is stamped with. If there are
* some spurious WAL files belonging to timelines that don't belong in
@ -359,11 +359,11 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
XLByteToPrevSeg(endptr, endsegno);
XLogFileName(lastoff, ThisTimeLineID, endsegno);
dir = AllocateDir("pg_xlog");
dir = AllocateDir("pg_wal");
if (!dir)
ereport(ERROR,
(errmsg("could not open directory \"%s\": %m", "pg_xlog")));
while ((de = ReadDir(dir, "pg_xlog")) != NULL)
(errmsg("could not open directory \"%s\": %m", "pg_wal")));
while ((de = ReadDir(dir, "pg_wal")) != NULL)
{
/* Does it look like a WAL segment, and is it in the range? */
if (IsXLogFileName(de->d_name) &&
@ -401,7 +401,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
qsort(walFiles, nWalFiles, sizeof(char *), compareWalFileNames);
/*
* There must be at least one xlog file in the pg_xlog directory,
* There must be at least one xlog file in the pg_wal directory,
* since we are doing backup-including-xlog.
*/
if (nWalFiles < 1)
@ -1054,23 +1054,23 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces,
}
/*
* We can skip pg_xlog, the WAL segments need to be fetched from the
* We can skip pg_wal, the WAL segments need to be fetched from the
* WAL archive anyway. But include it as an empty directory anyway, so
* we get permissions right.
*/
if (strcmp(pathbuf, "./pg_xlog") == 0)
if (strcmp(pathbuf, "./pg_wal") == 0)
{
/* If pg_xlog is a symlink, write it as a directory anyway */
/* If pg_wal is a symlink, write it as a directory anyway */
size += _tarWriteDir(pathbuf, basepathlen, &statbuf, sizeonly);
/*
* Also send archive_status directory (by hackishly reusing
* statbuf from above ...).
*/
size += _tarWriteHeader("./pg_xlog/archive_status", NULL, &statbuf,
size += _tarWriteHeader("./pg_wal/archive_status", NULL, &statbuf,
sizeonly);
continue; /* don't recurse into pg_xlog */
continue; /* don't recurse into pg_wal */
}
/* Allow symbolic links in pg_tblspc only */

View File

@ -18,7 +18,7 @@
* If the primary server ends streaming, but doesn't disconnect, walreceiver
* goes into "waiting" mode, and waits for the startup process to give new
* instructions. The startup process will treat that the same as
* disconnection, and will rescan the archive/pg_xlog directory. But when the
* disconnection, and will rescan the archive/pg_wal directory. But when the
* startup process wants to try streaming replication again, it will just
* nudge the existing walreceiver process that's waiting, instead of launching
* a new one.
@ -365,7 +365,7 @@ WalReceiverMain(void)
* we've already reached the end of the old timeline, the server will
* finish the streaming immediately, and we will go back to await
* orders from the startup process. If recovery_target_timeline is
* 'latest', the startup process will scan pg_xlog and find the new
* 'latest', the startup process will scan pg_wal and find the new
* history file, bump recovery target timeline, and ask us to restart
* on the new timeline.
*/
@ -742,7 +742,7 @@ WalRcvFetchTimeLineHistoryFiles(TimeLineID first, TimeLineID last)
tli)));
/*
* Write the file to pg_xlog.
* Write the file to pg_wal.
*/
writeTimeLineHistoryFile(tli, content, len);

View File

@ -586,7 +586,7 @@ StartReplication(StartReplicationCmd *cmd)
* segment that contains switchpoint, but on the new timeline, so
* that it doesn't end up with a partial segment. If you ask for a
* too old starting point, you'll get an error later when we fail
* to find the requested WAL segment in pg_xlog.
* to find the requested WAL segment in pg_wal.
*
* XXX: we could be more strict here and only allow a startpoint
* that's older than the switchpoint, if it's still in the same
@ -2058,7 +2058,7 @@ retry:
*
* For example, imagine that this server is currently on timeline
* 5, and we're streaming timeline 4. The switch from timeline 4
* to 5 happened at 0/13002088. In pg_xlog, we have these files:
* to 5 happened at 0/13002088. In pg_wal, we have these files:
*
* ...
* 000000040000000000000012

View File

@ -2787,7 +2787,7 @@ looks_like_temp_rel_name(const char *name)
* Issue fsync recursively on PGDATA and all its contents.
*
* We fsync regular files and directories wherever they are, but we
* follow symlinks only for pg_xlog and immediately under pg_tblspc.
* follow symlinks only for pg_wal and immediately under pg_tblspc.
* Other symlinks are presumed to point at files we're not responsible
* for fsyncing, and might not have privileges to write at all.
*
@ -2811,7 +2811,7 @@ SyncDataDirectory(void)
return;
/*
* If pg_xlog is a symlink, we'll need to recurse into it separately,
* If pg_wal is a symlink, we'll need to recurse into it separately,
* because the first walkdir below will ignore it.
*/
xlog_is_symlink = false;
@ -2820,16 +2820,16 @@ SyncDataDirectory(void)
{
struct stat st;
if (lstat("pg_xlog", &st) < 0)
if (lstat("pg_wal", &st) < 0)
ereport(LOG,
(errcode_for_file_access(),
errmsg("could not stat file \"%s\": %m",
"pg_xlog")));
"pg_wal")));
else if (S_ISLNK(st.st_mode))
xlog_is_symlink = true;
}
#else
if (pgwin32_is_junction("pg_xlog"))
if (pgwin32_is_junction("pg_wal"))
xlog_is_symlink = true;
#endif
@ -2841,7 +2841,7 @@ SyncDataDirectory(void)
#ifdef PG_FLUSH_DATA_WORKS
walkdir(".", pre_sync_fname, false, DEBUG1);
if (xlog_is_symlink)
walkdir("pg_xlog", pre_sync_fname, false, DEBUG1);
walkdir("pg_wal", pre_sync_fname, false, DEBUG1);
walkdir("pg_tblspc", pre_sync_fname, true, DEBUG1);
#endif
@ -2849,14 +2849,14 @@ SyncDataDirectory(void)
* Now we do the fsync()s in the same order.
*
* The main call ignores symlinks, so in addition to specially processing
* pg_xlog if it's a symlink, pg_tblspc has to be visited separately with
* pg_wal if it's a symlink, pg_tblspc has to be visited separately with
* process_symlinks = true. Note that if there are any plain directories
* in pg_tblspc, they'll get fsync'd twice. That's not an expected case
* so we don't worry about optimizing it.
*/
walkdir(".", datadir_fsync_fname, false, LOG);
if (xlog_is_symlink)
walkdir("pg_xlog", datadir_fsync_fname, false, LOG);
walkdir("pg_wal", datadir_fsync_fname, false, LOG);
walkdir("pg_tblspc", datadir_fsync_fname, true, LOG);
}

View File

@ -195,7 +195,7 @@ static const char *backend_options = "--single -F -O -j -c search_path=pg_catalo
static const char *const subdirs[] = {
"global",
"pg_xlog/archive_status",
"pg_wal/archive_status",
"pg_clog",
"pg_commit_ts",
"pg_dynshmem",
@ -2091,8 +2091,6 @@ make_postgres(FILE *cmdfd)
PG_CMD_PUTS(*line);
}
/*
* signal handler in case we are interrupted.
*
@ -2830,7 +2828,7 @@ create_xlog_or_symlink(void)
char *subdirloc;
/* form name of the place for the subdirectory or symlink */
subdirloc = psprintf("%s/pg_xlog", pg_data);
subdirloc = psprintf("%s/pg_wal", pg_data);
if (strcmp(xlog_dir, "") != 0)
{
@ -2963,7 +2961,7 @@ initialize_data_directory(void)
create_xlog_or_symlink();
/* Create required subdirectories (other than pg_xlog) */
/* Create required subdirectories (other than pg_wal) */
printf(_("creating subdirectories ... "));
fflush(stdout);
@ -3260,7 +3258,7 @@ main(int argc, char *argv[])
fputs(_("syncing data to disk ... "), stdout);
fflush(stdout);
fsync_pgdata(pg_data, progname);
fsync_pgdata(pg_data, progname, PG_VERSION_NUM);
check_ok();
return 0;
}
@ -3326,7 +3324,7 @@ main(int argc, char *argv[])
{
fputs(_("syncing data to disk ... "), stdout);
fflush(stdout);
fsync_pgdata(pg_data, progname);
fsync_pgdata(pg_data, progname, PG_VERSION_NUM);
check_ok();
}
else

View File

@ -55,6 +55,12 @@ typedef struct TablespaceList
TablespaceListCell *tail;
} TablespaceList;
/*
* pg_xlog has been renamed to pg_wal in version 10. This version number
* should be compared with PQserverVersion().
*/
#define MINIMUM_VERSION_FOR_PG_WAL 100000
/* Global options */
static char *basedir = NULL;
static TablespaceList tablespace_dirs = {NULL, NULL};
@ -526,15 +532,22 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier)
/* Error message already written in GetConnection() */
exit(1);
snprintf(param->xlogdir, sizeof(param->xlogdir), "%s/pg_xlog", basedir);
/* In post-10 cluster, pg_xlog has been renamed to pg_wal */
snprintf(param->xlogdir, sizeof(param->xlogdir), "%s/%s",
basedir,
PQserverVersion(conn) < MINIMUM_VERSION_FOR_PG_WAL ?
"pg_xlog" : "pg_wal");
/*
* Create pg_xlog/archive_status (and thus pg_xlog) so we can write to
* basedir/pg_xlog as the directory entry in the tar file may arrive
* later.
* Create pg_wal/archive_status or pg_xlog/archive_status (and thus
* pg_wal or pg_xlog) depending on the target server so we can write to
* basedir/pg_wal or basedir/pg_xlog as the directory entry in the tar
* file may arrive later.
*/
snprintf(statusdir, sizeof(statusdir), "%s/pg_xlog/archive_status",
basedir);
snprintf(statusdir, sizeof(statusdir), "%s/%s/archive_status",
basedir,
PQserverVersion(conn) < MINIMUM_VERSION_FOR_PG_WAL ?
"pg_xlog" : "pg_wal");
if (pg_mkdir_p(statusdir, S_IRWXU) != 0 && errno != EEXIST)
{
@ -1338,15 +1351,17 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum)
if (mkdir(filename, S_IRWXU) != 0)
{
/*
* When streaming WAL, pg_xlog will have been created
* by the wal receiver process. Also, when transaction
* log directory location was specified, pg_xlog has
* already been created as a symbolic link before
* starting the actual backup. So just ignore creation
* failures on related directories.
* When streaming WAL, pg_wal (or pg_xlog for pre-9.6
* clusters) will have been created by the wal receiver
* process. Also, when transaction log directory location
* was specified, pg_wal (or pg_xlog) has already been
* created as a symbolic link before starting the actual
* backup. So just ignore creation failures on related
* directories.
*/
if (!((pg_str_endswith(filename, "/pg_xlog") ||
pg_str_endswith(filename, "/archive_status")) &&
if (!((pg_str_endswith(filename, "/pg_wal") ||
pg_str_endswith(filename, "/pg_xlog")||
pg_str_endswith(filename, "/archive_status")) &&
errno == EEXIST))
{
fprintf(stderr,
@ -1634,15 +1649,10 @@ BaseBackup(void)
char xlogend[64];
int minServerMajor,
maxServerMajor;
int serverMajor;
int serverVersion,
serverMajor;
/*
* Connect in replication mode to the server
*/
conn = GetConnection();
if (!conn)
/* Error message already written in GetConnection() */
exit(1);
Assert(conn != NULL);
/*
* Check server version. BASE_BACKUP command was introduced in 9.1, so we
@ -1650,7 +1660,8 @@ BaseBackup(void)
*/
minServerMajor = 901;
maxServerMajor = PG_VERSION_NUM / 100;
serverMajor = PQserverVersion(conn) / 100;
serverVersion = PQserverVersion(conn);
serverMajor = serverVersion / 100;
if (serverMajor < minServerMajor || serverMajor > maxServerMajor)
{
const char *serverver = PQparameterStatus(conn, "server_version");
@ -1979,7 +1990,7 @@ BaseBackup(void)
}
else
{
(void) fsync_pgdata(basedir, progname);
(void) fsync_pgdata(basedir, progname, serverVersion);
}
}
@ -2296,6 +2307,14 @@ main(int argc, char **argv)
if (format == 'p' || strcmp(basedir, "-") != 0)
verify_dir_is_empty_or_create(basedir, &made_new_pgdata, &found_existing_pgdata);
/* connection in replication mode to server */
conn = GetConnection();
if (!conn)
{
/* Error message already written in GetConnection() */
exit(1);
}
/* Create transaction log symlink, if required */
if (strcmp(xlog_dir, "") != 0)
{
@ -2303,19 +2322,24 @@ main(int argc, char **argv)
verify_dir_is_empty_or_create(xlog_dir, &made_new_xlogdir, &found_existing_xlogdir);
/* form name of the place where the symlink must go */
linkloc = psprintf("%s/pg_xlog", basedir);
/*
* Form name of the place where the symlink must go. pg_xlog has
* been renamed to pg_wal in post-10 clusters.
*/
linkloc = psprintf("%s/%s", basedir,
PQserverVersion(conn) < MINIMUM_VERSION_FOR_PG_WAL ?
"pg_xlog" : "pg_wal");
#ifdef HAVE_SYMLINK
if (symlink(xlog_dir, linkloc) != 0)
{
fprintf(stderr, _("%s: could not create symbolic link \"%s\": %s\n"),
progname, linkloc, strerror(errno));
exit(1);
disconnect_and_exit(1);
}
#else
fprintf(stderr, _("%s: symlinks are not supported on this platform\n"));
exit(1);
disconnect_and_exit(1);
#endif
free(linkloc);
}

View File

@ -67,9 +67,9 @@ $node->command_ok([ 'pg_basebackup', '-D', "$tempdir/backup" ],
'pg_basebackup runs');
ok(-f "$tempdir/backup/PG_VERSION", 'backup was created');
# Only archive_status directory should be copied in pg_xlog/.
# Only archive_status directory should be copied in pg_wal/.
is_deeply(
[ sort(slurp_dir("$tempdir/backup/pg_xlog/")) ],
[ sort(slurp_dir("$tempdir/backup/pg_wal/")) ],
[ sort qw(. .. archive_status) ],
'no WAL files copied');
@ -230,12 +230,12 @@ like(
$node->command_ok(
[ 'pg_basebackup', '-D', "$tempdir/backupxf", '-X', 'fetch' ],
'pg_basebackup -X fetch runs');
ok(grep(/^[0-9A-F]{24}$/, slurp_dir("$tempdir/backupxf/pg_xlog")),
ok(grep(/^[0-9A-F]{24}$/, slurp_dir("$tempdir/backupxf/pg_wal")),
'WAL files copied');
$node->command_ok(
[ 'pg_basebackup', '-D', "$tempdir/backupxs", '-X', 'stream' ],
'pg_basebackup -X stream runs');
ok(grep(/^[0-9A-F]{24}$/, slurp_dir("$tempdir/backupxf/pg_xlog")),
ok(grep(/^[0-9A-F]{24}$/, slurp_dir("$tempdir/backupxf/pg_wal")),
'WAL files copied');
$node->command_fails(

View File

@ -890,7 +890,7 @@ FindEndOfXLOG(void)
newXlogSegNo = ControlFile.checkPointCopy.redo / ControlFile.xlog_seg_size;
/*
* Scan the pg_xlog directory to find existing WAL segment files. We
* Scan the pg_wal directory to find existing WAL segment files. We
* assume any present have been used; in most scenarios this should be
* conservative, because of xlog.c's attempts to pre-create files.
*/

View File

@ -131,10 +131,10 @@ recurse_dir(const char *datadir, const char *parentpath,
/*
* If it's a symlink within pg_tblspc, we need to recurse into it,
* to process all the tablespaces. We also follow a symlink if
* it's for pg_xlog. Symlinks elsewhere are ignored.
* it's for pg_wal. Symlinks elsewhere are ignored.
*/
if ((parentpath && strcmp(parentpath, "pg_tblspc") == 0) ||
strcmp(path, "pg_xlog") == 0)
strcmp(path, "pg_wal") == 0)
recurse_dir(datadir, path, callback);
#else
pg_fatal("\"%s\" is a symbolic link, but symbolic links are not supported on this platform\n",

View File

@ -79,11 +79,11 @@ process_source_file(const char *path, file_type_t type, size_t newsize,
return;
/*
* Pretend that pg_xlog is a directory, even if it's really a symlink. We
* Pretend that pg_wal is a directory, even if it's really a symlink. We
* don't want to mess with the symlink itself, nor complain if it's a
* symlink in source but not in target or vice versa.
*/
if (strcmp(path, "pg_xlog") == 0 && type == FILE_TYPE_SYMLINK)
if (strcmp(path, "pg_wal") == 0 && type == FILE_TYPE_SYMLINK)
type = FILE_TYPE_DIRECTORY;
/*
@ -120,7 +120,7 @@ process_source_file(const char *path, file_type_t type, size_t newsize,
switch (type)
{
case FILE_TYPE_DIRECTORY:
if (exists && !S_ISDIR(statbuf.st_mode) && strcmp(path, "pg_xlog") != 0)
if (exists && !S_ISDIR(statbuf.st_mode) && strcmp(path, "pg_wal") != 0)
{
/* it's a directory in source, but not in target. Strange.. */
pg_fatal("\"%s\" is not a directory\n", localpath);
@ -296,7 +296,7 @@ process_target_file(const char *path, file_type_t type, size_t oldsize,
/*
* Like in process_source_file, pretend that xlog is always a directory.
*/
if (strcmp(path, "pg_xlog") == 0 && type == FILE_TYPE_SYMLINK)
if (strcmp(path, "pg_wal") == 0 && type == FILE_TYPE_SYMLINK)
type = FILE_TYPE_DIRECTORY;
key.path = (char *) path;

View File

@ -54,7 +54,7 @@ static int SimpleXLogPageRead(XLogReaderState *xlogreader,
TimeLineID *pageTLI);
/*
* Read WAL from the datadir/pg_xlog, starting from 'startpoint' on timeline
* Read WAL from the datadir/pg_wal, starting from 'startpoint' on timeline
* index 'tliIndex' in target timeline history, until 'endpoint'. Make note of
* the data blocks touched by the WAL records, and return them in a page map.
*/

View File

@ -1,5 +1,5 @@
#
# Test pg_rewind when the target's pg_xlog directory is a symlink.
# Test pg_rewind when the target's pg_wal directory is a symlink.
#
use strict;
use warnings;
@ -30,10 +30,10 @@ sub run_test
my $test_master_datadir = $node_master->data_dir;
# turn pg_xlog into a symlink
print("moving $test_master_datadir/pg_xlog to $master_xlogdir\n");
move("$test_master_datadir/pg_xlog", $master_xlogdir) or die;
symlink($master_xlogdir, "$test_master_datadir/pg_xlog") or die;
# turn pg_wal into a symlink
print("moving $test_master_datadir/pg_wal to $master_xlogdir\n");
move("$test_master_datadir/pg_wal", $master_xlogdir) or die;
symlink($master_xlogdir, "$test_master_datadir/pg_wal") or die;
RewindTest::start_master();

View File

@ -14,7 +14,7 @@
#include <fcntl.h>
#include <sys/types.h>
static void check_data_dir(const char *pg_data);
static void check_data_dir(ClusterInfo *cluster);
static void check_bin_dir(ClusterInfo *cluster);
static void validate_exec(const char *dir, const char *cmdName);
@ -220,9 +220,9 @@ verify_directories(void)
pg_fatal("You must have read and write access in the current directory.\n");
check_bin_dir(&old_cluster);
check_data_dir(old_cluster.pgdata);
check_data_dir(&old_cluster);
check_bin_dir(&new_cluster);
check_data_dir(new_cluster.pgdata);
check_data_dir(&new_cluster);
}
@ -252,6 +252,32 @@ win32_check_directory_write_permissions(void)
#endif
/*
* check_single_dir()
*
* Check for the presence of a single directory in PGDATA, and fail if
* is it missing or not accessible.
*/
static void
check_single_dir(const char *pg_data, const char *subdir)
{
struct stat statBuf;
char subDirName[MAXPGPATH];
snprintf(subDirName, sizeof(subDirName), "%s%s%s", pg_data,
/* Win32 can't stat() a directory with a trailing slash. */
*subdir ? "/" : "",
subdir);
if (stat(subDirName, &statBuf) != 0)
report_status(PG_FATAL, "check for \"%s\" failed: %s\n",
subDirName, strerror(errno));
else if (!S_ISDIR(statBuf.st_mode))
report_status(PG_FATAL, "%s is not a directory\n",
subDirName);
}
/*
* check_data_dir()
*
@ -262,34 +288,27 @@ win32_check_directory_write_permissions(void)
*
*/
static void
check_data_dir(const char *pg_data)
check_data_dir(ClusterInfo *cluster)
{
char subDirName[MAXPGPATH];
int subdirnum;
const char *pg_data = cluster->pgdata;
/* start check with top-most directory */
const char *requiredSubdirs[] = {"", "base", "global", "pg_clog",
"pg_multixact", "pg_subtrans", "pg_tblspc", "pg_twophase",
"pg_xlog"};
/* get old and new cluster versions */
old_cluster.major_version = get_major_server_version(&old_cluster);
new_cluster.major_version = get_major_server_version(&new_cluster);
for (subdirnum = 0;
subdirnum < sizeof(requiredSubdirs) / sizeof(requiredSubdirs[0]);
++subdirnum)
{
struct stat statBuf;
check_single_dir(pg_data, "");
check_single_dir(pg_data, "base");
check_single_dir(pg_data, "global");
check_single_dir(pg_data, "pg_multixact");
check_single_dir(pg_data, "pg_subtrans");
check_single_dir(pg_data, "pg_tblspc");
check_single_dir(pg_data, "pg_twophase");
snprintf(subDirName, sizeof(subDirName), "%s%s%s", pg_data,
/* Win32 can't stat() a directory with a trailing slash. */
*requiredSubdirs[subdirnum] ? "/" : "",
requiredSubdirs[subdirnum]);
if (stat(subDirName, &statBuf) != 0)
report_status(PG_FATAL, "check for \"%s\" failed: %s\n",
subDirName, strerror(errno));
else if (!S_ISDIR(statBuf.st_mode))
report_status(PG_FATAL, "%s is not a directory\n",
subDirName);
}
/* pg_xlog has been renamed to pg_wal in post-10 cluster */
if (GET_MAJOR_VERSION(cluster->major_version) < 1000)
check_single_dir(pg_data, "pg_xlog");
else
check_single_dir(pg_data, "pg_wal");
}

View File

@ -680,7 +680,7 @@ usage(void)
printf(" -f, --follow keep retrying after reaching end of WAL\n");
printf(" -n, --limit=N number of records to display\n");
printf(" -p, --path=PATH directory in which to find log segment files\n");
printf(" (default: ./pg_xlog)\n");
printf(" (default: ./pg_wal)\n");
printf(" -r, --rmgr=RMGR only show records generated by resource manager RMGR\n");
printf(" use --rmgr=list to list valid resource manager names\n");
printf(" -s, --start=RECPTR start reading at log position RECPTR\n");

View File

@ -29,6 +29,11 @@
#define PG_FLUSH_DATA_WORKS 1
#endif
/*
* pg_xlog has been renamed to pg_wal in version 10.
*/
#define MINIMUM_VERSION_FOR_PG_WAL 100000
#ifdef PG_FLUSH_DATA_WORKS
static int pre_sync_fname(const char *fname, bool isdir,
const char *progname);
@ -40,25 +45,31 @@ static void walkdir(const char *path,
/*
* Issue fsync recursively on PGDATA and all its contents.
*
* We fsync regular files and directories wherever they are, but we
* follow symlinks only for pg_xlog and immediately under pg_tblspc.
* Other symlinks are presumed to point at files we're not responsible
* for fsyncing, and might not have privileges to write at all.
* We fsync regular files and directories wherever they are, but we follow
* symlinks only for pg_wal (or pg_xlog) and immediately under pg_tblspc.
* Other symlinks are presumed to point at files we're not responsible for
* fsyncing, and might not have privileges to write at all.
*
* serverVersion indicates the version of the server to be fsync'd.
*
* Errors are reported but not considered fatal.
*/
void
fsync_pgdata(const char *pg_data, const char *progname)
fsync_pgdata(const char *pg_data,
const char *progname,
int serverVersion)
{
bool xlog_is_symlink;
char pg_xlog[MAXPGPATH];
char pg_wal[MAXPGPATH];
char pg_tblspc[MAXPGPATH];
snprintf(pg_xlog, MAXPGPATH, "%s/pg_xlog", pg_data);
/* handle renaming of pg_xlog to pg_wal in post-10 clusters */
snprintf(pg_wal, MAXPGPATH, "%s/%s", pg_data,
serverVersion < MINIMUM_VERSION_FOR_PG_WAL ? "pg_xlog" : "pg_wal");
snprintf(pg_tblspc, MAXPGPATH, "%s/pg_tblspc", pg_data);
/*
* If pg_xlog is a symlink, we'll need to recurse into it separately,
* If pg_wal is a symlink, we'll need to recurse into it separately,
* because the first walkdir below will ignore it.
*/
xlog_is_symlink = false;
@ -67,14 +78,14 @@ fsync_pgdata(const char *pg_data, const char *progname)
{
struct stat st;
if (lstat(pg_xlog, &st) < 0)
if (lstat(pg_wal, &st) < 0)
fprintf(stderr, _("%s: could not stat file \"%s\": %s\n"),
progname, pg_xlog, strerror(errno));
progname, pg_wal, strerror(errno));
else if (S_ISLNK(st.st_mode))
xlog_is_symlink = true;
}
#else
if (pgwin32_is_junction(pg_xlog))
if (pgwin32_is_junction(pg_wal))
xlog_is_symlink = true;
#endif
@ -85,7 +96,7 @@ fsync_pgdata(const char *pg_data, const char *progname)
#ifdef PG_FLUSH_DATA_WORKS
walkdir(pg_data, pre_sync_fname, false, progname);
if (xlog_is_symlink)
walkdir(pg_xlog, pre_sync_fname, false, progname);
walkdir(pg_wal, pre_sync_fname, false, progname);
walkdir(pg_tblspc, pre_sync_fname, true, progname);
#endif
@ -93,14 +104,14 @@ fsync_pgdata(const char *pg_data, const char *progname)
* Now we do the fsync()s in the same order.
*
* The main call ignores symlinks, so in addition to specially processing
* pg_xlog if it's a symlink, pg_tblspc has to be visited separately with
* pg_wal if it's a symlink, pg_tblspc has to be visited separately with
* process_symlinks = true. Note that if there are any plain directories
* in pg_tblspc, they'll get fsync'd twice. That's not an expected case
* so we don't worry about optimizing it.
*/
walkdir(pg_data, fsync_fname, false, progname);
if (xlog_is_symlink)
walkdir(pg_xlog, fsync_fname, false, progname);
walkdir(pg_wal, fsync_fname, false, progname);
walkdir(pg_tblspc, fsync_fname, true, progname);
}

View File

@ -128,7 +128,7 @@ typedef XLogLongPageHeaderData *XLogLongPageHeader;
/*
* The XLog directory and control file (relative to $PGDATA)
*/
#define XLOGDIR "pg_xlog"
#define XLOGDIR "pg_wal"
#define XLOG_CONTROL_FILE "global/pg_control"
/*

View File

@ -53,6 +53,6 @@
*/
/* yyyymmddN */
#define CATALOG_VERSION_NO 201610121
#define CATALOG_VERSION_NO 201610201
#endif

View File

@ -17,7 +17,8 @@
extern int fsync_fname(const char *fname, bool isdir,
const char *progname);
extern void fsync_pgdata(const char *pg_data, const char *progname);
extern void fsync_pgdata(const char *pg_data, const char *progname,
int serverVersion);
extern int durable_rename(const char *oldfile, const char *newfile,
const char *progname);
extern int fsync_parent_path(const char *fname, const char *progname);

View File

@ -16,7 +16,7 @@
/* ----------
* Archiver control info.
*
* We expect that archivable files within pg_xlog will have names between
* We expect that archivable files within pg_wal will have names between
* MIN_XFN_CHARS and MAX_XFN_CHARS in length, consisting only of characters
* appearing in VALID_XFN_CHARS. The status files in archive_status have
* corresponding names with ".ready" or ".done" appended.