Showing results for 
Search instead for 
Did you mean: 

pg_basebackup in bart failing on WAL files

Level 3 Adventurer

pg_basebackup in bart failing on WAL files

Receiving the following error when trying to run a BART backup

pg_basebackup: could not get write-ahead log end position from server: ERROR:  requested WAL segment 000000160000035F00000083 has already been removed
pg_basebackup: removing data directory "/opt/edb/backup/epas10/1532010220112"

Here are the settings from the custom conf file on my DB server:

wal_buffers = 16MB
wal_log_hints = on
# wal_level
min_wal_size = 1GB
max_wal_size = 10GB
#wal_level = replica
max_wal_senders = 3
wal_keep_segments = 15

Any advice on what I can change?


Thank you

EDB Team Member

Re: pg_basebackup in bart failing on WAL files

Generally occurs when the past log file segments kept in the pg_xlog directory are removed and to overcome this we need to set the "wal_keepsegments" parameter to enough high value. This sets only the minimum number of segments retained in pg_xlog. 
As the wal_keep segment is set to "15" on your machine. We will suggest you set this value which is suitable for your environment, however, there is no thumb rule to set this parameter. So, you can do testing like benchmarking to know the correct suitable value. Please go through the below link for more details on wal_keep_segments:
You need to reload the server after setting the value for the wal_keep_segments for the modified changes to take effect. You can use the below command:
The below document for Bart also mentioned the same:
[ Article 5.4.3 ]
A low setting of the wal_keep_segments configuration parameter may result in the deletion of some WAL files before pg_basebackup has had a chance to save them to the BART backup catalog.
We also will strongly suggest you go through the below Bart configuration for archive_command and Postgresql.conf before taking backups:
[Article 4.2 ]
Hope this helps.
EDB Team Member

Re: pg_basebackup in bart failing on WAL files

Hi lgwapnitsky,


The above issue regarding the WAL segment removed during the backup method can be avoided using the streaming method (setting xlog-method to stream) of the transaction log in parallel with the creation of the backup for that database server


Please find the possible way's to avoid the WAL segment removed issue.

-X method

Includes the required transaction log files (WAL files) in the backup. This will include all transaction logs generated during the backup. If this option is specified, it is possible to start a postmaster directly in the extracted directory without the need to consult the log archive, thus making this a completely standalone backup.

The following methods for collecting the transaction logs are supported:


Stream the transaction log while the backup is created. This will open a second connection to the server and start streaming the transaction log in parallel while running the backup. Therefore, it will use up two connections configured by the max_wal_senders parameter. As long as the client can keep up with transaction log received, using this mode requires no extra transaction logs to be saved on the master.


Note: With stream method Plain format can be used only not compress with -z option.


For the error regarding the missing WAL segment, it could happen if Postgres completes two checkpoints when taking the backup. One thing that you could use is a replication slot that gives the guarantee that segments are retained. Those have been Integrated in pg_basebackup with 9.6.