Skip to content

Commit f0fc3af

Browse files
Add connection pooling settings
1 parent d38efb1 commit f0fc3af

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ Configure Caddy to use the PostgreSQL storage module. Example `Caddyfile`:
3333
The `dsn` parameter is a [PostgreSQL connection string](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING), either as a key/value string or as a connection URI.
3434

3535
The `sslmode` connection parameter defaults to `require`. We recommend setting a `statement_timeout` (e.g. `30s`) and other [basic parameters](https://brandur.org/fragments/postgres-parameters).
36+
37+
This module implementation already sets the following connection pooling parameters: maximum open connection (`10`), maximum idle connections (`3`), and connection maximum idle time (`1h`).

storage.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ func (s *PostgresStorage) Provision(ctx caddy.Context) error {
7878
return err
7979
}
8080

81+
// Limit number of open connections
82+
db.SetMaxOpenConns(10)
83+
// Limit idle connections to 3
84+
db.SetMaxIdleConns(3)
85+
// Close idle connections after 1 hour
86+
db.SetConnMaxIdleTime(time.Hour)
87+
8188
s.db = db
8289

8390
// Initialize pglock

0 commit comments

Comments
 (0)