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.
This commit is contained in:
Deluan 2026-09-05 00:08:43 -04:00
parent 0cf80707ac
commit a21c4c92fc

View File

@ -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