From e5863058e4e9f62a3f7f349424a56ed292a3ad93 Mon Sep 17 00:00:00 2001 From: Wei Quan Date: Tue, 14 Jul 2026 13:13:58 +0200 Subject: [PATCH 1/2] Add configurable PostgreSQL CCDB connection parameters Adds ccdb.psql.* BOSH properties for PostgreSQL-specific connection parameters across all 4 CC jobs (cloud_controller_ng, cloud_controller_worker, cloud_controller_clock, cc_deployment_updater). SQL parameters (psql.statement_timeout, psql.idle_in_transaction_session_timeout) are applied via connect_sqls on every new connection. libpq parameters (psql.keepalives, psql.keepalives_idle, psql.keepalives_interval, psql.keepalives_count) are passed directly to the PostgreSQL driver. --- jobs/cc_deployment_updater/spec | 12 +++++++++++ .../templates/cloud_controller_ng.yml.erb | 21 +++++++++++++++++++ jobs/cloud_controller_clock/spec | 13 +++++++++++- .../templates/cloud_controller_ng.yml.erb | 21 +++++++++++++++++++ jobs/cloud_controller_ng/spec | 12 +++++++++++ .../templates/cloud_controller_ng.yml.erb | 21 +++++++++++++++++++ jobs/cloud_controller_worker/spec | 12 +++++++++++ .../templates/cloud_controller_ng.yml.erb | 21 +++++++++++++++++++ 8 files changed, 132 insertions(+), 1 deletion(-) diff --git a/jobs/cc_deployment_updater/spec b/jobs/cc_deployment_updater/spec index c74688ff90..9ff4ab18c6 100644 --- a/jobs/cc_deployment_updater/spec +++ b/jobs/cc_deployment_updater/spec @@ -91,6 +91,18 @@ properties: description: "The period in seconds after which connections are expired (omit to never expire connections), passed directly to the Sequel gem - see https://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/connection_expiration_rb.html for details" ccdb.connection_expiration_random_delay: description: "The random delay in seconds to the expiration timeout (to prevent all connections being recreated simultaneously), passed directly to the Sequel gem - see https://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/connection_expiration_rb.html for details" + ccdb.psql.statement_timeout: + description: "PostgreSQL statement_timeout in milliseconds - kills queries that run longer than this value (PostgreSQL only)" + ccdb.psql.idle_in_transaction_session_timeout: + description: "PostgreSQL idle_in_transaction_session_timeout in milliseconds - closes sessions that remain idle in a transaction longer than this value (PostgreSQL only)" + ccdb.psql.keepalives: + description: "Enable TCP keepalives for PostgreSQL connections (1 to enable, 0 to disable; PostgreSQL only)" + ccdb.psql.keepalives_idle: + description: "Seconds of idle time before TCP keepalives are sent for PostgreSQL connections (PostgreSQL only)" + ccdb.psql.keepalives_interval: + description: "Seconds between TCP keepalive retransmissions for PostgreSQL connections (PostgreSQL only)" + ccdb.psql.keepalives_count: + description: "Maximum number of TCP keepalive retransmissions before the connection is considered dead (PostgreSQL only)" cc.readiness_port.deployment_updater: default: -1 diff --git a/jobs/cc_deployment_updater/templates/cloud_controller_ng.yml.erb b/jobs/cc_deployment_updater/templates/cloud_controller_ng.yml.erb index 5e33e8a692..558154c32c 100644 --- a/jobs/cc_deployment_updater/templates/cloud_controller_ng.yml.erb +++ b/jobs/cc_deployment_updater/templates/cloud_controller_ng.yml.erb @@ -78,6 +78,27 @@ db: &db <% if_p("ccdb.connection_expiration_random_delay") do |expiration_delay| %> connection_expiration_random_delay: <%= expiration_delay %> <% end %> +<% if_p("ccdb.psql.statement_timeout", "ccdb.psql.idle_in_transaction_session_timeout", "ccdb.psql.keepalives", "ccdb.psql.keepalives_idle", "ccdb.psql.keepalives_interval", "ccdb.psql.keepalives_count") do %> + psql: +<% if_p("ccdb.psql.statement_timeout") do |v| %> + statement_timeout: <%= v %> +<% end %> +<% if_p("ccdb.psql.idle_in_transaction_session_timeout") do |v| %> + idle_in_transaction_session_timeout: <%= v %> +<% end %> +<% if_p("ccdb.psql.keepalives") do |v| %> + keepalives: <%= v %> +<% end %> +<% if_p("ccdb.psql.keepalives_idle") do |v| %> + keepalives_idle: <%= v %> +<% end %> +<% if_p("ccdb.psql.keepalives_interval") do |v| %> + keepalives_interval: <%= v %> +<% end %> +<% if_p("ccdb.psql.keepalives_count") do |v| %> + keepalives_count: <%= v %> +<% end %> +<% end %> db_encryption_key: <%= p("cc.db_encryption_key") %> diff --git a/jobs/cloud_controller_clock/spec b/jobs/cloud_controller_clock/spec index d43f5d9aae..e9dec8a7ee 100644 --- a/jobs/cloud_controller_clock/spec +++ b/jobs/cloud_controller_clock/spec @@ -418,7 +418,18 @@ properties: description: "The period in seconds after which connections are expired (omit to never expire connections), passed directly to the Sequel gem - see https://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/connection_expiration_rb.html for details" ccdb.connection_expiration_random_delay: description: "The random delay in seconds to the expiration timeout (to prevent all connections being recreated simultaneously), passed directly to the Sequel gem - see https://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/connection_expiration_rb.html for details" - + ccdb.psql.statement_timeout: + description: "PostgreSQL statement_timeout in milliseconds - kills queries that run longer than this value (PostgreSQL only)" + ccdb.psql.idle_in_transaction_session_timeout: + description: "PostgreSQL idle_in_transaction_session_timeout in milliseconds - closes sessions that remain idle in a transaction longer than this value (PostgreSQL only)" + ccdb.psql.keepalives: + description: "Enable TCP keepalives for PostgreSQL connections (1 to enable, 0 to disable; PostgreSQL only)" + ccdb.psql.keepalives_idle: + description: "Seconds of idle time before TCP keepalives are sent for PostgreSQL connections (PostgreSQL only)" + ccdb.psql.keepalives_interval: + description: "Seconds between TCP keepalive retransmissions for PostgreSQL connections (PostgreSQL only)" + ccdb.psql.keepalives_count: + description: "Maximum number of TCP keepalive retransmissions before the connection is considered dead (PostgreSQL only)" uaa.ca_cert: description: "The certificate authority being used by UAA" uaa.ssl.port: diff --git a/jobs/cloud_controller_clock/templates/cloud_controller_ng.yml.erb b/jobs/cloud_controller_clock/templates/cloud_controller_ng.yml.erb index 8415ee6763..0a040dbbe9 100644 --- a/jobs/cloud_controller_clock/templates/cloud_controller_ng.yml.erb +++ b/jobs/cloud_controller_clock/templates/cloud_controller_ng.yml.erb @@ -179,6 +179,27 @@ db: &db <% if_p("ccdb.connection_expiration_random_delay") do |expiration_delay| %> connection_expiration_random_delay: <%= expiration_delay %> <% end %> +<% if_p("ccdb.psql.statement_timeout", "ccdb.psql.idle_in_transaction_session_timeout", "ccdb.psql.keepalives", "ccdb.psql.keepalives_idle", "ccdb.psql.keepalives_interval", "ccdb.psql.keepalives_count") do %> + psql: +<% if_p("ccdb.psql.statement_timeout") do |v| %> + statement_timeout: <%= v %> +<% end %> +<% if_p("ccdb.psql.idle_in_transaction_session_timeout") do |v| %> + idle_in_transaction_session_timeout: <%= v %> +<% end %> +<% if_p("ccdb.psql.keepalives") do |v| %> + keepalives: <%= v %> +<% end %> +<% if_p("ccdb.psql.keepalives_idle") do |v| %> + keepalives_idle: <%= v %> +<% end %> +<% if_p("ccdb.psql.keepalives_interval") do |v| %> + keepalives_interval: <%= v %> +<% end %> +<% if_p("ccdb.psql.keepalives_count") do |v| %> + keepalives_count: <%= v %> +<% end %> +<% end %> <% system_domain = p("system_domain") %> diff --git a/jobs/cloud_controller_ng/spec b/jobs/cloud_controller_ng/spec index ff0a3e61b5..2c21d6c6ab 100644 --- a/jobs/cloud_controller_ng/spec +++ b/jobs/cloud_controller_ng/spec @@ -783,6 +783,18 @@ properties: description: "The period in seconds after which connections are expired (omit to never expire connections), passed directly to the Sequel gem - see https://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/connection_expiration_rb.html for details" ccdb.connection_expiration_random_delay: description: "The random delay in seconds to the expiration timeout (to prevent all connections being recreated simultaneously), passed directly to the Sequel gem - see https://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/connection_expiration_rb.html for details" + ccdb.psql.statement_timeout: + description: "PostgreSQL statement_timeout in milliseconds - kills queries that run longer than this value (PostgreSQL only)" + ccdb.psql.idle_in_transaction_session_timeout: + description: "PostgreSQL idle_in_transaction_session_timeout in milliseconds - closes sessions that remain idle in a transaction longer than this value (PostgreSQL only)" + ccdb.psql.keepalives: + description: "Enable TCP keepalives for PostgreSQL connections (1 to enable, 0 to disable; PostgreSQL only)" + ccdb.psql.keepalives_idle: + description: "Seconds of idle time before TCP keepalives are sent for PostgreSQL connections (PostgreSQL only)" + ccdb.psql.keepalives_interval: + description: "Seconds between TCP keepalive retransmissions for PostgreSQL connections (PostgreSQL only)" + ccdb.psql.keepalives_count: + description: "Maximum number of TCP keepalive retransmissions before the connection is considered dead (PostgreSQL only)" ccdb.max_connections_per_local_worker: description: "Maximum database connections per cc local worker, if not set the ccng value is used (default)" ccdb.enable_paginate_window: diff --git a/jobs/cloud_controller_ng/templates/cloud_controller_ng.yml.erb b/jobs/cloud_controller_ng/templates/cloud_controller_ng.yml.erb index 0d0b95ef16..3e4ba8c0d1 100644 --- a/jobs/cloud_controller_ng/templates/cloud_controller_ng.yml.erb +++ b/jobs/cloud_controller_ng/templates/cloud_controller_ng.yml.erb @@ -241,6 +241,27 @@ db: &db migration_psql_worker_memory_kb: <%= psql_worker_memory_kb %> <% end %> enable_paginate_window: <%= p("ccdb.enable_paginate_window") %> +<% if_p("ccdb.psql.statement_timeout", "ccdb.psql.idle_in_transaction_session_timeout", "ccdb.psql.keepalives", "ccdb.psql.keepalives_idle", "ccdb.psql.keepalives_interval", "ccdb.psql.keepalives_count") do %> + psql: +<% if_p("ccdb.psql.statement_timeout") do |v| %> + statement_timeout: <%= v %> +<% end %> +<% if_p("ccdb.psql.idle_in_transaction_session_timeout") do |v| %> + idle_in_transaction_session_timeout: <%= v %> +<% end %> +<% if_p("ccdb.psql.keepalives") do |v| %> + keepalives: <%= v %> +<% end %> +<% if_p("ccdb.psql.keepalives_idle") do |v| %> + keepalives_idle: <%= v %> +<% end %> +<% if_p("ccdb.psql.keepalives_interval") do |v| %> + keepalives_interval: <%= v %> +<% end %> +<% if_p("ccdb.psql.keepalives_count") do |v| %> + keepalives_count: <%= v %> +<% end %> +<% end %> <% scheme = p("login.protocol") system_domain = p("system_domain") %> diff --git a/jobs/cloud_controller_worker/spec b/jobs/cloud_controller_worker/spec index 12860c8eb5..73f080d368 100644 --- a/jobs/cloud_controller_worker/spec +++ b/jobs/cloud_controller_worker/spec @@ -377,6 +377,18 @@ properties: description: "The period in seconds after which connections are expired (omit to never expire connections), passed directly to the Sequel gem - see https://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/connection_expiration_rb.html for details" ccdb.connection_expiration_random_delay: description: "The random delay in seconds to the expiration timeout (to prevent all connections being recreated simultaneously), passed directly to the Sequel gem - see https://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/connection_expiration_rb.html for details" + ccdb.psql.statement_timeout: + description: "PostgreSQL statement_timeout in milliseconds - kills queries that run longer than this value (PostgreSQL only)" + ccdb.psql.idle_in_transaction_session_timeout: + description: "PostgreSQL idle_in_transaction_session_timeout in milliseconds - closes sessions that remain idle in a transaction longer than this value (PostgreSQL only)" + ccdb.psql.keepalives: + description: "Enable TCP keepalives for PostgreSQL connections (1 to enable, 0 to disable; PostgreSQL only)" + ccdb.psql.keepalives_idle: + description: "Seconds of idle time before TCP keepalives are sent for PostgreSQL connections (PostgreSQL only)" + ccdb.psql.keepalives_interval: + description: "Seconds between TCP keepalive retransmissions for PostgreSQL connections (PostgreSQL only)" + ccdb.psql.keepalives_count: + description: "Maximum number of TCP keepalive retransmissions before the connection is considered dead (PostgreSQL only)" cc.database_encryption.keys: default: {} diff --git a/jobs/cloud_controller_worker/templates/cloud_controller_ng.yml.erb b/jobs/cloud_controller_worker/templates/cloud_controller_ng.yml.erb index 3506b48d4d..81b77244b4 100644 --- a/jobs/cloud_controller_worker/templates/cloud_controller_ng.yml.erb +++ b/jobs/cloud_controller_worker/templates/cloud_controller_ng.yml.erb @@ -134,6 +134,27 @@ db: &db <% if_p("ccdb.connection_expiration_random_delay") do |expiration_delay| %> connection_expiration_random_delay: <%= expiration_delay %> <% end %> +<% if_p("ccdb.psql.statement_timeout", "ccdb.psql.idle_in_transaction_session_timeout", "ccdb.psql.keepalives", "ccdb.psql.keepalives_idle", "ccdb.psql.keepalives_interval", "ccdb.psql.keepalives_count") do %> + psql: +<% if_p("ccdb.psql.statement_timeout") do |v| %> + statement_timeout: <%= v %> +<% end %> +<% if_p("ccdb.psql.idle_in_transaction_session_timeout") do |v| %> + idle_in_transaction_session_timeout: <%= v %> +<% end %> +<% if_p("ccdb.psql.keepalives") do |v| %> + keepalives: <%= v %> +<% end %> +<% if_p("ccdb.psql.keepalives_idle") do |v| %> + keepalives_idle: <%= v %> +<% end %> +<% if_p("ccdb.psql.keepalives_interval") do |v| %> + keepalives_interval: <%= v %> +<% end %> +<% if_p("ccdb.psql.keepalives_count") do |v| %> + keepalives_count: <%= v %> +<% end %> +<% end %> <% system_domain = p("system_domain") %> From 52f27bf132b33eb3612bdebe37bd9a3079b3f111 Mon Sep 17 00:00:00 2001 From: Wei Quan Date: Wed, 15 Jul 2026 15:47:31 +0200 Subject: [PATCH 2/2] Set safe defaults for all CC jobs --- jobs/cc_deployment_updater/spec | 6 ++++++ jobs/cloud_controller_clock/spec | 6 ++++++ jobs/cloud_controller_ng/spec | 6 ++++++ jobs/cloud_controller_worker/spec | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/jobs/cc_deployment_updater/spec b/jobs/cc_deployment_updater/spec index 9ff4ab18c6..2188d22e24 100644 --- a/jobs/cc_deployment_updater/spec +++ b/jobs/cc_deployment_updater/spec @@ -93,16 +93,22 @@ properties: description: "The random delay in seconds to the expiration timeout (to prevent all connections being recreated simultaneously), passed directly to the Sequel gem - see https://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/connection_expiration_rb.html for details" ccdb.psql.statement_timeout: description: "PostgreSQL statement_timeout in milliseconds - kills queries that run longer than this value (PostgreSQL only)" + default: 1800000 ccdb.psql.idle_in_transaction_session_timeout: description: "PostgreSQL idle_in_transaction_session_timeout in milliseconds - closes sessions that remain idle in a transaction longer than this value (PostgreSQL only)" + default: 600000 ccdb.psql.keepalives: description: "Enable TCP keepalives for PostgreSQL connections (1 to enable, 0 to disable; PostgreSQL only)" + default: 1 ccdb.psql.keepalives_idle: description: "Seconds of idle time before TCP keepalives are sent for PostgreSQL connections (PostgreSQL only)" + default: 30 ccdb.psql.keepalives_interval: description: "Seconds between TCP keepalive retransmissions for PostgreSQL connections (PostgreSQL only)" + default: 10 ccdb.psql.keepalives_count: description: "Maximum number of TCP keepalive retransmissions before the connection is considered dead (PostgreSQL only)" + default: 3 cc.readiness_port.deployment_updater: default: -1 diff --git a/jobs/cloud_controller_clock/spec b/jobs/cloud_controller_clock/spec index e9dec8a7ee..41eb4af64e 100644 --- a/jobs/cloud_controller_clock/spec +++ b/jobs/cloud_controller_clock/spec @@ -420,16 +420,22 @@ properties: description: "The random delay in seconds to the expiration timeout (to prevent all connections being recreated simultaneously), passed directly to the Sequel gem - see https://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/connection_expiration_rb.html for details" ccdb.psql.statement_timeout: description: "PostgreSQL statement_timeout in milliseconds - kills queries that run longer than this value (PostgreSQL only)" + default: 1800000 ccdb.psql.idle_in_transaction_session_timeout: description: "PostgreSQL idle_in_transaction_session_timeout in milliseconds - closes sessions that remain idle in a transaction longer than this value (PostgreSQL only)" + default: 600000 ccdb.psql.keepalives: description: "Enable TCP keepalives for PostgreSQL connections (1 to enable, 0 to disable; PostgreSQL only)" + default: 1 ccdb.psql.keepalives_idle: description: "Seconds of idle time before TCP keepalives are sent for PostgreSQL connections (PostgreSQL only)" + default: 30 ccdb.psql.keepalives_interval: description: "Seconds between TCP keepalive retransmissions for PostgreSQL connections (PostgreSQL only)" + default: 10 ccdb.psql.keepalives_count: description: "Maximum number of TCP keepalive retransmissions before the connection is considered dead (PostgreSQL only)" + default: 3 uaa.ca_cert: description: "The certificate authority being used by UAA" uaa.ssl.port: diff --git a/jobs/cloud_controller_ng/spec b/jobs/cloud_controller_ng/spec index 2c21d6c6ab..8c3783cebc 100644 --- a/jobs/cloud_controller_ng/spec +++ b/jobs/cloud_controller_ng/spec @@ -785,16 +785,22 @@ properties: description: "The random delay in seconds to the expiration timeout (to prevent all connections being recreated simultaneously), passed directly to the Sequel gem - see https://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/connection_expiration_rb.html for details" ccdb.psql.statement_timeout: description: "PostgreSQL statement_timeout in milliseconds - kills queries that run longer than this value (PostgreSQL only)" + default: 900000 ccdb.psql.idle_in_transaction_session_timeout: description: "PostgreSQL idle_in_transaction_session_timeout in milliseconds - closes sessions that remain idle in a transaction longer than this value (PostgreSQL only)" + default: 600000 ccdb.psql.keepalives: description: "Enable TCP keepalives for PostgreSQL connections (1 to enable, 0 to disable; PostgreSQL only)" + default: 1 ccdb.psql.keepalives_idle: description: "Seconds of idle time before TCP keepalives are sent for PostgreSQL connections (PostgreSQL only)" + default: 30 ccdb.psql.keepalives_interval: description: "Seconds between TCP keepalive retransmissions for PostgreSQL connections (PostgreSQL only)" + default: 10 ccdb.psql.keepalives_count: description: "Maximum number of TCP keepalive retransmissions before the connection is considered dead (PostgreSQL only)" + default: 3 ccdb.max_connections_per_local_worker: description: "Maximum database connections per cc local worker, if not set the ccng value is used (default)" ccdb.enable_paginate_window: diff --git a/jobs/cloud_controller_worker/spec b/jobs/cloud_controller_worker/spec index 73f080d368..1cd7dc4baa 100644 --- a/jobs/cloud_controller_worker/spec +++ b/jobs/cloud_controller_worker/spec @@ -379,16 +379,22 @@ properties: description: "The random delay in seconds to the expiration timeout (to prevent all connections being recreated simultaneously), passed directly to the Sequel gem - see https://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/connection_expiration_rb.html for details" ccdb.psql.statement_timeout: description: "PostgreSQL statement_timeout in milliseconds - kills queries that run longer than this value (PostgreSQL only)" + default: 1800000 ccdb.psql.idle_in_transaction_session_timeout: description: "PostgreSQL idle_in_transaction_session_timeout in milliseconds - closes sessions that remain idle in a transaction longer than this value (PostgreSQL only)" + default: 600000 ccdb.psql.keepalives: description: "Enable TCP keepalives for PostgreSQL connections (1 to enable, 0 to disable; PostgreSQL only)" + default: 1 ccdb.psql.keepalives_idle: description: "Seconds of idle time before TCP keepalives are sent for PostgreSQL connections (PostgreSQL only)" + default: 30 ccdb.psql.keepalives_interval: description: "Seconds between TCP keepalive retransmissions for PostgreSQL connections (PostgreSQL only)" + default: 10 ccdb.psql.keepalives_count: description: "Maximum number of TCP keepalive retransmissions before the connection is considered dead (PostgreSQL only)" + default: 3 cc.database_encryption.keys: default: {}