Database Reference
In-Depth Information
The following function is an example which returns information for a cluster with four
partitions, p0 to p3 :
CREATE OR REPLACE FUNCTION
plproxy.get_cluster_partitions(cluster_name
text)
RETURNS SETOF text AS $$
BEGIN
IF cluster_name = 'messaging' THEN
RETURN NEXT 'dbname=p0';
RETURN NEXT 'dbname=p1';
RETURN NEXT 'dbname=p2';
RETURN NEXT 'dbname=p3';
ELSE
RAISE EXCEPTION 'Unknown cluster';
END IF;
END;
$$ LANGUAGE plpgsql;
A production application might query some configuration tables or even read some
configuration files to return the connection strings. Once again, the number of parti-
tions returned must be a power of two. If you are absolutely sure that some partitions
are never used, you can return empty strings for these.
We also need to define a plproxy.get_cluster_version(cluster_name)
function. This is called on each request and if the cluster version has not changed,
the output from a cached result from plproxy.get_cluster_partitions can
be reused. So, it is best to make sure that this function is as fast as possible:
CREATE OR REPLACE FUNCTION
plproxy.get_cluster_version(cluster_name text)
RETURNS int4 AS $$
BEGIN
IF cluster_name = 'messaging' THEN
RETURN 1;
ELSE
RAISE EXCEPTION 'Unknown cluster';
Search WWH ::




Custom Search