Skip to content

Commit

Permalink
Fetch wal_keep_size, not wal_keep_segments, from Postgres 13
Browse files Browse the repository at this point in the history
The `wal_keep_segments` parameter introduced in v9.0 was replaced with
`wal_keep_size` in v13. Running Barman against Postgres 13 resulted in
errors like the following being logged:

    barman ERROR:  unrecognized configuration parameter "wal_keep_segments"
    barman STATEMENT:  SHOW "wal_keep_segments"

Here we change fetch_remote_status() to ask for wal_keep_size if the
server version is >= 13. We didn't use this value anywhere, so we don't
need any further changes to adapt to the different return value.

Signed-off-by: Abhijit Menon-Sen <ams@2ndQuadrant.com>
  • Loading branch information
amenonsen committed Jan 20, 2021
1 parent ec9080f commit 45ccd9d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
7 changes: 6 additions & 1 deletion barman/postgres.py
Expand Up @@ -827,7 +827,12 @@ def fetch_remote_status(self):
pg_settings.append('wal_level')
pg_settings.append('hot_standby')
pg_settings.append('max_wal_senders')
pg_settings.append('wal_keep_segments')
# Retrieve wal_keep_segments from version 9.0 onwards, until
# version 13.0, where it was renamed to wal_keep_size
if self.server_version < 130000:
pg_settings.append('wal_keep_segments')
else:
pg_settings.append('wal_keep_size')

if self.server_version >= 90300:
pg_settings.append('data_checksums')
Expand Down
3 changes: 2 additions & 1 deletion doc/manual/42-server-commands.en.md
Expand Up @@ -198,7 +198,8 @@ record of the transaction log. When the status file needs to be
cleaned, the `--reset` option can be used.

> **IMPORTANT:** If you are not using replication slots, you rely
> on the value of `wal_keep_segments`. Be aware that under high peeks
> on the value of `wal_keep_segments` (or `wal_keep_size` from
> PostgreSQL version 13.0 onwards). Be aware that under high peaks
> of workload on the database, the `receive-wal` process
> might fall behind and go out of sync. As a precautionary measure,
> Barman currently requires that users manually execute the command with the
Expand Down
35 changes: 35 additions & 0 deletions tests/test_postgres.py
Expand Up @@ -822,6 +822,8 @@ def test_current_xlog_file_name(self, is_in_recovery_mock, conn_mock):
new_callable=PropertyMock)
@patch('barman.postgres.PostgreSQLConnection.is_in_recovery',
new_callable=PropertyMock)
@patch('barman.postgres.PostgreSQLConnection.has_backup_privileges',
new_callable=PropertyMock)
@patch('barman.postgres.PostgreSQLConnection.is_superuser',
new_callable=PropertyMock)
@patch('barman.postgres.PostgreSQLConnection.server_txt_version',
Expand All @@ -847,6 +849,7 @@ def test_get_remote_status(self,
has_pgespresso_mock,
server_txt_version_mock,
is_superuser_mock,
has_backup_privileges_mock,
is_in_recovery_mock,
archive_timeout_mock,
checkpoint_timeout_mock,
Expand All @@ -867,6 +870,7 @@ def test_get_remote_status(self,
has_pgespresso_mock.return_value = True
server_txt_version_mock.return_value = '9.5.0'
is_in_recovery_mock.return_value = False
has_backup_privileges_mock.return_value = True
is_superuser_mock.return_value = True
get_configuration_files_mock.return_value = {'a': 'b'}
get_synchronous_standby_names_mock.return_value = []
Expand All @@ -885,6 +889,7 @@ def test_get_remote_status(self,
'max_replication_slots': 'a max_replication_slots value',
'wal_compression': 'a wal_compression value',
'wal_keep_segments': 'a wal_keep_segments value',
'wal_keep_size': 'a wal_keep_size value',
}

get_setting_mock.side_effect = lambda x: settings.get(x, 'unknown')
Expand Down Expand Up @@ -948,6 +953,36 @@ def test_get_remote_status(self,
'postgres_systemid': 6721602258895701769,
}

# Test PostgreSQL 13
conn_mock.return_value.server_version = 130000
result = server.postgres.fetch_remote_status()
assert result == {
'a': 'b',
'is_superuser': True,
'has_backup_privileges': True,
'is_in_recovery': False,
'current_lsn': 'DE/ADBEEF',
'current_xlog': '00000001000000DE00000000',
'data_directory': 'a directory',
'pgespresso_installed': True,
'server_txt_version': '9.5.0',
'wal_level': 'a wal_level value',
'current_size': 497354072,
'replication_slot_support': True,
'replication_slot': None,
'synchronous_standby_names': [],
'archive_timeout': 300,
'checkpoint_timeout': 600,
'wal_keep_size': 'a wal_keep_size value',
'hot_standby': 'a hot_standby value',
'max_wal_senders': 'a max_wal_senderse value',
'data_checksums': 'a data_checksums',
'max_replication_slots': 'a max_replication_slots value',
'wal_compression': 'a wal_compression value',
'xlog_segment_size': 8388608,
'postgres_systemid': 6721602258895701769,
}

# Test error management
server.postgres.close()
conn_mock.side_effect = psycopg2.DatabaseError
Expand Down

0 comments on commit 45ccd9d

Please sign in to comment.