4
* This file defines miscellaneous PostgreSQL utility functions.
6
* Copyright (C) 1999, Massimo Dal Zotto <dz@cs.unitn.it>
8
* This file is distributed under the GNU General Public License
9
* either version 2, or (at your option) any later version.
17
#include "access/heapam.h"
18
#include "access/htup.h"
19
#include "access/relscan.h"
20
#include "access/skey.h"
21
#include "access/tupdesc.h"
22
#include "catalog/catname.h"
23
#include "catalog/pg_listener.h"
24
#include "commands/async.h"
26
#include "storage/lmgr.h"
27
#include "utils/fmgroids.h"
28
#include "utils/rel.h"
29
#include "utils/tqual.h"
31
#include "misc_utils.h"
41
unlisten(char *relname)
43
Async_Unlisten(relname, getpid());
60
* Return the number of active listeners on a relation name.
63
active_listeners(text *relname)
75
int ourpid = getpid();
76
char listen_name[NAMEDATALEN];
78
lRel = heap_openr(ListenerRelationName, AccessShareLock);
79
tdesc = RelationGetDescr(lRel);
81
if (relname && (VARSIZE(relname) > VARHDRSZ))
83
MemSet(listen_name, 0, NAMEDATALEN);
84
len = Min(VARSIZE(relname) - VARHDRSZ, NAMEDATALEN - 1);
85
memcpy(listen_name, VARDATA(relname), len);
87
Anum_pg_listener_relname,
88
BTEqualStrategyNumber, F_NAMEEQ,
89
PointerGetDatum(listen_name));
90
sRel = heap_beginscan(lRel, SnapshotNow, 1, &key);
93
sRel = heap_beginscan(lRel, SnapshotNow, 0, (ScanKey) NULL);
95
while ((lTuple = heap_getnext(sRel, ForwardScanDirection)) != NULL)
97
d = heap_getattr(lTuple, Anum_pg_listener_pid, tdesc, &isnull);
98
pid = DatumGetInt32(d);
99
if ((pid == ourpid) || (kill(pid, 0) == 0))
104
heap_close(lRel, AccessShareLock);