pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Thiemo Kellner <thiemo@gelassene-pferde.biz>
To: PostgreSQL General <pgsql-general@lists.postgresql.org>
Subject: Re: dblink: could not send query: another command is already in progress
Date: Fri, 30 Mar 2018 07:39:46 +0200
Message-ID: <1522388386.2396.2.camel@cybertec.at> (raw)
In-Reply-To: <8d6c6faa-4878-68bf-d1b7-6b1f86c1445c@gelassene-pferde.biz>
References: <8d6c6faa-4878-68bf-d1b7-6b1f86c1445c@gelassene-pferde.biz>

Thiemo Kellner wrote:
> I try to use dblink to create a asynchronous logging facility. I have 
> the following code
> 
> [...]
>              perform dblink_send_query(
>                          V_DBLINK_CONNECTION_NAME,
>                          V_QUERY
>                      );
> raise notice 'Connection busy: %', dblink_is_busy(V_DBLINK_CONNECTION_NAME);
> raise notice 'Last error: %', 
> dblink_error_message(V_DBLINK_CONNECTION_NAME);
> raise notice 'Cancel query: %', 
> dblink_cancel_query(V_DBLINK_CONNECTION_NAME);
>              -- ??? commit needed?
> raise notice 'Connection busy: %', dblink_is_busy(V_DBLINK_CONNECTION_NAME);
>              while dblink_is_busy(V_DBLINK_CONNECTION_NAME) != 0 loop
>                  perform pg_sleep_for(V_WAIT_FOR);
> raise notice 'Waited for commit for % seconds', V_WAIT_FOR;
> raise notice 'Connection busy: %', dblink_is_busy(V_DBLINK_CONNECTION_NAME);
>              end loop;
>              perform dblink_send_query(
>                          V_DBLINK_CONNECTION_NAME,
>                          'commit'
>                      );
> 
> I get the following output.
> psql:testing/test.pg_sql:41: NOTICE:  Connection busy: 1 
> 
> psql:testing/test.pg_sql:41: NOTICE:  Last error: OK 
> 
> psql:testing/test.pg_sql:41: NOTICE:  Cancel query: OK 
> 
> psql:testing/test.pg_sql:41: NOTICE:  Connection busy: 0 
> 
> psql:testing/test.pg_sql:41: NOTICE:  could not send query: another 
> command is already in progress

> Has anyone an idea?

The cause of the error message is clear; as the documentation says:

  dblink_cancel_query attempts to cancel any query that is in progress on the named
  connection. Note that this is not certain to succeed (since, for example, the remote
  query might already have finished). A cancel request simply improves the odds that
  the query will fail soon. You must still complete the normal query protocol,
  for example by calling dblink_get_result.

Not sure if that answers all your questions.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com




view thread (8+ messages)  latest in thread

Message-ID: <1522388386.2396.2.camel@cybertec.at>
Permalink:  ../1522388386.2396.2.camel@cybertec.at/
Also on:    postgresql.org/message-id/1522388386.2396.2.camel@cybertec.at

 · 

reply

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: laurenz.albe@cybertec.at, thiemo@gelassene-pferde.biz
  Subject: Re: dblink: could not send query: another command is already in progress
  In-Reply-To: <1522388386.2396.2.camel@cybertec.at>
  References: <8d6c6faa-4878-68bf-d1b7-6b1f86c1445c@gelassene-pferde.biz> <1522388386.2396.2.camel@cybertec.at>

* 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