Home Explore Blog CI



postgresql

13th chunk of `doc/src/sgml/dblink.sgml`
59d235db72fa91b12768ce27dac2b568b3c3259b5976f3ce0000000100000fc4
 use.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><parameter>sql</parameter></term>
     <listitem>
      <para>
       The SQL statement that you wish to execute in the remote database,
       for example <literal>select * from pg_class</literal>.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </refsect1>

  <refsect1>
   <title>Return Value</title>

   <para>
    Returns 1 if the query was successfully dispatched, 0 otherwise.
   </para>
  </refsect1>

  <refsect1>
   <title>Examples</title>

<programlisting>
SELECT dblink_send_query('dtest1', 'SELECT * FROM foo WHERE f1 &lt; 3');
</programlisting>
  </refsect1>
 </refentry>

 <refentry id="contrib-dblink-is-busy">
  <indexterm>
   <primary>dblink_is_busy</primary>
  </indexterm>

  <refmeta>
   <refentrytitle>dblink_is_busy</refentrytitle>
   <manvolnum>3</manvolnum>
  </refmeta>

  <refnamediv>
   <refname>dblink_is_busy</refname>
   <refpurpose>checks if connection is busy with an async query</refpurpose>
  </refnamediv>

  <refsynopsisdiv>
<synopsis>
dblink_is_busy(text connname) returns int
</synopsis>
  </refsynopsisdiv>

  <refsect1>
   <title>Description</title>

   <para>
    <function>dblink_is_busy</function> tests whether an async query is in progress.
   </para>
  </refsect1>

  <refsect1>
   <title>Arguments</title>

   <variablelist>
    <varlistentry>
     <term><parameter>connname</parameter></term>
     <listitem>
      <para>
       Name of the connection to check.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </refsect1>

  <refsect1>
   <title>Return Value</title>

   <para>
    Returns 1 if connection is busy, 0 if it is not busy.
    If this function returns 0, it is guaranteed that
    <function>dblink_get_result</function> will not block.
   </para>
  </refsect1>

  <refsect1>
   <title>Examples</title>

<programlisting>
SELECT dblink_is_busy('dtest1');
</programlisting>
  </refsect1>
 </refentry>

 <refentry id="contrib-dblink-get-notify">
  <indexterm>
   <primary>dblink_get_notify</primary>
  </indexterm>

  <refmeta>
   <refentrytitle>dblink_get_notify</refentrytitle>
   <manvolnum>3</manvolnum>
  </refmeta>

  <refnamediv>
   <refname>dblink_get_notify</refname>
   <refpurpose>retrieve async notifications on a connection</refpurpose>
  </refnamediv>

  <refsynopsisdiv>
<synopsis>
dblink_get_notify() returns setof (notify_name text, be_pid int, extra text)
dblink_get_notify(text connname) returns setof (notify_name text, be_pid int, extra text)
</synopsis>
  </refsynopsisdiv>

  <refsect1>
   <title>Description</title>

   <para>
    <function>dblink_get_notify</function> retrieves notifications on either
    the unnamed connection, or on a named connection if specified.
    To receive notifications via dblink, <function>LISTEN</function> must
    first be issued, using <function>dblink_exec</function>.
    For details see <xref linkend="sql-listen"/> and <xref linkend="sql-notify"/>.
   </para>

  </refsect1>

  <refsect1>
   <title>Arguments</title>

   <variablelist>
    <varlistentry>
     <term><parameter>connname</parameter></term>
     <listitem>
      <para>
       The name of a named connection to get notifications on.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </refsect1>

  <refsect1>
   <title>Return Value</title>
    <para>Returns <type>setof (notify_name text, be_pid int, extra text)</type>, or an empty set if none.</para>
  </refsect1>

  <refsect1>
   <title>Examples</title>

<screen>
SELECT dblink_exec('LISTEN virtual');
 dblink_exec
-------------
 LISTEN
(1 row)

SELECT * FROM dblink_get_notify();
 notify_name | be_pid | extra
-------------+--------+-------
(0 rows)

NOTIFY virtual;
NOTIFY

SELECT * FROM dblink_get_notify();
 notify_name | be_pid | extra
-------------+--------+-------
 virtual     |   1229 |
(1 row)
</screen>
  </refsect1>
 </refentry>

 <refentry id="contrib-dblink-get-result">
  <indexterm>
   <primary>dblink_get_result</primary>

Title: dblink_is_busy and dblink_get_notify: Managing Asynchronous Queries and Retrieving Notifications
Summary
This section describes the `dblink_is_busy` function, which checks if a dblink connection is currently processing an asynchronous query. A return value of 1 indicates the connection is busy, while 0 guarantees that `dblink_get_result` will not block. It then introduces `dblink_get_notify`, which retrieves asynchronous notifications on either a named or the unnamed connection. To receive notifications, `LISTEN` must be issued beforehand using `dblink_exec`.