This document describes the parameters related to the write-ahead log category in the system configuration parameters.
Notes!
To ensure system stability and security, please be cautious when manually modifying the relevant parameters.
Before a WAL flush is initiated, commit_delay
adds a time delay (in microseconds).
commit_delay
. This is because if no other transactions are ready to commit, the delay is wasted. A delay is only executed when there are at least commit_siblings
(see below) other active transactions when a flush is about to be initiated.fsync
is disabled, no delay will be executed.Data type | Default value | Value range | Setting category |
---|---|---|---|
int | 0 | 0 ~ 100000 | master;session;reload;superuser |
The minimum number of concurrent active transactions required when enforcing the commit_delay
delay.
Data type | Default value | Value range | Setting category |
---|---|---|---|
int | 5 | 0 ~ 1000 | master;session;reload |
When this parameter is set to on
, the YMatrix server writes the entire contents of each page to the WAL during the first modification of the page after a checkpoint.
fsync
but is smaller. It should only be disabled if fsync
can be disabled.Data type | Default value | Setting category |
---|---|---|
boolean | on | segments;system;reload |
If this parameter is enabled, the YMatrix server will attempt to ensure that updates are physically written to disk by issuing the fsync()
system call or using one of several equivalent methods (see wal_sync_method
below). This ensures that the database cluster can be restored to a consistent state after an operating system or hardware crash.
initdb --sync-only
, when running sync, when unmounting the filesystem, or when restarting the server.full_page_writes
(see above).Data type | Default value | Setting category |
---|---|---|
boolean | on | segments;system;reload |
Specify the synchronization level. That is, whether a transaction needs to wait for WAL records to be written to disk before the command returns success
to the client.
on
. When set to off
, there will be a delay between reporting success to the client and truly ensuring that the transaction is not threatened by a server crash (the maximum delay is three times wal_writer_delay
). Unlike fsync, setting this parameter to off
does not introduce the risk of database inconsistency: an operating system or database crash may cause some recently committed transactions to be lost, but the database state is the same as if those transactions had been completely aborted. Therefore, when performance is more important than fully ensuring transaction durability, disabling synchronous_commit
can serve as an effective alternative.on
, the transaction on the primary server will not commit until the currently synchronized Standby server receives the transaction commit record response and flushes it to disk. This ensures that transactions will not be lost unless both the primary server and all synchronized Standby databases experience data corruption.remote_apply
, the commit will wait until the response from the current synchronized Standby indicates that it has received the transaction commit record and applied the transaction, at which point the transaction will become visible to queries on the Standby.remote_write
, the commit will wait until the response from the current synchronous standby indicates that it has received the transaction's commit record and has written it to its operating system. This setting is sufficient to ensure that data is preserved if the Standby server's YMatrix instance crashes, but it does not guarantee that data will be preserved if the Standby server experiences an operating system-level crash, as the data may not necessarily reach stable storage on the Standby machine.local
causes the commit to wait for local flushing to disk rather than replication completion. This is typically not the desired effect when using synchronous replication, but this option is provided for completeness.synchronous_standby_names
is empty, setting on
, remote_apply
, remote_write
, and local
all provide the same synchronization level: transaction commits only wait for local disk flushing.Parameter Value | Local Persistent Commit | YMatrix Crash Recovery Standby Persistent Commit | Operating System Crash Recovery Standby Persistent Commit | Standby Query Consistency |
---|---|---|---|---|
remote_apply | Y | Y | Y | Y |
on | Y | Y | Y | |
remote_write | Y | Y | ||
local | Y | |||
off |
Data type | Default value | Value range | Setting category |
---|---|---|---|
enum | on | on / off / true / false / yes / no / 1 / 0 / remote_apply / remote_write / local | segments;session;reload |
The amount of shared memory used for WAL data that has not yet been written to disk (measured in WAL blocks, i.e., XLOG_BLCKSZ bytes). - The default value -1
selects a size equal to 1/32 of shared_buffers (approximately 3%), but not less than 64KB
and not greater than the size of the WAL segment (typically 16MB
).
32KB
will be treated as 32KB
.wal_buffers
values are unlikely to provide significant benefits. However, setting this value to several megabytes can improve write performance on a busy server where many clients commit simultaneously.-1
yields reasonable results in most cases.数据类型 | 默认值 | 取值范围 | 设置分类 |
---|---|---|---|
int | -1 | -1 ~ INT_MAX/XLOG_BLCKSZ | segments;system;restart |
Enable compression operations for full-page writes.
on
, if full_page_writes
is also set to on
or during a base backup, the YMatrix server will compress the full page images written to the WAL. The compressed page images will be decompressed during WAL replay.Data Type | Default Value | Setting Category |
---|---|---|
boolean | off | segments;session;reload;superuser |
When this parameter is set to on
, new WAL files are padded with zeros.
off
, only the last bytes are written when the file is created, so it has an expected size.Data type | Default value | Setting category |
---|---|---|
boolean | on | segments;session;reload;superuser |
This parameter determines how much information is written to the WAL.
replica
, which writes enough data to support WAL archiving and replication, including running read-only queries on a standby server. minimal
removes all records except those necessary for recovery from a crash or immediate shutdown. Finally, logical
adds information required to support logical decoding. Each level includes all information from lower levels.minimal
level, WAL logs for certain bulk operations can be safely skipped, making those operations faster. Operations that can benefit from this optimization include: CREATE TABLE AS
,
CREATE INDEX
,
CLUSTER
,
COPY
to a table created or truncated in the same transaction.replica
level or higher must be used.logical
level, the same information as the replica
level is recorded, plus additional information required to extract logical change sets from the WAL. Using the logical
level will increase WAL capacity, especially if many tables are configured for REPLICA IDENTITY FULL
and numerous UPDATE
and DELETE
statements are executed.Data Type | Default Value | Value Range | Setting Category |
---|---|---|---|
enum | replica | replica / minimal / logical | segments;system;restart |
Perform full-page write operations for non-critical updates as well.
on
, the YMatrix server will write the entire contents of the disk page to the WAL after a checkpoint, even during the first modification of the page, including non-critical modifications to the so-called hint bits.Data type | Default value | Setting category |
---|---|---|
boolean | off | segments;system;restart |
Recycle WAL files.
on
, WAL files are recycled by renaming them to avoid creating new files.Data type | Default value | Setting category |
---|---|---|
boolean | on | segments;session;reload;superuser |
The method used to force WAL updates to disk.
open_datasync
(write WAL files using the O_DSYNC
option with open()
), fdatasync
(call fdatasync()
on each commit), fsync
(calling fsync()
at each commit), fsync_writethrough
(calling fsync()
at each commit, forcing any disk write cache to be flushed), open_sync
(writing WAL files using the O_SYNC
option with open()
)open_*
options can also use O_DIRECT
(if available).Data type | Default value | Value range | Setting category |
---|---|---|---|
enum | fsync / fdatasync(default on Linux) | open_datasync / fdatasync / fsync / fsync_writethrough / open_sync | segments;system;reload |
Specifies the frequency with which the WAL writer flushes the WAL, measured in milliseconds (ms).
wal_writer_delay
(unless awakened prematurely by an asynchronous commit transaction).wal_writer_delay
time and before the value of wal_writer_flush_after
WAL was generated, then the WAL will only be written to the operating system and not flushed to disk.wal_writer_delay
to a value that is not a multiple of 10 has the same effect as setting it to the next multiple of 10 greater than that value.Data type | Default value | Value range | Setting classification |
---|---|---|---|
int | 200 | 1 ~ 10000 | segments;system;reload |
Specifies the frequency at which the WAL writer flushes the WAL (in units of WAL blocks, i.e., XLOG_BLCKSZ bytes).
wal_writer_delay
and less than wal_writer_flush_after
WAL values have been generated since then, the WAL will only be written to the operating system and not flushed to disk.wal_writer_flush_after
is set to 0
, WAL data is always flushed immediately.Data type | Default value | Range | Setting category |
---|---|---|---|
int | 1048576/XLOG_BLCKSZ | 0 ~ INT_MAX | segments;system;reload |
Checkpoint target duration.
Data type | Default value | Value range | Setting category |
---|---|---|---|
floating point | 0.5 | 0.0 ~ 1.0 | segments;system;reload |
When the amount of data written during a checkpoint exceeds this parameter (in BLOCKS), an attempt is made to force the operating system (OS) to send these writes to the underlying storage.
fsync
or when the OS is writing back data in bulk in the background.0
, forced write-back is disabled.Data Type | Default Value | Valid Range | Setting Category |
---|---|---|---|
int | 0 | 0 ~ 256 | segments;system;reload |
The maximum time (in seconds) between automatic WAL checkpoints.
30 to 86400
(i.e., 60 days).Data type | Default value | Valid range | Setting category |
---|---|---|---|
int | 300 | 30 ~ 86400 | segments;system;reload |
If the interval between checkpoints caused by filling WAL segment files is less than the time specified by this parameter (in seconds), a message is written to the server log (meaning that the value of max_wal_size
should be increased).
0
disables the warning. If checkpoint_timeout
is lower than the value of this parameter, no warning will be generated.Data type | Default value | Valid range | Setting category |
---|---|---|---|
int | 30 | 0 ~ INT_MAX | segments;system;reload |
The maximum size (in MB) that the WAL is allowed to grow between automatic WAL checkpoints.
max_wal_size
, such as under heavy load, when archive_command
fails, or with a high wal_keep_segments
setting.Data type | Default value | Valid range | Setting category |
---|---|---|---|
int | 4096 | 2 ~ INT_MAX/1024 | segments;system;reload |
The minimum size (in MB) of the WAL allowed between automatic WAL checkpoints.
Data type | Default value | Value range | Setting category |
---|---|---|---|
int | 320 | 2 ~ INT_MAX/1024 | segments;system;reload |
A local shell command used to archive a Segment containing a completed WAL file.
%p
placeholders in the string must be replaced with the path to the file to be archived, while %f
must be replaced with the filename (the path is the cluster's data directory). If you want to embed a real %
character in the command, you can use %%
. For example: ‘test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f’
0
as the exit status when successful.archive_mode
is enabled when the server starts, it will be ignored. If archive_mode
is enabled and archive_command
is an empty string (default), WAL archiving will be temporarily disabled, but the server will continue to accumulate WAL segment files, awaiting a command to be provided.archive_command
to a command that only returns true but does not perform any action (e.g., /bin/true
or REM
on Windows) effectively disables archiving and breaks the WAL file chain required for archive recovery, so it should only be used in extremely rare cases.Data Type | Default Value | Setting Category |
---|---|---|
string | segments;system;reload |
When archive_mode
is enabled, completed WAL segments can be sent to the archive storage by setting the archive_command
command.
off
setting for disabling, there are two modes: on
and always
. During normal operation, there is no difference between these two modes, but when set to always
, the WAL archiver is also enabled during archive recovery or standby mode. In always
mode, all files recovered from the archive or received via streaming replication will be (re)archived.archive_mode
and archive_command
are independent variables, allowing archive_command
to be modified without affecting the archiving mode.wal_level
(see above) is set to minimal
, archive_mode
cannot be enabled.Data type | Default value | Valid range | Setting category |
---|---|---|---|
enum | off | off / on / always | segments;system;restart |
After exceeding this parameter value in seconds, force a switch to a new WAL segment file.
archive_command
is only called on completed WAL segments. Therefore, if your server generates very little WAL traffic (or the traffic generation cycle is very long), there will be a long delay between the completion of a transaction and its safe recording to the archive storage. To limit the time that unarchived data exists, you can set archive_timeout
to force the server to periodically switch to a new WAL segment file.archive_timeout
— it will take up a huge amount of archive storage. An archive_timeout
setting of around one minute is usually reasonable.0
, which disables this feature.Data type | Default value | Valid range | Setting category |
---|---|---|---|
int | 0 | 0 ~ INT_MAX/2 | segments;system;reload |
These parameters are only used in recovery mode. If you wish to perform any subsequent recovery operations, you must reset them.
“Recovery” covers using the server as a standby server or for performing target recovery. Typically, standby mode is used to provide high availability and/or read scalability, while target recovery is used to recover from data loss.To start the server in standby mode, create a file named standby.signal
in the data directory. The server will enter a recovery state and will not stop the recovery state at the end of the archived WAL, but will try to continue to maintain this state by connecting to the primary_conninfo
setting of the specified sending server and/or using restore_command
to obtain a new WAL segment. To start the server as the target recovery mode, create a file named recovery.signal
in the data directory. If both standby.signal
and recovery.signal
files are created, alternate mode is preferred. Target recovery mode ends when all archived WALs are played back or reaching recovery_target
.
Specifies the shell commands executed at each restart point.
%r
will be replaced with the name of the file containing the last available restart point. This is the earliest file that must be retained to make a recovery rebootable, so all files earlier than %r
can be safely removed. To embed a real %
character into this command, you need to write %%
. This information can be used to truncate the archive to the minimum required to support restart from the current recovery. For a single fallback configuration, the pg_archivecleanup
module is often used in archive_cleanup_command
, for example: archive_cleanup_command = 'pg_archivecleanup /mnt/server/archivedir %r'
.Data Type | Default | Set Category |
---|---|---|
string | segments; system; reload |
Specifies the shell command that is executed once when the recovery is completed.
archive_cleanup_command
, any %r
will be replaced with the name of the file containing the last available restart point.Data Type | Default | Set Category |
---|---|---|
string | segments; system; reload |
A local shell command to get an archived segment using a WAL file family.
%p
placeholder in the string will be replaced with the path to the file to be archived, and %f
will be replaced with the file name (the path is the data directory of the cluster). If you want to embed a real %
character into the command, you can use %%
. Any %r
will be replaced with the name of the file containing the previous available restart point. For example: 'cp /mnt/server/archivedir/%f %p'
.restore_command = 'cp /mnt/server/archivedir/%f "%p"'
restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"' # Windows
Data Type | Default | Set Category |
---|---|---|
string | segments; system; restart |
This part of the parameters is only set when performing directive recovery operations. By default, recovery will be restored to the end of the WAL log. This section of the parameters can be used to specify an earlier stop point.
Notes!
Inrecovery_target
,recovery_target_lsn
,recovery_target_name
,recovery_target_time
andrecovery_target_xid
, at most one can be used, and if multiple are used in the configuration file, an error will be generated.
This parameter specifies that the recovery ends as soon as possible after reaching the consistent state.
immediate
is currently the only allowed value.Data Type | Default Value | Value Range | Set Classification |
---|---|---|---|
string | immediate | segments; system; restart |
Specifies the actions the server should take immediately when the recovery target is reached.
pause
, indicating that the recovery will be paused. promote
means that the recovery will end and the server will start accepting the connection. shutdown
means that the server will be stopped after the recovery target is reached.pause
setting is: if this recovery target is to restore the most desired location, it allows querying to be performed on the database. The paused state can be continued with pg_wal_replay_resume()
, which will end the recovery. If this recovery target is not the desired stop point, shut down the server, change the recovery target setting to a later target and restart to continue recovery.shutdown
setting can come in handy. This instance will still be able to replay more WAL records (and in fact will have to replay from the next time it is started, from the last checkpoint to the current WAL record).recovery_target_action
is set to shutdown
, recovery.signal
will not be removed, and any subsequent startup will end with an immediate shutdown unless the configuration is changed or the recovery.signal
file is removed manually.hot_standby
is not enabled, the action set by pause
will be the same as shutdown
.Data Type | Default Value | Value Range | Set Classification |
---|---|---|---|
enum | pause | pause / promote / shutdown | segments; system; restart |
Specifies whether to stop (on) only after the specified recovery target, or only before the recovery target (off).
recovery_target_lsn
, recovery_target_time
or recovery_target_xid
are specified.Data Type | Default | Set Category |
---|---|---|
boolean | on | segments; system; restart |
This parameter specifies the WAL LSN that will continue to restore.
recovery_target_inclusive
(see above).Data Type | Default | Set Category |
---|---|---|
pg_lsn | segments; system; restart |
Specifies a named recovery point (created by pg_create_restore_point()
) and the recovery will enter the recovery point.
Data Type | Default | Set Category |
---|---|---|
string | segments; system; restart |
This parameter specifies the timestamp to which recovery will be executed.
recovery_target_inclusive
(see above).Data Type | Default | Set Category |
---|---|---|
timestamp | segments; system; restart |
Specifies to restore to a specific timeline.
current
restores along the same timeline as when performing a basic backup; the value latest
restores to the latest timeline found in the archive, which is useful in a backup server.Data Type | Default Value | Value Range | Set Classification |
---|---|---|---|
string | latest | current / latest / Timeline ID | segments; system; restart |
This parameter specifies the transaction ID to be entered by the recovery.
recovery_target_inclusive
(see above).Data Type | Default | Set Category |
---|---|---|
string | segments; system; restart |