Skip to content

Commit

Permalink
Merge pull request #81 from xmtp/pg-max-conns
Browse files Browse the repository at this point in the history
Fixes "too many clients" issue from PG by setting max open connections
  • Loading branch information
snormore authored May 9, 2023
2 parents dcf0717 + e4637c5 commit b13f040
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/store/postgres/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
"github.com/xmtp/xmtpd/pkg/zap"
)

const (
// Default in postgres is typically configured to be 100.
maxOpenConnections = 80
)

type DB struct {
*sql.DB
DSN string
Expand All @@ -18,6 +23,7 @@ func NewDB(opts *Options) (*DB, error) {
if err != nil {
return nil, err
}
db.SetMaxOpenConns(maxOpenConnections)
return &DB{
DB: db,
DSN: opts.DSN,
Expand Down
1 change: 1 addition & 0 deletions pkg/store/postgres/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ func (s *Store) heads(ctx context.Context, tx *sql.Tx) ([]multihash.Multihash, e
if err != nil {
return nil, err
}
defer rows.Close()

var cids []multihash.Multihash
for rows.Next() {
Expand Down

0 comments on commit b13f040

Please sign in to comment.