postgreSQL使用plproxy搭建集群注意的方面

来源:互联网 发布:城市公园命名数据库 编辑:程序博客网 时间:2024/06/05 09:23

PostgreSQL版本9.3 plproxy版本2.5

1在安装plprox后使用make installcheck来检查是否安装正确,提示错误,需要创建root用户,并且要创建数据及登陆的权限。并且登陆认证的时候,pg_hba.conf文件中的

方法要使用trust,不能使md5,所有的数据库认证都是trust。

2在安装plproxy的时候,使用make installcheck来检测,有一个错误,这个我忽略了,后面也没什么问题。

============== running regression test queries        ==============
test plproxy_init             ... ok
test plproxy_test             ... ok
test plproxy_select           ... ok
test plproxy_many             ... ok
test plproxy_errors           ... ok
test plproxy_clustermap       ... ok
test plproxy_dynamic_record   ... ok
test plproxy_encoding         ... FAILED (test process exited with exit code 2)
test plproxy_split            ... ok
test plproxy_target           ... ok
test plproxy_alter            ... ok
test plproxy_cancel           ... ok
test plproxy_sqlmed           ... ok
test plproxy_table            ... ok
test plproxy_range            ... ok

3我在安装的时候没有找到contrib下的plproxy.sql,但是在extension下是有的,我执行了下面的命令。
./psql -U postgres -h 127.0.0.1 -f /orainst/pgsql/share/extension/plproxy--2.5.0.sql -d MyCluster

4查找数据库节点的三个函数如下:

CREATE OR REPLACE FUNCTION plproxy.get_cluster_config(IN cluster_name text, OUT "key" text, OUT val text)
RETURNS SETOF record AS
$BODY$
BEGIN
key := 'statement_timeout';
val := 60;
RETURN NEXT;
RETURN;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100
ROWS 1000;


CREATE OR REPLACE FUNCTION plproxy.get_cluster_partitions(cluster_name text)
RETURNS SETOF text AS
$BODY$
BEGIN
IF cluster_name = 'My' THEN
RETURN NEXT 'dbname=MyCluster host=192.168.56.102'; 
RETURN NEXT 'dbname=MyCluster host=192.168.56.103'; 
RETURN;
END IF;
RAISE EXCEPTION 'Unknown cluster';
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100
ROWS 1000;


CREATE OR REPLACE FUNCTION plproxy.get_cluster_version(cluster_name text)
RETURNS integer AS
$BODY$
BEGIN
IF cluster_name = 'My' THEN
RETURN 1;
END IF;
RAISE EXCEPTION 'Unknown cluster';
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;

5在proxy数据库上创建下面的函数的时候总是提示没有plproxy语言,查看pg_language果然没有,后来检查发现是在proxy数据库上设置plproxy的时候没有指定数据库,建到postgres数据库上去了。要注意创建在正确的数据库上面。

create or replace function insert_user(i_username text,i_emailaddress text) returns integer as $$ cluster 'My';run on hashtext(i_use
rname);$$ LANGUAGE 'plproxy';
create or replace function get_user_email(i_username text) returns text as $$ cluster 'My';return on hashtext(i_username);
select email from china where username=i_username;
$$ LANGUAGE 'plproxy';

0 0
原创粉丝点击