Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mk9xk-00033P-Pj for pgsql-general@arkaria.postgresql.org; Mon, 08 Nov 2021 19:05:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mk9xj-0006We-NV for pgsql-general@arkaria.postgresql.org; Mon, 08 Nov 2021 19:05:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mk9xj-0006WT-D5 for pgsql-general@lists.postgresql.org; Mon, 08 Nov 2021 19:05:47 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mk9xh-0001rm-BI for pgsql-general@lists.postgresql.org; Mon, 08 Nov 2021 19:05:46 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 1A8J5fHN991132; Mon, 8 Nov 2021 14:05:42 -0500 From: Tom Lane To: Daniel Frey cc: pgsql-general@lists.postgresql.org Subject: Re: libpq: How to cancel a COPY ... TO statement? In-reply-to: <63674FDD-D20C-4EB3-A0E3-3C04C4BF802F@gmx.de> References: <63674FDD-D20C-4EB3-A0E3-3C04C4BF802F@gmx.de> Comments: In-reply-to Daniel Frey message dated "Mon, 08 Nov 2021 19:59:01 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <991130.1636398341.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 08 Nov 2021 14:05:41 -0500 Message-ID: <991131.1636398341@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Daniel Frey writes: > after sending a COPY ... TO statement with PQsendQuery(), how can I canc= el 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 PQg= etCopyData() until it returns -1, as this might be a lot of data being rea= d 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