Skip to content

Commit 3c6f378

Browse files
balasankarcClemens Beck
andcommitted
Merge branch 'add-new-pgbouncer-config-options' into 'master'
Add support for new pgbouncer settings See merge request https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/7219 Merged-by: Balasankar 'Balu' C <[email protected]> Approved-by: Dustin Collins <[email protected]> Approved-by: Balasankar 'Balu' C <[email protected]> Co-authored-by: Clemens Beck <[email protected]>
2 parents 46233bb + 974974a commit 3c6f378

File tree

5 files changed

+70
-1
lines changed

5 files changed

+70
-1
lines changed

files/gitlab-config-template/gitlab.rb.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,6 +3026,7 @@ external_url 'GENERATED_EXTERNAL_URL'
30263026
# pgbouncer['listen_addr'] = '0.0.0.0'
30273027
# pgbouncer['listen_port'] = '6432'
30283028
# pgbouncer['pool_mode'] = 'transaction'
3029+
# pgbouncer['max_prepared_statements'] = 0
30293030
# pgbouncer['server_reset_query'] = 'DISCARD ALL'
30303031
# pgbouncer['application_name_add_host'] = '1'
30313032
# pgbouncer['max_client_conn'] = '2048'
@@ -3042,6 +3043,7 @@ external_url 'GENERATED_EXTERNAL_URL'
30423043
# pgbouncer['admin_users'] = %w(gitlab-psql postgres pgbouncer)
30433044
# pgbouncer['stats_users'] = %w(gitlab-psql postgres pgbouncer)
30443045
# pgbouncer['ignore_startup_parameters'] = 'extra_float_digits'
3046+
# pgbouncer['track_extra_parameters'] = %w(IntervalStyle)
30453047
# pgbouncer['databases'] = {
30463048
# DATABASE_NAME: {
30473049
# host: HOSTNAME,
@@ -3058,6 +3060,7 @@ external_url 'GENERATED_EXTERNAL_URL'
30583060
# pgbouncer['unix_socket_group'] = nil
30593061
# pgbouncer['auth_type'] = 'md5'
30603062
# pgbouncer['auth_hba_file'] = nil
3063+
# pgbouncer['auth_dbname'] = nil
30613064
# pgbouncer['auth_query'] = 'SELECT username, password FROM public.pg_shadow_lookup($1)'
30623065
# pgbouncer['users'] = {
30633066
# USERNAME: {
@@ -3088,17 +3091,20 @@ external_url 'GENERATED_EXTERNAL_URL'
30883091
# pgbouncer['autodb_idle_timeout'] = 3600
30893092
# pgbouncer['suspend_timeout'] = 10
30903093
# pgbouncer['idle_transaction_timeout'] = 0
3094+
# pgbouncer['cancel_wait_timeout'] = 10
30913095
# pgbouncer['pkt_buf'] = 4096
30923096
# pgbouncer['listen_backlog'] = 128
30933097
# pgbouncer['sbuf_loopcnt'] = 5
30943098
# pgbouncer['max_packet_size'] = 2147483647
3099+
# pgbouncer['so_reuseport'] = 0
30953100
# pgbouncer['tcp_defer_accept'] = 0
30963101
# pgbouncer['tcp_socket_buffer'] = 0
30973102
# pgbouncer['tcp_keepalive'] = 1
30983103
# pgbouncer['tcp_keepcnt'] = 0
30993104
# pgbouncer['tcp_keepidle'] = 0
31003105
# pgbouncer['tcp_keepintvl'] = 0
31013106
# pgbouncer['disable_pqexec'] = 0
3107+
# default['pgbouncer']['peers'] = {}
31023108

31033109
## Pgbouncer client TLS options
31043110
# pgbouncer['client_tls_sslmode'] = 'disable'

files/gitlab-cookbooks/pgbouncer/attributes/default.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
default['pgbouncer']['listen_addr'] = '0.0.0.0'
99
default['pgbouncer']['listen_port'] = 6432
1010
default['pgbouncer']['pool_mode'] = 'transaction'
11+
default['pgbouncer']['max_prepared_statements'] = 0
1112
default['pgbouncer']['server_reset_query'] = 'DISCARD ALL'
1213
default['pgbouncer']['max_client_conn'] = 2048
1314
default['pgbouncer']['application_name_add_host'] = 1
@@ -24,6 +25,7 @@
2425
default['pgbouncer']['admin_users'] = %w(gitlab-psql postgres pgbouncer)
2526
default['pgbouncer']['stats_users'] = %w(gitlab-psql postgres pgbouncer)
2627
default['pgbouncer']['ignore_startup_parameters'] = 'extra_float_digits'
28+
default['pgbouncer']['track_extra_parameters'] = %w(IntervalStyle)
2729
default['pgbouncer']['databases_ini'] = '/var/opt/gitlab/pgbouncer/databases.ini'
2830
default['pgbouncer']['databases_ini_user'] = 'root'
2931
default['pgbouncer']['databases_json'] = '/var/opt/gitlab/pgbouncer/databases.json'
@@ -68,20 +70,24 @@
6870
default['pgbouncer']['autodb_idle_timeout'] = 3600
6971
default['pgbouncer']['suspend_timeout'] = 10
7072
default['pgbouncer']['idle_transaction_timeout'] = 0
73+
default['pgbouncer']['cancel_wait_timeout'] = 10
7174
default['pgbouncer']['pkt_buf'] = 4096
7275
default['pgbouncer']['listen_backlog'] = 128
7376
default['pgbouncer']['sbuf_loopcnt'] = 5
7477
default['pgbouncer']['max_packet_size'] = 2147483647
78+
default['pgbouncer']['so_reuseport'] = 0
7579
default['pgbouncer']['tcp_defer_accept'] = 0
7680
default['pgbouncer']['tcp_socket_buffer'] = 0
7781
default['pgbouncer']['tcp_keepalive'] = 1
7882
default['pgbouncer']['tcp_keepcnt'] = 0
7983
default['pgbouncer']['tcp_keepidle'] = 0
8084
default['pgbouncer']['tcp_keepintvl'] = 0
8185
default['pgbouncer']['disable_pqexec'] = 0
86+
default['pgbouncer']['peers'] = {}
8287

8388
default['pgbouncer']['auth_type'] = 'md5'
8489
default['pgbouncer']['auth_hba_file'] = nil
90+
default['pgbouncer']['auth_dbname'] = nil
8591
default['pgbouncer']['auth_query'] = 'SELECT username, password FROM public.pg_shadow_lookup($1)'
8692
default['pgbouncer']['users'] = {}
8793

files/gitlab-cookbooks/pgbouncer/templates/default/peers.ini.erb

Whitespace-only changes.

files/gitlab-cookbooks/pgbouncer/templates/default/pgbouncer.ini.erb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ auth_hba_file = <%= @auth_hba_file %>
123123
;; Query to use to fetch password from database. Result
124124
;; must have 2 columns - username and password hash.
125125
auth_query = <%= @auth_query %>
126+
127+
<% if @auth_dbname %>
128+
; Authentication database that can be set globally to run "auth_query".
129+
auth_dbname = <%= @auth_dbname %>
130+
<% end %>
131+
126132
;;;
127133
;;; Users allowed into database 'pgbouncer'
128134
;;;
@@ -143,6 +149,10 @@ stats_users = <%= @stats_users.join(', ') %>
143149
; statement - after statement finishes
144150
pool_mode = <%= @pool_mode %>
145151

152+
; Number of prepared statements to cache on a server connection (zero value
153+
; disables support of prepared statements).
154+
max_prepared_statements = <%= @max_prepared_statements %>
155+
146156
;
147157
; Query for cleaning connection immediately after releasing from client.
148158
; No need to put ROLLBACK here, pgbouncer does not reuse connections
@@ -163,6 +173,11 @@ server_reset_query = <%= @server_reset_query %>
163173
; If it is off, server_reset_query is used only for session-pooling.
164174
server_reset_query_always = <%= @server_reset_query_always %>
165175

176+
; Comma-separated list of parameters to track per client. The Postgres
177+
; parameters listed here will be cached per client by pgbouncer and
178+
; restored in server everytime the client runs a query.
179+
track_extra_parameters = <%= @track_extra_parameters.join(', ') %>
180+
166181
;
167182
; Comma-separated list of parameters to ignore when given
168183
; in startup packet. Newer JDBC versions require the
@@ -286,6 +301,12 @@ suspend_timeout = <%= @suspend_timeout %>
286301
;; this many seconds.
287302
idle_transaction_timeout = <%= @idle_transaction_timeout %>
288303

304+
;; Dangerous. Client connection is closed if the cancellation request
305+
;; is not assigned to a server in this time. Should be used to limit
306+
;; the time a client application blocks on a queued cancel request in
307+
;; case of a database or network failure. (default: 10)
308+
cancel_wait_timeout = <%= @cancel_wait_timeout %>
309+
289310
;;;
290311
;;; Low-level tuning options
291312
;;;
@@ -302,6 +323,9 @@ sbuf_loopcnt = <%= @sbuf_loopcnt %>
302323
;; Maximum Postgres protocol packet size.
303324
max_packet_size = <%= @max_packet_size %>
304325

326+
;; Set SO_REUSEPORT socket option
327+
so_reuseport = <%= @so_reuseport %>
328+
305329
;; networking options, for info: man 7 tcp
306330

