118) Postgres supports asynchronous notification via the LISTEN and NOTIFY commands. A backend registers its interest in a particular notification condition with the LISTEN command (and can stop listening with the UNLISTEN command). All backends listening on a particular condition will be notified asynchronously when a NOTIFY of that condition name is executed by any backend. No additional information is passed from the notifier to the listener. Thus, typically, any actual data that needs to be communicated is transferred through a database relation. Commonly the condition name is the same as the associated relation, but it is not necessary for there to be any associated relation.
Postgres �� LISTEN �� NOTIFY ���ޥ�ɤˤ����Ʊ�����ε�ǽ�ݡ��Ȥ��Ƥ��ޤ��� �Хå�����ɤ� LISTEN ���ޥ�ɤ�������ȡ� ��������ξ��˴ؿ�����ä����Ȥ���Ͽ���ޤ��� �ʤ����ߤ��ˤ� UNLISTEN ���ޥ�ɤ�Ȥ��ޤ��� ����ξ����ԤäƤ��뤹�٤ƤΥХå�����ɤϡ� Ʊ�����̾�� NOTIFY ���ޥ�ɤ�Ǥ�դΥХå�����ɤˤ�äƼ¹Ԥ��줿������ ��Ʊ��Ū�����Τ�����ޤ��� ���������Τ�ȯ��¦�������¦���Ϥ�����ղ�Ū�ʾ���Ϥ���ޤ��� �������äơ�ŵ��Ū�ˤ�ξ�Ԥδ֤Ǽ����Ϥ�ɬ�פΤ���ºݤΥǡ����ϡ� �ǡ����١�����졼�������̤���ž�����뤳�Ȥˤʤ�ޤ��� ����Ū�ˡ����̾�ϴ�Ϣ�����졼�����̾��Ʊ����ΤǤ����� ɬ����Ϣ�����졼�����ɬ�פȤ����櫓�ǤϤ���ޤ���
119) libpq applications submit LISTEN and UNLISTEN commands as ordinary SQL queries. Subsequently, arrival of NOTIFY messages can be detected by calling PQnotifies().
libpq ���ץꥱ�������ϡ� �̾�� SQL �ˤ���䤤��碌��Ʊ���褦�� LISTEN ����� UNLISTEN ���ޥ�ɤ�ȯ�Ԥ��뤳�Ȥ��Ǥ��ޤ��� ���Υ�å�����������ϡ�³���� PQnotifies() ��ƤӽФ��и��ФǤ��ޤ���
PQnotifies 120) Returns the next notification from a list of unhandled notification messages received from the backend. Returns NULL if there are no pending notifications. Once a notification is returned from PQnotifies, it is considered handled and will be removed from the list of notifications. �Хå�����ɤ�������������Υ�å������Τ����� �ޤ���������Ƥ��ʤ���ΤΥꥹ�Ȥ��鼡�����Τ��֤��ޤ��� ��α������Τ��ʤ��ʤ�� NULL ���֤��ޤ��� PQnotifies �����Τ��֤��Ȥ������ΤϤ�Ϥ�������Ѥ����ΤȤߤʤ��졤 ���Υꥹ�Ȥ����������ޤ���
PGnotify* PQnotifies(PGconn *conn);
121)
typedef struct pgNotify
{
char relname[NAMEDATALEN]; /* name of relation */
* containing data */
int be_pid; /* process id of backend */
} PGnotify;
typedef struct pgNotify
{
char relname[NAMEDATALEN]; /* �ǡ�����ޤ��졼������̾�� */
int be_pid; /* �Хå�����ɤΥץ����� ID */
} PGnotify;
122)
After processing a PGnotify object returned by PQnotifies,
be sure to free it with free() to avoid a memory leak.
NOTE: in Postgres 6.4 and later,
the be_pid is the notifying backend's, whereas in earlier versions
it was always your own backend's PID.
���������ɤ����ᡤPQnotifies ���֤��� PGnotify ���֥������Ȥ�
���������ä���ɬ�� free() ���ΰ�������Ƥ���������
���� 6.4 ������ΥС������Ǥϡ�
be_pid �������³���Ƥ���Хå�����ɤΥץ����� ID ���ä��Τ��Ф���
6.4 �Ȥ���ʹߤ� Postgres
�Ǥ����Τ�ȯ�Ԥ����Хå�����ɤΥץ����� ID �ˤʤ�ޤ���
123) The second sample program gives an example of the use of asynchronous notification.
�ʤ��������ܤΥ���ץ�ץ�����ब��Ʊ�����Τ���Ѥ�����Ǥ���
124) PQnotifies() does not actually read backend data; it just returns messages previously absorbed by another libpq function. In prior releases of libpq, the only way to ensure timely receipt of NOTIFY messages was to constantly submit queries, even empty ones, and then check PQnotifies() after each PQexec(). While this still works, it is deprecated as a waste of processing power. A better way to check for NOTIFY messages when you have no useful queries to make is to call PQconsumeInput(), then check PQnotifies(). You can use select(2) to wait for backend data to arrive, thereby using no CPU power unless there is something to do. Note that this will work OK whether you use PQsendQuery/PQgetResult or plain old PQexec for queries. You should, however, remember to check PQnotifies() after each PQgetResult or PQexec to see if any notifications came in during the processing of the query.
PQnotify �ϼºݤ˥Хå�����ɤΥǡ������ɤ߽Ф��櫓�ǤϤ���ޤ��� �����ñ�ˡ�¾�� libpq �ؿ����ۼ����Ƥ��ޤäƤ������Υ�å��������֤������Ǥ��� �����Υ����� libpq ���ȡ� ���Υ�å�������Ŭ�ڤʻ����dzμ¤˼������ˤϡ� �����䤤��碌�Ǥ�ʤ�Ǥ⡤�Ȥˤ���������֤��Ȥ��䤤��碌�����ꡤ ������ PQexec() ��¹Ԥ��뤿�Ӥ� PQnotify() ������å����뤷������ޤ���Ǥ����� ���Ǥ⤳����ˡ��ư��ޤ���������ǽ�Ϥ�̵�̻Ȥ��뤳�Ȥˤʤ�Τ� ���Ƥ����Ƥ��������� �¹Ԥ���٤��䤤��碌���ʤ��Ȥ������Υ�å�����������å�����褤��ˡ�ϡ� �ޤ� PQconsumeInput() ��ƤӽФ������줫�� PQnotifies() ������å����뤳�ȤǤ��� �Хå�����ɤ���Υǡ���������� select(2) ���ԤĤ��Ȥ��Ǥ��� ��ɬ�פ�ư��� CPU �ѥ����Ƥ��ޤ����Ȥ�����ޤ��� �ʤ���������䤤��碌�� PQsendQuery �� PQgetResult ��Ȥä��Ȥ��Ǥ⡤ �ޤ��Ϥ��ʤ��ߤ� PQexec ��Ȥä��Ȥ��Ǥ�ư��ޤ��� ���������Τ��䤤��碌�ν�������Ϥ��Ƥ��ʤ����ɤ����� PQgetResult�����뤤�� PQexec �μ¹Ԥ��Ȥ� PQnotifies() ��Ĵ�٤뤳�Ȥ� ˺��ʤ��褦�ˤ��Ƥ����٤��Ǥ���