dongxia1390 2017-11-01 16:04
浏览 30
已采纳

SQL查询在服务器上完成,但程序永不恢复

I am connecting my go scripts to redshift using go-lang postgres driver. When query takes 5+ minutes to complete, my program never gets its control back. After checking the query at redshift-server I do see that query completed in ~7 minutes.

Not sure why is this happening.

My code

func truncate_and_populate_set_1(db *sql.DB, parameter string){
  insert_q := `...`
  db := GetDB()
  util.ExeQ(db, insert_q)
  log.Println("Done adding records to table")
}

func GetDB() *sql.DB {
  connection_string := "postgres://%s:%s@host"
  db, err := sql.Open("postgres", connection_string)
  if err != nil {
    fmt.Println(err)
  }
  return db
}

func ExeQ(db *sql.DB, query string) {
_, err := db.Exec(query)
if err != nil {
    log.Fatal(err)
  }
}
  • 写回答

1条回答 默认 最新

  • drkrsx3135168 2017-11-10 16:40
    关注

    You need to alter the keep alive behavior of the library that's managing the Redshift connection. Unfortuantely I can't advise you on how to do that in Go.

    For a JDBC URL you could append the options:

    jdbc:redshift://my-cluster … :5439/user?tcpKeepAlive=true&TCPKeepAliveMinutes=2
    

    See the documentation here for more options: http://docs.aws.amazon.com/redshift/latest/mgmt/troubleshooting-connections.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 MATLAB四叉树处理长方形tif文件
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 使用Java milo连接Kepserver服务端报错?
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了