Merge pull request #297 from AppFlowy-IO/connection-lifetime

feat: added pg connection lifetime
This commit is contained in:
Zack 2024-02-06 11:37:00 +08:00 committed by GitHub
commit 5fe94e9c59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 0 deletions

View File

@ -338,6 +338,8 @@ async fn get_connection_pool(setting: &DatabaseSetting) -> Result<PgPool, Error>
PgPoolOptions::new()
.max_connections(setting.max_connections)
.acquire_timeout(Duration::from_secs(10))
.max_lifetime(Duration::from_secs(60 * 60))
.idle_timeout(Duration::from_secs(60))
.connect_with(setting.with_db())
.await
.map_err(|e| anyhow::anyhow!("Failed to connect to postgres database: {}", e))