plproxy 之三 测试1

深藏阁楼爱情的钟 2023-02-16 15:27 23阅读 0赞

os: centos 7.4.1708
db: postgresql 11.8
plproxy: 2.9

PL/Proxy is database partitioning system implemented as PL language.

就是可以用来水平分库

  1. 192.168.56.111 p1
  2. 192.168.56.112 p2
  3. 192.168.56.113 n1
  4. 192.168.56.114 n2

这4个节点都需要安装 postgresql 11 及 plproxy

版本

  1. # cat /etc/centos-release
  2. CentOS Linux release 7.4.1708 (Core)
  3. #
  4. #
  5. # yum list installed |grep -i postgresql
  6. postgresql11.x86_64 11.8-1PGDG.rhel7 @pgdg11
  7. postgresql11-contrib.x86_64 11.8-1PGDG.rhel7 @pgdg11
  8. postgresql11-debuginfo.x86_64 11.5-1PGDG.rhel7 @pgdg11
  9. postgresql11-devel.x86_64 11.8-1PGDG.rhel7 @pgdg11
  10. postgresql11-docs.x86_64 11.8-1PGDG.rhel7 @pgdg11
  11. postgresql11-libs.x86_64 11.8-1PGDG.rhel7 @pgdg11
  12. postgresql11-llvmjit.x86_64 11.8-1PGDG.rhel7 @pgdg11
  13. postgresql11-odbc.x86_64 12.01.0000-1PGDG.rhel7 @pgdg11
  14. postgresql11-plperl.x86_64 11.8-1PGDG.rhel7 @pgdg11
  15. postgresql11-plpython.x86_64 11.8-1PGDG.rhel7 @pgdg11
  16. postgresql11-pltcl.x86_64 11.8-1PGDG.rhel7 @pgdg11
  17. postgresql11-server.x86_64 11.8-1PGDG.rhel7 @pgdg11
  18. postgresql11-tcl.x86_64 2.4.0-2.rhel7.1 @pgdg11
  19. postgresql11-test.x86_64 11.8-1PGDG.rhel7 @pgdg11
  20. # su - postgres
  21. Last login: Wed Jan 15 18:34:12 CST 2020 on pts/0
  22. $
  23. $
  24. $ psql -c "select version();"
  25. version
  26. ---------------------------------------------------------------------------------------------------------
  27. PostgreSQL 11.8 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit
  28. (1 row)

测试1

p1,p2 节点创建公共调用函数

  1. $ psql
  2. postgres=# \c proxydb
  3. proxydb=# CREATE OR REPLACE FUNCTION public.f_tmp_t0(sql text)
  4. RETURNS SETOF record
  5. LANGUAGE plproxy
  6. STRICT
  7. AS $function$
  8. cluster 'srv_plproxy_cluster';
  9. run on all;
  10. $function$;
  11. proxy=# grant execute on function public.f_tmp_t0(text) to proxy;

n1,n2 节点创建实体函数及业务表

  1. $ psql -U yewu yewudb
  2. yewudb=# CREATE OR REPLACE FUNCTION public.f_tmp_t0(sql text)
  3. RETURNS SETOF record
  4. LANGUAGE plpgsql
  5. STRICT
  6. AS $function$
  7. declare
  8. rec record;
  9. begin
  10. for rec in execute sql loop
  11. return next rec;
  12. end loop;
  13. return;
  14. end;
  15. $function$;
  16. yewudb=# create table tmp_t0 (c0 int8,c1 varchar(100));

然后在 p1,p2 任意一节点执行公共调用函数

  1. $ psql -U proxy proxydb
  2. proxydb=# select * from public.f_tmp_t0('select count(1) from tmp_t0') as t(rec int8);
  3. rec
  4. -----
  5. 0
  6. 0
  7. (2 rows)

参考:
http://wiki.postgresql.org/wiki/PL/Proxy

https://github.com/plproxy/plproxy

http://plproxy.github.io/
http://plproxy.github.io/tutorial.html

发表评论

表情:
评论列表 (有 0 条评论,23人围观)

还没有评论,来说两句吧...

相关阅读