host_datanode_1 datanode_1host_datanode_2 datanode_2host_datanode_3 datanode_3host_coordinator_3 gtm-proxy, coordinator_3host_coordinator_2 gtm-proxy, coordinator_2host_coordinator_1 gtm-proxy, coordinator_1host_gtm-standby gtm-standbyhost_gtm gtm
gtm, gtm-standby 4191gtm-proxy 4192coordinator, datanode 4193coordinator_pooler_manager_port 4194
gtm /pgxc_gtm/workgtm-standby /pgxc_gtm/workgtm-proxy /pgxc_gtm_proxy/workcoordinator /pgxcdata/data01/pg_rootdatanode /pgxcdata/data01/pg_root
/etc/hosts10.10.1.212 db-host_gtm.sky-mobi.com db-host_gtm10.10.1.89 db-host_gtm-standby.sky-mobi.com db-host_gtm-standby10.10.1.63 db-host_coordinator_1.sky-mobi.com db-host_coordinator_110.10.1.55 db-host_coordinator_2.sky-mobi.com db-host_coordinator_210.10.1.236 db-host_coordinator_3.sky-mobi.com db-host_coordinator_310.10.1.235 db-host_datanode_3.sky-mobi.com db-host_datanode_310.10.1.227 db-host_datanode_2.sky-mobi.com db-host_datanode_210.10.1.207 db-host_datanode_1.sky-mobi.com db-host_datanode_1
useradd pgxctar -zxvf pgxc_v0.9.7.tar.gzchown -R pgxc:pgxc pgxcsu - pgxcvi .bash_profileexport PS1="$USER@`/bin/hostname -s`-> "export PGPORT=4193export PGDATA=/pgxcdata/data01/pg_rootexport LANG=en_US.utf8export PGHOME=/opt/pgxc0.9.7export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/libexport DATE=`date +"%Y%m%d%H%M"`export PATH=$PGHOME/bin:$PATH:.export MANPATH=$PGHOME/share/man:$MANPATHalias rm='rm -i'alias ll='ls -lh'cd pgxc./configure --prefix=/opt/pgxc0.9.7 --with-pgport=4193 --with-perl --with-python --with-openssl --with-pam --without-ldap --with-libxml --with-libxslt --enable-thread-safety && gmakesu - rootcd pgxcgmake installmkdir $PGHOME/share/mancp -r /opt/soft_bak/pgxc/doc-xc/src/sgml/man1 $PGHOME/share/mancp -r /opt/soft_bak/pgxc/doc-xc/src/sgml/man3 $PGHOME/share/mancp -r /opt/soft_bak/pgxc/doc-xc/src/sgml/man7 $PGHOME/share/mansu - pgxcpsql -Vpsql (PostgreSQL) 9.1.2contains support for command-line editing
mkdir -p /pgxc_gtm/workcp /opt/pgxc0.9.7/share/postgresql/gtm.conf.sample /pgxc_gtm/work/gtm.confchown -R pgxc:pgxc /pgxc_gtmvi /pgxc_gtm/work/gtm.confnodename = '1'listen_addresses = '0.0.0.0'port = 4191startup = ACTlog_file = 'gtm.log'log_min_messages = NOTICE
gtm_ctl start -S gtm -D /pgxc_gtm/work -l /pgxc_gtm/work/gtm_ctl.log
gtm_ctl status -S gtm -D /pgxc_gtm/workpid: 2219data: /pgxc_gtm/workactive: 1
mkdir -p /pgxc_gtm/workcp /opt/pgxc0.9.7/share/postgresql/gtm.conf.sample /pgxc_gtm/work/gtm.confchown -R pgxc:pgxc /pgxc_gtmvi /pgxc_gtm/work/gtm.confnodename = '2'listen_addresses = '0.0.0.0'port = 4191startup = STANDBYactive_host = 'db-host_gtm'active_port = 4191keepalives_idle = 60keepalives_interval = 10keepalives_count = 10log_file = 'gtm.log'log_min_messages = NOTICE
gtm_ctl start -S gtm -D /pgxc_gtm/work -l /pgxc_gtm/work/gtm_ctl.log
gtm_ctl status -S gtm -D /pgxc_gtm/workpid: 30694data: /pgxc_gtm/workactive: 0
mkdir -p /pgxc_gtm_proxy/workcp /opt/pgxc0.9.7/share/postgresql/gtm_proxy.conf.sample /pgxc_gtm_proxy/work/gtm_proxy.confchown -R pgxc:pgxc /pgxc_gtm_proxyvi /pgxc_gtm_proxy/work/gtm_proxy.confnodename = '1'listen_addresses = '0.0.0.0'port = 4192worker_threads = 2gtm_host = 'db-host_gtm'gtm_port = 4191keepalives_idle = 60keepalives_interval = 10keepalives_count = 10log_file = 'gtm_proxy.log'log_min_messages = NOTICE
gtm_ctl start -S gtm_proxy -D /pgxc_gtm_proxy/work -l /pgxc_gtm_proxy/work/gtm_ctl.log
ps -ewf|grep gtm_proxy
initdb --nodename datanode_1 -D /pgxcdata/data01/pg_root -E UTF8 --locale=C -W -A md5initdb --nodename datanode_2 -D /pgxcdata/data01/pg_root -E UTF8 --locale=C -W -A md5initdb --nodename datanode_3 -D /pgxcdata/data01/pg_root -E UTF8 --locale=C -W -A md5
listen_addresses = '0.0.0.0' # what IP address(es) to listen on;port = 4193 # (change requires restart)max_connections = 2000 # (change requires restart) # 大于或等于所有coordinator配置的max_pool_size的总和superuser_reserved_connections = 13 # (change requires restart)password_encryption = ontcp_keepalives_idle = 60 # TCP_KEEPIDLE, in seconds;tcp_keepalives_interval = 10 # TCP_KEEPINTVL, in seconds;tcp_keepalives_count = 10 # TCP_KEEPCNT;shared_buffers = 1024MB # min 128kBmax_prepared_transactions = 2000 # zero disables the featuremaintenance_work_mem = 512MB # min 1MBmax_stack_depth = 8MB # min 100kBvacuum_cost_delay = 10ms # 0-100 millisecondsvacuum_cost_limit = 500 # 1-10000 creditssynchronous_commit = off # synchronization level; on, off, or localwal_sync_method = fdatasync # the default is the first optionwal_writer_delay = 10ms # 1-10000 millisecondscheckpoint_segments = 128 # in logfile segments, min 1, 16MB eachcheckpoint_timeout = 15min # range 30s-1hrandom_page_cost = 2.0 # same scale as aboveeffective_cache_size = 20480MBlog_destination = 'csvlog' # Valid values are combinations oflogging_collector = on # Enable capturing of stderr and csvloglog_directory = '/var/applog/pg_log' # directory where log files are written,log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern,log_file_mode = 0600 # creation mode for log files,log_truncate_on_rotation = on # If on, an existing log file with thelog_rotation_age = 1d # Automatic rotation of logfiles willlog_rotation_size = 10MB # Automatic rotation of logfiles willlog_checkpoints = onautovacuum = on # Enable autovacuum subprocess? 'on'log_autovacuum_min_duration = 0 # -1 disables, 0 logs all actions anddatestyle = 'iso, mdy'lc_messages = 'C' # locale for system error messagelc_monetary = 'C' # locale for monetary formattinglc_numeric = 'C' # locale for number formattinglc_time = 'C' # locale for time formattingdefault_text_search_config = 'pg_catalog.english'gtm_host = 'db-host_gtm' # Host name or address of GTMgtm_port = 4191 # Port of GTMpgxc_node_name = 'datanode_1' # Coordinator or Datanode namestrict_statement_checking = on # Forbid PG-XC-unsafe SQL
host all all 10.10.1.63/32 trusthost all all 10.10.1.55/32 trusthost all all 10.10.1.236/32 trusthost all all 10.10.1.235/32 trusthost all all 10.10.1.227/32 trusthost all all 10.10.1.207/32 trusthost all all 0.0.0.0/0 md5
pg_ctl start -D /pgxcdata/data01/pg_root -Z datanode
initdb --nodename coordinator_1 -D /pgxcdata/data01/pg_root -E UTF8 --locale=C -W -A md5initdb --nodename coordinator_2 -D /pgxcdata/data01/pg_root -E UTF8 --locale=C -W -A md5initdb --nodename coordinator_3 -D /pgxcdata/data01/pg_root -E UTF8 --locale=C -W -A md5
listen_addresses = '0.0.0.0' # what IP address(es) to listen on;port = 4193 # (change requires restart)max_connections = 1000 # (change requires restart) # 指应用最多可以与coordinator建立多少个连接superuser_reserved_connections = 13 # (change requires restart)password_encryption = ontcp_keepalives_idle = 60 # TCP_KEEPIDLE, in seconds;tcp_keepalives_interval = 10 # TCP_KEEPINTVL, in seconds;tcp_keepalives_count = 10 # TCP_KEEPCNT;shared_buffers = 1024MB # min 128kBmax_prepared_transactions = 1000 # zero disables the featuremaintenance_work_mem = 512MB # min 1MBmax_stack_depth = 8MB # min 100kBvacuum_cost_delay = 10ms # 0-100 millisecondsvacuum_cost_limit = 500 # 1-10000 creditssynchronous_commit = off # synchronization level; on, off, or localwal_sync_method = fdatasync # the default is the first optionwal_writer_delay = 10ms # 1-10000 millisecondscheckpoint_segments = 128 # in logfile segments, min 1, 16MB eachcheckpoint_timeout = 15min # range 30s-1hrandom_page_cost = 2.0 # same scale as aboveeffective_cache_size = 20480MBlog_destination = 'csvlog' # Valid values are combinations oflogging_collector = on # Enable capturing of stderr and csvloglog_directory = '/var/applog/pg_log' # directory where log files are written,log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern,log_file_mode = 0600 # creation mode for log files,log_truncate_on_rotation = on # If on, an existing log file with thelog_rotation_age = 1d # Automatic rotation of logfiles willlog_rotation_size = 10MB # Automatic rotation of logfiles willlog_checkpoints = onautovacuum = on # Enable autovacuum subprocess? 'on'log_autovacuum_min_duration = 0 # -1 disables, 0 logs all actions anddatestyle = 'iso, mdy'lc_messages = 'C' # locale for system error messagelc_monetary = 'C' # locale for monetary formattinglc_numeric = 'C' # locale for number formattinglc_time = 'C' # locale for time formattingdefault_text_search_config = 'pg_catalog.english'gtm_host = 'db-host_gtm' # Host name or address of GTMgtm_port = 4191 # Port of GTMpooler_port = 4194 # Pool Manager TCP portmin_pool_size = 1 # Initial pool size # 指coordinator和datanode建立的连接max_pool_size = 100 # Maximum pool size # 指coordinator和datanode建立的连接persistent_datanode_connections = on # Set persistent connection mode for poolerpgxc_node_name = 'coordinator_1' # Coordinator or Datanode namestrict_statement_checking = on # Forbid PG-XC-unsafe SQL
host all all 10.10.1.63/32 trusthost all all 10.10.1.55/32 trusthost all all 10.10.1.236/32 trusthost all all 10.10.1.235/32 trusthost all all 10.10.1.227/32 trusthost all all 10.10.1.207/32 trusthost all all 0.0.0.0/0 md5
pg_ctl start -D /pgxcdata/data01/pg_root -Z coordinator
psql -d template1 -U pgxcdrop node coordinator_1;drop node coordinator_2;drop node coordinator_3;drop node datanode_1;drop node datanode_2;drop node datanode_3;create node coordinator_1 with (type='coordinator', host='db-host_coordinator_1', port=4193);create node coordinator_2 with (type='coordinator', host='db-host_coordinator_2', port=4193);create node coordinator_3 with (type='coordinator', host='db-host_coordinator_3', port=4193);create node datanode_1 with (type='datanode', host='db-host_datanode_1', port=4193, PRIMARY, PREFERRED);create node datanode_2 with (type='datanode', host='db-host_datanode_2', port=4193, PREFERRED);create node datanode_3 with (type='datanode', host='db-host_datanode_3', port=4193, PREFERRED);alter node coordinator_1 with (host='db-host_coordinator_1', port=4193);alter node coordinator_2 with (host='db-host_coordinator_2', port=4193);alter node coordinator_3 with (host='db-host_coordinator_3', port=4193);alter node datanode_1 with (type='datanode', host='db-host_datanode_1', port=4193, PRIMARY, PREFERRED);alter node datanode_2 with (type='datanode', host='db-host_datanode_2', port=4193, PREFERRED);alter node datanode_3 with (type='datanode', host='db-host_datanode_3', port=4193, PREFERRED);
create database digoal;\c digoal digoaldigoal=# create table user_info_hash(id int primary key,firstname text,lastname text,info text) distribute by hash(id) to node datanode_1,datanode_2,datanode_3;NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "user_info_hash_pkey" for table "user_info_hash"CREATE TABLEdigoal=# create table user_info_modulo(id int primary key,firstname text,lastname text,info text) distribute by modulo(id) to node datanode_1,datanode_2,datanode_3;NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "user_info_modulo_pkey" for table "user_info_modulo"CREATE TABLEdigoal=# create table user_info_rr(id int,firstname text,lastname text,info text) distribute by round robin to node datanode_1,datanode_2,datanode_3;CREATE TABLEdigoal=# create table user_info_replica(id int primary key,firstname text,lastname text,info text) distribute by replication to node datanode_1,datanode_2,datanode_3;NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "user_info_replica_pkey" for table "user_info_replica"CREATE TABLE
digoal=# insert into user_info_hash select generate_series(1,10000),'zhou','digoal','DBA';INSERT 0 10000Time: 5260.994 msdigoal=# insert into user_info_modulo select generate_series(1,10000),'zhou','digoal','DBA';INSERT 0 10000Time: 5305.979 msdigoal=# insert into user_info_rr select generate_series(1,10000),'zhou','digoal','DBA';INSERT 0 10000Time: 5124.162 msdigoal=# insert into user_info_replica select generate_series(1,10000),'zhou','digoal','DBA';
pg_catalog | pgxc_class | table | pgxcpg_catalog | pgxc_group | table | pgxcpg_catalog | pgxc_node | table | pgxcpg_catalog | pgxc_prepared_xacts | view | pgxc
digoal=# select * from pgxc_class;pcrelid | pclocatortype | pcattnum | pchashalgorithm | pchashbuckets | nodeoids---------+---------------+----------+-----------------+---------------+-------------------16422 | H | 1 | 1 | 4096 | 16405 16406 16407
digoal=# select * from pgxc_node;node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred---------------+-----------+-----------+--------------------+----------------+------------------coordinator_1 | C | 4193 | host_coordinator_1 | f | fdatanode_1 | D | 4193 | host_datanode_1 | t | tdatanode_2 | D | 4193 | host_datanode_2 | f | tdatanode_3 | D | 4193 | host_datanode_3 | f | tcoordinator_2 | C | 4193 | host_coordinator_2 | f | fcoordinator_3 | C | 4193 | host_coordinator_3 | f | f