307331
;; Linux: notify program about new connection only if there
@@ -354,6 +378,14 @@ disable_pqexec = <%= @disable_pqexec %>
354378
;service_name = pgbouncer
355379
;job_name = pgbouncer
356380

381+
;;;
382+
;;; Peers
383+
;;;
384+
[peers]
385+
<% @peers.each do |peer_id, settings| %>
386+
<%= peer_id %> = <%= settings.map{ |k,v| "#{k}=#{v}" }.join(' ') %>
387+
<% end %>
388+
357389
;; Read additional config from the /etc/pgbouncer/pgbouncer-other.ini file
358390
;%include /etc/pgbouncer/pgbouncer-other.ini
359391
%include <%= @databases_ini %>

spec/chef/cookbooks/pgbouncer/recipes/pgbouncer_spec.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
expect(content).to match(/^listen_addr = 0\.0\.0\.0$/)
7373
expect(content).to match(/^listen_port = 6432$/)
7474
expect(content).to match(/^pool_mode = transaction$/)
75+
expect(content).to match(/^max_prepared_statements = 0$/)
7576
expect(content).to match(/^server_reset_query = DISCARD ALL$/)
7677
expect(content).to match(/^application_name_add_host = 1$/)
7778
expect(content).to match(/^max_client_conn = 2048$/)
@@ -90,6 +91,7 @@
9091
expect(content).to match(/^admin_users = gitlab-psql, postgres, pgbouncer$/)
9192
expect(content).to match(/^stats_users = gitlab-psql, postgres, pgbouncer$/)
9293
expect(content).to match(/^ignore_startup_parameters = extra_float_digits$/)
94+
expect(content).to match(/^track_extra_parameters = IntervalStyle$/)
9395
expect(content).to match(%r{^unix_socket_dir = /var/opt/gitlab/pgbouncer$})
9496
expect(content).to match(%r{^%include /var/opt/gitlab/pgbouncer/databases.ini})
9597
expect(content).to match(/^unix_socket_mode = 0777$/)
@@ -120,10 +122,12 @@
120122
expect(content).to match(/^autodb_idle_timeout = 3600$/)
121123
expect(content).to match(/^suspend_timeout = 10$/)
122124
expect(content).to match(/^idle_transaction_timeout = 0$/)
125+
expect(content).to match(/^cancel_wait_timeout = 10$/)
123126
expect(content).to match(/^pkt_buf = 4096$/)
124127
expect(content).to match(/^listen_backlog = 128$/)
125128
expect(content).to match(/^sbuf_loopcnt = 5$/)
126129
expect(content).to match(/^max_packet_size = 2147483647$/)
130+
expect(content).to match(/^so_reuseport = 0$/)
127131
expect(content).to match(/^tcp_defer_accept = 0$/)
128132
expect(content).to match(/^tcp_socket_buffer = 0$/)
129133
expect(content).to match(/^tcp_keepalive = 1$/)
@@ -141,6 +145,7 @@
141145
expect(content).not_to match(%r{^server_tls_cert_file =})
142146
expect(content).not_to match(%r{^max_db_connections =})
143147
expect(content).not_to match(%r{^max_user_connections =})
148+
expect(content).not_to match(%r{^auth_dbname =})
144149
}
145150
end
146151

@@ -222,6 +227,24 @@
222227
.with(user: 'fakeuser', group: 'gitlab-psql')
223228
end
224229
end
230+
231+
context 'peers' do
232+
it 'configures the peers section' do
233+
stub_gitlab_rb(
234+
pgbouncer: {
235+
enable: true,
236+
peers: {
237+
1 => { host: 'host1', port: '9001' },
238+
2 => { host: 'host2', port: '9002' },
239+
}
240+
}
241+
)
242+
expect(chef_run).to render_file(pgbouncer_ini).with_content { |content|
243+
expect(content).to match(%r{^1 = host=host1 port=9001$})
244+
expect(content).to match(%r{^2 = host=host2 port=9002$})
245+
}
246+
end
247+
end
225248
end
226249

227250
context 'authentication' do
@@ -233,13 +256,15 @@
233256
pgbouncer: {
234257
enable: true,
235258
auth_hba_file: '/fake/hba_file',
236-
auth_query: 'SELECT * FROM FAKETABLE'
259+
auth_query: 'SELECT * FROM FAKETABLE',
260+
auth_dbname: 'fakedb',
237261
}
238262
}
239263
)
240264
expect(chef_run).to render_file(pgbouncer_ini).with_content { |content|
241265
expect(content).to match(%r{^auth_hba_file = /fake/hba_file$})
242266
expect(content).to match(/^auth_query = SELECT \* FROM FAKETABLE$/)
267+
expect(content).to match(/^auth_dbname = fakedb$/)
243268
}
244269
end
245270

0 commit comments

Comments
 (0)