add_keepalive_params

Function add_keepalive_params 

Source
pub fn add_keepalive_params(connection_string: &str) -> String
Expand description

Add TCP keepalive parameters to a PostgreSQL connection string

Automatically adds keepalive parameters to prevent idle connection timeouts when connecting through load balancers (like AWS ELB). These parameters ensure that TCP keepalive packets are sent regularly to keep the connection alive.

Parameters added:

  • keepalives=1: Enable TCP keepalives
  • keepalives_idle=60: Send first keepalive after 60 seconds of idle time
  • keepalives_interval=10: Send subsequent keepalives every 10 seconds

If any of these parameters already exist in the connection string, they are not overwritten.

§Arguments

  • connection_string - Original PostgreSQL connection URL

§Returns

Connection string with keepalive parameters added

§Examples

let url = "postgresql://user:pass@host:5432/db";
let url_with_keepalives = add_keepalive_params(url);
assert!(url_with_keepalives.contains("keepalives=1"));
assert!(url_with_keepalives.contains("keepalives_idle=60"));
assert!(url_with_keepalives.contains("keepalives_interval=10"));