CentOS 5.7 x64flex-2.5.35PostgreSQL-9.1.1plproxy-2.2pgfincore-v1.1libevent-1.4.14b-stablepgbouncer 1.4.2
1. pgbench : 172.16.3.1762. pgbouncer on pgbench HOST :172.16.3.176:1998(proxy0 = host=172.16.3.150 dbname=proxy port=1921 pool_size=16proxy1 = host=172.16.3.39 dbname=proxy port=1921 pool_size=16proxy2 = host=172.16.3.40 dbname=proxy port=1921 pool_size=16proxy3 = host=172.16.3.33 dbname=proxy port=1921 pool_size=16)3. PostgreSQL 数据节点 : 172.16.3.150:1921/digoal, 172.16.3.39:1921/digoal, 172.16.3.40:1921/digoal, 172.16.3.33:1921/digoal4. PostgreSQL plproxy节点 : 172.16.3.150:1921/proxy, 172.16.3.39:1921/proxy, 172.16.3.40:1921/proxy, 172.16.3.33:1921/proxy5. pgbouncers on plproxy HOST :172.16.3.150:1999, 172.16.3.39:1999, 172.16.3.40:1999, 172.16.3.33:1999(digoal0 = host=172.16.3.150 dbname=digoal port=1921 pool_size=8digoal1 = host=172.16.3.39 dbname=digoal port=1921 pool_size=8digoal2 = host=172.16.3.40 dbname=digoal port=1921 pool_size=8digoal3 = host=172.16.3.33 dbname=digoal port=1921 pool_size=8)
./configure && make && make install
./configure --prefix=/opt/pgsql --with-pgport=1921 --with-perl --with-python --with-openssl --with-pam --without-ldap --with-libxml --with-libxslt --enable-thread-safety --with-wal-segsize=64gmake worldgmake install-world
mv plproxy-2.2 postgresql-9.1.1/contrib/plproxy-2.2make PG_CONFIG=/path/to/pg_configmake install PG_CONFIG=/path/to/pg_config
mv pgfincore-v1.1 postgresql-9.1.1/contrib/pgfincore-v1.1cp pgfincore.control /make cleanmakesumake install PG_CONFIG=/path/to/pg_config
./configure && make && make install
./configure --prefix=/opt/pgbouncer && make && make install
proxy=> \c proxy postgresupdate pg_language set lanpltrusted='t' where lanname='plproxy';
CREATE EXTENSION pgfincore;
postgres@db-digoal-> cat config1999.ini[databases]digoal0 = host=172.16.3.150 dbname=digoal port=1921 pool_size=8digoal1 = host=172.16.3.39 dbname=digoal port=1921 pool_size=8digoal2 = host=172.16.3.40 dbname=digoal port=1921 pool_size=8digoal3 = host=172.16.3.33 dbname=digoal port=1921 pool_size=8[pgbouncer]pool_mode = transactionlisten_port = 1999unix_socket_dir = /opt/pgbouncer/etclisten_addr = *auth_type = md5auth_file = /opt/pgbouncer/etc/users1999.txtlogfile = /dev/nullpidfile = /opt/pgbouncer/etc/pgbouncer1999.pidmax_client_conn = 10000reserve_pool_timeout = 0server_reset_query =admin_users = pgbouncer_adminstats_users = pgbouncer_guestignore_startup_parameters = extra_float_digitspostgres@db-digoal-> cat users1999.txt"digoal" "md5462f71c79368ccf422f8a773ef40074d"
postgres@db-digoal-> cat config1998.ini[databases]proxy0 = host=172.16.3.150 dbname=proxy port=1921 pool_size=16proxy1 = host=172.16.3.39 dbname=proxy port=1921 pool_size=16proxy2 = host=172.16.3.40 dbname=proxy port=1921 pool_size=16proxy3 = host=172.16.3.33 dbname=proxy port=1921 pool_size=16[pgbouncer]pool_mode = transactionlisten_port = 1998unix_socket_dir = /opt/pgbouncer/configlisten_addr = *auth_type = md5auth_file = /opt/pgbouncer/config/users.txtlogfile = /dev/nullpidfile = /opt/pgbouncer/config/pgbouncer1998.pidmax_client_conn = 1500reserve_pool_timeout = 0server_reset_query =admin_users = pgbouncer_adminstats_users = pgbouncer_guestignore_startup_parameters = extra_float_digits
proxy=# \c digoal digoalcreate table user_info(userid int,engname text,cnname text,occupation text,birthday date,signname text,email text,qq numeric,crt_time timestamp without time zone,mod_time timestamp without time zone);create table user_login_rec(userid int,login_time timestamp without time zone,ip inet);create table user_logout_rec(userid int,logout_time timestamp without time zone,ip inet);
insert into user_info (userid,engname,cnname,occupation,birthday,signname,email,qq,crt_time,mod_time)select generate_series(0,50000000,4),'digoal.zhou','德哥','DBA','1970-01-01',E'公益是一辈子的事, I\'m Digoal.Zhou, Just do it!','digoal@126.com',276732431,clock_timestamp(),NULL;
insert into user_info (userid,engname,cnname,occupation,birthday,signname,email,qq,crt_time,mod_time)select generate_series(1,50000000,4),'digoal.zhou','德哥','DBA','1970-01-01',E'公益是一辈子的事, I\'m Digoal.Zhou, Just do it!','digoal@126.com',276732431,clock_timestamp(),NULL;
insert into user_info (userid,engname,cnname,occupation,birthday,signname,email,qq,crt_time,mod_time)select generate_series(2,50000000,4),'digoal.zhou','德哥','DBA','1970-01-01',E'公益是一辈子的事, I\'m Digoal.Zhou, Just do it!','digoal@126.com',276732431,clock_timestamp(),NULL;
insert into user_info (userid,engname,cnname,occupation,birthday,signname,email,qq,crt_time,mod_time)select generate_series(3,50000000,4),'digoal.zhou','德哥','DBA','1970-01-01',E'公益是一辈子的事, I\'m Digoal.Zhou, Just do it!','digoal@126.com',276732431,clock_timestamp(),NULL;
set work_mem='2048MB';set maintenance_work_mem='2048MB';alter table user_info add constraint pk_user_info primary key (userid) using index tablespace digoal_idx;
create or replace function f_user_login(i_userid int,OUT o_userid int,OUT o_engname text,OUT o_cnname text,OUT o_occupation text,OUT o_birthday date,OUT o_signname text,OUT o_email text,OUT o_qq numeric)as $BODY$declarebeginselect userid,engname,cnname,occupation,birthday,signname,email,qqinto o_userid,o_engname,o_cnname,o_occupation,o_birthday,o_signname,o_email,o_qqfrom user_info where userid=i_userid;insert into user_login_rec (userid,login_time,ip) values (i_userid,now(),inet_client_addr());return;end;$BODY$language plpgsql;
create or replace function f_user_logout(i_userid int,OUT o_result int)as $BODY$declarebegininsert into user_logout_rec (userid,logout_time,ip) values (i_userid,now(),inet_client_addr());o_result := 0;return;exceptionwhen others theno_result := 1;return;end;$BODY$language plpgsql;
CREATE SERVER digoal FOREIGN DATA WRAPPER plproxyOPTIONS (connection_lifetime '1800',disable_binary '1',p0 'dbname=digoal0 host=127.0.0.1 port=1999 client_encoding=UTF8',p1 'dbname=digoal1 host=127.0.0.1 port=1999 client_encoding=UTF8',p2 'dbname=digoal2 host=127.0.0.1 port=1999 client_encoding=UTF8',p3 'dbname=digoal3 host=127.0.0.1 port=1999 client_encoding=UTF8');
CREATE USER MAPPING FOR proxy SERVER digoalOPTIONS (user 'digoal', password 'digoal');
grant usage on foreign server digoal to proxy;
\c proxy proxy登录函数:CREATE OR REPLACE FUNCTION f_user_login(i_userid int,OUT o_userid int,OUT o_engname text,OUT o_cnname text,OUT o_occupation text,OUT o_birthday date,OUT o_signname text,OUT o_email text,OUT o_qq numeric)as $BODY$CLUSTER 'digoal';RUN ON i_userid;target digoal.f_user_login;$BODY$LANGUAGE plproxy;退出函数:create or replace function f_user_logout(i_userid int,OUT o_result int)as $BODY$CLUSTER 'digoal';RUN ON i_userid;target digoal.f_user_logout;$BODY$language plproxy;
postgres@db-digoal-> cat begin.sh#!/bin/bashnohup pgbench -M extended -r -c 8 -f /home/postgres/digoal_bench/login.sql -j 8 -n -T 180 -h 127.0.0.1 -p 1998 -U proxy proxy0 >>./login_0.log 2>&1 &nohup pgbench -M extended -r -c 8 -f /home/postgres/digoal_bench/login.sql -j 8 -n -T 180 -h 127.0.0.1 -p 1998 -U proxy proxy1 >>./login_1.log 2>&1 &nohup pgbench -M extended -r -c 8 -f /home/postgres/digoal_bench/login.sql -j 8 -n -T 180 -h 127.0.0.1 -p 1998 -U proxy proxy2 >>./login_2.log 2>&1 &nohup pgbench -M extended -r -c 8 -f /home/postgres/digoal_bench/login.sql -j 8 -n -T 180 -h 127.0.0.1 -p 1998 -U proxy proxy3 >>./login_3.log 2>&1 &nohup pgbench -M extended -r -c 8 -f /home/postgres/digoal_bench/logout.sql -j 8 -n -T 180 -h 127.0.0.1 -p 1998 -U proxy proxy0 >>./logout_0.log 2>&1 &nohup pgbench -M extended -r -c 8 -f /home/postgres/digoal_bench/logout.sql -j 8 -n -T 180 -h 127.0.0.1 -p 1998 -U proxy proxy1 >>./logout_1.log 2>&1 &nohup pgbench -M extended -r -c 8 -f /home/postgres/digoal_bench/logout.sql -j 8 -n -T 180 -h 127.0.0.1 -p 1998 -U proxy proxy2 >>./logout_2.log 2>&1 &nohup pgbench -M extended -r -c 8 -f /home/postgres/digoal_bench/logout.sql -j 8 -n -T 180 -h 127.0.0.1 -p 1998 -U proxy proxy3 >>./logout_3.log 2>&1 &postgres@db-digoal-> cat login.sql\setrandom userid 0 50000000SELECT f_user_login(:userid);postgres@db-digoal-> cat logout.sql\setrandom userid 0 50000000SELECT f_user_logout(:userid);
postgres@db-digoal-> cat login_0.logtransaction type: Custom queryscaling factor: 1query mode: extendednumber of clients: 8number of threads: 8duration: 180 snumber of transactions actually processed: 665468tps = 3695.624216 (including connections establishing)tps = 3695.675102 (excluding connections establishing)statement latencies in milliseconds:0.002366 \setrandom userid 0 500000002.158355 SELECT f_user_login(:userid);postgres@db-digoal-> cat login_1.logtransaction type: Custom queryscaling factor: 1query mode: extendednumber of clients: 8number of threads: 8duration: 180 snumber of transactions actually processed: 665288tps = 3694.720318 (including connections establishing)tps = 3694.777428 (excluding connections establishing)statement latencies in milliseconds:0.002289 \setrandom userid 0 500000002.159063 SELECT f_user_login(:userid);postgres@db-digoal-> cat login_2.logtransaction type: Custom queryscaling factor: 1query mode: extendednumber of clients: 8number of threads: 8duration: 180 snumber of transactions actually processed: 645371tps = 3585.275832 (including connections establishing)tps = 3585.340161 (excluding connections establishing)statement latencies in milliseconds:0.002341 \setrandom userid 0 500000002.225684 SELECT f_user_login(:userid);postgres@db-digoal-> cat login_3.logtransaction type: Custom queryscaling factor: 1query mode: extendednumber of clients: 8number of threads: 8duration: 180 snumber of transactions actually processed: 732428tps = 4068.985625 (including connections establishing)tps = 4069.059175 (excluding connections establishing)statement latencies in milliseconds:0.002358 \setrandom userid 0 500000001.960421 SELECT f_user_login(:userid);postgres@db-digoal-> cat logout_0.logtransaction type: Custom queryscaling factor: 1query mode: extendednumber of clients: 8number of threads: 8duration: 180 snumber of transactions actually processed: 774532tps = 4302.899259 (including connections establishing)tps = 4302.942647 (excluding connections establishing)statement latencies in milliseconds:0.002279 \setrandom userid 0 500000001.853726 SELECT f_user_logout(:userid);postgres@db-digoal-> cat logout_1.logtransaction type: Custom queryscaling factor: 1query mode: extendednumber of clients: 8number of threads: 8duration: 180 snumber of transactions actually processed: 773650tps = 4298.002332 (including connections establishing)tps = 4298.047243 (excluding connections establishing)statement latencies in milliseconds:0.002308 \setrandom userid 0 500000001.855774 SELECT f_user_logout(:userid);postgres@db-digoal-> cat logout_2.logtransaction type: Custom queryscaling factor: 1query mode: extendednumber of clients: 8number of threads: 8duration: 180 snumber of transactions actually processed: 752476tps = 4180.389824 (including connections establishing)tps = 4180.437536 (excluding connections establishing)statement latencies in milliseconds:0.002331 \setrandom userid 0 500000001.908120 SELECT f_user_logout(:userid);postgres@db-digoal-> cat logout_3.logtransaction type: Custom queryscaling factor: 1query mode: extendednumber of clients: 8number of threads: 8duration: 180 snumber of transactions actually processed: 855429tps = 4752.346080 (including connections establishing)tps = 4752.383363 (excluding connections establishing)statement latencies in milliseconds:0.002288 \setrandom userid 0 500000001.677890 SELECT f_user_logout(:userid);