From 5c8da92a6dee63375748c8de0f3f3af53d529949 Mon Sep 17 00:00:00 2001 From: Otto Richter Date: Wed, 14 Jan 2026 10:10:02 +0100 Subject: [PATCH] config: Lower default `[database].MAX_OPEN_CONNS` (#10821) Resolves https://codeberg.org/forgejo/forgejo/issues/10584 Codeberg mostly uses about 30 connections with rare peaks, so I think it's safe to assume that this value is reasonable even for large Forgejo deployments, and only needs to be adjusted for very busy instances. In practice, the open connections likely remain lower due to the connection lifetime and maximum idle connections (which could maybe also be tuned later). A value of 30 would technically allow 3 full-loaded Forgejo instances to operate on one PostgreSQL instance (30 * 3 = 90 < 97) without conflicting. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10821 Reviewed-by: Michael Kriese Co-authored-by: Otto Richter Co-committed-by: Otto Richter --- custom/conf/app.example.ini | 4 ++-- modules/setting/database.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 01d02700b2..20eb64f38a 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -417,8 +417,8 @@ DB_TYPE = sqlite3 ;; Database connection max idle time, 0 prevents closing due to idle time. ;CONN_MAX_IDLETIME = 0 ;; -;; Database maximum number of open connections, default is 100 which is the lowest default from Postgres (MariaDB + MySQL default to 151). Ensure you only increase the value if you configured your database server accordingly. -;MAX_OPEN_CONNS = 100 +;; Database maximum number of open connections. Ensure you only increase the value if your database server is configured to handle the amount of open connections accordingly. +;MAX_OPEN_CONNS = 30 ;; ;; Whether execute database models migrations automatically ;AUTO_MIGRATION = true diff --git a/modules/setting/database.go b/modules/setting/database.go index bd20edf9c2..4edd0897d8 100644 --- a/modules/setting/database.go +++ b/modules/setting/database.go @@ -96,7 +96,7 @@ func loadDBSetting(rootCfg ConfigProvider) { Database.ConnMaxLifetime = sec.Key("CONN_MAX_LIFETIME").MustDuration(0) } Database.ConnMaxIdleTime = sec.Key("CONN_MAX_IDLETIME").MustDuration(0) - Database.MaxOpenConns = sec.Key("MAX_OPEN_CONNS").MustInt(100) + Database.MaxOpenConns = sec.Key("MAX_OPEN_CONNS").MustInt(30) Database.IterateBufferSize = sec.Key("ITERATE_BUFFER_SIZE").MustInt(50) Database.LogSQL = sec.Key("LOG_SQL").MustBool(false)