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

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

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)