├── LICENSE ├── README.md ├── osx_arch_linux_qemu ├── README.md ├── enoch_rev2839_boot └── start_mac.sh └── postgresql_repmgr_pgbouncer ├── README.md ├── etc └── repmgr.conf ├── pgbouncer ├── pgbouncer.database.ini ├── pgbouncer.ini └── userlist.txt ├── postgresql ├── pg_hba.conf ├── pg_ident.conf └── postgresql.conf ├── repmgr └── promote.sh └── walk.txt /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tutorials -------------------------------------------------------------------------------- /osx_arch_linux_qemu/README.md: -------------------------------------------------------------------------------- 1 | Running OSX on arch linux with qemu 2 | 3 | https://drive.google.com/drive/folders/0B9yc23K1dK0JSEFEc0VOVjkzdUk 4 | 5 | https://github.com/kholia/OSX-KVM/raw/master/enoch_rev2839_boot 6 | 7 | 8 | pacman -S qemu bridge-utils libvirt firewalld 9 | 10 | 11 | qemu-img convert -p -O qcow2 OSX-Capitan.vmdk OSX-Capitan.qcow2 12 | -------------------------------------------------------------------------------- /osx_arch_linux_qemu/enoch_rev2839_boot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nirzaf/tutorials/41e5bf65ee56a65714f0937ed6397afb8c98a641/osx_arch_linux_qemu/enoch_rev2839_boot -------------------------------------------------------------------------------- /osx_arch_linux_qemu/start_mac.sh: -------------------------------------------------------------------------------- 1 | systemctl start firewalld 2 | echo -e '\x1B[01;93m[*] firewalld service start!' 3 | systemctl start libvirtd 4 | echo -e '\x1B[01;93m[*] libvirtd deamon start!' 5 | 6 | ip tuntap add dev tap0 mode tap > /dev/null 2>&1 7 | ip link set tap0 up promisc on > /dev/null 2>&1 8 | 9 | echo -e '\033[0;32m[+] tap0 interface is ready' 10 | 11 | if ! (/usr/bin/ethtool virbr0 | grep -q "Link detected: no") > /dev/null 2>&1 ; then 12 | echo -e '\x1B[01;93m[!] WAITING FOR "virbr0" ...' 13 | fi 14 | 15 | while : 16 | do 17 | if (/usr/bin/ethtool virbr0 | grep -q "Link detected: no") > /dev/null 2>&1 ; then 18 | echo -e '\033[0;32m[+] virbr0 interface is ready.' 19 | brctl addif virbr0 tap0 > /dev/null 2>&1 20 | echo -e '\033[0;32m[+] virbr0 bridge success!' 21 | 22 | break 23 | fi 24 | done 25 | 26 | /usr/bin/qemu-system-x86_64 -enable-kvm -m 8192 -cpu core2duo,kvm=off -machine pc-q35-2.4 -smp 4,cores=2 -usb -device usb-kbd -device usb-mouse -device isa-applesmc,osk="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc" -kernel "/media/VMS-HDD/OSX/enoch_rev2839_boot" -smbios type=2 -daemonize -hda "/media/VMS-HDD/OSX/OSX-Capitan.qcow2" -netdev tap,id=net0,ifname=tap0,script=no,downscript=no -device e1000-82545em,netdev=net0,id=net0,mac=52:54:00:c9:18:27 > /dev/null 2>&1 27 | echo -e '\033[0;32m[+] Mac Start Success!' 28 | -------------------------------------------------------------------------------- /postgresql_repmgr_pgbouncer/README.md: -------------------------------------------------------------------------------- 1 | Installing and Configuring 3 postgresql server with replication ( master, slave) and repmgr for failover with pgbouncer for connection pooling 2 | -------------------------------------------------------------------------------- /postgresql_repmgr_pgbouncer/etc/repmgr.conf: -------------------------------------------------------------------------------- 1 | failover=automatic 2 | promote_command=/var/lib/pgsql/repmgr/promote.sh 3 | follow_command='repmgr standby follow -f /etc/repmgr.conf --log-to-file' 4 | cluster=cluster1 5 | node=2 6 | node_name=p2 7 | conninfo='host=p2 user=repmgr dbname=repmgr' 8 | master_response_timeout=30 9 | pg_bindir=/usr/local/bin/ 10 | service_start_command = systemctl start postgresql-9.6 11 | service_stop_command = systemctl stop postgresql-9.6 12 | service_restart_command = systemctl restart postgresql-9.6 13 | -------------------------------------------------------------------------------- /postgresql_repmgr_pgbouncer/pgbouncer/pgbouncer.database.ini: -------------------------------------------------------------------------------- 1 | [databases] 2 | 3 | test_db= host=p1 dbname=test_db -------------------------------------------------------------------------------- /postgresql_repmgr_pgbouncer/pgbouncer/pgbouncer.ini: -------------------------------------------------------------------------------- 1 | ;; database name = connect string 2 | ;; 3 | ;; connect string params: 4 | ;; dbname= host= port= user= password= 5 | ;; client_encoding= datestyle= timezone= 6 | ;; pool_size= connect_query= 7 | [databases] 8 | 9 | ; foodb over unix socket 10 | ;foodb = 11 | 12 | ; redirect bardb to bazdb on localhost 13 | ;bardb = host=localhost dbname=bazdb 14 | 15 | %include /etc/pgbouncer/pgbouncer.database.ini 16 | 17 | ; access to dest database will go with single user 18 | ;forcedb = host=127.0.0.1 port=300 user=baz password=foo client_encoding=UNICODE datestyle=ISO connect_query='SELECT 1' 19 | 20 | ; use custom pool sizes 21 | ;nondefaultdb = pool_size=50 reserve_pool_size=10 22 | 23 | ; fallback connect string 24 | ;* = host=testserver 25 | 26 | ;; Configuration section 27 | [pgbouncer] 28 | 29 | ;;; 30 | ;;; Administrative settings 31 | ;;; 32 | 33 | logfile = /var/log/pgbouncer/pgbouncer.log 34 | pidfile = /var/run/pgbouncer/pgbouncer.pid 35 | 36 | ;;; 37 | ;;; Where to wait for clients 38 | ;;; 39 | 40 | ; ip address or * which means all ip-s 41 | listen_addr = * 42 | listen_port = 6432 43 | 44 | ; unix socket is also used for -R. 45 | ; On debian it should be /var/run/postgresql 46 | ;unix_socket_dir = /tmp 47 | ;unix_socket_mode = 0777 48 | ;unix_socket_group = 49 | 50 | ;;; 51 | ;;; TLS settings for accepring clients 52 | ;;; 53 | 54 | ;; disable, allow, require, verify-ca, verify-full 55 | ;client_tls_sslmode = disable 56 | 57 | ;; Path to file that contains trusted CA certs 58 | ;client_tls_ca_file = 59 | 60 | ;; Private key and cert to present to clients. 61 | ;; Required for accepting TLS connections from clients. 62 | ;client_tls_key_file = 63 | ;client_tls_cert_file = 64 | 65 | ;; fast, normal, secure, legacy, 66 | ;client_tls_ciphers = fast 67 | 68 | ;; all, secure, tlsv1.0, tlsv1.1, tlsv1.2 69 | ;client_tls_protocols = all 70 | 71 | ;; none, auto, legacy 72 | ;client_tls_dheparams = auto 73 | 74 | ;; none, auto, 75 | ;client_tls_ecdhcurve = auto 76 | 77 | ;;; 78 | ;;; TLS settings for connecting to backend databases 79 | ;;; 80 | 81 | ;; disable, allow, require, verify-ca, verify-full 82 | ;server_tls_sslmode = disable 83 | 84 | ;; Path to that contains trusted CA certs 85 | ;server_tls_ca_file = 86 | 87 | ;; Private key and cert to present to backend. 88 | ;; Needed only if backend server require client cert. 89 | ;server_tls_key_file = 90 | ;server_tls_cert_file = 91 | 92 | ;; all, secure, tlsv1.0, tlsv1.1, tlsv1.2 93 | ;server_tls_protocols = all 94 | 95 | ;; fast, normal, secure, legacy, 96 | ;server_tls_ciphers = fast 97 | 98 | ;;; 99 | ;;; Authentication settings 100 | ;;; 101 | 102 | ; any, trust, plain, crypt, md5 103 | auth_type = md5 104 | ;auth_file = /8.0/main/global/pg_auth 105 | auth_file = /etc/pgbouncer/userlist.txt 106 | 107 | ;; Path to HBA-style auth config 108 | ;auth_hba_file = 109 | 110 | ;; Query to use to fetch password from database. Result 111 | ;; must have 2 columns - username and password hash. 112 | ;auth_query = SELECT usename, passwd FROM pg_shadow WHERE usename=$1 113 | 114 | ;;; 115 | ;;; Users allowed into database 'pgbouncer' 116 | ;;; 117 | 118 | ; comma-separated list of users, who are allowed to change settings 119 | admin_users = manager 120 | 121 | ; comma-separated list of users who are just allowed to use SHOW command 122 | stats_users = manager 123 | 124 | ;;; 125 | ;;; Pooler personality questions 126 | ;;; 127 | 128 | ; When server connection is released back to pool: 129 | ; session - after client disconnects 130 | ; transaction - after transaction finishes 131 | ; statement - after statement finishes 132 | pool_mode = transaction 133 | 134 | ; 135 | ; Query for cleaning connection immediately after releasing from client. 136 | ; No need to put ROLLBACK here, pgbouncer does not reuse connections 137 | ; where transaction is left open. 138 | ; 139 | ; Query for 8.3+: 140 | ; DISCARD ALL; 141 | ; 142 | ; Older versions: 143 | ; RESET ALL; SET SESSION AUTHORIZATION DEFAULT 144 | ; 145 | ; Empty if transaction pooling is in use. 146 | ; 147 | server_reset_query = DISCARD ALL 148 | 149 | 150 | ; Whether server_reset_query should run in all pooling modes. 151 | ; If it is off, server_reset_query is used only for session-pooling. 152 | ;server_reset_query_always = 0 153 | 154 | ; 155 | ; Comma-separated list of parameters to ignore when given 156 | ; in startup packet. Newer JDBC versions require the 157 | ; extra_float_digits here. 158 | ; 159 | ;ignore_startup_parameters = extra_float_digits 160 | 161 | ; 162 | ; When taking idle server into use, this query is ran first. 163 | ; SELECT 1 164 | ; 165 | ;server_check_query = select 1 166 | 167 | ; If server was used more recently that this many seconds ago, 168 | ; skip the check query. Value 0 may or may not run in immediately. 169 | ;server_check_delay = 30 170 | 171 | ;; Use as application_name on server. 172 | ;application_name_add_host = 0 173 | 174 | ;;; 175 | ;;; Connection limits 176 | ;;; 177 | 178 | ; total number of clients that can connect 179 | max_client_conn = 100 180 | 181 | ; default pool size. 20 is good number when transaction pooling 182 | ; is in use, in session pooling it needs to be the number of 183 | ; max clients you want to handle at any moment 184 | default_pool_size = 20 185 | 186 | ;; Minimum number of server connections to keep in pool. 187 | min_pool_size = 5 188 | 189 | ; how many additional connection to allow in case of trouble 190 | reserve_pool_size = 5 191 | 192 | ; if a clients needs to wait more than this many seconds, use reserve pool 193 | reserve_pool_timeout = 3 194 | 195 | ; how many total connections to a single database to allow from all pools 196 | ;max_db_connections = 50 197 | ;max_user_connections = 50 198 | 199 | ; If off, then server connections are reused in LIFO manner 200 | ;server_round_robin = 0 201 | 202 | ;;; 203 | ;;; Logging 204 | ;;; 205 | 206 | ;; Syslog settings 207 | ;syslog = 0 208 | ;syslog_facility = daemon 209 | ;syslog_ident = pgbouncer 210 | 211 | ; log if client connects or server connection is made 212 | ;log_connections = 1 213 | 214 | ; log if and why connection was closed 215 | ;log_disconnections = 1 216 | 217 | ; log error messages pooler sends to clients 218 | ;log_pooler_errors = 1 219 | 220 | ;; Period for writing aggregated stats into log. 221 | ;stats_period = 60 222 | 223 | ;; Logging verbosity. Same as -v switch on command line. 224 | ;verbose=0 225 | 226 | ;;; 227 | ;;; Timeouts 228 | ;;; 229 | 230 | ;; Close server connection if its been connected longer. 231 | ;server_lifetime = 1200 232 | 233 | ;; Close server connection if its not been used in this time. 234 | ;; Allows to clean unnecessary connections from pool after peak. 235 | ;server_idle_timeout = 60 236 | 237 | ;; Cancel connection attempt if server does not answer takes longer. 238 | ;server_connect_timeout = 15 239 | 240 | ;; If server login failed (server_connect_timeout or auth failure) 241 | ;; then wait this many second. 242 | ;server_login_retry = 15 243 | 244 | ;; Dangerous. Server connection is closed if query does not return 245 | ;; in this time. Should be used to survive network problems, 246 | ;; _not_ as statement_timeout. (default: 0) 247 | ;query_timeout = 0 248 | 249 | ;; Dangerous. Client connection is closed if the query is not assigned 250 | ;; to a server in this time. Should be used to limit the number of queued 251 | ;; queries in case of a database or network failure. (default: 120) 252 | ;query_wait_timeout = 120 253 | 254 | ;; Dangerous. Client connection is closed if no activity in this time. 255 | ;; Should be used to survive network problems. (default: 0) 256 | ;client_idle_timeout = 0 257 | 258 | ;; Disconnect clients who have not managed to log in after connecting 259 | ;; in this many seconds. 260 | ;client_login_timeout = 60 261 | 262 | ;; Clean automatically created database entries (via "*") if they 263 | ;; stay unused in this many seconds. 264 | ; autodb_idle_timeout = 3600 265 | 266 | ;; How long SUSPEND/-R waits for buffer flush before closing connection. 267 | ;suspend_timeout = 10 268 | 269 | ;; Close connections which are in "IDLE in transaction" state longer than 270 | ;; this many seconds. 271 | ;idle_transaction_timeout = 0 272 | 273 | ;;; 274 | ;;; Low-level tuning options 275 | ;;; 276 | 277 | ;; buffer for streaming packets 278 | ;pkt_buf = 4096 279 | 280 | ;; man 2 listen 281 | ;listen_backlog = 128 282 | 283 | ;; Max number pkt_buf to process in one event loop. 284 | ;sbuf_loopcnt = 5 285 | 286 | ;; Maximum Postgres protocol packet size. 287 | ;max_packet_size = 2147483647 288 | 289 | ;; networking options, for info: man 7 tcp 290 | 291 | ;; Linux: notify program about new connection only if there 292 | ;; is also data received. (Seconds to wait.) 293 | ;; On Linux the default is 45, on other OS'es 0. 294 | ;tcp_defer_accept = 0 295 | 296 | ;; In-kernel buffer size (Linux default: 4096) 297 | ;tcp_socket_buffer = 0 298 | 299 | ;; whether tcp keepalive should be turned on (0/1) 300 | ;tcp_keepalive = 1 301 | 302 | ;; following options are Linux-specific. 303 | ;; they also require tcp_keepalive=1 304 | 305 | ;; count of keepaliva packets 306 | ;tcp_keepcnt = 0 307 | 308 | ;; how long the connection can be idle, 309 | ;; before sending keepalive packets 310 | ;tcp_keepidle = 0 311 | 312 | ;; The time between individual keepalive probes. 313 | ;tcp_keepintvl = 0 314 | 315 | ;; DNS lookup caching time 316 | ;dns_max_ttl = 15 317 | 318 | ;; DNS zone SOA lookup period 319 | ;dns_zone_check_period = 0 320 | 321 | ;; DNS negative result caching time 322 | ;dns_nxdomain_ttl = 15 323 | 324 | ;;; 325 | ;;; Random stuff 326 | ;;; 327 | 328 | ;; Hackish security feature. Helps against SQL-injection - when PQexec is disabled, 329 | ;; multi-statement cannot be made. 330 | ;disable_pqexec=0 331 | 332 | ;; Config file to use for next RELOAD/SIGHUP. 333 | ;; By default contains config file from command line. 334 | ;conffile 335 | 336 | ;; Win32 service name to register as. job_name is alias for service_name, 337 | ;; used by some Skytools scripts. 338 | ;service_name = pgbouncer 339 | ;job_name = pgbouncer 340 | 341 | ;; Read additional config from the /etc/pgbouncer/pgbouncer-other.ini file 342 | ;%include /etc/pgbouncer/pgbouncer.database.ini 343 | -------------------------------------------------------------------------------- /postgresql_repmgr_pgbouncer/pgbouncer/userlist.txt: -------------------------------------------------------------------------------- 1 | "user_test" "md5f572704c72d613f3958ff5a30ea21dcc" 2 | "manager" "md5fafccb29ba54a4352929a02bf4626203" -------------------------------------------------------------------------------- /postgresql_repmgr_pgbouncer/postgresql/pg_hba.conf: -------------------------------------------------------------------------------- 1 | # PostgreSQL Client Authentication Configuration File 2 | # =================================================== 3 | # 4 | # Refer to the "Client Authentication" section in the PostgreSQL 5 | # documentation for a complete description of this file. A short 6 | # synopsis follows. 7 | # 8 | # This file controls: which hosts are allowed to connect, how clients 9 | # are authenticated, which PostgreSQL user names they can use, which 10 | # databases they can access. Records take one of these forms: 11 | # 12 | # local DATABASE USER METHOD [OPTIONS] 13 | # host DATABASE USER ADDRESS METHOD [OPTIONS] 14 | # hostssl DATABASE USER ADDRESS METHOD [OPTIONS] 15 | # hostnossl DATABASE USER ADDRESS METHOD [OPTIONS] 16 | # 17 | # (The uppercase items must be replaced by actual values.) 18 | # 19 | # The first field is the connection type: "local" is a Unix-domain 20 | # socket, "host" is either a plain or SSL-encrypted TCP/IP socket, 21 | # "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a 22 | # plain TCP/IP socket. 23 | # 24 | # DATABASE can be "all", "sameuser", "samerole", "replication", a 25 | # database name, or a comma-separated list thereof. The "all" 26 | # keyword does not match "replication". Access to replication 27 | # must be enabled in a separate record (see example below). 28 | # 29 | # USER can be "all", a user name, a group name prefixed with "+", or a 30 | # comma-separated list thereof. In both the DATABASE and USER fields 31 | # you can also write a file name prefixed with "@" to include names 32 | # from a separate file. 33 | # 34 | # ADDRESS specifies the set of hosts the record matches. It can be a 35 | # host name, or it is made up of an IP address and a CIDR mask that is 36 | # an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that 37 | # specifies the number of significant bits in the mask. A host name 38 | # that starts with a dot (.) matches a suffix of the actual host name. 39 | # Alternatively, you can write an IP address and netmask in separate 40 | # columns to specify the set of hosts. Instead of a CIDR-address, you 41 | # can write "samehost" to match any of the server's own IP addresses, 42 | # or "samenet" to match any address in any subnet that the server is 43 | # directly connected to. 44 | # 45 | # METHOD can be "trust", "reject", "md5", "password", "gss", "sspi", 46 | # "ident", "peer", "pam", "ldap", "radius" or "cert". Note that 47 | # "password" sends passwords in clear text; "md5" is preferred since 48 | # it sends encrypted passwords. 49 | # 50 | # OPTIONS are a set of options for the authentication in the format 51 | # NAME=VALUE. The available options depend on the different 52 | # authentication methods -- refer to the "Client Authentication" 53 | # section in the documentation for a list of which options are 54 | # available for which authentication methods. 55 | # 56 | # Database and user names containing spaces, commas, quotes and other 57 | # special characters must be quoted. Quoting one of the keywords 58 | # "all", "sameuser", "samerole" or "replication" makes the name lose 59 | # its special character, and just match a database or username with 60 | # that name. 61 | # 62 | # This file is read on server startup and when the postmaster receives 63 | # a SIGHUP signal. If you edit the file on a running system, you have 64 | # to SIGHUP the postmaster for the changes to take effect. You can 65 | # use "pg_ctl reload" to do that. 66 | 67 | # Put your actual configuration here 68 | # ---------------------------------- 69 | # 70 | # If you want to allow non-local connections, you need to add more 71 | # "host" records. In that case you will also need to make PostgreSQL 72 | # listen on a non-local interface via the listen_addresses 73 | # configuration parameter, or via the -i or -h command line switches. 74 | 75 | 76 | 77 | # TYPE DATABASE USER ADDRESS METHOD 78 | 79 | # "local" is for Unix domain socket connections only 80 | # local all all peer 81 | # IPv4 local connections: 82 | # host all all 127.0.0.1/32 ident 83 | # IPv6 local connections: 84 | host all all ::1/128 ident 85 | # Allow replication connections from localhost, by a user with the 86 | # replication privilege. 87 | #local replication postgres peer 88 | #host replication postgres 127.0.0.1/32 ident 89 | #host replication postgres ::1/128 ident 90 | 91 | local replication repmgr trust 92 | host replication repmgr p1 trust 93 | host replication repmgr p2 trust 94 | host replication repmgr p3 trust 95 | 96 | local repmgr repmgr trust 97 | host repmgr repmgr p1 trust 98 | host repmgr repmgr p2 trust 99 | host repmgr repmgr p3 trust 100 | 101 | host test_db user_test pgb1 md5 102 | -------------------------------------------------------------------------------- /postgresql_repmgr_pgbouncer/postgresql/pg_ident.conf: -------------------------------------------------------------------------------- 1 | # PostgreSQL User Name Maps 2 | # ========================= 3 | # 4 | # Refer to the PostgreSQL documentation, chapter "Client 5 | # Authentication" for a complete description. A short synopsis 6 | # follows. 7 | # 8 | # This file controls PostgreSQL user name mapping. It maps external 9 | # user names to their corresponding PostgreSQL user names. Records 10 | # are of the form: 11 | # 12 | # MAPNAME SYSTEM-USERNAME PG-USERNAME 13 | # 14 | # (The uppercase quantities must be replaced by actual values.) 15 | # 16 | # MAPNAME is the (otherwise freely chosen) map name that was used in 17 | # pg_hba.conf. SYSTEM-USERNAME is the detected user name of the 18 | # client. PG-USERNAME is the requested PostgreSQL user name. The 19 | # existence of a record specifies that SYSTEM-USERNAME may connect as 20 | # PG-USERNAME. 21 | # 22 | # If SYSTEM-USERNAME starts with a slash (/), it will be treated as a 23 | # regular expression. Optionally this can contain a capture (a 24 | # parenthesized subexpression). The substring matching the capture 25 | # will be substituted for \1 (backslash-one) if present in 26 | # PG-USERNAME. 27 | # 28 | # Multiple maps may be specified in this file and used by pg_hba.conf. 29 | # 30 | # No map names are defined in the default configuration. If all 31 | # system user names and PostgreSQL user names are the same, you don't 32 | # need anything in this file. 33 | # 34 | # This file is read on server startup and when the postmaster receives 35 | # a SIGHUP signal. If you edit the file on a running system, you have 36 | # to SIGHUP the postmaster for the changes to take effect. You can 37 | # use "pg_ctl reload" to do that. 38 | 39 | # Put your actual configuration here 40 | # ---------------------------------- 41 | 42 | # MAPNAME SYSTEM-USERNAME PG-USERNAME 43 | -------------------------------------------------------------------------------- /postgresql_repmgr_pgbouncer/postgresql/postgresql.conf: -------------------------------------------------------------------------------- 1 | # ----------------------------- 2 | # PostgreSQL configuration file 3 | # ----------------------------- 4 | # 5 | # This file consists of lines of the form: 6 | # 7 | # name = value 8 | # 9 | # (The "=" is optional.) Whitespace may be used. Comments are introduced with 10 | # "#" anywhere on a line. The complete list of parameter names and allowed 11 | # values can be found in the PostgreSQL documentation. 12 | # 13 | # The commented-out settings shown in this file represent the default values. 14 | # Re-commenting a setting is NOT sufficient to revert it to the default value; 15 | # you need to reload the server. 16 | # 17 | # This file is read on server startup and when the server receives a SIGHUP 18 | # signal. If you edit the file on a running system, you have to SIGHUP the 19 | # server for the changes to take effect, or use "pg_ctl reload". Some 20 | # parameters, which are marked below, require a server shutdown and restart to 21 | # take effect. 22 | # 23 | # Any parameter can also be given as a command-line option to the server, e.g., 24 | # "postgres -c log_connections=on". Some parameters can be changed at run time 25 | # with the "SET" SQL command. 26 | # 27 | # Memory units: kB = kilobytes Time units: ms = milliseconds 28 | # MB = megabytes s = seconds 29 | # GB = gigabytes min = minutes 30 | # TB = terabytes h = hours 31 | # d = days 32 | 33 | 34 | #------------------------------------------------------------------------------ 35 | # FILE LOCATIONS 36 | #------------------------------------------------------------------------------ 37 | 38 | # The default values of these variables are driven from the -D command-line 39 | # option or PGDATA environment variable, represented here as ConfigDir. 40 | 41 | #data_directory = 'ConfigDir' # use data in another directory 42 | # (change requires restart) 43 | #hba_file = 'ConfigDir/pg_hba.conf' # host-based authentication file 44 | # (change requires restart) 45 | #ident_file = 'ConfigDir/pg_ident.conf' # ident configuration file 46 | # (change requires restart) 47 | 48 | # If external_pid_file is not explicitly set, no extra PID file is written. 49 | #external_pid_file = '' # write an extra PID file 50 | # (change requires restart) 51 | 52 | 53 | #------------------------------------------------------------------------------ 54 | # CONNECTIONS AND AUTHENTICATION 55 | #------------------------------------------------------------------------------ 56 | 57 | # - Connection Settings - 58 | 59 | listen_addresses = '*' # what IP address(es) to listen on; 60 | # comma-separated list of addresses; 61 | # defaults to 'localhost'; use '*' for all 62 | # (change requires restart) 63 | #port = 5432 # (change requires restart) 64 | max_connections = 100 # (change requires restart) 65 | #superuser_reserved_connections = 3 # (change requires restart) 66 | #unix_socket_directories = '/var/run/postgresql, /tmp' # comma-separated list of directories 67 | # (change requires restart) 68 | #unix_socket_group = '' # (change requires restart) 69 | #unix_socket_permissions = 0777 # begin with 0 to use octal notation 70 | # (change requires restart) 71 | #bonjour = off # advertise server via Bonjour 72 | # (change requires restart) 73 | #bonjour_name = '' # defaults to the computer name 74 | # (change requires restart) 75 | 76 | # - Security and Authentication - 77 | 78 | #authentication_timeout = 1min # 1s-600s 79 | #ssl = off # (change requires restart) 80 | #ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers 81 | # (change requires restart) 82 | #ssl_prefer_server_ciphers = on # (change requires restart) 83 | #ssl_ecdh_curve = 'prime256v1' # (change requires restart) 84 | #ssl_cert_file = 'server.crt' # (change requires restart) 85 | #ssl_key_file = 'server.key' # (change requires restart) 86 | #ssl_ca_file = '' # (change requires restart) 87 | #ssl_crl_file = '' # (change requires restart) 88 | #password_encryption = on 89 | #db_user_namespace = off 90 | #row_security = on 91 | 92 | # GSSAPI using Kerberos 93 | #krb_server_keyfile = '' 94 | #krb_caseins_users = off 95 | 96 | # - TCP Keepalives - 97 | # see "man 7 tcp" for details 98 | 99 | #tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds; 100 | # 0 selects the system default 101 | #tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds; 102 | # 0 selects the system default 103 | #tcp_keepalives_count = 0 # TCP_KEEPCNT; 104 | # 0 selects the system default 105 | 106 | 107 | #------------------------------------------------------------------------------ 108 | # RESOURCE USAGE (except WAL) 109 | #------------------------------------------------------------------------------ 110 | 111 | # - Memory - 112 | 113 | shared_buffers = 128MB # min 128kB 114 | # (change requires restart) 115 | #huge_pages = try # on, off, or try 116 | # (change requires restart) 117 | #temp_buffers = 8MB # min 800kB 118 | #max_prepared_transactions = 0 # zero disables the feature 119 | # (change requires restart) 120 | # Caution: it is not advisable to set max_prepared_transactions nonzero unless 121 | # you actively intend to use prepared transactions. 122 | #work_mem = 4MB # min 64kB 123 | #maintenance_work_mem = 64MB # min 1MB 124 | #replacement_sort_tuples = 150000 # limits use of replacement selection sort 125 | #autovacuum_work_mem = -1 # min 1MB, or -1 to use maintenance_work_mem 126 | #max_stack_depth = 2MB # min 100kB 127 | dynamic_shared_memory_type = posix # the default is the first option 128 | # supported by the operating system: 129 | # posix 130 | # sysv 131 | # windows 132 | # mmap 133 | # use none to disable dynamic shared memory 134 | 135 | # - Disk - 136 | 137 | #temp_file_limit = -1 # limits per-process temp file space 138 | # in kB, or -1 for no limit 139 | 140 | # - Kernel Resource Usage - 141 | 142 | #max_files_per_process = 1000 # min 25 143 | # (change requires restart) 144 | shared_preload_libraries = 'repmgr_funcs' # (change requires restart) 145 | 146 | # - Cost-Based Vacuum Delay - 147 | 148 | #vacuum_cost_delay = 0 # 0-100 milliseconds 149 | #vacuum_cost_page_hit = 1 # 0-10000 credits 150 | #vacuum_cost_page_miss = 10 # 0-10000 credits 151 | #vacuum_cost_page_dirty = 20 # 0-10000 credits 152 | #vacuum_cost_limit = 200 # 1-10000 credits 153 | 154 | # - Background Writer - 155 | 156 | #bgwriter_delay = 200ms # 10-10000ms between rounds 157 | #bgwriter_lru_maxpages = 100 # 0-1000 max buffers written/round 158 | #bgwriter_lru_multiplier = 2.0 # 0-10.0 multiplier on buffers scanned/round 159 | #bgwriter_flush_after = 512kB # measured in pages, 0 disables 160 | 161 | # - Asynchronous Behavior - 162 | 163 | #effective_io_concurrency = 1 # 1-1000; 0 disables prefetching 164 | #max_worker_processes = 8 # (change requires restart) 165 | #max_parallel_workers_per_gather = 0 # taken from max_worker_processes 166 | #old_snapshot_threshold = -1 # 1min-60d; -1 disables; 0 is immediate 167 | # (change requires restart) 168 | #backend_flush_after = 0 # measured in pages, 0 disables 169 | 170 | 171 | #------------------------------------------------------------------------------ 172 | # WRITE AHEAD LOG 173 | #------------------------------------------------------------------------------ 174 | 175 | # - Settings - 176 | 177 | wal_level = hot_standby # minimal, replica, or logical 178 | # (change requires restart) 179 | #fsync = on # flush data to disk for crash safety 180 | # (turning this off can cause 181 | # unrecoverable data corruption) 182 | #synchronous_commit = on # synchronization level; 183 | # off, local, remote_write, remote_apply, or on 184 | #wal_sync_method = fsync # the default is the first option 185 | # supported by the operating system: 186 | # open_datasync 187 | # fdatasync (default on Linux) 188 | # fsync 189 | # fsync_writethrough 190 | # open_sync 191 | #full_page_writes = on # recover from partial page writes 192 | #wal_compression = off # enable compression of full-page writes 193 | wal_log_hints = on # also do full page writes of non-critical updates 194 | # (change requires restart) 195 | #wal_buffers = -1 # min 32kB, -1 sets based on shared_buffers 196 | # (change requires restart) 197 | #wal_writer_delay = 200ms # 1-10000 milliseconds 198 | #wal_writer_flush_after = 1MB # measured in pages, 0 disables 199 | 200 | #commit_delay = 0 # range 0-100000, in microseconds 201 | #commit_siblings = 5 # range 1-1000 202 | 203 | # - Checkpoints - 204 | 205 | #checkpoint_timeout = 5min # range 30s-1d 206 | #max_wal_size = 1GB 207 | #min_wal_size = 80MB 208 | #checkpoint_completion_target = 0.5 # checkpoint target duration, 0.0 - 1.0 209 | #checkpoint_flush_after = 256kB # measured in pages, 0 disables 210 | #checkpoint_warning = 30s # 0 disables 211 | 212 | # - Archiving - 213 | 214 | archive_mode = on # enables archiving; off, on, or always 215 | # (change requires restart) 216 | archive_command = '/bin/true' # command to use to archive a logfile segment 217 | # placeholders: %p = path of file to archive 218 | # %f = file name only 219 | # e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f' 220 | #archive_timeout = 0 # force a logfile segment switch after this 221 | # number of seconds; 0 disables 222 | 223 | 224 | #------------------------------------------------------------------------------ 225 | # REPLICATION 226 | #------------------------------------------------------------------------------ 227 | 228 | # - Sending Server(s) - 229 | 230 | # Set these on the master and on any standby that will send replication data. 231 | 232 | max_wal_senders = 10 # max number of walsender processes 233 | # (change requires restart) 234 | #wal_keep_segments = 0 # in logfile segments, 16MB each; 0 disables 235 | #wal_sender_timeout = 60s # in milliseconds; 0 disables 236 | 237 | #max_replication_slots = 0 # max number of replication slots 238 | # (change requires restart) 239 | #track_commit_timestamp = off # collect timestamp of transaction commit 240 | # (change requires restart) 241 | 242 | # - Master Server - 243 | 244 | # These settings are ignored on a standby server. 245 | 246 | #synchronous_standby_names = '' # standby servers that provide sync rep 247 | # number of sync standbys and comma-separated list of application_name 248 | # from standby(s); '*' = all 249 | #vacuum_defer_cleanup_age = 0 # number of xacts by which cleanup is delayed 250 | 251 | # - Standby Servers - 252 | 253 | # These settings are ignored on a master server. 254 | 255 | hot_standby = on # "on" allows queries during recovery 256 | # (change requires restart) 257 | #max_standby_archive_delay = 30s # max delay before canceling queries 258 | # when reading WAL from archive; 259 | # -1 allows indefinite delay 260 | #max_standby_streaming_delay = 30s # max delay before canceling queries 261 | # when reading streaming WAL; 262 | # -1 allows indefinite delay 263 | #wal_receiver_status_interval = 10s # send replies at least this often 264 | # 0 disables 265 | #hot_standby_feedback = off # send info from standby to prevent 266 | # query conflicts 267 | #wal_receiver_timeout = 60s # time that receiver waits for 268 | # communication from master 269 | # in milliseconds; 0 disables 270 | #wal_retrieve_retry_interval = 5s # time to wait before retrying to 271 | # retrieve WAL after a failed attempt 272 | 273 | 274 | #------------------------------------------------------------------------------ 275 | # QUERY TUNING 276 | #------------------------------------------------------------------------------ 277 | 278 | # - Planner Method Configuration - 279 | 280 | #enable_bitmapscan = on 281 | #enable_hashagg = on 282 | #enable_hashjoin = on 283 | #enable_indexscan = on 284 | #enable_indexonlyscan = on 285 | #enable_material = on 286 | #enable_mergejoin = on 287 | #enable_nestloop = on 288 | #enable_seqscan = on 289 | #enable_sort = on 290 | #enable_tidscan = on 291 | 292 | # - Planner Cost Constants - 293 | 294 | #seq_page_cost = 1.0 # measured on an arbitrary scale 295 | #random_page_cost = 4.0 # same scale as above 296 | #cpu_tuple_cost = 0.01 # same scale as above 297 | #cpu_index_tuple_cost = 0.005 # same scale as above 298 | #cpu_operator_cost = 0.0025 # same scale as above 299 | #parallel_tuple_cost = 0.1 # same scale as above 300 | #parallel_setup_cost = 1000.0 # same scale as above 301 | #min_parallel_relation_size = 8MB 302 | #effective_cache_size = 4GB 303 | 304 | # - Genetic Query Optimizer - 305 | 306 | #geqo = on 307 | #geqo_threshold = 12 308 | #geqo_effort = 5 # range 1-10 309 | #geqo_pool_size = 0 # selects default based on effort 310 | #geqo_generations = 0 # selects default based on effort 311 | #geqo_selection_bias = 2.0 # range 1.5-2.0 312 | #geqo_seed = 0.0 # range 0.0-1.0 313 | 314 | # - Other Planner Options - 315 | 316 | #default_statistics_target = 100 # range 1-10000 317 | #constraint_exclusion = partition # on, off, or partition 318 | #cursor_tuple_fraction = 0.1 # range 0.0-1.0 319 | #from_collapse_limit = 8 320 | #join_collapse_limit = 8 # 1 disables collapsing of explicit 321 | # JOIN clauses 322 | #force_parallel_mode = off 323 | 324 | 325 | #------------------------------------------------------------------------------ 326 | # ERROR REPORTING AND LOGGING 327 | #------------------------------------------------------------------------------ 328 | 329 | # - Where to Log - 330 | 331 | log_destination = 'stderr' # Valid values are combinations of 332 | # stderr, csvlog, syslog, and eventlog, 333 | # depending on platform. csvlog 334 | # requires logging_collector to be on. 335 | 336 | # This is used when logging to stderr: 337 | logging_collector = on # Enable capturing of stderr and csvlog 338 | # into log files. Required to be on for 339 | # csvlogs. 340 | # (change requires restart) 341 | 342 | # These are only used if logging_collector is on: 343 | log_directory = 'pg_log' # directory where log files are written, 344 | # can be absolute or relative to PGDATA 345 | log_filename = 'postgresql-%a.log' # log file name pattern, 346 | # can include strftime() escapes 347 | #log_file_mode = 0600 # creation mode for log files, 348 | # begin with 0 to use octal notation 349 | log_truncate_on_rotation = on # If on, an existing log file with the 350 | # same name as the new log file will be 351 | # truncated rather than appended to. 352 | # But such truncation only occurs on 353 | # time-driven rotation, not on restarts 354 | # or size-driven rotation. Default is 355 | # off, meaning append to existing files 356 | # in all cases. 357 | log_rotation_age = 1d # Automatic rotation of logfiles will 358 | # happen after that time. 0 disables. 359 | log_rotation_size = 0 # Automatic rotation of logfiles will 360 | # happen after that much log output. 361 | # 0 disables. 362 | 363 | # These are relevant when logging to syslog: 364 | #syslog_facility = 'LOCAL0' 365 | #syslog_ident = 'postgres' 366 | #syslog_sequence_numbers = on 367 | #syslog_split_messages = on 368 | 369 | # This is only relevant when logging to eventlog (win32): 370 | #event_source = 'PostgreSQL' 371 | 372 | # - When to Log - 373 | 374 | #client_min_messages = notice # values in order of decreasing detail: 375 | # debug5 376 | # debug4 377 | # debug3 378 | # debug2 379 | # debug1 380 | # log 381 | # notice 382 | # warning 383 | # error 384 | 385 | #log_min_messages = warning # values in order of decreasing detail: 386 | # debug5 387 | # debug4 388 | # debug3 389 | # debug2 390 | # debug1 391 | # info 392 | # notice 393 | # warning 394 | # error 395 | # log 396 | # fatal 397 | # panic 398 | 399 | #log_min_error_statement = error # values in order of decreasing detail: 400 | # debug5 401 | # debug4 402 | # debug3 403 | # debug2 404 | # debug1 405 | # info 406 | # notice 407 | # warning 408 | # error 409 | # log 410 | # fatal 411 | # panic (effectively off) 412 | 413 | #log_min_duration_statement = -1 # -1 is disabled, 0 logs all statements 414 | # and their durations, > 0 logs only 415 | # statements running at least this number 416 | # of milliseconds 417 | 418 | 419 | # - What to Log - 420 | 421 | #debug_print_parse = off 422 | #debug_print_rewritten = off 423 | #debug_print_plan = off 424 | #debug_pretty_print = on 425 | #log_checkpoints = off 426 | #log_connections = off 427 | #log_disconnections = off 428 | #log_duration = off 429 | #log_error_verbosity = default # terse, default, or verbose messages 430 | #log_hostname = off 431 | log_line_prefix = '< %m > ' # special values: 432 | # %a = application name 433 | # %u = user name 434 | # %d = database name 435 | # %r = remote host and port 436 | # %h = remote host 437 | # %p = process ID 438 | # %t = timestamp without milliseconds 439 | # %m = timestamp with milliseconds 440 | # %n = timestamp with milliseconds (as a Unix epoch) 441 | # %i = command tag 442 | # %e = SQL state 443 | # %c = session ID 444 | # %l = session line number 445 | # %s = session start timestamp 446 | # %v = virtual transaction ID 447 | # %x = transaction ID (0 if none) 448 | # %q = stop here in non-session 449 | # processes 450 | # %% = '%' 451 | # e.g. '<%u%%%d> ' 452 | #log_lock_waits = off # log lock waits >= deadlock_timeout 453 | #log_statement = 'none' # none, ddl, mod, all 454 | #log_replication_commands = off 455 | #log_temp_files = -1 # log temporary files equal or larger 456 | # than the specified size in kilobytes; 457 | # -1 disables, 0 logs all temp files 458 | log_timezone = 'Iran' 459 | 460 | 461 | # - Process Title - 462 | 463 | #cluster_name = '' # added to process titles if nonempty 464 | # (change requires restart) 465 | #update_process_title = on 466 | 467 | 468 | #------------------------------------------------------------------------------ 469 | # RUNTIME STATISTICS 470 | #------------------------------------------------------------------------------ 471 | 472 | # - Query/Index Statistics Collector - 473 | 474 | #track_activities = on 475 | #track_counts = on 476 | #track_io_timing = off 477 | #track_functions = none # none, pl, all 478 | #track_activity_query_size = 1024 # (change requires restart) 479 | #stats_temp_directory = 'pg_stat_tmp' 480 | 481 | 482 | # - Statistics Monitoring - 483 | 484 | #log_parser_stats = off 485 | #log_planner_stats = off 486 | #log_executor_stats = off 487 | #log_statement_stats = off 488 | 489 | 490 | #------------------------------------------------------------------------------ 491 | # AUTOVACUUM PARAMETERS 492 | #------------------------------------------------------------------------------ 493 | 494 | #autovacuum = on # Enable autovacuum subprocess? 'on' 495 | # requires track_counts to also be on. 496 | #log_autovacuum_min_duration = -1 # -1 disables, 0 logs all actions and 497 | # their durations, > 0 logs only 498 | # actions running at least this number 499 | # of milliseconds. 500 | #autovacuum_max_workers = 3 # max number of autovacuum subprocesses 501 | # (change requires restart) 502 | #autovacuum_naptime = 1min # time between autovacuum runs 503 | #autovacuum_vacuum_threshold = 50 # min number of row updates before 504 | # vacuum 505 | #autovacuum_analyze_threshold = 50 # min number of row updates before 506 | # analyze 507 | #autovacuum_vacuum_scale_factor = 0.2 # fraction of table size before vacuum 508 | #autovacuum_analyze_scale_factor = 0.1 # fraction of table size before analyze 509 | #autovacuum_freeze_max_age = 200000000 # maximum XID age before forced vacuum 510 | # (change requires restart) 511 | #autovacuum_multixact_freeze_max_age = 400000000 # maximum multixact age 512 | # before forced vacuum 513 | # (change requires restart) 514 | #autovacuum_vacuum_cost_delay = 20ms # default vacuum cost delay for 515 | # autovacuum, in milliseconds; 516 | # -1 means use vacuum_cost_delay 517 | #autovacuum_vacuum_cost_limit = -1 # default vacuum cost limit for 518 | # autovacuum, -1 means use 519 | # vacuum_cost_limit 520 | 521 | 522 | #------------------------------------------------------------------------------ 523 | # CLIENT CONNECTION DEFAULTS 524 | #------------------------------------------------------------------------------ 525 | 526 | # - Statement Behavior - 527 | 528 | #search_path = '"$user", public' # schema names 529 | #default_tablespace = '' # a tablespace name, '' uses the default 530 | #temp_tablespaces = '' # a list of tablespace names, '' uses 531 | # only default tablespace 532 | #check_function_bodies = on 533 | #default_transaction_isolation = 'read committed' 534 | #default_transaction_read_only = off 535 | #default_transaction_deferrable = off 536 | #session_replication_role = 'origin' 537 | #statement_timeout = 0 # in milliseconds, 0 is disabled 538 | #lock_timeout = 0 # in milliseconds, 0 is disabled 539 | #idle_in_transaction_session_timeout = 0 # in milliseconds, 0 is disabled 540 | #vacuum_freeze_min_age = 50000000 541 | #vacuum_freeze_table_age = 150000000 542 | #vacuum_multixact_freeze_min_age = 5000000 543 | #vacuum_multixact_freeze_table_age = 150000000 544 | #bytea_output = 'hex' # hex, escape 545 | #xmlbinary = 'base64' 546 | #xmloption = 'content' 547 | #gin_fuzzy_search_limit = 0 548 | #gin_pending_list_limit = 4MB 549 | 550 | # - Locale and Formatting - 551 | 552 | datestyle = 'iso, mdy' 553 | #intervalstyle = 'postgres' 554 | timezone = 'Iran' 555 | #timezone_abbreviations = 'Default' # Select the set of available time zone 556 | # abbreviations. Currently, there are 557 | # Default 558 | # Australia (historical usage) 559 | # India 560 | # You can create your own file in 561 | # share/timezonesets/. 562 | #extra_float_digits = 0 # min -15, max 3 563 | #client_encoding = sql_ascii # actually, defaults to database 564 | # encoding 565 | 566 | # These settings are initialized by initdb, but they can be changed. 567 | lc_messages = 'en_US.UTF-8' # locale for system error message 568 | # strings 569 | lc_monetary = 'en_US.UTF-8' # locale for monetary formatting 570 | lc_numeric = 'en_US.UTF-8' # locale for number formatting 571 | lc_time = 'en_US.UTF-8' # locale for time formatting 572 | 573 | # default configuration for text search 574 | default_text_search_config = 'pg_catalog.english' 575 | 576 | # - Other Defaults - 577 | 578 | #dynamic_library_path = '$libdir' 579 | #local_preload_libraries = '' 580 | #session_preload_libraries = '' 581 | 582 | 583 | #------------------------------------------------------------------------------ 584 | # LOCK MANAGEMENT 585 | #------------------------------------------------------------------------------ 586 | 587 | #deadlock_timeout = 1s 588 | #max_locks_per_transaction = 64 # min 10 589 | # (change requires restart) 590 | #max_pred_locks_per_transaction = 64 # min 10 591 | # (change requires restart) 592 | 593 | 594 | #------------------------------------------------------------------------------ 595 | # VERSION/PLATFORM COMPATIBILITY 596 | #------------------------------------------------------------------------------ 597 | 598 | # - Previous PostgreSQL Versions - 599 | 600 | #array_nulls = on 601 | #backslash_quote = safe_encoding # on, off, or safe_encoding 602 | #default_with_oids = off 603 | #escape_string_warning = on 604 | #lo_compat_privileges = off 605 | #operator_precedence_warning = off 606 | #quote_all_identifiers = off 607 | #sql_inheritance = on 608 | #standard_conforming_strings = on 609 | #synchronize_seqscans = on 610 | 611 | # - Other Platforms and Clients - 612 | 613 | #transform_null_equals = off 614 | 615 | 616 | #------------------------------------------------------------------------------ 617 | # ERROR HANDLING 618 | #------------------------------------------------------------------------------ 619 | 620 | #exit_on_error = off # terminate session on any error? 621 | #restart_after_crash = on # reinitialize after backend crash? 622 | 623 | 624 | #------------------------------------------------------------------------------ 625 | # CONFIG FILE INCLUDES 626 | #------------------------------------------------------------------------------ 627 | 628 | # These options allow settings to be loaded from files other than the 629 | # default postgresql.conf. 630 | 631 | #include_dir = 'conf.d' # include files ending in '.conf' from 632 | # directory 'conf.d' 633 | #include_if_exists = 'exists.conf' # include file only if it exists 634 | #include = 'special.conf' # include file 635 | 636 | 637 | #------------------------------------------------------------------------------ 638 | # CUSTOMIZED OPTIONS 639 | #------------------------------------------------------------------------------ 640 | 641 | # Add settings for extensions here 642 | -------------------------------------------------------------------------------- /postgresql_repmgr_pgbouncer/repmgr/promote.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -u 3 | set -e 4 | 5 | # Configurable items 6 | PGBOUNCER_HOSTS="pgb1" # you can add any pgbouncer host here 7 | PGBOUNCER_DATABASE_INI="/etc/pgbouncer/pgbouncer.database.ini" 8 | PGBOUNCER_DATABASE="test_db" 9 | PGBOUNCER_PORT=6432 10 | 11 | REPMGR_DB="repmgr" 12 | REPMGR_USER="repmgr" 13 | REPMGR_SCHEMA="repmgr_cluster1" 14 | 15 | # manager user password 16 | export PGPASSWORD=manager_password 17 | 18 | # 1. Pause running pgbouncer instances 19 | for HOST in $PGBOUNCER_HOSTS 20 | do 21 | psql -t -c "pause" -h $HOST -p $PGBOUNCER_PORT -U manager pgbouncer 22 | done 23 | 24 | # 2. Promote this node from standby to master 25 | 26 | repmgr standby promote -f /etc/repmgr.conf --log-to-file 27 | 28 | # 3. Reconfigure pgbouncer instances 29 | 30 | PGBOUNCER_DATABASE_INI_NEW="/tmp/pgbouncer.database.ini" 31 | 32 | for HOST in $PGBOUNCER_HOSTS 33 | do 34 | # Recreate the pgbouncer config file 35 | echo -e "[databases]\n" > $PGBOUNCER_DATABASE_INI_NEW 36 | 37 | psql -d $REPMGR_DB -U $REPMGR_USER -t -A \ 38 | -c "SELECT '${PGBOUNCER_DATABASE}= host=' || name || ' dbname=${PGBOUNCER_DATABASE}' \ 39 | FROM ${REPMGR_SCHEMA}.repl_nodes \ 40 | WHERE active = TRUE AND type='master'" >> $PGBOUNCER_DATABASE_INI_NEW 41 | 42 | rsync $PGBOUNCER_DATABASE_INI_NEW $HOST:$PGBOUNCER_DATABASE_INI --inplace || EXIT_CODE=$? && true 43 | 44 | echo $EXIT_CODE 45 | 46 | psql -tc "reload" -h $HOST -p $PGBOUNCER_PORT -U manager pgbouncer 47 | psql -tc "resume" -h $HOST -p $PGBOUNCER_PORT -U manager pgbouncer 48 | 49 | done 50 | 51 | # Clean up generated file 52 | rm $PGBOUNCER_DATABASE_INI_NEW 53 | 54 | echo "Reconfiguration of pgbouncer complete" 55 | -------------------------------------------------------------------------------- /postgresql_repmgr_pgbouncer/walk.txt: -------------------------------------------------------------------------------- 1 | # master 2 | 3 | yum install -y http://yum.postgresql.org/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm 4 | 5 | yum install -y postgresql96 postgresql96-contrib postgresql96-server repmgr96 6 | 7 | export PATH=$PATH:/usr/pgsql-9.6/bin 8 | ln -s /usr/pgsql-9.6/bin/* /usr/local/bin/ 9 | 10 | postgresql96-setup initdb 11 | 12 | # config postgre.conf 13 | # config pg_hba.conf 14 | 15 | systemctl start postgresql-9.6 16 | 17 | 18 | # config /etc/repmgr.conf on all nodes 19 | 20 | 21 | 22 | su - postgres 23 | 24 | createuser -s repmgr 25 | createdb repmgr -O repmgr 26 | repmgr -f /etc/repmgr.conf master register 27 | 28 | psql 29 | 30 | CREATE role manager LOGIN PASSWORD 'manager_password' SUPERUSER; 31 | CREATE USER user_test WITH PASSWORD 'user_password'; 32 | CREATE DATABASE test_db; 33 | GRANT ALL PRIVILEGES ON DATABASE test_db to user_test; 34 | 35 | \q 36 | 37 | 38 | ---- 39 | 40 | su - postgres 41 | 42 | repmgr -h p1 -U repmgr -d repmgr -D /var/lib/pgsql/9.6/data/ -f /etc/repmgr.conf standby clone 43 | sudo systemctl start postgresql-9.6 44 | repmgr standby register 45 | 46 | # for verify 47 | psql -U repmgr repmgr 48 | select * from repmgr_cluster1.repl_nodes; 49 | 50 | # run repmgrd just on slaves 51 | repmgrd -m -d -p /var/run/repmgrd.pid -f /etc/repmgr.conf --verbose >> $HOME/repmgr/repmgr.log 2>&1 52 | ps aux | grep repmgrd 53 | 54 | # for status 55 | psql -U repmgr repmgr 56 | select * from repmgr_cluster1.repl_status ; 57 | 58 | 59 | ------------------------------------------------------------------------------------ 60 | # after faild master , convert to slave 61 | # rm -rf /data 62 | 63 | # clone 64 | repmgr -h p2 -U repmgr -d repmgr -D /var/lib/pgsql/9.6/data/ -f /etc/repmgr.conf standby clone --force 65 | 66 | # reigster as standby 67 | repmgr standby register --force 68 | 69 | # run repmgrd 70 | repmgrd -d -p /var/run/repmgrd -f /etc/repmgr.conf --verbose >> $HOME/repmgr/repmgr.log 2>&1 71 | 72 | 73 | ------------------------------------------------------------------------------------- 74 | 75 | # for switching an slave to master 76 | 77 | # kill repmgrd on all slaves 78 | killall -9 repmgrd 79 | 80 | # on salve to be promoted 81 | repmgr -f /etc/repmgr.conf -C /etc/repmgr.conf standby switchover -v 82 | 83 | 84 | 85 | 86 | yum install pgbouncer -y 87 | 88 | # set /etc/pgbouncer/pgbouncer.ini 89 | # set /etc/pgbouncer/pgbouncer.database.ino 90 | # set /etc/pgbouncer/userlist.txt 91 | 92 | systemctl start pgbouncer 93 | 94 | user=manager; passw=manager_password; echo -n md5; echo $passwd$user | md5sum 95 | user=user_test; passw=user_password; echo -n md5; echo $passwd$user | md5sum 96 | 97 | 98 | --------------------------------------------------------------------------------