From: Tom Lane <tgl@sss.pgh.pa.us>
To: Daniel Frey <d.frey@gmx.de>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: libpq: How to cancel a COPY ... TO statement?
Date: Mon, 08 Nov 2021 14:05:41 -0500
Message-ID: <991131.1636398341@sss.pgh.pa.us> (raw)
In-Reply-To: <63674FDD-D20C-4EB3-A0E3-3C04C4BF802F@gmx.de>
References: <63674FDD-D20C-4EB3-A0E3-3C04C4BF802F@gmx.de>
Daniel Frey <d.frey@gmx.de> writes:
> after sending a COPY ... TO statement with PQsendQuery(), how can I cancel it properly?
> I tried using PQcancel(),
That's the correct way.
> but it seems to have no effect. Calling PQgetCopyData() or PQgetResult() afterwards does not go into a failure state. And I don't want to call PQgetCopyData() until it returns -1, as this might be a lot of data being read from the server that I don't need.
You can't expect instantaneous response to a cancel. For one thing, the
server might have already stuffed a good deal of data down the pipe.
You should keep pulling (and discarding) data until you get the end
or error response.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, d.frey@gmx.de
Subject: Re: libpq: How to cancel a COPY ... TO statement?
In-Reply-To: <991131.1636398341@sss.pgh.pa.us>
References: <63674FDD-D20C-4EB3-A0E3-3C04C4BF802F@gmx.de> <991131.1636398341@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox