This topic describes how to use pgpool of PostgreSQL that is installed on an Elastic Compute Service (ECS) instance to implement read/write splitting for your primary and read-only ApsaraDB RDS for PostgreSQL instances.

Background information

If you do not use pgpool to ensure high availability, pgpool is stateless. The decrease in performance can be ignored. pgpool also supports horizontal scaling of your database system. You can use pgpool and the high availability architecture of ApsaraDB RDS for PostgreSQL to implement read/write splitting.

Set up a test environment

If you have created a primary RDS instance that runs PostgreSQL 10 with local SSDs and have attached read-only RDS instances to the primary RDS instance, you need to only install pgpool. For more information, see Create an ApsaraDB RDS for PostgreSQL instance and Create a read-only ApsaraDB RDS for PostgreSQL instance. After you install pgpool, go to Configure pgpool.

Note Read-only RDS instances for primary RDS instances that use standard SSDs or enhanced SSDs (ESSDs) are under development.

Test environment:

  • The ECS instance must provide 16 CPU cores, 64 GB of memory, and 1.8 TB of storage capacity that is available on standard SSDs.
  • The ECS instance runs 64-bit CentOS 7.7.

Procedure:

  1. Modify the sysctl.conf file.
    sudo vi /etc/sysctl.conf  
    
    # add by digoal.zhou                
    fs.aio-max-nr = 1048576                
    fs.file-max = 76724600                
    
    # Optional. Set the kernel.core_pattern parameter to /data01/corefiles/core_%e_%u_%t_%s.%p.                         
    # The /data01/corefiles directory is created with the 777 permission before testing. If a symbolic link is used, change the directory to 777.        
    
    kernel.sem = 4096 2147483647 2147483646 512000                    
    # Specify the semaphore. You can run the ipcs -l or -u command to obtain the semaphore count. Each group of 16 processes requires a semaphore with a count of 17.                 
    
    kernel.shmall = 107374182                      
    # Specify the total size of shared memory segments. Recommended value: 80% of the memory capacity. Unit: pages.                 
    kernel.shmmax = 274877906944                   
    # Specify the maximum size of a single shared memory segment. Recommended value: 50% of the memory capacity. Unit: bytes. In PostgreSQL versions later than PostgreSQL 9.2, the use of shared memory significantly drops.                 
    kernel.shmmni = 819200                         
    # Specify the total number of shared memory segments that can be generated. At least two shared memory segments must be generated within each PostgreSQL cluster. 
    
    net.core.netdev_max_backlog = 10000                
    net.core.rmem_default = 262144                       
    # The default setting of the socket receive buffer in bytes.                
    net.core.rmem_max = 4194304                          
    # The maximum receive socket buffer size in bytes                
    net.core.wmem_default = 262144                       
    # The default setting (in bytes) of the socket send buffer.                
    net.core.wmem_max = 4194304                          
    # The maximum send socket buffer size in bytes.                
    net.core.somaxconn = 4096                
    net.ipv4.tcp_max_syn_backlog = 4096                
    net.ipv4.tcp_keepalive_intvl = 20                
    net.ipv4.tcp_keepalive_probes = 3                
    net.ipv4.tcp_keepalive_time = 60                
    net.ipv4.tcp_mem = 8388608 12582912 16777216                
    net.ipv4.tcp_fin_timeout = 5                
    net.ipv4.tcp_synack_retries = 2                
    net.ipv4.tcp_syncookies = 1                    
    # Enable SYN cookies. If an SYN waiting queue overflows, you can enable SYN cookies to defend against a small number of SYN attacks.                 
    net.ipv4.tcp_timestamps = 1                    
    # Reduce the time after which a network socket enters the TIME-WAIT state. 
    net.ipv4.tcp_tw_recycle = 0                    
    # If you set this parameter to 1 to enable the recycle feature, network sockets in the TIME-WAIT state over TCP connections are recycled. However, if network address translation (NAT) is used, TCP connections may fail. We recommend that you set this parameter to 0 on the database server. 
    net.ipv4.tcp_tw_reuse = 1                      
    # Enable the reuse feature. This feature enables network sockets in the TIME-WAIT state to be reused over new TCP connections. 
    net.ipv4.tcp_max_tw_buckets = 262144                
    net.ipv4.tcp_rmem = 8192 87380 16777216                
    net.ipv4.tcp_wmem = 8192 65536 16777216                
    
    net.nf_conntrack_max = 1200000                
    net.netfilter.nf_conntrack_max = 1200000                
    
    vm.dirty_background_bytes = 409600000                       
    # If the size of dirty pages reaches the specified limit, a background scheduling process, such as pdflush, is invoked to flush the dirty pages that are generated n seconds earlier to disks. The value of n is calculated by using the following formula: n = Value of the dirty_expire_centisecs parameter/100.                 
    # The default limit is 10% of the memory capacity. If the memory capacity is large, we recommend that you specify the limit in bytes.                 
    
    vm.dirty_expire_centisecs = 3000                             
    # Specify the maximum period to retain dirty pages. Dirty pages are flushed to disks after the time period specified by this parameter elapses. The value 3000 indicates 30 seconds.                 
    vm.dirty_ratio = 95                                          
    # The processes that users call to write data onto disks, such as fsync and fdatasync, must actively flush dirty pages to disks. This applies when the background scheduling process to flush dirty pages is slow and the size of dirty pages exceeds 95% of the memory capacity.                 
    # Set this parameter properly to prevent user-called processes from flushing dirty pages to disks. This allows you to create multiple RDS instances on a single server and use control groups to limit the input/output operations per second (IOPS) per instance.                   
    
    vm.dirty_writeback_centisecs = 100                            
    # Specify the time interval at which the background scheduling process, such as pdflush, flushes dirty pages to disks. The value 100 indicates 1 second.                 
    
    vm.swappiness = 0                
    # Disable the swapping feature.                 
    
    vm.mmap_min_addr = 65536                
    vm.overcommit_memory = 0                     
    # Specify whether you can allocate more memory than the host has available. If you set this parameter to 1, the system always considers the available memory sufficient. If the memory capacity provided in the test environment is low, we recommend that you set this parameter to 1. 
    
    vm.overcommit_ratio = 90                     
    # Specify the memory capacity that can be allocated when the overcommit_memory parameter is set to 2.                 
    vm.swappiness = 0                            
    # Disable the swapping feature.                 
    vm.zone_reclaim_mode = 0                     
    # Disable non-uniform memory access (NUMA). You can also disable NUMA in the vmlinux file.             
    net.ipv4.ip_local_port_range = 40000 65535                    
    # Specify the range of TCP or UDP port numbers for the host to allocate.                 
    fs.nr_open=20480000                
    # Specify the maximum number of file handles that a single process can open.                 
    
    # Take note of the following parameters:             
    #vm.extra_free_kbytes = 4096000   # If the host provides a low memory capacity, do not specify a large value such as 4096000. If you specify a large value, the host may fail to be started. 
    #vm.min_free_kbytes = 6291456    # We recommend that you increase the value of the vm.min_free_kbytes parameter by 1 GB for every 32 GB of memory.      
    # If the host does not provide much memory, we recommend that you do not configure vm.extra_free_kbytes and vm.min_free_kbytes.                 
    # vm.nr_hugepages = 66536                    
    # If the size of the shared buffer exceeds 64 GB, we recommend that you use huge pages. You can specify the page size by setting the Hugepagesize parameter in the /proc/meminfo file.                 
    #vm.lowmem_reserve_ratio = 1 1 1                
    # If the memory capacity exceeds 64 GB, we recommend that you set this parameter. Otherwise, we recommend that you retain the default value 256 256 32.     
  2. Modify the limits.conf file.
    sudo vi /etc/security/limits.conf  
    
    * soft    nofile  1024000                
    * hard    nofile  1024000                
    * soft    nproc   unlimited                
    * hard    nproc   unlimited                
    * soft    core    unlimited                
    * hard    core    unlimited                
    * soft    memlock unlimited                
    * hard    memlock unlimited    
    
    # Comment out the other parameters in the limits.conf file.  
    # Comment out the /etc/security/limits.d/20-nproc.conf file.   
  3. Disable transparent huge pages, configure huge pages, and start PostgreSQL.
    sudo chmod +x /etc/rc.d/rc.local  
    
    sudo vi /etc/rc.local  
    
    # Disable transparent huge pages.   
    if test -f /sys/kernel/mm/transparent_hugepage/enabled; then                
       echo never > /sys/kernel/mm/transparent_hugepage/enabled                
    fi    
    
    # Configure huge pages for two instances. Each instance has a shared buffer of 16 GB.   
    #sysctl -w vm.nr_hugepages=17000  
    
    # Start the two instances.   
    su - postgres -c "pg_ctl start -D /data01/pg12_3389/pg_data"  
    su - postgres -c "pg_ctl start -D /data01/pg12_8002/pg_data"  
  4. Create a file system.
    Warning If you use a new disk, you must confirm that the new disk belongs to the vdb partition instead of the vda partition. If the new disk belongs to the vda partition, data may be deleted from the new disk.
    parted -a optimal -s /dev/vdb mklabel gpt mkpart primary 1MiB 100%FREE     
    mkfs.ext4 /dev/vdb1 -m 0 -O extent,uninit_bg -E lazy_itable_init=1 -b 4096 -T largefile -L vdb1  
    vi /etc/fstab   
    LABEL=vdb1 /data01 ext4 defaults,noatime,nodiratime,nodelalloc,barrier=0,data=writeback 0 0  
    
    mkdir /data01  
    mount -a  
  5. Start irqbalance.
    sudo systemctl status irqbalance     
    sudo systemctl enable irqbalance        
    sudo systemctl start irqbalance       
    sudo systemctl status irqbalance    
  6. Install PostgreSQL 10 and pgpool.
    sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm        
    sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm       
    sudo yum search all postgresql  
    sudo yum search all pgpool  
    sudo yum install -y postgresql12*    
    sudo yum install -y pgpool-II-12-extensions      
  7. Initialize the data directory of your database system.
    mkdir /data01/pg12_3389  
    sudo chown postgres:postgres /data01/pg12_3389  
  8. Configure environment variables for the postgres user.
    su - postgres  
    vi .bash_profile  
    
    # Append the following parameters:    
    export PS1="$USER@`/bin/hostname -s`-> "      
    export PGPORT=3389  
    export PGDATA=/data01/pg12_$PGPORT/pg_data     
    
    export LANG=en_US.utf8      
    export PGHOME=/usr/pgsql-12      
    export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH      
    export DATE=`date +"%Y%m%d%H%M"`      
    export PATH=$PGHOME/bin:$PATH:.      
    export MANPATH=$PGHOME/share/man:$MANPATH      
    export PGHOST=$PGDATA      
    export PGUSER=postgres      
    export PGDATABASE=db1  
    alias rm='rm -i'      
    alias ll='ls -lh'      
    unalias vi      
  9. Initialize your primary RDS instance.
    initdb -D $PGDATA -U postgres -E UTF8 --lc-collate=C --lc-ctype=en_US.utf8  
  10. Modify the postgresql.conf file.
    listen_addresses = '0.0.0.0'  
    port = 3389  
    max_connections = 1500  
    superuser_reserved_connections = 13  
    unix_socket_directories = '., /var/run/postgresql, /tmp'  
    tcp_keepalives_idle = 60  
    tcp_keepalives_interval = 10  
    tcp_keepalives_count = 10  
    shared_buffers = 16GB  
    huge_pages = on  
    work_mem = 8MB  
    maintenance_work_mem = 1GB  
    dynamic_shared_memory_type = posix  
    vacuum_cost_delay = 0  
    bgwriter_delay = 10ms  
    bgwriter_lru_maxpages = 1000  
    bgwriter_lru_multiplier = 10.0  
    bgwriter_flush_after = 512kB  
    effective_io_concurrency = 0  
    max_worker_processes = 128  
    max_parallel_maintenance_workers = 3  
    max_parallel_workers_per_gather = 4  
    parallel_leader_participation = off  
    max_parallel_workers = 8  
    backend_flush_after = 256  
    wal_level = replica  
    synchronous_commit = off  
    full_page_writes = on  
    wal_compression = on  
    wal_buffers = 16MB  
    wal_writer_delay = 10ms  
    wal_writer_flush_after = 1MB  
    checkpoint_timeout = 15min  
    max_wal_size = 64GB  
    min_wal_size = 8GB  
    checkpoint_completion_target = 0.2  
    checkpoint_flush_after = 256kB  
    random_page_cost = 1.1  
    effective_cache_size = 48GB  
    log_destination = 'csvlog'  
    logging_collector = on  
    log_directory = 'log'  
    log_filename = 'postgresql-%a.log'  
    log_truncate_on_rotation = on  
    log_rotation_age = 1d  
    log_rotation_size = 0  
    log_min_duration_statement = 1s  
    log_checkpoints = on  
    log_connections = on  
    log_disconnections = on  
    log_line_prefix = '%m [%p] '  
    log_statement = 'ddl'  
    log_timezone = 'Asia/Shanghai'  
    autovacuum = on  
    log_autovacuum_min_duration = 0  
    autovacuum_vacuum_scale_factor = 0.1  
    autovacuum_analyze_scale_factor = 0.05  
    autovacuum_freeze_max_age = 800000000  
    autovacuum_multixact_freeze_max_age = 900000000  
    autovacuum_vacuum_cost_delay = 0  
    vacuum_freeze_table_age = 750000000  
    vacuum_multixact_freeze_table_age = 750000000  
    datestyle = 'iso, mdy'  
    timezone = 'Asia/Shanghai'  
    lc_messages = 'en_US.utf8'  
    lc_monetary = 'en_US.utf8'  
    lc_numeric = 'en_US.utf8'  
    lc_time = 'en_US.utf8'  
    default_text_search_config = 'pg_catalog.english'  
  11. Modify the pg_hba.conf file.
    Note Pgpool-II is installed on the same ECS instance as the database server on which PostgreSQL resides. If you specify 127.0.0.1 in the pg_hba.conf file, you must enter the correct password to ensure a successful logon.
    # "local" is for Unix domain socket connections only  
    local   all             all                                     trust  
    # IPv4 local connections:  
    host    all             all             127.0.0.1/32            md5  
    # IPv6 local connections:  
    host    all             all             ::1/128                 trust  
    # Allow replication connections from localhost, by a user with the  
    # replication privilege.  
    local   replication     all                                     trust  
    host    replication     all             127.0.0.1/32            trust  
    host    replication     all             ::1/128                 trust  
    host db123 digoal 0.0.0.0/0 md5  
  12. Create a user authorized with streaming replication permissions.
    create role rep123 login replication encrypted password 'xxxxxxx';  
    CREATE ROLE  
  13. Create a user who is authorized to manage your RDS instances.
    create role digoal login encrypted password 'xxxxxxx';  
    CREATE ROLE  
    
    create database db123 owner digoal;  
    CREATE DATABASE  
  14. Create a user who is authorized to check the health heartbeats between Pgpool and your read-only RDS instances. With the parameters of Pgpool properly configured, this user can check the write-ahead logging (WAL) replay latency on each read-only RDS instance.
    create role nobody login encrypted password 'xxxxxxx';  

