Skip to content

Commit

Permalink
fix(db): sets max open and idle connections for postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
pallabpain committed Nov 30, 2023
1 parent b01f1f1 commit 85ffa20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Code reorganisation, a lot of code has moved, please review the following PRs accordingly [#1444](https://github.com/juanfont/headscale/pull/1444)

### Changes
- Set max open and idle connections for postgres

## 0.22.3 (2023-05-12)

Expand All @@ -19,7 +20,7 @@
### Changes

- Add environment flags to enable pprof (profiling) [#1382](https://github.com/juanfont/headscale/pull/1382)
- Profiles are continously generated in our integration tests.
- Profiles are continously generated in our integration tests.
- Fix systemd service file location in `.deb` packages [#1391](https://github.com/juanfont/headscale/pull/1391)
- Improvements on Noise implementation [#1379](https://github.com/juanfont/headscale/pull/1379)
- Replace node filter logic, ensuring nodes with access can see eachother [#1381](https://github.com/juanfont/headscale/pull/1381)
Expand Down
9 changes: 8 additions & 1 deletion hscontrol/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,17 @@ func (h *Headscale) openDB() (*gorm.DB, error) {
sqlDB.SetConnMaxIdleTime(time.Hour)

case Postgres:
db, err = gorm.Open(postgres.Open(h.dbString), &gorm.Config{
db, err := gorm.Open(postgres.Open(h.dbString), &gorm.Config{
DisableForeignKeyConstraintWhenMigrating: true,
Logger: log,
})

sqlDB, _ := db.DB()
sqlDB.SetMaxOpenConns(10)

Check failure on line 260 in hscontrol/db.go

View workflow job for this annotation

GitHub Actions / golangci-lint

mnd: Magic number: 10, in <argument> detected (gomnd)

Check failure on line 260 in hscontrol/db.go

View workflow job for this annotation

GitHub Actions / golangci-lint

mnd: Magic number: 10, in <argument> detected (gomnd)
sqlDB.SetMaxIdleConns(10)

Check failure on line 261 in hscontrol/db.go

View workflow job for this annotation

GitHub Actions / golangci-lint

mnd: Magic number: 10, in <argument> detected (gomnd)

Check failure on line 261 in hscontrol/db.go

View workflow job for this annotation

GitHub Actions / golangci-lint

mnd: Magic number: 10, in <argument> detected (gomnd)
sqlDB.SetConnMaxIdleTime(time.Hour)

return db, err
}

if err != nil {
Expand Down

0 comments on commit 85ffa20

Please sign in to comment.