From 2323810b06ad57771c05341a199158d5ebaf9a10 Mon Sep 17 00:00:00 2001 From: sam Date: Tue, 10 Sep 2024 18:52:13 +0200 Subject: [PATCH] feat(backend): add option to disable postgres connection pooling --- Foxnouns.Backend/Config.cs | 1 + Foxnouns.Backend/Database/DatabaseContext.cs | 1 + Foxnouns.Backend/config.example.ini | 2 ++ 3 files changed, 4 insertions(+) diff --git a/Foxnouns.Backend/Config.cs b/Foxnouns.Backend/Config.cs index 96d724b..0781443 100644 --- a/Foxnouns.Backend/Config.cs +++ b/Foxnouns.Backend/Config.cs @@ -36,6 +36,7 @@ public class Config public class DatabaseConfig { public string Url { get; init; } = string.Empty; + public bool? EnablePooling { get; init; } public int? Timeout { get; init; } public int? MaxPoolSize { get; init; } } diff --git a/Foxnouns.Backend/Database/DatabaseContext.cs b/Foxnouns.Backend/Database/DatabaseContext.cs index 8ce0d6f..70477f2 100644 --- a/Foxnouns.Backend/Database/DatabaseContext.cs +++ b/Foxnouns.Backend/Database/DatabaseContext.cs @@ -26,6 +26,7 @@ public class DatabaseContext : DbContext { var connString = new NpgsqlConnectionStringBuilder(config.Database.Url) { + Pooling = config.Database.EnablePooling ?? true, Timeout = config.Database.Timeout ?? 5, MaxPoolSize = config.Database.MaxPoolSize ?? 50, MinPoolSize = 0, diff --git a/Foxnouns.Backend/config.example.ini b/Foxnouns.Backend/config.example.ini index 941c25c..7522cba 100644 --- a/Foxnouns.Backend/config.example.ini +++ b/Foxnouns.Backend/config.example.ini @@ -30,6 +30,8 @@ MetricsPort = 5001 [Database] ; The database URL in ADO.NET format. Url = "Host=localhost;Database=foxnouns_net;Username=pronouns;Password=pronouns" +; Whether to enable connection pooling. This should be turned off if using pgbouncer. Defaults to true. +EnablePooling = true ; The timeout for opening new connections. Defaults to 5. Timeout = 5 ; The maximum number of open connections. Defaults to 50.