From a21c4c92fc677b0213ddc54738dd8cc1e321928f Mon Sep 17 00:00:00 2001 From: Deluan Date: Sat, 5 Sep 2026 00:08:43 -0400 Subject: [PATCH] perf(pglite): keep pooled connections idle instead of churning them database/sql keeps only 2 idle connections by default, so with 4 open the pool closed and reopened connections constantly: about 225 Terminate+handshake cycles per minute during a scan on roy. Every handshake goes through the single backend, and the first query after a handshake is where the lost replies were seen. --- db/db.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db/db.go b/db/db.go index 246d9cf3c..f22d4087d 100644 --- a/db/db.go +++ b/db/db.go @@ -55,7 +55,10 @@ func Db() *sql.DB { log.Fatal("Error opening database", err) } // One PGlite backend means one PG session; the bridge serializes clients onto it. + // Keep every connection idle rather than churning handshakes through the backend. db.SetMaxOpenConns(4) + db.SetMaxIdleConns(4) + db.SetConnMaxLifetime(0) abs, _ := filepath.Abs(socketDir) log.Info("Embedded PGlite ready", "psql", "PGPASSWORD=x PGSSLMODE=disable psql -h "+abs+" -U postgres navidrome") return db