database/postgres: set max open conns

Open at most 25 connections. Should fix errors such as
"pq: sorry, too many clients already".
This commit is contained in:
Simon Ser 2022-07-25 19:00:14 +02:00
parent d0868722cd
commit 8849669d61
1 changed files with 4 additions and 0 deletions

View File

@ -175,6 +175,10 @@ func OpenPostgresDB(source string) (Database, error) {
return nil, err
}
// By default sql.DB doesn't have a connection limit. This can cause errors
// because PostgreSQL has a default of 100 max connections.
sqlPostgresDB.SetMaxOpenConns(25)
db := &PostgresDB{db: sqlPostgresDB}
if err := db.upgrade(); err != nil {
sqlPostgresDB.Close()