#-----------------------------# cluster: pg-test#-----------------------------pg-test:# define cluster named 'pg-test'# - cluster members - #hosts:10.10.10.11:{pg_seq: 1, pg_role: primary, ansible_host:node-1}10.10.10.12:{pg_seq: 2, pg_role: replica, ansible_host:node-2}10.10.10.13:{pg_seq: 3, pg_role: offline, ansible_host:node-3}# - cluster configs - #vars:# basic settingspg_cluster:pg-test # define actual cluster namepg_version:13# define installed pgsql versionnode_tune:tiny # tune node into oltp|olap|crit|tiny modepg_conf:tiny.yml # tune pgsql into oltp/olap/crit/tiny mode# business users, adjust on your own needspg_users:- name:test # example production user have read-write accesspassword:test # example user's passwordroles:[dbrole_readwrite] # dborole_admin|dbrole_readwrite|dbrole_readonly|dbrole_offlinepgbouncer:true# production user that access via pgbouncercomment:default test user for production usagepg_databases:# create a business database 'test'- name:test # use the simplest formpg_default_database:test # default database will be used as primary monitor target# proxy settingsvip_mode:l2 # enable/disable vip (require members in same LAN)vip_address:10.10.10.3# virtual ip addressvip_cidrmask:8# cidr network mask lengthvip_interface:eth1 # interface to add virtual ip
- name:primary # service name {{ pg_cluster }}_primarysrc_ip:"*"src_port:5433dst_port:pgbouncer # 5433 route to pgbouncercheck_url:/primary # primary health check, success when instance is primaryselector:"[]"# select all instance as primary service candidate
# replica service will route {ip|name}:5434 to replica pgbouncer (5434->6432 ro)- name:replica # service name {{ pg_cluster }}_replicasrc_ip:"*"src_port:5434dst_port:pgbouncercheck_url:/read-only # read-only health check. (including primary)selector:"[]"# select all instance as replica service candidateselector_backup:"[? pg_role == `primary`]"# primary are used as backup server in replica service
# default service will route {ip|name}:5436 to primary postgres (5436->5432 primary)- name:default # service's actual name is {{ pg_cluster }}-{{ service.name }}src_ip:"*"# service bind ip address, * for all, vip for cluster virtual ip addresssrc_port:5436# bind port, mandatorydst_port: postgres # target port:postgres|pgbouncer|port_number , pgbouncer(6432) by defaultcheck_method: http # health check method:only http is available for nowcheck_port: patroni # health check port:patroni|pg_exporter|port_number , patroni by defaultcheck_url:/primary # health check url path, / as defaultcheck_code:200# health check http code, 200 as defaultselector:"[]"# instance selectorhaproxy:# haproxy specific fieldsmaxconn:3000# default front-end connectionbalance:roundrobin # load balance algorithm (roundrobin by default)default_server_options:'inter 3s fastinter 1s downinter 5s rise 3 fall 3 on-marked-down shutdown-sessions slowstart 30s maxconn 3000 maxqueue 128 weight 100'
# offline service will route {ip|name}:5438 to offline postgres (5438->5432 offline)- name:offline # service name {{ pg_cluster }}_replicasrc_ip:"*"src_port:5438dst_port:postgrescheck_url:/replica # offline MUST be a replicaselector:"[? pg_role == `offline` || pg_offline_query ]"# instances with pg_role == 'offline' or instance marked with 'pg_offline_query == true'selector_backup:"[? pg_role == `replica` && !pg_offline_query]"# replica are used as backup server in offline service
# primary service will route {ip|name}:5433 to primary pgbouncer (5433->6432 rw)- name:primary # service name {{ pg_cluster }}_primarysrc_ip:"*"src_port:5433dst_port:pgbouncer # 5433 route to pgbouncercheck_url:/primary # primary health check, success when instance is primaryselector:"[]"# select all instance as primary service candidate# replica service will route {ip|name}:5434 to replica pgbouncer (5434->6432 ro)- name:replica # service name {{ pg_cluster }}_replicasrc_ip:"*"src_port:5434dst_port:pgbouncercheck_url:/read-only # read-only health check. (including primary)selector:"[]"# select all instance as replica service candidateselector_backup:"[? pg_role == `primary`]"# primary are used as backup server in replica service# default service will route {ip|name}:5436 to primary postgres (5436->5432 primary)- name:default # service's actual name is {{ pg_cluster }}-{{ service.name }}src_ip:"*"# service bind ip address, * for all, vip for cluster virtual ip addresssrc_port:5436# bind port, mandatorydst_port: postgres # target port:postgres|pgbouncer|port_number , pgbouncer(6432) by defaultcheck_method: http # health check method:only http is available for nowcheck_port: patroni # health check port:patroni|pg_exporter|port_number , patroni by defaultcheck_url:/primary # health check url path, / as defaultcheck_code:200# health check http code, 200 as defaultselector:"[]"# instance selectorhaproxy:# haproxy specific fieldsmaxconn:3000# default front-end connectionbalance:roundrobin # load balance algorithm (roundrobin by default)default_server_options:'inter 3s fastinter 1s downinter 5s rise 3 fall 3 on-marked-down shutdown-sessions slowstart 30s maxconn 3000 maxqueue 128 weight 100'# offline service will route {ip|name}:5438 to offline postgres (5438->5432 offline)- name:offline # service name {{ pg_cluster }}_replicasrc_ip:"*"src_port:5438dst_port:postgrescheck_url:/replica # offline MUST be a replicaselector:"[? pg_role == `offline` || pg_offline_query ]"# instances with pg_role == 'offline' or instance marked with 'pg_offline_query == true'selector_backup:"[? pg_role == `replica` && !pg_offline_query]"# replica are used as backup server in offline service
# - system roles - #pg_replication_username:replicator # system replication userpg_replication_password:DBUser.Replicator # system replication passwordpg_monitor_username:dbuser_monitor # system monitor userpg_monitor_password:DBUser.Monitor # system monitor passwordpg_admin_username:dbuser_admin # system admin userpg_admin_password:DBUser.Admin # system admin password# - default roles - ## chekc http://pigsty.cc/zh/docs/concepts/provision/acl/ for more detailpg_default_roles:# common production readonly user- name:dbrole_readonly # production read-only roleslogin:falsecomment:role for global readonly access# common production read-write user- name:dbrole_readwrite # production read-write roleslogin:falseroles:[dbrole_readonly] # read-write includes read-only accesscomment:role for global read-write access# offline have same privileges as readonly, but with limited hba access on offline instance only# for the purpose of running slow queries, interactive queries and perform ETL tasks- name:dbrole_offlinelogin:falsecomment:role for restricted read-only access (offline instance)# admin have the privileges to issue DDL changes- name:dbrole_adminlogin:falsebypassrls:truecomment:role for object creationroles:[dbrole_readwrite,pg_monitor,pg_signal_backend]# dbsu, name is designated by `pg_dbsu`. It's not recommend to set password for dbsu- name:postgressuperuser:truecomment:system superuser# default replication user, name is designated by `pg_replication_username`, and password is set by `pg_replication_password`- name:replicatorreplication:trueroles:[pg_monitor, dbrole_readonly]comment:system replicator# default replication user, name is designated by `pg_monitor_username`, and password is set by `pg_monitor_password`- name:dbuser_monitorconnlimit:16comment:system monitor userroles:[pg_monitor, dbrole_readonly]# default admin user, name is designated by `pg_admin_username`, and password is set by `pg_admin_password`- name:dbuser_adminbypassrls:truecomment:system admin userroles:[dbrole_admin]# default stats user, for ETL and slow queries- name:dbuser_statspassword:DBUser.Statscomment:business offline user for offline queries and ETLroles:[dbrole_offline]
pg_databases:- name:meta # name is the only required field for a databaseowner:postgres # optional, database ownertemplate:template1 # optional, template1 by defaultencoding:UTF8 # optional, UTF8 by defaultlocale:C # optional, C by defaultallowconn:true# optional, true by default, false disable connect at allrevokeconn:false# optional, false by default, true revoke connect from public # (only default user and owner have connect privilege on database)tablespace:pg_default # optional, 'pg_default' is the default tablespaceconnlimit:-1# optional, connection limit, -1 or none disable limit (default)extensions:# optional, extension name and where to create- {name: postgis, schema:public}parameters:# optional, extra parameters with ALTER DATABASEenable_partitionwise_join:truepgbouncer:true# optional, add this database to pgbouncer list? true by defaultcomment:pigsty meta database # optional, comment string for database
#==============================================================## Default HBA#==============================================================## allow local su with ident"local all postgres identlocal replication postgres ident# allow local user password accesslocal all all md5# allow local/intranet replication with passwordlocal replication replicator md5host replication replicator 127.0.0.1/32 md5host all replicator 10.0.0.0/8 md5host all replicator 172.16.0.0/12 md5host all replicator 192.168.0.0/16 md5host replication replicator 10.0.0.0/8 md5host replication replicator 172.16.0.0/12 md5host replication replicator 192.168.0.0/16 md5# allow local role monitor with passwordlocal all dbuser_monitor md5host all dbuser_monitor 127.0.0.1/32 md5#==============================================================## Extra HBA#==============================================================## add extra hba rules here#==============================================================## primary HBA#==============================================================##==============================================================## special HBA for instance marked with 'pg_offline_query = true'#==============================================================##==============================================================## Common HBA#==============================================================## allow meta node password accesshost all all 10.10.10.10/32 md5# allow intranet admin password accesshost all +dbrole_admin 10.0.0.0/8 md5host all +dbrole_admin 172.16.0.0/12 md5host all +dbrole_admin 192.168.0.0/16 md5# allow intranet password accesshost all all 10.0.0.0/8 md5host all all 172.16.0.0/12 md5host all all 192.168.0.0/16 md5# allow local read/write (local production user via pgbouncer)local all +dbrole_readonly md5host all +dbrole_readonly 127.0.0.1/32 md5#==============================================================## Ad Hoc HBA#===========================================================