drcj64241 2016-03-31 11:31
浏览 53

带有Golang的Postgresql,问题

I have created an Api with golang and postgresql as database.

after several requests, the API crashes with an error 500 and a log that displays

pq : sorry , too many customers already

At first it was because I did not close rows when i select, so i have rows.close() all.

But it's not that because i have already this error.

Then saw the launch of the database takes only 3ms, I thought I should start and close the database on every request to reset all connections, but thinking about it a little more, this is nonsense.

So I ask you, how this error works , is that the client connections are reset after a certain time or connection is cut off until a server reboot for client?

If it resets after a certain time , what are the disadvantages of increasing the maximum number of client connection?

My code:

I open my db like this at start of program :

    var gest Gestion

    type Gestion struct {
        Db *sql.DB
        DbLog *sql.DB
    }



func InitDbUser() *sql.DB {
      dbinfo := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable", DB_USER, DB_PASSWORD, DB_NAME)
      db, err := sql.Open("postgres", dbinfo)
      LogFatalError(err)
      err2 := db.Ping()
      LogFatalError(err2)
      return db
}

func main() {

    gest.Db = InitDbUser()

        defer gest.Db.Close()
        //routing is here

    }

And when i use this request in my psql :

select min_val,max_val from pg_settings where name='max_connections';

I get hat :

 min_val | max_val
---------+---------
 1       | 8388607

Sorry for my english, i hope you understand what I ask :)

  • 写回答

1条回答 默认 最新

  • duanjuduo4573 2016-03-31 11:41
    关注

    You can check the max_connection setting of PG, that might be the problem here:

    select min_val,max_val from pg_settings where name='max_connections'
    
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度