Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g80x6-0006u1-82 for psycopg@arkaria.postgresql.org; Thu, 04 Oct 2018 10:33:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g80x4-0005Fy-M0 for psycopg@arkaria.postgresql.org; Thu, 04 Oct 2018 10:33:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g80x4-0005Fr-Gu for psycopg@lists.postgresql.org; Thu, 04 Oct 2018 10:33:50 +0000 Received: from mail.dndg.it ([178.32.136.2]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g80wx-0001kc-62 for psycopg@postgresql.org; Thu, 04 Oct 2018 10:33:50 +0000 Received: from [10.94.33.108] (93-50-194-114.ip153.fastwebnet.it [93.50.194.114]) by mail.dndg.it (Postfix) with ESMTPSA id A7832A02E0; Thu, 4 Oct 2018 10:39:04 +0000 (UTC) Subject: Re: Copy command hangs in poll() function To: Daniele Varrazzo , akshay.joshi@enterprisedb.com Cc: psycopg@postgresql.org References: From: Federico Di Gregorio Organization: DNDG srl Message-ID: <2e0825ec-c42e-d61b-a80a-d54156ec910a@dndg.it> Date: Thu, 4 Oct 2018 12:33:41 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SURBL_BLOCKED, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 10/04/2018 12:26 PM, Daniele Varrazzo wrote: > On Thu, Oct 4, 2018 at 6:35 AM Akshay Joshi > > > wrote: > > Hello > > As per documentation http://initd.org/psycopg/docs/advanced.html >  Copy commands are not > supported in asynchronous mode, but this will be probably > implemented in a future release. In pgAdmin4 (open source) we have > used async connection to run the SQL query on PostgreSQL database > and uses poll() function to poll the results. When user runs any > *COPY *command application hangs at poll() function. > > > If copy command not supported then at least it should not hang the > application. poll() function should return the proper error message. > > Can you please provide that fix until support for copy command won't > come. > > > Uhm, I see: > >     In [2]: cnn = psycopg2.connect("") >     In [3]: cur = cnn.cursor() >     In [4]: cur.execute("copy (select 1 as x) to stdout") > > --------------------------------------------------------------------------- >     ProgrammingError                          Traceback (most recent > call last) >     in () >     ----> 1 cur.execute("copy (select 1 as x) to stdout") >     ProgrammingError: can't execute COPY TO: use the copy_to() method > instead > > but: > >     In [6]: cnn = psycopg2.connect("", async=True) >     In [7]: cnn.poll() >     Out[7]: 2 >     In [8]: cnn.poll() >     Out[8]: 1 >     In [9]: cnn.poll() >     Out[9]: 0 > >     In [12]: cur.execute("copy (select 1 as x) to stdout") >     In [14]: cnn.poll() >     ^C -- hung > > So yes, I'll take a look if there is a way to detect we get in this > state. But I'm not sure it's possible, because we might not have > received a result yet that tells we are in a state not allowed (in a COPY). > > Observation: maybe EnterpriseDB has resources enough to help us > debugging and fixing this issue, or maybe even implement async copy? Also, let me add that if the only way to detect the situation is by analyzing the query, we'll never do that. Also, IMHO, it is perfectly fine that a sequence of operations that is documented as "not working" hangs - it is not something you can do by error: you're ignoring the documentation. federico -- Federico Di Gregorio federico.digregorio@dndg.it DNDG srl http://dndg.it I filosofi son come i sociologi: il mondo non lo capiscono. -- A.R.M.