Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Ian Doob Technology
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Patroni Cluster
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Patroni === <pre> sudo mkdir -p /etc/patroni/ sudo chown -R postgres:postgres /etc/patroni/ </pre> As the postgres user, create a configuration file. </br> <pre> sudo -iu postgres vi /etc/patroni/patroni.yml namespace: /db/ scope: cluster_1 name: $THIS_NAME log: format: '%(asctime)s %(levelname)s: %(message)s' level: INFO max_queue_size: 1000 traceback_level: ERROR type: plain restapi: listen: 0.0.0.0:8008 connect_address: $THIS_IP:8008 etcd3: hosts: - 192.168.59.101:2379 - 192.168.59.102:2379 - 192.168.59.103:2379 bootstrap: dcs: ttl: 30 loop_wait: 10 retry_timeout: 10 maximum_lag_on_failover: 1048576 postgresql: use_pg_rewind: true use_slots: true parameters: wal_level: replica hot_standby: "on" wal_keep_segments: 10 max_wal_senders: 5 max_replication_slots: 10 wal_log_hints: "on" logging_collector: 'on' max_wal_size: '10GB' archive_mode: "on" archive_timeout: 600s archive_command: "/bin/true" initdb: # Note: It needs to be a list (some options need values, others are switches) - encoding: UTF8 - data-checksums pg_hba: # Add following lines to pg_hba.conf after running 'initdb' - host replication replicator 127.0.0.1/32 trust - host replication replicator 0.0.0.0/0 md5 - host all all 0.0.0.0/0 md5 - host all all ::0/0 md5 # Some additional users which needs to be created after initializing new cluster users: admin: password: qaz123 options: - createrole - createdb postgresql: listen: 0.0.0.0:5432 connect_address: $THIS_IP:5432 data_dir: /var/lib/postgresql/17 bin_dir: /usr/lib/postgresql/17/bin pgpass: /tmp/pgpass0 authentication: replication: username: replicator password: replPasswd superuser: username: postgres password: qaz123 parameters: unix_socket_directories: "/var/run/postgresql/" tags: nofailover: false noloadbalance: false clonefrom: false nosync: false </pre> Validate the configuration file </br> <pre> patroni --validate-config /etc/patroni/patroni.yml </pre> ==== Service ==== <pre> sudo vi /etc/systemd/system/multi-user.target.wants/patroni.service [Unit] Description=Runners to orchestrate a high-availability PostgreSQL After=network.target [Service] Type=simple User=postgres Group=postgres # Start the patroni process ExecStart=/usr/bin/patroni /etc/patroni/patroni.yml # Send HUP to reload from patroni.yml ExecReload=/bin/kill -s HUP $MAINPID # Only kill the patroni process, not it's children, so it will gracefully stop postgres KillMode=process # Give a reasonable amount of time for the server to start up/shut down TimeoutSec=30 # Restart the service if it crashed Restart=on-failure [Install] WantedBy=multi-user.target </pre> Set permissions of the data directory to 700 </br> <pre> sudo -iu postgres chmod 700 /var/lib/postgresql/17 </pre> Start the patroni service </br> <pre> sudo systemctl daemon-reload sudo systemctl start patroni </pre> Check status <pre> export PATRONICTL_CONFIG_FILE=/etc/patroni/patroni.yml patronictl -c /etc/patroni/patroni.yml list + Cluster: cluster_1 (7439347493790530098) ------+----+-----------+ | Member | Host | Role | State | TL | Lag in MB | +---------+----------------+---------+-----------+----+-----------+ | debian1 | 192.168.59.101 | Replica | streaming | 1 | 0 | | debian2 | 192.168.59.102 | Replica | streaming | 1 | 0 | | debian3 | 192.168.59.103 | Leader | running | 1 | | +---------+----------------+---------+-----------+----+-----------+ </pre> Change configuration </br> <pre> PATRONICTL_CONFIG_FILE=/etc/patroni/patroni.yml patronictl edit-config --pg archive_command="pgbackrest --stanza=ian archive-push %p" </pre> ==== Issues ==== Replication showed the following error <pre> ERROR: Requested starting point 0/4000000 is ahead of the WAL flush position of this server 0/3000060 </pre> The replica instance needed to be re-initialised </br> <pre> patronictl -c /etc/patroni/patroni.yml reinit <scope> <name> </pre>
Summary:
Please note that all contributions to Ian Doob Technology may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
My wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width