Create a secondary RDS instance

To simplify the test procedure, perform the following steps to create a secondary RDS instance on the same ECS instance as your primary ApsaraDB RDS instance:

  1. Use pg_basebackup to create a secondary RDS instance online.
    pg_basebackup -D /data01/pg12_8002/pg_data -F p --checkpoint=fast -P -h 127.0.0.1 -p 3389 -U rep123  
  2. Modify the postgresql.conf file of the secondary RDS instance.
    cd /data01/pg12_8002/pg_data   
    
    vi postgresql.conf  
    
    # The secondary ApsaraDB RDS instance has the following configurations different from the primary ApsaraDB RDS instance:  
    port = 8002  
    primary_conninfo = 'hostaddr=127.0.0.1 port=3389 user=rep123' # You do not need to set the password because trust relationships are configured on the primary RDS instance.   
    hot_standby = on  
    wal_receiver_status_interval = 1s  
    wal_receiver_timeout = 10s  
    recovery_target_timeline = 'latest'  
  3. Configure the standby.signal file of the secondary RDS instance.
    cd /data01/pg12_8002/pg_data   
    
    touch standby.signal  
  4. Check whether the data synchronization between the primary and secondary RDS instances is normal.
    db1=# select * from pg_stat_replication ;  
    -[ RECORD 1 ]----+------------------------------  
    pid              | 21065  
    usesysid         | 10  
    usename          | postgres  
    application_name | walreceiver  
    client_addr      | 127.0.0.1  
    client_hostname  |   
    client_port      | 47064  
    backend_start    | 2020-02-29 00:26:28.485427+08  
    backend_xmin     |   
    state            | streaming  
    sent_lsn         | 0/52000060  
    write_lsn        | 0/52000060  
    flush_lsn        | 0/52000060  
    replay_lsn       | 0/52000060  
    write_lag        |   
    flush_lag        |   
    replay_lag       |   
    sync_priority    | 0  
    sync_state       | async  
    reply_time       | 2020-02-29 01:32:40.635183+08  

