add connection pool settings in ConnectToPostgreSQL function
This commit is contained in:
2
.github/workflows/docker-image.yml
vendored
2
.github/workflows/docker-image.yml
vendored
@@ -4,7 +4,7 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- test
|
- dev
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
)
|
)
|
||||||
@@ -26,6 +27,11 @@ func ConnectToPostgreSQL() (*sql.DB, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set connection pool settings
|
||||||
|
db.SetMaxOpenConns(25) // Maximum number of open connections to the database
|
||||||
|
db.SetMaxIdleConns(25) // Maximum number of connections in the idle connection pool
|
||||||
|
db.SetConnMaxLifetime(1 * time.Hour) // Maximum amount of time a connection may be reused
|
||||||
|
|
||||||
fmt.Println("Connection to PostgreSQL opened successfully :D")
|
fmt.Println("Connection to PostgreSQL opened successfully :D")
|
||||||
|
|
||||||
// Ping database to verify connection
|
// Ping database to verify connection
|
||||||
|
|||||||
Reference in New Issue
Block a user