SlideShare a Scribd company logo
Pl/proxy The PostgreSQL Company Command Prompt, Inc. Joshua D. Drake [email_address]
Purpose Cross database queries Horizontal Partitioning Sort of... Federated databases Gotchas
Requirements PostgreSQL 8.2.5 Yes it can run on 8.2.0 but nobody runs less than stable release right? PostgreSQL 8.3 But it doesn't exist yet. pgxs apt-get install postgresql-server-dev-8.2 Pgfoundry http://pgfoundry.org/projects/plproxy
Cross Database Queries Sometimes you just have to: SELECT * FROM  dblink('dbname=users_2005  host=192.168.3.254',  'SELECT userid FROM ... But wouldn't it be great if you could: SELECT userid_return('linuxpoet'); You always use functions to control your data flow right?
So what do we do? (install PL/proxy then...) Create a function on server 192.168.3.5 CREATE OR REPLACE FUNCTION userid_return(text) RETURNS integer AS  $$  SELECT CASE WHEN id IS NULL THEN 0 ELSE id END  FROM users  WHERE username = $1;  $$ LANGUAGE 'SQL'; Create a function on localhost CREATE OR REPLACE userid_return(text) RETURNS integer AS  $$  CONNECT 'dbname=users_2005 host=192.168.3.254 port=6000';  $$  LANGUAGE 'plproxy';
Which does what exactly? The function userid_return(text) on the localhost is a thin wrapper to allow execution of a remote function. The two functions must be named identically. The CONNECT argument is used to determine which remote server to connect to.
If I was a Dolphin mysql> CREATE DATABASE menagerie; mysql> USE menagerie; Database changed Sorry Wrong Database
Consider remote validity CREATE TABLE sessions (id bigserial PRIMARY KEY,  userid integer CHECK(is_valid_user(userid) IS TRUE),  sdate timestamp DEFAULT current_timestamp); Function is_valid_user(integer): CREATE OR REPLACE FUNCTION is_valid_user(integer) RETURNS boolean AS  $$  CONNECT 'dbname=users_2005 host=192.168.3.254 port=6000';  $$  LANGUAGE 'plproxy';
Wait, what just happen? Created function on 192.168.3.254 CREATE OR REPLACE FUNCTION is_valid_user(integer) RETURNS boolean AS  $$  SELECT CASE WHEN id = $1  THEN TRUE  ELSE FALSE  END  FROM users  WHERE id = $1;  $$ LANGUAGE 'SQL';
Then.. on the localhost CREATE OR REPLACE FUNCTION is_valid_user(integer) RETURNS boolean AS  $$  CONNECT 'dbname=users_2005 host=192.168.3.254 port=6000';  $$  LANGUAGE 'plproxy'; CREATE TABLE sessions (id bigserial PRIMARY KEY,  userid integer CHECK(is_valid_user(userid) IS TRUE),  sdate timestamp DEFAULT current_timestamp);
Lastly to prove the perversion 192.168.3.254> select * from users; id | username  |  created  ----+-----------+---------------------------- 1 | linuxpoet | 2005-10-19 17:44:28.819438 locahost> INSERT INTO sessions (userid,sdate)  VALUES (2,current_timestamp); ERROR:  new row for relation "sessions" violates check constraint "sessions_userid_check" locahost> INSERT INTO sessions (userid,sdate)  VALUES (1,current_timestamp); INSERT 0 1
Wait, that means... Exactly, you can have a check constraint that checks the validity of data on a local relation against the validity of data on a remote relation.
Horizontal Partitioning PL/proxy has the ability to not only perform basic data checks on remote partitions but can also use multiple partitions in various ways to achieve greater scalability. ANY – Using the RUN ON 'ANY' method within a PL/proxy function will cause PL/proxy to choose an arbitrary partition to perform the function execution on. (Consider usernames may be on every node).
ALL or nothing ALL – Using the RUN ON 'ALL” method will cause PL/proxy, to execute the desired function on ”ALL” nodes simultaenously (in parrellel).  The key is that it executes simultaneously. You are not waiting for a single partition to return data before the function can be executed on the next partition. Once all results have been returned via the nodes, PL/proxy will then perform a UNION ALL on the data and return it to the client.
EXACT The RUN ON 'EXACT' mode causes PL/proxy to run on exactly ”1” node. The node is specified within the function body.
Gotchas PL/proxy should be considered Alpha software. Although it is being used in production by some companies, it is fragile and documentation is non-existant. When used for specific purposes it is very stable. No software should be able to crash the backend.
Thanks I think the title says it all.

More Related Content

PDF
Getting Started with PL/Proxy
PDF
using Mithril.js + postgREST to build and consume API's
PPTX
PostgREST Design Philosophy
PPTX
A Tour of PostgREST
PDF
9.1 Mystery Tour
PDF
Recent Updates at Embulk Meetup #3
PDF
Embuk internals
PDF
Using Embulk at Treasure Data
Getting Started with PL/Proxy
using Mithril.js + postgREST to build and consume API's
PostgREST Design Philosophy
A Tour of PostgREST
9.1 Mystery Tour
Recent Updates at Embulk Meetup #3
Embuk internals
Using Embulk at Treasure Data

What's hot (20)

PPTX
Cake PHP 3 Presentaion
PDF
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
PDF
Embulk at Treasure Data
PDF
Découvrir dtrace en ligne de commande.
PPTX
System performance tuning
PDF
Hacking ansible
PPTX
Introduction to PostgreSQL
PDF
WebCamp 2016: DevOps. Николай Дойков: Опыт создания клауда для потокового вид...
PPT
Async programming on NET
PPTX
psCloudstack Internals
PDF
Embulk - 進化するバルクデータローダ
PDF
Our challenge for Bulkload reliability improvement
PDF
Ansible, Simplicity, and the Zen of Python
PDF
Wrangling WP_Cron - WordCamp Grand Rapids 2014
PDF
Building Distributed System with Celery on Docker Swarm
PDF
2014-10-30 Taverna 3 status
PDF
Ansible leveraging 2.0
PPTX
동기화 시대를 뛰어넘는 비동기 프로그래밍
PDF
Runmodes and Configs for Fun and Profit
PDF
More tips n tricks
Cake PHP 3 Presentaion
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Embulk at Treasure Data
Découvrir dtrace en ligne de commande.
System performance tuning
Hacking ansible
Introduction to PostgreSQL
WebCamp 2016: DevOps. Николай Дойков: Опыт создания клауда для потокового вид...
Async programming on NET
psCloudstack Internals
Embulk - 進化するバルクデータローダ
Our challenge for Bulkload reliability improvement
Ansible, Simplicity, and the Zen of Python
Wrangling WP_Cron - WordCamp Grand Rapids 2014
Building Distributed System with Celery on Docker Swarm
2014-10-30 Taverna 3 status
Ansible leveraging 2.0
동기화 시대를 뛰어넘는 비동기 프로그래밍
Runmodes and Configs for Fun and Profit
More tips n tricks
Ad

Similar to Plproxy (20)

PPT
A brief introduction to PostgreSQL
PDF
Postgres Vienna DB Meetup 2014
PPT
Sydney Oracle Meetup - execution plans
PDF
9.1 Grand Tour
PDF
Oracle API Gateway Installation
PDF
plProxy, pgBouncer, pgBalancer
ODP
Porting Applications From Oracle To PostgreSQL
PDF
Best Practices for Effectively Running dbt in Airflow
PDF
Presto anatomy
PDF
CoreOS, or How I Learned to Stop Worrying and Love Systemd
ODP
Msql
PPT
Php Data Objects
PPT
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
PDF
Catalyst MVC
PPT
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
PDF
Performance Tuning Using oratop
PDF
[245] presto 내부구조 파헤치기
PPT
Accelerated data access
PDF
Development Setup of B-Translator
ODP
Practical catalyst
A brief introduction to PostgreSQL
Postgres Vienna DB Meetup 2014
Sydney Oracle Meetup - execution plans
9.1 Grand Tour
Oracle API Gateway Installation
plProxy, pgBouncer, pgBalancer
Porting Applications From Oracle To PostgreSQL
Best Practices for Effectively Running dbt in Airflow
Presto anatomy
CoreOS, or How I Learned to Stop Worrying and Love Systemd
Msql
Php Data Objects
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Catalyst MVC
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Performance Tuning Using oratop
[245] presto 내부구조 파헤치기
Accelerated data access
Development Setup of B-Translator
Practical catalyst
Ad

More from Joshua Drake (13)

PDF
Defining Your Goal: Starting Your Own Business
PDF
Defining Your Goal: Starting Your Own Business
PDF
An evening with Postgresql
PDF
Dumb Simple PostgreSQL Performance (NYCPUG)
ODP
East09 Keynote
ODP
Go Replicator
PDF
Pitr Made Easy
PDF
Introduction to PgBench
PDF
Developing A Procedural Language For Postgre Sql
PDF
PostgreSQL Conference: East 08
PDF
PostgreSQL Conference: West 08
PDF
What MySQL can learn from PostgreSQL
PDF
Northern Arizona State ACM talk (10/08)
Defining Your Goal: Starting Your Own Business
Defining Your Goal: Starting Your Own Business
An evening with Postgresql
Dumb Simple PostgreSQL Performance (NYCPUG)
East09 Keynote
Go Replicator
Pitr Made Easy
Introduction to PgBench
Developing A Procedural Language For Postgre Sql
PostgreSQL Conference: East 08
PostgreSQL Conference: West 08
What MySQL can learn from PostgreSQL
Northern Arizona State ACM talk (10/08)

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
MYSQL Presentation for SQL database connectivity
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
Teaching material agriculture food technology
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Assigned Numbers - 2025 - Bluetooth® Document
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
MYSQL Presentation for SQL database connectivity
The AUB Centre for AI in Media Proposal.docx
Advanced methodologies resolving dimensionality complications for autism neur...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
gpt5_lecture_notes_comprehensive_20250812015547.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Mobile App Security Testing_ A Comprehensive Guide.pdf
Machine learning based COVID-19 study performance prediction
Network Security Unit 5.pdf for BCA BBA.
Building Integrated photovoltaic BIPV_UPV.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Reach Out and Touch Someone: Haptics and Empathic Computing
Teaching material agriculture food technology
20250228 LYD VKU AI Blended-Learning.pptx
Electronic commerce courselecture one. Pdf
Empathic Computing: Creating Shared Understanding
Assigned Numbers - 2025 - Bluetooth® Document

Plproxy

  • 1. Pl/proxy The PostgreSQL Company Command Prompt, Inc. Joshua D. Drake [email_address]
  • 2. Purpose Cross database queries Horizontal Partitioning Sort of... Federated databases Gotchas
  • 3. Requirements PostgreSQL 8.2.5 Yes it can run on 8.2.0 but nobody runs less than stable release right? PostgreSQL 8.3 But it doesn't exist yet. pgxs apt-get install postgresql-server-dev-8.2 Pgfoundry http://pgfoundry.org/projects/plproxy
  • 4. Cross Database Queries Sometimes you just have to: SELECT * FROM dblink('dbname=users_2005 host=192.168.3.254', 'SELECT userid FROM ... But wouldn't it be great if you could: SELECT userid_return('linuxpoet'); You always use functions to control your data flow right?
  • 5. So what do we do? (install PL/proxy then...) Create a function on server 192.168.3.5 CREATE OR REPLACE FUNCTION userid_return(text) RETURNS integer AS $$ SELECT CASE WHEN id IS NULL THEN 0 ELSE id END FROM users WHERE username = $1; $$ LANGUAGE 'SQL'; Create a function on localhost CREATE OR REPLACE userid_return(text) RETURNS integer AS $$ CONNECT 'dbname=users_2005 host=192.168.3.254 port=6000'; $$ LANGUAGE 'plproxy';
  • 6. Which does what exactly? The function userid_return(text) on the localhost is a thin wrapper to allow execution of a remote function. The two functions must be named identically. The CONNECT argument is used to determine which remote server to connect to.
  • 7. If I was a Dolphin mysql> CREATE DATABASE menagerie; mysql> USE menagerie; Database changed Sorry Wrong Database
  • 8. Consider remote validity CREATE TABLE sessions (id bigserial PRIMARY KEY, userid integer CHECK(is_valid_user(userid) IS TRUE), sdate timestamp DEFAULT current_timestamp); Function is_valid_user(integer): CREATE OR REPLACE FUNCTION is_valid_user(integer) RETURNS boolean AS $$ CONNECT 'dbname=users_2005 host=192.168.3.254 port=6000'; $$ LANGUAGE 'plproxy';
  • 9. Wait, what just happen? Created function on 192.168.3.254 CREATE OR REPLACE FUNCTION is_valid_user(integer) RETURNS boolean AS $$ SELECT CASE WHEN id = $1 THEN TRUE ELSE FALSE END FROM users WHERE id = $1; $$ LANGUAGE 'SQL';
  • 10. Then.. on the localhost CREATE OR REPLACE FUNCTION is_valid_user(integer) RETURNS boolean AS $$ CONNECT 'dbname=users_2005 host=192.168.3.254 port=6000'; $$ LANGUAGE 'plproxy'; CREATE TABLE sessions (id bigserial PRIMARY KEY, userid integer CHECK(is_valid_user(userid) IS TRUE), sdate timestamp DEFAULT current_timestamp);
  • 11. Lastly to prove the perversion 192.168.3.254> select * from users; id | username | created ----+-----------+---------------------------- 1 | linuxpoet | 2005-10-19 17:44:28.819438 locahost> INSERT INTO sessions (userid,sdate) VALUES (2,current_timestamp); ERROR: new row for relation "sessions" violates check constraint "sessions_userid_check" locahost> INSERT INTO sessions (userid,sdate) VALUES (1,current_timestamp); INSERT 0 1
  • 12. Wait, that means... Exactly, you can have a check constraint that checks the validity of data on a local relation against the validity of data on a remote relation.
  • 13. Horizontal Partitioning PL/proxy has the ability to not only perform basic data checks on remote partitions but can also use multiple partitions in various ways to achieve greater scalability. ANY – Using the RUN ON 'ANY' method within a PL/proxy function will cause PL/proxy to choose an arbitrary partition to perform the function execution on. (Consider usernames may be on every node).
  • 14. ALL or nothing ALL – Using the RUN ON 'ALL” method will cause PL/proxy, to execute the desired function on ”ALL” nodes simultaenously (in parrellel). The key is that it executes simultaneously. You are not waiting for a single partition to return data before the function can be executed on the next partition. Once all results have been returned via the nodes, PL/proxy will then perform a UNION ALL on the data and return it to the client.
  • 15. EXACT The RUN ON 'EXACT' mode causes PL/proxy to run on exactly ”1” node. The node is specified within the function body.
  • 16. Gotchas PL/proxy should be considered Alpha software. Although it is being used in production by some companies, it is fragile and documentation is non-existant. When used for specific purposes it is very stable. No software should be able to crash the backend.
  • 17. Thanks I think the title says it all.