fix: ограничить пул Postgres и реже писать прогресс скана

- DB_MAX_OPEN_CONNS (25), DB_MAX_IDLE_CONNS (10), DB_CONN_MAX_LIFETIME_SEC (1800)

- Throttle UpdateScan прогресса в Runner (500ms), меньше одновременных запросов к БД

Устраняет FATAL too many clients при больших сканах и частом опросе GetScan

Made-with: Cursor
This commit is contained in:
PTah
2026-04-13 15:33:25 +10:00
parent 088be32ec5
commit 6ad59c9990
3 changed files with 73 additions and 10 deletions
+9
View File
@@ -57,6 +57,15 @@ func makeStore(cfg config.Config) (scans.Store, func()) {
log.Fatalf("db ping failed: %v", err)
}
db.SetMaxOpenConns(cfg.DBMaxOpenConns)
db.SetMaxIdleConns(cfg.DBMaxIdleConns)
if cfg.DBConnMaxLifetime > 0 {
db.SetConnMaxLifetime(cfg.DBConnMaxLifetime)
log.Printf("postgres pool: max_open=%d max_idle=%d conn_max_lifetime=%v", cfg.DBMaxOpenConns, cfg.DBMaxIdleConns, cfg.DBConnMaxLifetime)
} else {
log.Printf("postgres pool: max_open=%d max_idle=%d conn_max_lifetime=off", cfg.DBMaxOpenConns, cfg.DBMaxIdleConns)
}
if cfg.RunMigrations {
if err = store.RunMigrations(db); err != nil {
_ = db.Close()