1

I have the following function:

func DeleteReservation(roomId int32, db *pgx.Conn) error {

    _, err := db.Query(context.Background(), `
    DELETE FROM 
        reservation
    WHERE 
        room_id = $1
    `, roomId)

    if err != nil {
        return err
    }

    return nil
}

Every time i call it I get conn busy back from pgx. I have an insert and select function and they both seem to work fine. Im pretty sure this did work earlier today. Any one know of a reason why the conn busy would be coming back for the above call? I tried using QueryRow too and got the same issue

discodowney
  • 1,475
  • 6
  • 28
  • 58
  • I just tried exec, im still getting the same thing. If I change the sql to use a different kind of statement it works, like an insert, but the delete just returns conn busy. – discodowney Apr 09 '22 at 18:30
  • 1
    Note also that `pgx.Conn` represents a single connection and is not safe for concurrent use, so make sure that you are not passing it around to different goroutines. And also that you close every instance after you're done with it. If you want something that's safe for concurrency and is effectively the same as the std lib's `sql.DB` then you should use `pgxpool.Pool` instead of `pgx.Conn`. – mkopriva Apr 09 '22 at 18:49
  • Looks like it was my pgAdmin. Super weird that it only blocked deletes but its working now. Thats for the Pool suggestion. Had totally slipped my mind – discodowney Apr 09 '22 at 19:39

0 Answers0