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

What's hot (20)

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

Similar to Plproxy (20)

PDF
plProxy, pgBouncer, pgBalancer
elliando dias
 
PDF
MySQL Proxy
Manikanda kumar
 
PDF
Database Tools by Skype
elliando dias
 
PDF
ProxySQL Tutorial - PLAM 2016
Derek Downey
 
PDF
Moskva Architecture Highload
Ontico
 
PDF
MySQL Proxy tutorial
Giuseppe Maxia
 
PDF
My Sql Proxy
Liu Lizhi
 
PDF
HandsOn ProxySQL Tutorial - PLSC18
Derek Downey
 
PDF
PostgreSQL - Case Study
S.Shayan Daneshvar
 
PDF
Get PostgreSQL Server Programming - Second Edition Dar free all chapters
kapuilakna
 
PDF
Pl/Python
Command Prompt., Inc
 
KEY
Building and Distributing PostgreSQL Extensions Without Learning C
David Wheeler
 
PPTX
PostgreSQL - Object Relational Database
Mubashar Iqbal
 
PDF
PostgreSQL Server Programming Second Edition Usama Dar Hannu Krosing Jim Mlod...
trddarvai
 
PDF
Extensions on PostgreSQL
Alpaca
 
PDF
PostgreSQL Server Programming 2nd Edition Usama Dar
bhaveeranirh
 
PDF
Building a Complex, Real-Time Data Management Application
Jonathan Katz
 
PPT
Asko Oja Moskva Architecture Highload
Ontico
 
PDF
Porting Oracle Applications to PostgreSQL
Peter Eisentraut
 
PDF
ProxySQL - High Performance and HA Proxy for MySQL
René Cannaò
 
plProxy, pgBouncer, pgBalancer
elliando dias
 
MySQL Proxy
Manikanda kumar
 
Database Tools by Skype
elliando dias
 
ProxySQL Tutorial - PLAM 2016
Derek Downey
 
Moskva Architecture Highload
Ontico
 
MySQL Proxy tutorial
Giuseppe Maxia
 
My Sql Proxy
Liu Lizhi
 
HandsOn ProxySQL Tutorial - PLSC18
Derek Downey
 
PostgreSQL - Case Study
S.Shayan Daneshvar
 
Get PostgreSQL Server Programming - Second Edition Dar free all chapters
kapuilakna
 
Building and Distributing PostgreSQL Extensions Without Learning C
David Wheeler
 
PostgreSQL - Object Relational Database
Mubashar Iqbal
 
PostgreSQL Server Programming Second Edition Usama Dar Hannu Krosing Jim Mlod...
trddarvai
 
Extensions on PostgreSQL
Alpaca
 
PostgreSQL Server Programming 2nd Edition Usama Dar
bhaveeranirh
 
Building a Complex, Real-Time Data Management Application
Jonathan Katz
 
Asko Oja Moskva Architecture Highload
Ontico
 
Porting Oracle Applications to PostgreSQL
Peter Eisentraut
 
ProxySQL - High Performance and HA Proxy for MySQL
René Cannaò
 
Ad

More from Joshua Drake (13)

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

Recently uploaded (20)

PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 

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.