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)
  }
}

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