Skip to content

Commit 4823137

Browse files
authored
Cast server_config keys to strings in postgresql_config to avoid unnecessary converges (#782)
Reading the existing config on the node in `load_current_value` returns string keys. If you then pass the same configuration but with symbol keys to `server_config` in `postgresql_config`, `converge_if_changed` will believe the resource changed and proceed with converging. The keys are already cast to strings before being passed to the `template` resource, so the template itself doesn't actually change but the `postgresql_config` resource still believes it changed, so any notifications will fire. For example, if you have the resource reload postgresql on change, it'll reload each time the node is converged. By casting the keys to strings when coercing the property, the resource will no longer believe it changed when the only difference was the class of the key, thus it wont fire notifications unnecessarily. Signed-off-by: Chris Gunther <chris@room118solutions.com>
1 parent 0b0da2c commit 4823137

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This file is used to list changes made in the last 3 major versions of the postg
44

55
## Unreleased
66

7+
- Cast `server_config` keys to strings in `postgresql_config` to avoid unnecessary converges
8+
79
## 12.0.3 - *2024-12-30*
810

911
- Bump version to force supermarket release

resources/config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
property :server_config, Hash,
5050
default: {},
51-
coerce: proc { |p| p.deep_sort },
51+
coerce: proc { |p| p.transform_keys(&:to_s).deep_sort },
5252
description: 'PostgreSQL server configuration options'
5353

5454
load_current_value do |new_resource|

test/cookbooks/test/recipes/server_install_os.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@
1010

1111
postgresql_config 'postgresql-server' do
1212
server_config({
13-
'max_connections' => 110,
14-
'shared_buffers' => '128MB',
15-
'log_destination' => 'stderr',
16-
'logging_collector' => true,
17-
'log_directory' => 'log',
18-
'log_filename' => 'postgresql-%a.log',
19-
'log_rotation_age' => '1d',
20-
'log_rotation_size' => 0,
21-
'log_truncate_on_rotation' => true,
22-
'log_line_prefix' => '%m [%p]',
23-
'log_timezone' => 'Etc/UTC',
24-
'datestyle' => 'iso, mdy',
25-
'timezone' => 'Etc/UTC',
26-
'lc_messages' => 'C',
27-
'lc_monetary' => 'C',
28-
'lc_numeric' => 'C',
29-
'lc_time' => 'C',
30-
'default_text_search_config' => 'pg_catalog.english',
13+
max_connections: 110,
14+
shared_buffers: '128MB',
15+
log_destination: 'stderr',
16+
logging_collector: true,
17+
log_directory: 'log',
18+
log_filename: 'postgresql-%a.log',
19+
log_rotation_age: '1d',
20+
log_rotation_size: 0,
21+
log_truncate_on_rotation: true,
22+
log_line_prefix: '%m [%p]',
23+
log_timezone: 'Etc/UTC',
24+
datestyle: 'iso, mdy',
25+
timezone: 'Etc/UTC',
26+
lc_messages: 'C',
27+
lc_monetary: 'C',
28+
lc_numeric: 'C',
29+
lc_time: 'C',
30+
default_text_search_config: 'pg_catalog.english',
3131
})
3232

3333
notifies :restart, 'postgresql_service[postgresql]', :delayed

0 commit comments

Comments
 (0)