Skip to content

Commit 5b380fb

Browse files
authored
Set the default Connection Lifetime to one hour (#5662)
Connection Lifetime can also be used to limit memory growth of PostgreSQL connection. Certain caches only grow over time, the most common example is the cache for table metadata: the "relcache". For systems with many tables (often times due to partitioning) this relcache slowly grows larger and larger. By putting a 1 hour limit on a connection lifetime such excessive growth is limited. This same 1 hour limit is used for PgBouncer its equivalent server_lifetime config option. (I'm the maintainer of PgBouncer)
1 parent c86e5ef commit 5b380fb

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/Npgsql/NpgsqlConnectionStringBuilder.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,13 +777,17 @@ public int ConnectionPruningInterval
777777
/// <summary>
778778
/// The total maximum lifetime of connections (in seconds). Connections which have exceeded this value will be
779779
/// destroyed instead of returned from the pool. This is useful in clustered configurations to force load
780-
/// balancing between a running server and a server just brought online.
780+
/// balancing between a running server and a server just brought online. It can also be useful to prevent
781+
/// runaway memory growth of connections at the PostgreSQL server side, because in some cases very long lived
782+
/// connections slowly consume more and more memory over time.
783+
/// Defaults to 3600 seconds (1 hour).
781784
/// </summary>
782-
/// <value>The time (in seconds) to wait, or 0 to to make connections last indefinitely (the default).</value>
785+
/// <value>The time (in seconds) to wait, or 0 to to make connections last indefinitely.</value>
783786
[Category("Pooling")]
784787
[Description("The total maximum lifetime of connections (in seconds).")]
785788
[DisplayName("Connection Lifetime")]
786789
[NpgsqlConnectionStringProperty("Load Balance Timeout")]
790+
[DefaultValue(3600)]
787791
public int ConnectionLifetime
788792
{
789793
get => _connectionLifetime;

0 commit comments

Comments
 (0)