mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-22 11:13:23 +02:00
pghackers proposal of 8-Nov. All the existing cross-type comparison operators (int2/int4/int8 and float4/float8) have appropriate support. The original proposal of storing the right-hand-side datatype as part of the primary key for pg_amop and pg_amproc got modified a bit in the event; it is easier to store zero as the 'default' case and only store a nonzero when the operator is actually cross-type. Along the way, remove the long-since-defunct bigbox_ops operator class.
111 lines
2.1 KiB
C
111 lines
2.1 KiB
C
/*
|
|
* misc_utils.c --
|
|
*
|
|
* This file defines miscellaneous PostgreSQL utility functions.
|
|
*
|
|
* Copyright (C) 1999, Massimo Dal Zotto <dz@cs.unitn.it>
|
|
*
|
|
* This file is distributed under the GNU General Public License
|
|
* either version 2, or (at your option) any later version.
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
#include <unistd.h>
|
|
#include <signal.h>
|
|
|
|
#include "access/heapam.h"
|
|
#include "access/htup.h"
|
|
#include "access/relscan.h"
|
|
#include "access/skey.h"
|
|
#include "access/tupdesc.h"
|
|
#include "catalog/catname.h"
|
|
#include "catalog/pg_listener.h"
|
|
#include "commands/async.h"
|
|
#include "fmgr.h"
|
|
#include "storage/lmgr.h"
|
|
#include "utils/fmgroids.h"
|
|
#include "utils/rel.h"
|
|
#include "utils/tqual.h"
|
|
|
|
#include "misc_utils.h"
|
|
|
|
#undef MIN
|
|
#define MIN(x,y) ((x)<=(y) ? (x) : (y))
|
|
|
|
|
|
int
|
|
backend_pid()
|
|
{
|
|
return getpid();
|
|
}
|
|
|
|
int
|
|
unlisten(char *relname)
|
|
{
|
|
Async_Unlisten(relname, getpid());
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
max(int x, int y)
|
|
{
|
|
return ((x > y) ? x : y);
|
|
}
|
|
|
|
int
|
|
min(int x, int y)
|
|
{
|
|
return ((x < y) ? x : y);
|
|
}
|
|
|
|
/*
|
|
* Return the number of active listeners on a relation name.
|
|
*/
|
|
int
|
|
active_listeners(text *relname)
|
|
{
|
|
HeapTuple lTuple;
|
|
Relation lRel;
|
|
HeapScanDesc sRel;
|
|
TupleDesc tdesc;
|
|
ScanKeyData key;
|
|
Datum d;
|
|
bool isnull;
|
|
int len,
|
|
pid;
|
|
int count = 0;
|
|
int ourpid = getpid();
|
|
char listen_name[NAMEDATALEN];
|
|
|
|
lRel = heap_openr(ListenerRelationName, AccessShareLock);
|
|
tdesc = RelationGetDescr(lRel);
|
|
|
|
if (relname && (VARSIZE(relname) > VARHDRSZ))
|
|
{
|
|
MemSet(listen_name, 0, NAMEDATALEN);
|
|
len = MIN(VARSIZE(relname) - VARHDRSZ, NAMEDATALEN - 1);
|
|
memcpy(listen_name, VARDATA(relname), len);
|
|
ScanKeyInit(&key,
|
|
Anum_pg_listener_relname,
|
|
BTEqualStrategyNumber, F_NAMEEQ,
|
|
PointerGetDatum(listen_name));
|
|
sRel = heap_beginscan(lRel, SnapshotNow, 1, &key);
|
|
}
|
|
else
|
|
sRel = heap_beginscan(lRel, SnapshotNow, 0, (ScanKey) NULL);
|
|
|
|
while ((lTuple = heap_getnext(sRel, ForwardScanDirection)) != NULL)
|
|
{
|
|
d = heap_getattr(lTuple, Anum_pg_listener_pid, tdesc, &isnull);
|
|
pid = DatumGetInt32(d);
|
|
if ((pid == ourpid) || (kill(pid, SIGTSTP) == 0))
|
|
count++;
|
|
}
|
|
heap_endscan(sRel);
|
|
|
|
heap_close(lRel, AccessShareLock);
|
|
|
|
return count;
|
|
}
|