Configure pgpool

  1. Query the location in which pgpool is installed.
    rpm -qa|grep pgpool  
    pgpool-II-12-extensions-4.1.1-1.rhel7.x86_64  
    pgpool-II-12-4.1.1-1.rhel7.x86_64  
    
    rpm -ql pgpool-II-12-4.1.1  
  2. Modify the pgpool.conf file.
    cd /etc/pgpool-II-12/  
    
    cp pgpool.conf.sample-stream pgpool.conf  
    
    vi pgpool.conf  
    
    # ----------------------------  
    # pgPool-II configuration file  
    # ----------------------------  
    #  
    # This file consists of lines of the form:  
    #  
    #   name = value  
    #  
    # Whitespace may be used.  Comments are introduced with "#" anywhere on a line.  
    # The complete list of parameter names and allowed values can be found in the  
    # pgPool-II documentation.  
    #  
    # This file is read on server startup and when the server receives a SIGHUP  
    # signal.  If you edit the file on a running system, you have to SIGHUP the  
    # server for the changes to take effect, or use "pgpool reload".  Some  
    # parameters, which are marked below, require a server shutdown and restart to  
    # take effect.  
    #  
    
    
    #------------------------------------------------------------------------------  
    # CONNECTIONS  
    #------------------------------------------------------------------------------  
    
    # - pgpool Connection Settings -  
    
    listen_addresses = '0.0.0.0'  
                                       # Host name or IP address to listen on:  
                                       # '*' for all, '' for no TCP/IP connections  
                                       # (change requires restart)  
    port = 8001   
                                       # Port number  
                                       # (change requires restart)  
    socket_dir = '/tmp'  
                                       # Unix domain socket path  
                                       # The Debian package defaults to  
                                       # /var/run/postgresql  
                                       # (change requires restart)  
    reserved_connections = 0  
                                       # Number of reserved connections.  
                                       # Pgpool-II does not accept connections if over  
                                       # num_init_chidlren - reserved_connections.  
    
    
    # - pgpool Communication Manager Connection Settings -  
    
    pcp_listen_addresses = ''  
                                       # Host name or IP address for pcp process to listen on:  
                                       # '*' for all, '' for no TCP/IP connections  
                                       # (change requires restart)  
    pcp_port = 9898  
                                       # Port number for pcp  
                                       # (change requires restart)  
    pcp_socket_dir = '/tmp'  
                                       # Unix domain socket path for pcp  
                                       # The Debian package defaults to  
                                       # /var/run/postgresql  
                                       # (change requires restart)  
    listen_backlog_multiplier = 2  
                                       # Set the backlog parameter of listen(2) to  
                                       # num_init_children * listen_backlog_multiplier.  
                                       # (change requires restart)  
    serialize_accept = off  
                                       # whether to serialize accept() call to avoid thundering herd problem  
                                       # (change requires restart)  
    
    # - Backend Connection Settings -  
    
    backend_hostname0 = '127.0.0.1'  
                                       # Host name or IP address to connect to for backend 0  
    backend_port0 = 3389   
                                       # Port number for backend 0  
    backend_weight0 = 1  
                                       # Weight for backend 0 (only in load balancing mode)  
    backend_data_directory0 = '/data01/pg12_3389/pg_data'  
                                       # Data directory for backend 0  
    backend_flag0 = 'ALWAYS_MASTER'  
                                       # Controls various backend behavior  
                                       # ALLOW_TO_FAILOVER, DISALLOW_TO_FAILOVER  
                                       # or ALWAYS_MASTER  
    backend_application_name0 = 'server0'  
                                       # walsender's application_name, used for "show pool_nodes" command  
    backend_hostname1 = '127.0.0.1'  
    backend_port1 = 8002  
    backend_weight1 = 1  
    backend_data_directory1 = '/data01/pg12_8002/pg_data'  
    backend_flag1 = 'DISALLOW_TO_FAILOVER'  
    backend_application_name1 = 'server1'  
    
    # - Authentication -  
    
    enable_pool_hba = on   
                                       # Use pool_hba.conf for client authentication  
    pool_passwd = 'pool_passwd'  
                                       # File name of pool_passwd for md5 authentication.  
                                       # "" disables pool_passwd.  
                                       # (change requires restart)  
    authentication_timeout = 60  
                                       # Delay in seconds to complete client authentication  
                                       # 0 means no timeout.  
    
    allow_clear_text_frontend_auth = off  
                                       # Allow Pgpool-II to use clear text password authentication  
                                       # with clients, when pool_passwd does not  
                                       # contain the user password  
    
    # - SSL Connections -  
    
    ssl = off  
                                       # Enable SSL support  
                                       # (change requires restart)  
    #ssl_key = './server.key'  
                                       # Path to the SSL private key file  
                                       # (change requires restart)  
    #ssl_cert = './server.cert'  
                                       # Path to the SSL public certificate file  
                                       # (change requires restart)  
    #ssl_ca_cert = ''  
                                       # Path to a single PEM format file  
                                       # containing CA root certificate(s)  
                                       # (change requires restart)  
    #ssl_ca_cert_dir = ''  
                                       # Directory containing CA root certificate(s)  
                                       # (change requires restart)  
    
    ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL'  
                                       # Allowed SSL ciphers  
                                       # (change requires restart)  
    ssl_prefer_server_ciphers = off  
                                       # Use server's SSL cipher preferences,  
                                       # rather than the client's  
                                       # (change requires restart)  
    ssl_ecdh_curve = 'prime256v1'  
                                       # Name of the curve to use in ECDH key exchange  
    ssl_dh_params_file = ''  
                                       # Name of the file containing Diffie-Hellman parameters used  
                                       # for so-called ephemeral DH family of SSL cipher.  
    
    #------------------------------------------------------------------------------  
    # POOLS  
    #------------------------------------------------------------------------------  
    
    # - Concurrent session and pool size -  
    
    num_init_children = 128   
                                       # Number of concurrent sessions allowed  
                                       # (change requires restart)  
    max_pool = 4  
                                       # Number of connection pool caches per connection  
                                       # (change requires restart)  
    
    # - Life time -  
    
    child_life_time = 300  
                                       # Pool exits after being idle for this many seconds  
    child_max_connections = 0  
                                       # Pool exits after receiving that many connections  
                                       # 0 means no exit  
    connection_life_time = 0  
                                       # Connection to backend closes after being idle for this many seconds  
                                       # 0 means no close  
    client_idle_limit = 0  
                                       # Client is disconnected after being idle for that many seconds  
                                       # (even inside an explicit transactions!)  
                                       # 0 means no disconnection  
    
    
    #------------------------------------------------------------------------------  
    # LOGS  
    #------------------------------------------------------------------------------  
    
    # - Where to log -  
    
    log_destination = 'syslog'  
                                       # Where to log  
                                       # Valid values are combinations of stderr,  
                                       # and syslog. Default to stderr.  
    
    # - What to log -  
    
    log_line_prefix = '%t: pid %p: '   # printf-style string to output at beginning of each log line.  
    
    log_connections = on  
                                       # Log connections  
    log_hostname = off  
                                       # Hostname will be shown in ps status  
                                       # and in logs if connections are logged  
    log_statement = off  
                                       # Log all statements  
    log_per_node_statement = off  
                                       # Log all statements  
                                       # with node and backend informations  
    log_client_messages = off  
                                       # Log any client messages  
    log_standby_delay = 'if_over_threshold'  
                                       # Log standby delay  
                                       # Valid values are combinations of always,  
                                       # if_over_threshold, none  
    
    # - Syslog specific -  
    
    syslog_facility = 'LOCAL0'  
                                       # Syslog local facility. Default to LOCAL0  
    syslog_ident = 'pgpool'  
                                       # Syslog program identification string  
                                       # Default to 'pgpool'  
    
    # - Debug -  
    
    #log_error_verbosity = default          # terse, default, or verbose messages  
    
    #client_min_messages = notice           # values in order of decreasing detail:  
                                            #   debug5  
                                            #   debug4  
                                            #   debug3  
                                            #   debug2  
                                            #   debug1  
                                            #   log  
                                            #   notice  
                                            #   warning  
                                            #   error  
    
    #log_min_messages = warning             # values in order of decreasing detail:  
                                            #   debug5  
                                            #   debug4  
                                            #   debug3  
                                            #   debug2  
                                            #   debug1  
                                            #   info  
                                            #   notice  
                                            #   warning  
                                            #   error  
                                            #   log  
                                            #   fatal  
                                            #   panic  
    
    #------------------------------------------------------------------------------  
    # FILE LOCATIONS  
    #------------------------------------------------------------------------------  
    
    pid_file_name = '/var/run/pgpool-II-12/pgpool.pid'  
                                       # PID file name  
                                       # Can be specified as relative to the"  
                                       # location of pgpool.conf file or  
                                       # as an absolute path  
                                       # (change requires restart)  
    logdir = '/tmp'  
                                       # Directory of pgPool status file  
                                       # (change requires restart)  
    
    
    #------------------------------------------------------------------------------  
    # CONNECTION POOLING  
    #------------------------------------------------------------------------------  
    
    connection_cache = on  
                                       # Activate connection pools  
                                       # (change requires restart)  
    
                                       # Semicolon separated list of queries  
                                       # to be issued at the end of a session  
                                       # The default is for 8.3 and later  
    reset_query_list = 'ABORT; DISCARD ALL'  
                                       # The following one is for 8.2 and before  
    #reset_query_list = 'ABORT; RESET ALL; SET SESSION AUTHORIZATION DEFAULT'  
    
    
    #------------------------------------------------------------------------------  
    # REPLICATION MODE  
    #------------------------------------------------------------------------------  
    
    replication_mode = off  
                                       # Activate replication mode  
                                       # (change requires restart)  
    replicate_select = off  
                                       # Replicate SELECT statements  
                                       # when in replication mode  
                                       # replicate_select is higher priority than  
                                       # load_balance_mode.  
    
    insert_lock = off  
                                       # Automatically locks a dummy row or a table  
                                       # with INSERT statements to keep SERIAL data  
                                       # consistency  
                                       # Without SERIAL, no lock will be issued  
    lobj_lock_table = ''  
                                       # When rewriting lo_create command in  
                                       # replication mode, specify table name to  
                                       # lock  
    
    # - Degenerate handling -  
    
    replication_stop_on_mismatch = off  
                                       # On disagreement with the packet kind  
                                       # sent from backend, degenerate the node  
                                       # which is most likely "minority"  
                                       # If off, just force to exit this session  
    
    failover_if_affected_tuples_mismatch = off  
                                       # On disagreement with the number of affected  
                                       # tuples in UPDATE/DELETE queries, then  
                                       # degenerate the node which is most likely  
                                       # "minority".  
                                       # If off, just abort the transaction to  
                                       # keep the consistency  
    
    
    #------------------------------------------------------------------------------  
    # LOAD BALANCING MODE  
    #------------------------------------------------------------------------------  
    
    load_balance_mode = on  
                                       # Activate load balancing mode  
                                       # (change requires restart)  
    ignore_leading_white_space = on  
                                       # Ignore leading white spaces of each query  
    white_function_list = ''  
                                       # Comma separated list of function names  
                                       # that don't write to database  
                                       # Regexp are accepted  
    black_function_list = 'currval,lastval,nextval,setval'  
                                       # Comma separated list of function names  
                                       # that write to database  
                                       # Regexp are accepted  
    
    black_query_pattern_list = ''  
                                       # Semicolon separated list of query patterns  
                                       # that should be sent to primary node  
                                       # Regexp are accepted  
                                       # valid for streaming replication mode only.  
    
    database_redirect_preference_list = ''  
                                       # comma separated list of pairs of database and node id.  
                                       # example: postgres:primary,mydb[0-4]:1,mydb[5-9]:2'  
                                       # valid for streaming replication mode only.  
    
    app_name_redirect_preference_list = ''  
                                       # comma separated list of pairs of app name and node id.  
                                       # example: 'psql:primary,myapp[0-4]:1,myapp[5-9]:standby'  
                                       # valid for streaming replication mode only.  
    allow_sql_comments = off  
                                       # if on, ignore SQL comments when judging if load balance or  
                                       # query cache is possible.  
                                       # If off, SQL comments effectively prevent the judgment  
                                       # (pre 3.4 behavior).  
    
    disable_load_balance_on_write = 'transaction'  
                                       # Load balance behavior when write query is issued  
                                       # in an explicit transaction.  
                                       # Note that any query not in an explicit transaction  
                                       # is not affected by the parameter.  
                                       # 'transaction' (the default): if a write query is issued,  
                                       # subsequent read queries will not be load balanced  
                                       # until the transaction ends.  
                                       # 'trans_transaction': if a write query is issued,  
                                       # subsequent read queries in an explicit transaction  
                                       # will not be load balanced until the session ends.  
                                       # 'always': if a write query is issued, read queries will  
                                       # not be load balanced until the session ends.  
    
    statement_level_load_balance = off  
                                       # Enables statement level load balancing  
    
    #------------------------------------------------------------------------------  
    # MASTER/SLAVE MODE  
    #------------------------------------------------------------------------------  
    
    master_slave_mode = on  
                                       # Activate master/slave mode  
                                       # (change requires restart)  
    master_slave_sub_mode = 'stream'  
                                       # Master/slave sub mode  
                                       # Valid values are combinations stream, slony  
                                       # or logical. Default is stream.  
                                       # (change requires restart)  
    
    # - Streaming -  
    
    sr_check_period = 3   
                                       # Streaming replication check period  
                                       # Disabled (0) by default  
    sr_check_user = 'nobody'  
                                       # Streaming replication check user  
                                       # This is necessary even if you disable streaming  
                                       # replication delay check by sr_check_period = 0  
    sr_check_password = ''  
                                       # Password for streaming replication check user  
                                       # Leaving it empty will make Pgpool-II to first look for the  
                                       # Password in pool_passwd file before using the empty password  
    
    sr_check_database = 'postgres'  
                                       # Database name for streaming replication check  
    delay_threshold = 512000  
                                       # Threshold before not dispatching query to standby node  
                                       # Unit is in bytes  
                                       # Disabled (0) by default  
    
    # - Special commands -  
    
    follow_master_command = ''  
                                       # Executes this command after master failover  
                                       # Special values:  
                                       #   %d = failed node id  
                                       #   %h = failed node host name  
                                       #   %p = failed node port number  
                                       #   %D = failed node database cluster path  
                                       #   %m = new master node id  
                                       #   %H = new master node hostname  
                                       #   %M = old master node id  
                                       #   %P = old primary node id  
                                       #   %r = new master port number  
                                       #   %R = new master database cluster path  
                                       #   %N = old primary node hostname  
                                       #   %S = old primary node port number  
                                       #   %% = '%' character  
    
    #------------------------------------------------------------------------------  
    # HEALTH CHECK GLOBAL PARAMETERS  
    #------------------------------------------------------------------------------  
    
    health_check_period = 5  
                                       # Health check period  
                                       # Disabled (0) by default  
    health_check_timeout = 10  
                                       # Health check timeout  
                                       # 0 means no timeout  
    health_check_user = 'nobody'  
                                       # Health check user  
    health_check_password = ''  
                                       # Password for health check user  
                                       # Leaving it empty will make Pgpool-II to first look for the  
                                       # Password in pool_passwd file before using the empty password  
    
    health_check_database = ''  
                                       # Database name for health check. If '', tries 'postgres' first,   
    health_check_max_retries = 60   
                                       # Maximum number of times to retry a failed health check before giving up.  
    health_check_retry_delay = 1  
                                       # Amount of time to wait (in seconds) between retries.  
    connect_timeout = 10000  
                                       # Timeout value in milliseconds before giving up to connect to backend.  
                                       # Default is 10000 ms (10 second). Flaky network user may want to increase  
                                       # the value. 0 means no timeout.  
                                       # Note that this value is not only used for health check,  
                                       # but also for ordinary connection to backend.  
    
    #------------------------------------------------------------------------------  
    # HEALTH CHECK PER NODE PARAMETERS (OPTIONAL)  
    #------------------------------------------------------------------------------  
    #health_check_period0 = 0  
    #health_check_timeout0 = 20  
    #health_check_user0 = 'nobody'  
    #health_check_password0 = ''  
    #health_check_database0 = ''  
    #health_check_max_retries0 = 0  
    #health_check_retry_delay0 = 1  
    #connect_timeout0 = 10000  
    
    #------------------------------------------------------------------------------  
    # FAILOVER AND FAILBACK  
    #------------------------------------------------------------------------------  
    
    failover_command = ''  
                                       # Executes this command at failover  
                                       # Special values:  
                                       #   %d = failed node id  
                                       #   %h = failed node host name  
                                       #   %p = failed node port number  
                                       #   %D = failed node database cluster path  
                                       #   %m = new master node id  
                                       #   %H = new master node hostname  
                                       #   %M = old master node id  
                                       #   %P = old primary node id  
                                       #   %r = new master port number  
                                       #   %R = new master database cluster path  
                                       #   %N = old primary node hostname  
                                       #   %S = old primary node port number  
                                       #   %% = '%' character  
    failback_command = ''  
                                       # Executes this command at failback.  
                                       # Special values:  
                                       #   %d = failed node id  
                                       #   %h = failed node host name  
                                       #   %p = failed node port number  
                                       #   %D = failed node database cluster path  
                                       #   %m = new master node id  
                                       #   %H = new master node hostname  
                                       #   %M = old master node id  
                                       #   %P = old primary node id  
                                       #   %r = new master port number  
                                       #   %R = new master database cluster path  
                                       #   %N = old primary node hostname  
                                       #   %S = old primary node port number  
                                       #   %% = '%' character  
    
    failover_on_backend_error = off  
                                       # Initiates failover when reading/writing to the  
                                       # backend communication socket fails  
                                       # If set to off, pgpool will report an  
                                       # error and disconnect the session.  
    
    detach_false_primary = off  
                                       # Detach false primary if on. Only  
                                       # valid in streaming replication  
                                       # mode and with PostgreSQL 9.6 or  
                                       # after.  
    
    search_primary_node_timeout = 300  
                                       # Timeout in seconds to search for the  
                                       # primary node when a failover occurs.  
                                       # 0 means no timeout, keep searching  
                                       # for a primary node forever.  
    
    #------------------------------------------------------------------------------  
    # ONLINE RECOVERY  
    #------------------------------------------------------------------------------  
    
    recovery_user = 'nobody'  
                                       # Online recovery user  
    recovery_password = ''  
                                       # Online recovery password  
                                       # Leaving it empty will make Pgpool-II to first look for the  
                                       # Password in pool_passwd file before using the empty password  
    
    recovery_1st_stage_command = ''  
                                       # Executes a command in first stage  
    recovery_2nd_stage_command = ''  
                                       # Executes a command in second stage  
    recovery_timeout = 90  
                                       # Timeout in seconds to wait for the  
                                       # recovering node's postmaster to start up  
                                       # 0 means no wait  
    client_idle_limit_in_recovery = 0  
                                       # Client is disconnected after being idle  
                                       # for that many seconds in the second stage  
                                       # of online recovery  
                                       # 0 means no disconnection  
                                       # -1 means immediate disconnection  
    
    auto_failback = off  
                                       # Detached backend node reattach automatically  
                                       # if replication_state is 'streaming'.  
    auto_failback_interval = 60  
                                       # Min interval of executing auto_failback in  
                                       # seconds.  
    
    #------------------------------------------------------------------------------  
    # WATCHDOG  
    #------------------------------------------------------------------------------  
    
    # - Enabling -  
    
    use_watchdog = off  
                                        # Activates watchdog  
                                        # (change requires restart)  
    
    # -Connection to up stream servers -  
    
    trusted_servers = ''  
                                        # trusted server list which are used  
                                        # to confirm network connection  
                                        # (hostA,hostB,hostC,...)  
                                        # (change requires restart)  
    ping_path = '/bin'  
                                        # ping command path  
                                        # (change requires restart)  
    
    # - Watchdog communication Settings -  
    
    wd_hostname = ''  
                                        # Host name or IP address of this watchdog  
                                        # (change requires restart)  
    wd_port = 9000  
                                        # port number for watchdog service  
                                        # (change requires restart)  
    wd_priority = 1  
                                        # priority of this watchdog in leader election  
                                        # (change requires restart)  
    
    wd_authkey = ''  
                                        # Authentication key for watchdog communication  
                                        # (change requires restart)  
    
    wd_ipc_socket_dir = '/tmp'  
                                        # Unix domain socket path for watchdog IPC socket  
                                        # The Debian package defaults to  
                                        # /var/run/postgresql  
                                        # (change requires restart)  
    
    
    # - Virtual IP control Setting -  
    
    delegate_IP = ''  
                                        # delegate IP address  
                                        # If this is empty, virtual IP never bring up.  
                                        # (change requires restart)  
    if_cmd_path = '/sbin'  
                                        # path to the directory where if_up/down_cmd exists  
                                        # If if_up/down_cmd starts with "/", if_cmd_path will be ignored.  
                                        # (change requires restart)  
    if_up_cmd = '/usr/bin/sudo /sbin/ip addr add $_IP_$/24 dev eth0 label eth0:0'  
                                        # startup delegate IP command  
                                        # (change requires restart)  
    if_down_cmd = '/usr/bin/sudo /sbin/ip addr del $_IP_$/24 dev eth0'  
                                        # shutdown delegate IP command  
                                        # (change requires restart)  
    arping_path = '/usr/sbin'  
                                        # arping command path  
                                        # If arping_cmd starts with "/", if_cmd_path will be ignored.  
                                        # (change requires restart)  
    arping_cmd = '/usr/bin/sudo /usr/sbin/arping -U $_IP_$ -w 1 -I eth0'  
                                        # arping command  
                                        # (change requires restart)  
    
    # - Behaviour on escalation Setting -  
    
    clear_memqcache_on_escalation = on  
                                        # Clear all the query cache on shared memory  
                                        # when standby pgpool escalate to active pgpool  
                                        # (= virtual IP holder).  
                                        # This should be off if client connects to pgpool  
                                        # not using virtual IP.  
                                        # (change requires restart)  
    wd_escalation_command = ''  
                                        # Executes this command at escalation on new active pgpool.  
                                        # (change requires restart)  
    wd_de_escalation_command = ''  
                                        # Executes this command when master pgpool resigns from being master.  
                                        # (change requires restart)  
    
    # - Watchdog consensus settings for failover -  
    
    failover_when_quorum_exists = on  
                                        # Only perform backend node failover  
                                        # when the watchdog cluster holds the quorum  
                                        # (change requires restart)  
    
    failover_require_consensus = on  
                                        # Perform failover when majority of Pgpool-II nodes  
                                        # agrees on the backend node status change  
                                        # (change requires restart)  
    
    allow_multiple_failover_requests_from_node = off  
                                        # A Pgpool-II node can cast multiple votes  
                                        # for building the consensus on failover  
                                        # (change requires restart)  
    
    
    enable_consensus_with_half_votes = off  
                                        # apply majority rule for consensus and quorum computation  
                                        # at 50% of votes in a cluster with even number of nodes.  
                                        # when enabled the existence of quorum and consensus  
                                        # on failover is resolved after receiving half of the  
                                        # total votes in the cluster, otherwise both these  
                                        # decisions require at least one more vote than  
                                        # half of the total votes.  
                                        # (change requires restart)  
    
    # - Lifecheck Setting -  
    
    # -- common --  
    
    wd_monitoring_interfaces_list = ''  # Comma separated list of interfaces names to monitor.  
                                        # if any interface from the list is active the watchdog will  
                                        # consider the network is fine  
                                        # 'any' to enable monitoring on all interfaces except loopback  
                                        # '' to disable monitoring  
                                        # (change requires restart)  
    
    wd_lifecheck_method = 'heartbeat'  
                                        # Method of watchdog lifecheck ('heartbeat' or 'query' or 'external')  
                                        # (change requires restart)  
    wd_interval = 10  
                                        # lifecheck interval (sec) > 0  
                                        # (change requires restart)  
    
    # -- heartbeat mode --  
    
    wd_heartbeat_port = 9694  
                                        # Port number for receiving heartbeat signal  
                                        # (change requires restart)  
    wd_heartbeat_keepalive = 2  
                                        # Interval time of sending heartbeat signal (sec)  
                                        # (change requires restart)  
    wd_heartbeat_deadtime = 30  
                                        # Deadtime interval for heartbeat signal (sec)  
                                        # (change requires restart)  
    heartbeat_destination0 = 'host0_ip1'  
                                        # Host name or IP address of destination 0  
                                        # for sending heartbeat signal.  
                                        # (change requires restart)  
    heartbeat_destination_port0 = 9694   
                                        # Port number of destination 0 for sending  
                                        # heartbeat signal. Usually this is the  
                                        # same as wd_heartbeat_port.  
                                        # (change requires restart)  
    heartbeat_device0 = ''  
                                        # Name of NIC device (such like 'eth0')  
                                        # used for sending/receiving heartbeat  
                                        # signal to/from destination 0.  
                                        # This works only when this is not empty  
                                        # and pgpool has root privilege.  
                                        # (change requires restart)  
    
    #heartbeat_destination1 = 'host0_ip2'  
    #heartbeat_destination_port1 = 9694  
    #heartbeat_device1 = ''  
    
    # -- query mode --  
    
    wd_life_point = 3  
                                        # lifecheck retry times  
                                        # (change requires restart)  
    wd_lifecheck_query = 'SELECT 1'  
                                        # lifecheck query to pgpool from watchdog  
                                        # (change requires restart)  
    wd_lifecheck_dbname = 'template1'  
                                        # Database name connected for lifecheck  
                                        # (change requires restart)  
    wd_lifecheck_user = 'nobody'  
                                        # watchdog user monitoring pgpools in lifecheck  
                                        # (change requires restart)  
    wd_lifecheck_password = ''  
                                        # Password for watchdog user in lifecheck  
                                        # Leaving it empty will make Pgpool-II to first look for the  
                                        # Password in pool_passwd file before using the empty password  
                                        # (change requires restart)  
    
    # - Other pgpool Connection Settings -  
    
    #other_pgpool_hostname0 = 'host0'  
                                        # Host name or IP address to connect to for other pgpool 0  
                                        # (change requires restart)  
    #other_pgpool_port0 = 5432  
                                        # Port number for other pgpool 0  
                                        # (change requires restart)  
    #other_wd_port0 = 9000  
                                        # Port number for other watchdog 0  
                                        # (change requires restart)  
    #other_pgpool_hostname1 = 'host1'  
    #other_pgpool_port1 = 5432  
    #other_wd_port1 = 9000  
    
    
    #------------------------------------------------------------------------------  
    # OTHERS  
    #------------------------------------------------------------------------------  
    relcache_expire = 0  
                                       # Life time of relation cache in seconds.  
                                       # 0 means no cache expiration(the default).  
                                       # The relation cache is used for cache the  
                                       # query result against PostgreSQL system  
                                       # catalog to obtain various information  
                                       # including table structures or if it's a  
                                       # temporary table or not. The cache is  
                                       # maintained in a pgpool child local memory  
                                       # and being kept as long as it survives.  
                                       # If someone modify the table by using  
                                       # ALTER TABLE or some such, the relcache is  
                                       # not consistent anymore.  
                                       # For this purpose, cache_expiration  
                                       # controls the life time of the cache.  
    relcache_size = 8192  
                                       # Number of relation cache  
                                       # entry. If you see frequently:  
                                       # "pool_search_relcache: cache replacement happend"  
                                       # in the pgpool log, you might want to increate this number.  
    
    check_temp_table = catalog  
                                       # Temporary table check method. catalog, trace or none.  
                                       # Default is catalog.  
    
    check_unlogged_table = on  
                                       # If on, enable unlogged table check in SELECT statements.  
                                       # This initiates queries against system catalog of primary/master  
                                       # thus increases load of master.  
                                       # If you are absolutely sure that your system never uses unlogged tables  
                                       # and you want to save access to primary/master, you could turn this off.  
                                       # Default is on.  
    enable_shared_relcache = on  
                                       # If on, relation cache stored in memory cache,  
                                       # the cache is shared among child process.  
                                       # Default is on.  
                                       # (change requires restart)  
    
    relcache_query_target = master     # Target node to send relcache queries. Default is master (primary) node.  
                                       # If load_balance_node is specified, queries will be sent to load balance node.  
    #------------------------------------------------------------------------------  
    # IN MEMORY QUERY MEMORY CACHE  
    #------------------------------------------------------------------------------  
    memory_cache_enabled = off  
                                       # If on, use the memory cache functionality, off by default  
                                       # (change requires restart)  
    memqcache_method = 'shmem'  
                                       # Cache storage method. either 'shmem'(shared memory) or  
                                       # 'memcached'. 'shmem' by default  
                                       # (change requires restart)  
    memqcache_memcached_host = 'localhost'  
                                       # Memcached host name or IP address. Mandatory if  
                                       # memqcache_method = 'memcached'.  
                                       # Defaults to localhost.  
                                       # (change requires restart)  
    memqcache_memcached_port = 11211  
                                       # Memcached port number. Mandatory if memqcache_method = 'memcached'.  
                                       # Defaults to 11211.  
                                       # (change requires restart)  
    memqcache_total_size = 67108864  
                                       # Total memory size in bytes for storing memory cache.  
                                       # Mandatory if memqcache_method = 'shmem'.  
                                       # Defaults to 64MB.  
                                       # (change requires restart)  
    memqcache_max_num_cache = 1000000  
                                       # Total number of cache entries. Mandatory  
                                       # if memqcache_method = 'shmem'.  
                                       # Each cache entry consumes 48 bytes on shared memory.  
                                       # Defaults to 1,000,000(45.8MB).  
                                       # (change requires restart)  
    memqcache_expire = 0  
                                       # Memory cache entry life time specified in seconds.  
                                       # 0 means infinite life time. 0 by default.  
                                       # (change requires restart)  
    memqcache_auto_cache_invalidation = on  
                                       # If on, invalidation of query cache is triggered by corresponding  
                                       # DDL/DML/DCL(and memqcache_expire).  If off, it is only triggered  
                                       # by memqcache_expire.  on by default.  
                                       # (change requires restart)  
    memqcache_maxcache = 409600  
                                       # Maximum SELECT result size in bytes.  
                                       # Must be smaller than memqcache_cache_block_size. Defaults to 400KB.  
                                       # (change requires restart)  
    memqcache_cache_block_size = 1048576  
                                       # Cache block size in bytes. Mandatory if memqcache_method = 'shmem'.  
                                       # Defaults to 1MB.  
                                       # (change requires restart)  
    memqcache_oiddir = '/var/log/pgpool/oiddir'  
                                       # Temporary work directory to record table oids  
                                       # (change requires restart)  
    white_memqcache_table_list = ''  
                                       # Comma separated list of table names to memcache  
                                       # that don't write to database  
                                       # Regexp are accepted  
    black_memqcache_table_list = ''  
                                       # Comma separated list of table names not to memcache  
                                       # that don't write to database  
                                       # Regexp are accepted  

    You must reconfigure the following parameters:

    listen_addresses = '0.0.0.0'  
    port = 8001  
    socket_dir = '/tmp'  
    reserved_connections = 0  
    
    pcp_listen_addresses = ''  
    pcp_port = 9898  
    pcp_socket_dir = '/tmp'  
    
    # - Backend Connection Settings -  
    
    backend_hostname0 = '127.0.0.1'  
                                       # Host name or IP address to connect to for backend 0  
    backend_port0 = 3389   
                                       # Port number for backend 0  
    backend_weight0 = 1  
                                       # Weight for backend 0 (only in load balancing mode)  
    backend_data_directory0 = '/data01/pg12_3389/pg_data'  
                                       # Data directory for backend 0  
    backend_flag0 = 'ALWAYS_MASTER'  
                                       # Controls various backend behavior  
                                       # ALLOW_TO_FAILOVER, DISALLOW_TO_FAILOVER  
                                       # or ALWAYS_MASTER  
    backend_application_name0 = 'server0'  
                                       # walsender's application_name, used for "show pool_nodes" command  
    backend_hostname1 = '127.0.0.1'  
    backend_port1 = 8002  
    backend_weight1 = 1  
    backend_data_directory1 = '/data01/pg12_8002/pg_data'  
    backend_flag1 = 'DISALLOW_TO_FAILOVER'  
    backend_application_name1 = 'server1'  
    
    # - Authentication -  
    
    enable_pool_hba = on   
    
                                       # Use pool_hba.conf for client authentication  
    pool_passwd = 'pool_passwd'  
                                       # File name of pool_passwd for md5 authentication.  
                                       # "" disables pool_passwd.  
                                       # (change requires restart)  
    allow_clear_text_frontend_auth = off  
                                       # Allow Pgpool-II to use clear text password authentication  
                                       # with clients, when pool_passwd does not  
                                       # contain the user password  
    
    # - Concurrent session and pool size -  
    
    num_init_children = 128   
                                       # Number of concurrent sessions allowed  
                                       # (change requires restart)  
    max_pool = 4  
                                       # Number of connection pool caches per connection  
                                       # (change requires restart)  
    
    # - Life time -  
    
    child_life_time = 300  
                                       # Pool exits after being idle for this many seconds  
    child_max_connections = 0  
                                       # Pool exits after receiving that many connections  
                                       # 0 means no exit  
    connection_life_time = 0  
                                       # Connection to backend closes after being idle for this many seconds  
                                       # 0 means no close  
    client_idle_limit = 0  
                                       # Client is disconnected after being idle for that many seconds  
                                       # (even inside an explicit transactions!)  
                                       # 0 means no disconnection  
    
    #------------------------------------------------------------------------------  
    # LOGS  
    #------------------------------------------------------------------------------  
    
    # - Where to log -  
    
    log_destination = 'syslog'  
                                       # Where to log  
                                       # Valid values are combinations of stderr,  
                                       # and syslog. Default to stderr.  
    log_connections = on  
                                       # Log connections  
    
    log_standby_delay = 'if_over_threshold'  
                                       # Log standby delay  
                                       # Valid values are combinations of always,  
                                       # if_over_threshold, none  
    
    #------------------------------------------------------------------------------  
    # FILE LOCATIONS  
    #------------------------------------------------------------------------------  
    
    pid_file_name = '/var/run/pgpool-II-12/pgpool.pid'  
                                       # PID file name  
                                       # Can be specified as relative to the"  
                                       # location of pgpool.conf file or  
                                       # as an absolute path  
                                       # (change requires restart)  
    logdir = '/tmp'  
                                       # Directory of pgPool status file  
                                       # (change requires restart)  
    
    #------------------------------------------------------------------------------  
    # CONNECTION POOLING  
    #------------------------------------------------------------------------------  
    
    connection_cache = on  
                                       # Activate connection pools  
                                       # (change requires restart)  
    
                                       # Semicolon separated list of queries  
                                       # to be issued at the end of a session  
                                       # The default is for 8.3 and later  
    reset_query_list = 'ABORT; DISCARD ALL'  
    
    #------------------------------------------------------------------------------  
    # LOAD BALANCING MODE  
    #------------------------------------------------------------------------------  
    
    load_balance_mode = on  
                                       # Activate load balancing mode  
                                       # (change requires restart)  
    ignore_leading_white_space = on  
                                       # Ignore leading white spaces of each query  
    white_function_list = ''  
                                       # Comma separated list of function names  
                                       # that don't write to database  
                                       # Regexp are accepted  
    black_function_list = 'currval,lastval,nextval,setval'  
                                       # Comma separated list of function names  
                                       # that write to database  
                                       # Regexp are accepted  
    
    black_query_pattern_list = ''  
                                       # Semicolon separated list of query patterns  
                                       # that should be sent to primary node  
                                       # Regexp are accepted  
                                       # valid for streaming replication mode only.  
    
    database_redirect_preference_list = ''  
                                       # comma separated list of pairs of database and node id.  
                                       # example: postgres:primary,mydb[0-4]:1,mydb[5-9]:2'  
                                       # valid for streaming replication mode only.  
    
    app_name_redirect_preference_list = ''  
                                       # comma separated list of pairs of app name and node id.  
                                       # example: 'psql:primary,myapp[0-4]:1,myapp[5-9]:standby'  
                                       # valid for streaming replication mode only.  
    allow_sql_comments = off  
                                       # if on, ignore SQL comments when judging if load balance or  
                                       # query cache is possible.  
                                       # If off, SQL comments effectively prevent the judgment  
                                       # (pre 3.4 behavior).  
    
    disable_load_balance_on_write = 'transaction'  
                                       # Load balance behavior when write query is issued  
                                       # in an explicit transaction.  
                                       # Note that any query not in an explicit transaction  
                                       # is not affected by the parameter.  
                                       # 'transaction' (the default): if a write query is issued,  
                                       # subsequent read queries will not be load balanced  
                                       # until the transaction ends.  
                                       # 'trans_transaction': if a write query is issued,  
                                       # subsequent read queries in an explicit transaction  
                                       # will not be load balanced until the session ends.  
                                       # 'always': if a write query is issued, read queries will  
                                       # not be load balanced until the session ends.  
    
    statement_level_load_balance = off  
                                       # Enables statement level load balancing  
    
    #------------------------------------------------------------------------------  
    # MASTER/SLAVE MODE  
    #------------------------------------------------------------------------------  
    
    master_slave_mode = on  
                                       # Activate master/slave mode  
                                       # (change requires restart)  
    master_slave_sub_mode = 'stream'  
                                       # Master/slave sub mode  
                                       # Valid values are combinations stream, slony  
                                       # or logical. Default is stream.  
                                       # (change requires restart)  
    
    # - Streaming -  
    
    sr_check_period = 3   
                                       # Streaming replication check period  
                                       # Disabled (0) by default  
    sr_check_user = 'nobody'  
                                       # Streaming replication check user  
                                       # This is necessary even if you disable streaming  
                                       # replication delay check by sr_check_period = 0  
    sr_check_password = ''  
                                       # Password for streaming replication check user  
                                       # Leaving it empty will make Pgpool-II to first look for the  
                                       # Password in pool_passwd file before using the empty password  
    
    sr_check_database = 'postgres'  
                                       # Database name for streaming replication check  
    delay_threshold = 512000  
                                       # Threshold before not dispatching query to standby node  
                                       # Unit is in bytes  
                                       # Disabled (0) by default  
    
    
    #------------------------------------------------------------------------------  
    # HEALTH CHECK GLOBAL PARAMETERS  
    #------------------------------------------------------------------------------  
    
    health_check_period = 5  
                                       # Health check period  
                                       # Disabled (0) by default  
    health_check_timeout = 10  
                                       # Health check timeout  
                                       # 0 means no timeout  
    health_check_user = 'nobody'  
                                       # Health check user  
    health_check_password = ''  
                                       # Password for health check user  
                                       # Leaving it empty will make Pgpool-II to first look for the  
                                       # Password in pool_passwd file before using the empty password  
    
    health_check_database = ''  
                                       # Database name for health check. If '', tries 'postgres' first,   
    health_check_max_retries = 60   
                                       # Maximum number of times to retry a failed health check before giving up.  
    health_check_retry_delay = 1  
                                       # Amount of time to wait (in seconds) between retries.  
    connect_timeout = 10000  
                                       # Timeout value in milliseconds before giving up to connect to backend.  
                                       # Default is 10000 ms (10 second). Flaky network user may want to increase  
                                       # the value. 0 means no timeout.  
                                       # Note that this value is not only used for health check,  
                                       # but also for ordinary connection to backend.  
    
    #------------------------------------------------------------------------------  
    # FAILOVER AND FAILBACK  
    #------------------------------------------------------------------------------  
    
    failover_on_backend_error = off  
                                       # Initiates failover when reading/writing to the  
                                       # backend communication socket fails  
                                       # If set to off, pgpool will report an  
                                       # error and disconnect the session.  
    
    
    relcache_expire = 0  # After the configuration file is restructured, we recommend that you set this parameter to 1, reload the configuration file, and then set this parameter to 0 again. You also have the option to set this parameter to a specific point in time.      
                                       # Life time of relation cache in seconds.  
                                       # 0 means no cache expiration(the default).  
                                       # The relation cache is used for cache the  
                                       # query result against PostgreSQL system  
                                       # catalog to obtain various information  
                                       # including table structures or if it's a  
                                       # temporary table or not. The cache is  
                                       # maintained in a pgpool child local memory  
                                       # and being kept as long as it survives.  
                                       # If someone modify the table by using  
                                       # ALTER TABLE or some such, the relcache is  
                                       # not consistent anymore.  
                                       # For this purpose, cache_expiration  
                                       # controls the life time of the cache.  
    relcache_size = 8192  
                                       # Number of relation cache  
                                       # entry. If you see frequently:  
                                       # "pool_search_relcache: cache replacement happend"  
                                       # in the pgpool log, you might want to increate this number.  
  3. Configure the pool_passwd file.
    Note If you connect to your RDS instances by using pgpool, you must configure the pool_passwd file because pgpool supports the authentication protocol of PostgreSQL.
    cd /etc/pgpool-II-12  
    
    # Run the following command:  
    #pg_md5 --md5auth --username=username password  
    # Generate the passwords of the digoal and nobody users. The passwords are automatically written into the pool_passwd file. 
    pg_md5 --md5auth --username=digoal "xxxxxxx"  
    pg_md5 --md5auth --username=nobody "xxxxxxx"  
  4. Use the system to automatically generate the pool_passwd file.
    cd /etc/pgpool-II-12  
    cat pool_passwd   
    digoal:md54dd55116da69d3d03bf2e3a1470564f9  
    nobody:md54240e76623e2511d607f431043a5d1c1 
  5. Configure the pgpool_hba file.
    cd /etc/pgpool-II-12  
    cp pool_hba.conf.sample pool_hba.conf  
    vi pool_hba.conf  
    
    host all all 0.0.0.0/0 md5  
  6. Configure the pcp.conf file.
    Note The pcp.conf file is used to manage the users and passwords of pgpool. It is not related to the users and passwords of your RDS instances.
    cd /etc/pgpool-II-12  
    
    # pg_md5 abc  # In this command, you set the password to abc and encrypt it by using the MD5 encryption algorithm.   
    900150983cd24fb0d6963f7d28e17f72  
    
    cp pcp.conf.sample pcp.conf  
    
    vi pcp.conf  
    
    USERID:MD5PASSWD  
    manage:900150983cd24fb0d6963f7d28e17f72  # In this command, the manage user is used to manage PCP. 
  7. Start pgpool.
    cd /etc/pgpool-II-12  
    pgpool -f ./pgpool.conf -a ./pool_hba.conf -F ./pcp.conf  
    Note If you want to view the logs of pgpool, run the following command:
    less /var/log/messages   
  8. Use pgpool to connect to your RDS instances.
    psql -h 127.0.0.1 -p 8001 -U digoal postgres  
    Connection established

