Postgresql 분산 플러그인plproxy

6420 단어 postgresql
저자: 고명걸 메일박스:[email protected]날짜:2017년 7월 4일
Simple remote function call
노드 61/62(datanode)
CREATE TABLE users (username text, email text);
insert into users values ('user0', '[email protected]');
insert into users values ('user1', '[email protected]');
insert into users values ('user2', '[email protected]');

노드 60(proxy)
create or replace extension plproxy;

CREATE FUNCTION get_user_email(i_username text)
RETURNS SETOF text AS $$
    CONNECT 'host=localhost port=9461 dbname=postgres connect_timeout=10';
    SELECT email FROM users WHERE username = $1;
$$ LANGUAGE plproxy;

SELECT * from get_user_email('user0');

Configuring Pl/Proxy clusters with SQL/MED
노드 60(proxy)
CREATE FOREIGN DATA WRAPPER plproxy;

CREATE SERVER usercluster FOREIGN DATA WRAPPER plproxy
OPTIONS (connection_lifetime '1800',
         p0 'host=localhost port=9461 dbname=postgres connect_timeout=10',
         p1 'host=localhost port=9462 dbname=postgres connect_timeout=10' );

CREATE USER MAPPING FOR PUBLIC SERVER usercluster;

Partitioned remote call
노드 60(proxy)
CREATE OR REPLACE FUNCTION insert_user(i_username text, i_emailaddress text)
RETURNS integer AS $$
    CLUSTER 'usercluster';
    RUN ON hashtext(i_username);
$$ LANGUAGE plproxy;

노드 61/62(datanode)
CREATE OR REPLACE FUNCTION insert_user(i_username text, i_emailaddress text)
RETURNS integer AS $$
       INSERT INTO users (username, email) VALUES ($1,$2);
       SELECT 1;
$$ LANGUAGE SQL;

Putting it all together
노드 60(proxy)
SELECT insert_user('Sven','[email protected]');
SELECT insert_user('Marko', '[email protected]');
SELECT insert_user('Steve','[email protected]');

plproxy–2.7.0.sql
-- handler function
CREATE FUNCTION plproxy_call_handler ()
RETURNS language_handler AS 'plproxy' LANGUAGE C;

-- validator function
CREATE FUNCTION plproxy_validator (oid)
RETURNS void AS 'plproxy' LANGUAGE C;

-- language
CREATE LANGUAGE plproxy HANDLER plproxy_call_handler VALIDATOR plproxy_validator;

-- validator function
CREATE FUNCTION plproxy_fdw_validator (text[], oid)
RETURNS boolean AS 'plproxy' LANGUAGE C;

-- foreign data wrapper
CREATE FOREIGN DATA WRAPPER plproxy VALIDATOR plproxy_fdw_validator;

좋은 웹페이지 즐겨찾기