go resource_error ai_generated true

error: sql: connection pool exhausted

ID: go/sql-max-open-connections-exceeded

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2024-11-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.22 active

Root Cause

连接池中的连接数达到最大值,且所有连接都在使用中。

generic

中文

连接池中的连接数达到最大值,且所有连接都在使用中。

Workarounds

  1. 90% success
    设置合理池大小:
    db.SetMaxOpenConns(50)
    db.SetMaxIdleConns(10)
    db.SetConnMaxLifetime(time.Hour)
  2. 95% success
    确保所有连接关闭:
    defer rows.Close()
    defer stmt.Close()

Dead Ends

Common approaches that don't work:

  1. 70% fail

    数据库服务器可能过载。

  2. 90% fail

    导致连接泄漏,更快耗尽。