FAQ

  • How do I test whether read/write splitting is implemented?

    You can connect to your RDS instances by using pgpool and call the pg_is_in_recovery() function. Then, close the connection, re-establish a connection, and call the pg_is_in_recovery() function again. If you receive the value false and then the value true, pgpool routes requests to your primary RDS instance and then to your read-only RDS instances. This indicates that read/write splitting is successful.

  • Does pgpool increase the latency?

    pgpool increases the latency slightly. In the test environment you set up in this topic, the latency increases by about 0.12 milliseconds.

  • How does pgpool check the latency and health on my read-only RDS instances?
    • If the WAL replay latency on a read-only RDS instance exceeds the specified limit, pgpool stops routing SQL requests to the read-only instance. pgpool resumes routing SQL requests to the read-only instance only after it detects that the WAL replay latency on the read-only instance falls below the specified limit.
      Note You can connect to your primary RDS instance and query the location in which the current WAL data record is written. This location is referred to as log sequence number (LSN) 1. Then, connect to a read-only RDS instance and query the location in which the current WAL data record is replayed. This location is referred to as LSN 2. You can obtain the number of bytes between LSN 1 and LSN 2. This number indicates the latency.
    • pgpool monitors the health of your read-only RDS instances. If a read-only RDS instance is unhealthy, pgpool stops routing requests to the read-only instance.
  • How do I stop pgpool and reload the configuration of pgpool?
    Run the pgpool --help command to obtain more information about the commands used in pgpool. Example:
    cd /etc/pgpool-II-12  
    pgpool -f ./pgpool.conf -m fast stop   
  • How do I configure pgpool if more than one read-only RDS instance is attached to my primary RDS instance?

    Add the configurations of all the attached read-only RDS instances to the pgpool.conf file. Example:

    backend_hostname1 = 'xx.xx.xxx.xx'  
    backend_port1 = 8002  
    backend_weight1 = 1  
    backend_data_directory1 = '/data01/pg12_8002/pg_data'  
    backend_flag1 = 'DISALLOW_TO_FAILOVER'  
    backend_application_name1 = 'server1'  
    
    backend_hostname2 = 'xx.xx.xx.xx'  
    backend_port1 = 8002  
    backend_weight1 = 1  
    backend_data_directory1 = '/data01/pg12_8002/pg_data'  
    backend_flag1 = 'DISALLOW_TO_FAILOVER'  
    backend_application_name1 = 'server1'  
  • How do I use pcp to view the status of my read-only RDS instances?

    To obtain the status of your read-only RDS instances by using pcp, run the following command:

    # pcp_node_info -U manage -h /tmp -p 9898 -n 1 -v  
    Password: Enter the password.  
    
    
    Hostname               : 127.0.0.1  
    Port                   : 8002  
    Status                 : 2  
    Weight                 : 0.500000  
    Status Name            : up  
    Role                   : standby  
    Replication Delay      : 0  
    Replication State      :   
    Replication Sync State :   
    Last Status Change     : 2020-02-29 00:20:29  
  • Which listening ports are used by pgpool for read/write splitting?

    The following listening ports are used by pgpool for read/write splitting:

    • Primary RDS instance: Port 3389
    • Secondary RDS instance: Port 8002
    • pgpool: Port 8001
    • pcp: Port 9898