-
Why call rows.Close() takes too long time when I call it after I exit from loop rows.Next() before processing all elements of loop.
rowsClose duration: 1m2.5488669s |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The PostgreSQL server will still send all the rows.
That's basically what pgx is doing. It still has to read everything that comes over the wire until it receives the You can use https://pkg.go.dev/github.com/jackc/pgx/[email protected]/pgconn#PgConn.CancelRequest to send the PostgreSQL server a cancel request message. However, due to limitations of the PostgreSQL protocol, it is difficult to use in a perfectly reliable manner. An alternative is to cancel the context used for your query. However, partially due to the before mentioned limitations, it will close the connection entirely rather than just cancel the query. If you are using pgxpool this should not be an issue as it will transparently create a new connection, but if you are specifically using a single connection that behavior would be inconvenient. |
Beta Was this translation helpful? Give feedback.
The PostgreSQL server will still send all the rows.
That's basically what pgx is doing. It still has to read everything that comes over the wire until it receives the
ReadyForQuery
message.You can use https://pkg.go.dev/github.com/jackc/pgx/[email protected]/pgconn#PgConn.CancelRequest to send the PostgreSQL server a cancel request message. However, due to limitations of the PostgreSQL protocol, it is difficult to use in a perfectly reliable manner.
An alternative is to cancel the context used for your query. However, partially due to t…