plproxy
plproxy
plproxy : Database partitioning implemented as procedural language
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 2520 | plproxy
|
plproxy
|
2.11.0 |
OLAP
|
BSD 0-Clause
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d--
|
No
|
Yes
|
No
|
Yes
|
no
|
no
|
| Relationships | |
|---|---|
| See Also | citus
dblink
postgres_fdw
pg_partman
odbc_fdw
jdbc_fdw
citus_columnar
columnar
|
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG
|
2.11.0 |
18
17
16
15
14
|
plproxy |
- |
| RPM | PGDG
|
2.11.0 |
18
17
16
15
14
|
plproxy_$v |
- |
| DEB | PGDG
|
2.11.0 |
18
17
16
15
14
|
postgresql-$v-plproxy |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PIGSTY 2.11.0
|
PIGSTY 2.11.0
|
PIGSTY 2.11.0
|
el8.aarch64
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PIGSTY 2.11.0
|
PIGSTY 2.11.0
|
PIGSTY 2.11.0
|
el9.x86_64
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PIGSTY 2.11.0
|
PIGSTY 2.11.0
|
PIGSTY 2.11.0
|
el9.aarch64
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PIGSTY 2.11.0
|
PIGSTY 2.11.0
|
PIGSTY 2.11.0
|
el10.x86_64
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
el10.aarch64
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
d12.x86_64
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
d12.aarch64
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
d13.x86_64
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
d13.aarch64
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
u22.x86_64
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
u22.aarch64
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
u24.x86_64
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
u24.aarch64
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
PGDG 2.11.0
|
Source
Install
Make sure PGDG repo available:
pig repo add pgdg -u # add pgdg repo and update cacheInstall this extension with pig:
pig install plproxy; # install via package name, for the active PG version
pig install plproxy -v 18; # install for PG 18
pig install plproxy -v 17; # install for PG 17
pig install plproxy -v 16; # install for PG 16
pig install plproxy -v 15; # install for PG 15
pig install plproxy -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION plproxy;Usage
plproxy: Database partitioning implemented as procedural language
PL/Proxy is a PostgreSQL procedural language handler that enables remote procedure calls between PostgreSQL databases, with optional sharding.
Create the Extension
CREATE EXTENSION plproxy;Language Statements
PL/Proxy functions use four types of statements:
Cluster selection – connect to a pre-configured cluster:
CREATE FUNCTION get_user(i_id int) RETURNS SETOF users AS $$
CLUSTER 'mycluster';
RUN ON i_id;
$$ LANGUAGE plproxy;Direct connection – use a connection string:
CREATE FUNCTION get_config(key text) RETURNS text AS $$
CONNECT 'host=remotehost dbname=config';
SELECT val FROM config WHERE key = $1;
$$ LANGUAGE plproxy;Execution Modes
RUN ON hash – route to a specific partition based on a hash:
CREATE FUNCTION get_user_settings(i_username text) RETURNS SETOF user_settings AS $$
RUN ON namehash(i_username);
$$ LANGUAGE plproxy;RUN ON ALL – execute on all databases in parallel:
CREATE FUNCTION get_all_counts() RETURNS SETOF record AS $$
RUN ON ALL;
SELECT count(*) FROM users;
$$ LANGUAGE plproxy;RUN ON ANY – randomly select a server:
CREATE FUNCTION get_random_quote() RETURNS text AS $$
RUN ON ANY;
SELECT quote FROM quotes ORDER BY random() LIMIT 1;
$$ LANGUAGE plproxy;Cluster Configuration
Clusters are configured using SQL/MED (Management of External Data):
CREATE SERVER mycluster FOREIGN DATA WRAPPER plproxy
OPTIONS (
connection_lifetime '1800',
p0 'host=node0 dbname=mydb',
p1 'host=node1 dbname=mydb',
p2 'host=node2 dbname=mydb',
p3 'host=node3 dbname=mydb'
);
CREATE USER MAPPING FOR CURRENT_USER
SERVER mycluster
OPTIONS (user 'proxy_user', password 'secret');Last updated on