Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f3cLe-0005Sd-TG for pgsql-general@arkaria.postgresql.org; Wed, 04 Apr 2018 06:56:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f3cLd-0006X3-Ew for pgsql-general@arkaria.postgresql.org; Wed, 04 Apr 2018 06:56:45 +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 1f3cLd-0006Wu-7L for pgsql-general@lists.postgresql.org; Wed, 04 Apr 2018 06:56:45 +0000 Received: from mx1.mailbox.org ([80.241.60.212]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f3cLV-0005si-1C for pgsql-general@lists.postgresql.org; Wed, 04 Apr 2018 06:56:44 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id 02C6542BED; Wed, 4 Apr 2018 08:56:34 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id mnzGJdvvSd4q; Wed, 4 Apr 2018 08:56:33 +0200 (CEST) Message-ID: <1522822316.2456.9.camel@cybertec.at> Subject: Re: dblink: could not send query: another command is already in progress From: Laurenz Albe To: Thiemo Kellner , PostgreSQL General In-Reply-To: References: <8d6c6faa-4878-68bf-d1b7-6b1f86c1445c@gelassene-pferde.biz> <1522388386.2396.2.camel@cybertec.at> <1522401246.2396.16.camel@cybertec.at> <62f4ba30-6302-89af-2341-16c821427158@gelassene-pferde.biz> <1522747691.2414.5.camel@cybertec.at> Organization: Cybertec Content-Type: text/plain; charset="UTF-8" Date: Wed, 04 Apr 2018 08:11:56 +0200 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Thiemo Kellner wrote: > > The other thing is that you seem to call "dblink_get_result" on any existing > > connection before use. But you can only call the function if there is a > > result outstanding. > > I call dblink_get_result only if I do not open a dblink connection, i. > e. only on second and following function calls. I put more notice output > into the code showing that dblink_send_query has been called once before > the first call of dblink_get_result. I changed my query to reflect > return bigint value of the called function write_message_to_table. Error > persists. That's not going to work. You can only call dblink_get_result if there is an outstanding result. You cannot call it on an idle connection, that will cause an error. You should write your code so that whenever dblink_send_query has been called, you also call dblink_get_result, regardless if the query has been cancelled or not, so that you always leave the connection in the "ready for query" state. Then you don't have to clean up. Of course you could also ignore the error you get on dblink_get_result, but that is ugly. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com