active_postgres 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_postgres/components/base.rb +10 -0
- data/lib/active_postgres/components/core.rb +0 -10
- data/lib/active_postgres/components/pgbouncer.rb +21 -8
- data/lib/active_postgres/components/repmgr.rb +6 -0
- data/lib/active_postgres/version.rb +1 -1
- data/templates/pgbouncer.ini.erb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 503ec5557f2365458cfe544af059bb5636e82be153a58926978c62ff43384b6f
|
|
4
|
+
data.tar.gz: 20d9bad0c0cbde26d214d304f379854d8d8dd548f06f86462840dad56f0f4580
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 26ad8c310458b4e4ecdce1586b98cce9b062260b060e8779481e965c3d2c3d092a93691956372dbf62bd3e138d2b68e97b9dc135748da8a5f4481b683d739c1b
|
|
7
|
+
data.tar.gz: c9ee9f54f725cf43398815a79c621579ac1dad70b36ab997a413905a8cd5222eea42ca0e3397928f26ccf48fc1f1c10da18d9aef31cabfd62eff4ab3aadd0f84
|
|
@@ -23,6 +23,16 @@ module ActivePostgres
|
|
|
23
23
|
|
|
24
24
|
protected
|
|
25
25
|
|
|
26
|
+
def substitute_private_ip(pg_config, private_ip)
|
|
27
|
+
pg_config.transform_values do |value|
|
|
28
|
+
if value.is_a?(String)
|
|
29
|
+
value.gsub('${private_ip}', private_ip)
|
|
30
|
+
else
|
|
31
|
+
value
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
26
36
|
def render_template(template_name, binding_context)
|
|
27
37
|
template_path = File.join(ActivePostgres.root, 'templates', template_name)
|
|
28
38
|
template = ERB.new(File.read(template_path), trim_mode: '-')
|
|
@@ -96,16 +96,6 @@ module ActivePostgres
|
|
|
96
96
|
optimal_settings.merge(user_postgresql)
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
-
def substitute_private_ip(pg_config, private_ip)
|
|
100
|
-
pg_config.transform_values do |value|
|
|
101
|
-
if value.is_a?(String)
|
|
102
|
-
value.gsub('${private_ip}', private_ip)
|
|
103
|
-
else
|
|
104
|
-
value
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
99
|
def install_packages_only(host)
|
|
110
100
|
puts " Installing packages on #{host} (cluster will be created by repmgr)..."
|
|
111
101
|
ssh_executor.install_postgres(host, config.version)
|
|
@@ -52,37 +52,50 @@ module ActivePostgres
|
|
|
52
52
|
def install_on_host(host)
|
|
53
53
|
puts " Installing PgBouncer on #{host}..."
|
|
54
54
|
|
|
55
|
-
# Get user config
|
|
56
55
|
user_config = config.component_config(:pgbouncer)
|
|
57
56
|
|
|
58
|
-
# Calculate optimal pool settings based on PostgreSQL max_connections
|
|
59
57
|
max_connections = get_postgres_max_connections(host)
|
|
60
58
|
optimal_pool = ConnectionPooler.calculate_optimal_pool_sizes(max_connections)
|
|
61
59
|
|
|
62
|
-
# Merge: user config overrides calculated settings
|
|
63
60
|
pgbouncer_config = optimal_pool.merge(user_config)
|
|
64
|
-
|
|
61
|
+
ssl_enabled = config.component_enabled?(:ssl)
|
|
65
62
|
|
|
66
63
|
puts " Calculated pool settings for max_connections=#{max_connections}"
|
|
67
64
|
|
|
68
|
-
# Install package
|
|
69
65
|
ssh_executor.execute_on_host(host) do
|
|
70
66
|
execute :sudo, 'apt-get', 'install', '-y', '-qq', 'pgbouncer'
|
|
71
67
|
end
|
|
72
68
|
|
|
73
|
-
# Upload configuration
|
|
74
69
|
upload_template(host, 'pgbouncer.ini.erb', '/etc/pgbouncer/pgbouncer.ini', binding, mode: '644')
|
|
75
70
|
|
|
76
|
-
|
|
71
|
+
setup_ssl_certs(host) if ssl_enabled
|
|
72
|
+
|
|
77
73
|
create_userlist(host)
|
|
78
74
|
|
|
79
|
-
# Enable and start
|
|
80
75
|
ssh_executor.execute_on_host(host) do
|
|
81
76
|
execute :sudo, 'systemctl', 'enable', 'pgbouncer'
|
|
82
77
|
execute :sudo, 'systemctl', 'restart', 'pgbouncer'
|
|
83
78
|
end
|
|
84
79
|
end
|
|
85
80
|
|
|
81
|
+
def setup_ssl_certs(host)
|
|
82
|
+
puts ' Setting up SSL certificates for PgBouncer...'
|
|
83
|
+
version = config.version
|
|
84
|
+
|
|
85
|
+
ssh_executor.execute_on_host(host) do
|
|
86
|
+
execute :sudo, 'cp', "/etc/postgresql/#{version}/main/server.crt", '/etc/pgbouncer/server.crt'
|
|
87
|
+
execute :sudo, 'cp', "/etc/postgresql/#{version}/main/server.key", '/etc/pgbouncer/server.key'
|
|
88
|
+
execute :sudo, 'chmod', '640', '/etc/pgbouncer/server.key'
|
|
89
|
+
execute :sudo, 'chown', 'postgres:postgres', '/etc/pgbouncer/server.key'
|
|
90
|
+
execute :sudo, 'chown', 'postgres:postgres', '/etc/pgbouncer/server.crt'
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
ssl_chain = secrets.resolve('ssl_chain')
|
|
94
|
+
if ssl_chain
|
|
95
|
+
ssh_executor.upload_file(host, ssl_chain, '/etc/pgbouncer/ca.crt', mode: '644', owner: 'postgres:postgres')
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
86
99
|
def get_postgres_max_connections(host)
|
|
87
100
|
# Try to get max_connections from running PostgreSQL
|
|
88
101
|
postgres_user = config.postgres_user
|
|
@@ -107,6 +107,9 @@ module ActivePostgres
|
|
|
107
107
|
|
|
108
108
|
# Performance tuning is handled by the Core component
|
|
109
109
|
pg_config = component_config[:postgresql] || {}
|
|
110
|
+
# Substitute ${private_ip} with the host's actual private IP
|
|
111
|
+
private_ip = config.replication_host_for(host)
|
|
112
|
+
pg_config = substitute_private_ip(pg_config, private_ip)
|
|
110
113
|
_ = pg_config # Used in ERB template
|
|
111
114
|
|
|
112
115
|
upload_template(host, 'postgresql.conf.erb', "/etc/postgresql/#{version}/main/postgresql.conf", binding,
|
|
@@ -307,6 +310,9 @@ module ActivePostgres
|
|
|
307
310
|
|
|
308
311
|
# Performance tuning is handled by the Core component
|
|
309
312
|
pg_config = component_config[:postgresql] || {}
|
|
313
|
+
# Substitute ${private_ip} with the standby's actual private IP
|
|
314
|
+
private_ip = config.replication_host_for(standby_host)
|
|
315
|
+
pg_config = substitute_private_ip(pg_config, private_ip)
|
|
310
316
|
_ = pg_config # Used in ERB template
|
|
311
317
|
|
|
312
318
|
ssh_executor.execute_on_host(standby_host) do
|
data/templates/pgbouncer.ini.erb
CHANGED
|
@@ -44,6 +44,14 @@ log_connections = <%= pgbouncer_config[:log_connections] || 1 %>
|
|
|
44
44
|
log_disconnections = <%= pgbouncer_config[:log_disconnections] || 1 %>
|
|
45
45
|
log_pooler_errors = <%= pgbouncer_config[:log_pooler_errors] || 1 %>
|
|
46
46
|
|
|
47
|
+
<% if ssl_enabled %>
|
|
48
|
+
# Client TLS (incoming connections from Rails)
|
|
49
|
+
client_tls_sslmode = require
|
|
50
|
+
client_tls_key_file = /etc/pgbouncer/server.key
|
|
51
|
+
client_tls_cert_file = /etc/pgbouncer/server.crt
|
|
52
|
+
client_tls_ca_file = /etc/pgbouncer/ca.crt
|
|
53
|
+
<% end %>
|
|
54
|
+
|
|
47
55
|
# Process management
|
|
48
56
|
<% if pgbouncer_config[:pidfile] %>
|
|
49
57
|
pidfile = <%= pgbouncer_config[:pidfile] %>
|