From: | Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> |
---|---|
To: | Thiemo Kellner <thiemo(at)gelassene-pferde(dot)biz>, PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: dblink: could not send query: another command is already in progress |
Date: | 2018-03-30 05:39:46 |
Message-ID: | 1522388386.2396.2.camel@cybertec.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Laurenz Albe | 2018-03-30 05:49:38 | Re: Asynchronous Trigger? |
Previous Message | Peter Geoghegan | 2018-03-29 23:07:43 | Re: Autovacuum behavior with rapid insert/delete 9.6 |