summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2021-09-20 18:20:21 +0200
committerLibravatar GitHub <noreply@github.com>2021-09-20 18:20:21 +0200
commitffc55e9b15461c47f0fc38bb53495026bace10e8 (patch)
tree646651bbf177f3d5ecb70dd6596fdfd7237f627d
parentuse timestamptz instead of timestamp (#237) (diff)
downloadgotosocial-ffc55e9b15461c47f0fc38bb53495026bace10e8.tar.xz
tweak db settings slightly (#238)
-rw-r--r--internal/db/bundb/bundb.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/internal/db/bundb/bundb.go b/internal/db/bundb/bundb.go
index 400535da7..e1879f247 100644
--- a/internal/db/bundb/bundb.go
+++ b/internal/db/bundb/bundb.go
@@ -27,6 +27,7 @@ import (
"errors"
"fmt"
"os"
+ "runtime"
"strings"
"time"
@@ -116,6 +117,7 @@ func NewBunDBService(ctx context.Context, c *config.Config, log *logrus.Logger)
return nil, fmt.Errorf("could not create bundb postgres options: %s", err)
}
sqldb = stdlib.OpenDB(*opts)
+ tweakConnectionValues(sqldb)
conn = WrapDBConn(bun.NewDB(sqldb, pgdialect.New()), log)
case dbTypeSqlite:
// SQLITE
@@ -133,6 +135,7 @@ func NewBunDBService(ctx context.Context, c *config.Config, log *logrus.Logger)
if err != nil {
return nil, fmt.Errorf("could not open sqlite db: %s", err)
}
+ tweakConnectionValues(sqldb)
conn = WrapDBConn(bun.NewDB(sqldb, sqlitedialect.New()), log)
if c.DBConfig.Address == "file::memory:?cache=shared" {
@@ -319,10 +322,18 @@ func deriveBunDBPGOptions(c *config.Config) (*pgx.ConnConfig, error) {
cfg.TLSConfig = tlsConfig
cfg.Database = c.DBConfig.Database
cfg.PreferSimpleProtocol = true
+ cfg.RuntimeParams["application_name"] = c.ApplicationName
return cfg, nil
}
+// https://bun.uptrace.dev/postgres/running-bun-in-production.html#database-sql
+func tweakConnectionValues(sqldb *sql.DB) {
+ maxOpenConns := 4 * runtime.GOMAXPROCS(0)
+ sqldb.SetMaxOpenConns(maxOpenConns)
+ sqldb.SetMaxIdleConns(maxOpenConns)
+}
+
/*
CONVERSION FUNCTIONS
*/