{"id":369580,"date":"2024-05-21T04:06:41","date_gmt":"2024-05-21T04:06:41","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=369580"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=369580","title":{"rendered":"<span>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 Patroni \u0432 PostgresSQL<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9f8\/be3\/a5e\/9f8be3a5edcce969c386fdc7e427182c.png\" width=\"780\" height=\"439\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9f8\/be3\/a5e\/9f8be3a5edcce969c386fdc7e427182c.png\"\/><\/figure>\n<p><strong>Patroni<\/strong> \u2013 \u043e\u043f\u0435\u043d\u0441\u043e\u0440\u0441\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u041f\u043e\u0441\u0442\u0433\u0440\u0435\u0441\u0435. \u0422.\u0435 \u043c\u043e\u0436\u043d\u043e <strong>\u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043d\u0430 \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440<\/strong> \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0431\u043e\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e. <\/p>\n<p>Patroni \u043c\u043e\u0436\u0435\u0442 \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u0432\u043a\u043b\u044e\u0447\u0430\u044f <a href=\"https:\/\/etcd.io\/\">etcd<\/a>, <a href=\"https:\/\/zookeeper.apache.org\/\">ZooKeeper<\/a>, <a href=\"https:\/\/www.consul.io\/\">Consul <\/a>\u0438 <a href=\"https:\/\/kubernetes.io\/\">Kubernetes<\/a>.<\/p>\n<h4>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 <\/h4>\n<p>\u0414\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043d\u0443\u0436\u0435\u043d \u043f\u0438\u0442\u043e\u043d \u0432\u044b\u0448\u0435 3.4 \u0432\u0435\u0440\u0441\u0438\u0438 \u0438 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e pip. Patroni \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0443\u0449\u0435\u043d \u043d\u0430 \u043b\u044e\u0431\u043e\u0439 \u041e\u0421, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0435\u0439 Python:<\/p>\n<pre><code class=\"bash\">pip install patroni[etcd]<\/code><\/pre>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442 Patroni \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 etcd. \u0415\u0441\u043b\u0438 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0443\u0436\u043d\u043e ZooKeeper \u0438\u043b\u0438 Consul, \u0442\u044b \u043f\u0440\u043e\u0441\u0442\u043e <code>[etcd]<\/code> \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 <code>[zookeeper]<\/code> \u0438\u043b\u0438 <code>[consul]<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<p>Patroni \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u044f DCS \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 etcd \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c URL \u0443\u0437\u043b\u043e\u0432 etcd \u0432 \u043a\u043e\u043d\u0444. \u0444\u0430\u0439\u043b\u0435 Patroni:<\/p>\n<pre><code class=\"yaml\">etcd:   hosts: localhost:2379<\/code><\/pre>\n<p>\u0414\u043b\u044f ZooKeeper \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"yaml\">zookeeper:   hosts: localhost:2181<\/code><\/pre>\n<p>\u0410 \u0434\u043b\u044f Consul \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u043c\u0435\u0442 \u0432\u0438\u0434:<\/p>\n<pre><code class=\"yaml\">consul:   host: localhost:8500<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 DCS \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0434\u043b\u044f Patroni. \u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>patroni.yml<\/code> \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 PostgreSQL \u0441 Patroni.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"yaml\">scope: postgres namespace: \/db\/ name: postgresql0  restapi:   listen: 0.0.0.0:8008   connect_address: localhost:8008  etcd:   hosts: localhost:2379  bootstrap:   dcs:     ttl: 30     loop_wait: 10     retry_timeout: 10     maximum_lag_on_failover: 1048576   initdb:   - encoding: UTF8   - data-checksums   pg_hba:   - host replication replicator 127.0.0.1\/32 md5   - host all all 0.0.0.0\/0 md5   users:     admin:       password: admin       options:         - createrole         - createdb  postgresql:   listen: 0.0.0.0:5432   connect_address: localhost:5432   data_dir: \/data\/patroni   pgpass: \/tmp\/pgpass   authentication:     replication:       username: replicator       password: rep-pass     superuser:       username: postgres       password: secretpassword   parameters:     unix_socket_directories: '.'<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c:<\/p>\n<pre><code class=\"bash\">patroni \/path\/to\/patroni.yml<\/code><\/pre>\n<p>Patroni \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043a\u043b\u0430\u0441\u0442\u0435\u0440 PostgreSQL, \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0435\u0433\u043e \u0432 DCS \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 HTTP API<\/p>\n<h4>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e Patroni<\/h4>\n<p><strong>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f Patroni<\/strong> \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><code>scope<\/code>: \u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 DCS<\/p>\n<\/li>\n<li>\n<p><code>namespace<\/code>: \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0434\u043b\u044f \u043a\u043b\u044e\u0447\u0435\u0439 \u0432 DCS, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b \u0432 \u043e\u0431\u0449\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435<\/p>\n<\/li>\n<li>\n<p><code>name<\/code>: \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0438\u043c\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0443\u0437\u043b\u0430 \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0441\u043e\u0431\u044b\u0435 <strong>\u043a\u043e\u043d\u0444\u044b \u0434\u043b\u044f dcs:<\/strong><\/p>\n<ul>\n<li>\n<p><code>etcd<\/code>: \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0434\u043b\u044f etcd \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 <code>hosts<\/code>, <code>protocol<\/code>, <code>ca_file<\/code>, <code>cert_file<\/code>, \u0438 <code>key_file<\/code> \u0434\u043b\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><code>zookeeper<\/code>: \u0434\u043b\u044f ZooKeeper \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f <code>hosts<\/code>, <code>session_timeout<\/code>, \u0438 <code>reconnect_timeout<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>consul<\/code>: \u0434\u043b\u044f Consul \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0442\u0441\u044f <code>host<\/code>, <code>token<\/code>, <code>consistency<\/code>, \u0438 <code>scheme<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f PostgreSQL<\/strong> \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0434, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p><code>connect_address<\/code>: \u0430\u0434\u0440\u0435\u0441, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c PostgreSQL \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><code>data_dir<\/code>: \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 PostgreSQL.<\/p>\n<\/li>\n<li>\n<p><code>pgpass<\/code>: \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u0441 \u043f\u0430\u0440\u043e\u043b\u044f\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p><code>recovery_conf<\/code>: \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f \u0444\u0430\u0439\u043b\u0430 recovery.conf<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438<\/strong> \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0435\u0439 \u0438 \u0432\u044b\u0431\u043e\u0440\u043e\u043c \u043b\u0438\u0434\u0435\u0440\u0430.<\/p>\n<ul>\n<li>\n<p><code>maximum_lag_on_failover<\/code>: \u043c\u0430\u043a\u0441. \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u043e\u0442\u0441\u0442\u0430\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u043f\u0440\u0438 failover.<\/p>\n<\/li>\n<li>\n<p><code>retry_timeout<\/code>: t \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0434 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>Patroni \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>watchdog<\/strong> \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0433\u043e failover:<\/p>\n<ul>\n<li>\n<p><code>mode<\/code>: \u0440\u0435\u0436\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u044b watchdog (off, automatic, required).<\/p>\n<\/li>\n<li>\n<p><code>device<\/code>: \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e watchdog.<\/p>\n<\/li>\n<li>\n<p><code>safety_margin<\/code>: t \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439 \u0441\u0431\u043e\u044f.<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0415\u0449\u0435 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u043d\u0444:<\/strong><\/p>\n<pre><code class=\"yaml\">scope: my_cluster namespace: \/db\/ name: node1  restapi:   listen: 0.0.0.0:8008   connect_address: 192.168.1.1:8008  etcd:   hosts: localhost:2379  bootstrap:   dcs:     ttl: 30     loop_wait: 10     retry_timeout: 10     maximum_lag_on_failover: 1048576   initdb:   - encoding: UTF8   - data-checksums   pg_hba:   - host replication replicator 127.0.0.1\/32 md5   - host all all 0.0.0.0\/0 md5  postgresql:   listen: 0.0.0.0:5432   connect_address: 192.168.1.1:5432   data_dir: \/var\/lib\/postgresql\/data   pgpass: \/tmp\/pgpass   authentication:     replication:       username: replicator       password: secret     superuser:       username: postgres       password: secret<\/code><\/pre>\n<h4>Patroni REST API   <\/h4>\n<p>Patroni REST API \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u0443\u0437\u043b\u0430, \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0440\u043e\u043b\u0435\u0439 \u043c\u0435\u0436\u0434\u0443 \u0443\u0437\u043b\u0430\u043c\u0438, \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0438 \u0442.\u0434. API \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c REST, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 HTTP \u043c\u0435\u0442\u043e\u0434\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a GET \u0438 POST, \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438.<\/p>\n<p>\u0421\u0430\u043c\u044b\u0439 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u2013 \u044d\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 GET \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u043a\u043e\u0440\u043d\u044e API. \u0412 \u043e\u0442\u0432\u0435\u0442\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 JSON, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0440\u043e\u043b\u044c \u0443\u0437\u043b\u0430, \u0432\u0435\u0440\u0441\u0438\u044e PostgreSQL, \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0438 \u0442.\u043f<\/p>\n<pre><code class=\"python\">import requests  response = requests.get('http:\/\/patroni-api-endpoint:8008\/') status_info = response.json()  print(status_info)<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c switchover \u0438 failover \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. \u0414\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f switchover, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c POST \u0437\u0430\u043f\u0440\u043e\u0441 \u043a <code>\/switchover<\/code> endpoint, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044f \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0443\u0437\u0435\u043b \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0440\u043e\u043b\u0438 \u043b\u0438\u0434\u0435\u0440\u0430:<\/p>\n<pre><code class=\"python\">response = requests.post(     'http:\/\/patroni-api-endpoint:8008\/switchover',     json={         \"leader\": \"current_leader_name\",         \"candidate\": \"target_replica_name\"     } )  print(response.json())<\/code><\/pre>\n<p>\u0414\u043b\u044f failover \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c, \u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043d\u0430 <code>\/failover<\/code> endpoint.<\/p>\n<p>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u043d\u0430 \u043b\u0435\u0442\u0443 \u2013 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c POST \u0437\u0430\u043f\u0440\u043e\u0441 \u043a <code>\/reload<\/code> endpoint \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0443\u0437\u043b\u043e\u0432:<\/p>\n<pre><code class=\"python\">response = requests.post('http:\/\/patroni-api-endpoint:8008\/reload') print(response.status_code)<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 endpoints \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a <code>\/history<\/code> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0438 failover \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, <code>\/config<\/code> \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0438 <code>\/cluster<\/code> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0432\u0441\u0435\u0445 \u0443\u0437\u043b\u0430\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430.<\/p>\n<h4>Bootstrap \u0440\u0435\u043f\u043b\u0438\u043a <\/h4>\n<p>Bootstrap \u0440\u0435\u043f\u043b\u0438\u043a \u0432 Patron \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0431\u0430\u0437\u043e\u0432\u044b\u0439 backup \u0441 \u043c\u0430\u0441\u0442\u0435\u0440\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e backup (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>pg_basebackup<\/code> \u0438\u043b\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0440\u043e\u0434\u0435 Barman, WAL-E, WAL-G), \u0438\u043b\u0438 \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u0438.<\/p>\n<p>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f Patroni \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 bootstrap. \u041f\u0440\u0438\u043c\u0435\u0440 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0434\u043b\u044f <code>patroni.yml<\/code>:<\/p>\n<pre><code class=\"yaml\">bootstrap:   method: pg_basebackup   pg_basebackup:     command: pg_basebackup -h master_host -D \/var\/lib\/postgresql\/data\/pgdata -U replicator -vP -W     retries: 5     retry_timeout: 10<\/code><\/pre>\n<p>\u0424\u0430\u0439\u043b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 bootstrap, \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e backup, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b <code>initdb<\/code> \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 <code>pg_hba<\/code> \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0438 \u0443\u0447\u0435\u0442\u043a\u0443 \u044e\u0437\u0435\u0440\u0430.<\/p>\n<p>Patroni \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432 bootstrap, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u0444\u0438\u0447\u0438:<\/p>\n<ul>\n<li>\n<p><strong>pg_basebackup<\/strong>: \u0441\u0442\u0430\u043d\u0434. \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 PostgreSQL \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e backup. \u041f\u0440\u043e\u0441\u0442\u043e \u0438 \u043d\u0430\u0434\u0435\u0436\u043d\u043e, \u043d\u043e \u043d\u0435 \u043e\u0447 \u0431\u044b\u0441\u0442\u0440\u043e<\/p>\n<\/li>\n<li>\n<p><strong>WAL-E\/WAL-G<\/strong>: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u0438\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0440\u0435\u043f\u043b\u0438\u043a\u0438, \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 backup, \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0445\u0441\u044f \u0432 \u043e\u0431\u043b\u0430\u0447\u043d\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435. <\/p>\n<\/li>\n<li>\n<p><strong>Barman<\/strong>: \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f backup \u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f PostgreSQL, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0441 Patroni \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0435\u043f\u043b\u0438\u043a.<\/p>\n<\/li>\n<li>\n<p><strong>Clone from replica<\/strong>: \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0440\u0435\u043f\u043b\u0438\u043a\u0443<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f WAL-E \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 bootstrap:<\/p>\n<pre><code class=\"yaml\">bootstrap:   method: wal_e   wal_e:     command: wal-e backup-fetch \/var\/lib\/postgresql\/data\/pgdata LATEST     envdir: \/etc\/wal-e.d\/env     recovery_conf:       restore_command: wal-e wal-fetch \"%f\" \"%p\"<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0444\u0438\u0433 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 WAL-E \u0434\u043b\u044f \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e backup \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 <code>restore_command<\/code> \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f WAL \u0444\u0430\u0439\u043b\u043e\u0432.<\/p>\n<hr\/>\n<p><em>\u0412 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0445\u043e\u0447\u0443 \u043d\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0443 \u043c\u043e\u0438\u0445 \u0434\u0440\u0443\u0437\u0435\u0439 \u0438\u0437 <\/em><a href=\"https:\/\/otus.pw\/AYZD\/\"><em>OTUS<\/em><\/a><em> \u0435\u0441\u0442\u044c \u0440\u044f\u0434 \u043a\u0443\u0440\u0441\u043e\u0432 \u043f\u043e \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435, \u0433\u0434\u0435 \u043f\u0440\u0435\u043f\u043e\u0434\u0430\u044e\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443\u044e\u0449\u0438\u0435 \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u044b \u043e\u0442\u0440\u0430\u0441\u043b\u0438. <\/em><a href=\"https:\/\/otus.pw\/AYZD\/\"><em>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435<\/em><\/a><em>.<\/em><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/797135\/\"> https:\/\/habr.com\/ru\/articles\/797135\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<p><strong>Patroni<\/strong> \u2013 \u043e\u043f\u0435\u043d\u0441\u043e\u0440\u0441\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u041f\u043e\u0441\u0442\u0433\u0440\u0435\u0441\u0435. \u0422.\u0435 \u043c\u043e\u0436\u043d\u043e <strong>\u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043d\u0430 \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440<\/strong> \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0431\u043e\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e. <\/p>\n<p>Patroni \u043c\u043e\u0436\u0435\u0442 \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u0432\u043a\u043b\u044e\u0447\u0430\u044f <a href=\"https:\/\/etcd.io\/\">etcd<\/a>, <a href=\"https:\/\/zookeeper.apache.org\/\">ZooKeeper<\/a>, <a href=\"https:\/\/www.consul.io\/\">Consul <\/a>\u0438 <a href=\"https:\/\/kubernetes.io\/\">Kubernetes<\/a>.<\/p>\n<h4>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 <\/h4>\n<p>\u0414\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043d\u0443\u0436\u0435\u043d \u043f\u0438\u0442\u043e\u043d \u0432\u044b\u0448\u0435 3.4 \u0432\u0435\u0440\u0441\u0438\u0438 \u0438 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e pip. Patroni \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0443\u0449\u0435\u043d \u043d\u0430 \u043b\u044e\u0431\u043e\u0439 \u041e\u0421, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0435\u0439 Python:<\/p>\n<pre><code class=\"bash\">pip install patroni[etcd]<\/code><\/pre>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442 Patroni \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 etcd. \u0415\u0441\u043b\u0438 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0443\u0436\u043d\u043e ZooKeeper \u0438\u043b\u0438 Consul, \u0442\u044b \u043f\u0440\u043e\u0441\u0442\u043e <code>[etcd]<\/code> \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 <code>[zookeeper]<\/code> \u0438\u043b\u0438 <code>[consul]<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<p>Patroni \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u044f DCS \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 etcd \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c URL \u0443\u0437\u043b\u043e\u0432 etcd \u0432 \u043a\u043e\u043d\u0444. \u0444\u0430\u0439\u043b\u0435 Patroni:<\/p>\n<pre><code class=\"yaml\">etcd:   hosts: localhost:2379<\/code><\/pre>\n<p>\u0414\u043b\u044f ZooKeeper \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"yaml\">zookeeper:   hosts: localhost:2181<\/code><\/pre>\n<p>\u0410 \u0434\u043b\u044f Consul \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u043c\u0435\u0442 \u0432\u0438\u0434:<\/p>\n<pre><code class=\"yaml\">consul:   host: localhost:8500<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 DCS \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0434\u043b\u044f Patroni. \u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>patroni.yml<\/code> \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 PostgreSQL \u0441 Patroni.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"yaml\">scope: postgres namespace: \/db\/ name: postgresql0  restapi:   listen: 0.0.0.0:8008   connect_address: localhost:8008  etcd:   hosts: localhost:2379  bootstrap:   dcs:     ttl: 30     loop_wait: 10     retry_timeout: 10     maximum_lag_on_failover: 1048576   initdb:   - encoding: UTF8   - data-checksums   pg_hba:   - host replication replicator 127.0.0.1\/32 md5   - host all all 0.0.0.0\/0 md5   users:     admin:       password: admin       options:         - createrole         - createdb  postgresql:   listen: 0.0.0.0:5432   connect_address: localhost:5432   data_dir: \/data\/patroni   pgpass: \/tmp\/pgpass   authentication:     replication:       username: replicator       password: rep-pass     superuser:       username: postgres       password: secretpassword   parameters:     unix_socket_directories: '.'<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c:<\/p>\n<pre><code class=\"bash\">patroni \/path\/to\/patroni.yml<\/code><\/pre>\n<p>Patroni \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043a\u043b\u0430\u0441\u0442\u0435\u0440 PostgreSQL, \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0435\u0433\u043e \u0432 DCS \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 HTTP API<\/p>\n<h4>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e Patroni<\/h4>\n<p><strong>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f Patroni<\/strong> \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><code>scope<\/code>: \u0438\u043c\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 DCS<\/p>\n<\/li>\n<li>\n<p><code>namespace<\/code>: \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0434\u043b\u044f \u043a\u043b\u044e\u0447\u0435\u0439 \u0432 DCS, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b \u0432 \u043e\u0431\u0449\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435<\/p>\n<\/li>\n<li>\n<p><code>name<\/code>: \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0438\u043c\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0443\u0437\u043b\u0430 \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0441\u043e\u0431\u044b\u0435 <strong>\u043a\u043e\u043d\u0444\u044b \u0434\u043b\u044f dcs:<\/strong><\/p>\n<ul>\n<li>\n<p><code>etcd<\/code>: \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0434\u043b\u044f etcd \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 <code>hosts<\/code>, <code>protocol<\/code>, <code>ca_file<\/code>, <code>cert_file<\/code>, \u0438 <code>key_file<\/code> \u0434\u043b\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><code>zookeeper<\/code>: \u0434\u043b\u044f ZooKeeper \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f <code>hosts<\/code>, <code>session_timeout<\/code>, \u0438 <code>reconnect_timeout<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>consul<\/code>: \u0434\u043b\u044f Consul \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0442\u0441\u044f <code>host<\/code>, <code>token<\/code>, <code>consistency<\/code>, \u0438 <code>scheme<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f PostgreSQL<\/strong> \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0434, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p><code>connect_address<\/code>: \u0430\u0434\u0440\u0435\u0441, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c PostgreSQL \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><code>data_dir<\/code>: \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 PostgreSQL.<\/p>\n<\/li>\n<li>\n<p><code>pgpass<\/code>: \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u0441 \u043f\u0430\u0440\u043e\u043b\u044f\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p><code>recovery_conf<\/code>: \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f \u0444\u0430\u0439\u043b\u0430 recovery.conf<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438<\/strong> \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0435\u0439 \u0438 \u0432\u044b\u0431\u043e\u0440\u043e\u043c \u043b\u0438\u0434\u0435\u0440\u0430.<\/p>\n<ul>\n<li>\n<p><code>maximum_lag_on_failover<\/code>: \u043c\u0430\u043a\u0441. \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u043e\u0442\u0441\u0442\u0430\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u043f\u0440\u0438 failover.<\/p>\n<\/li>\n<li>\n<p><code>retry_timeout<\/code>: t \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0434 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>Patroni \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>watchdog<\/strong> \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0433\u043e failover:<\/p>\n<ul>\n<li>\n<p><code>mode<\/code>: \u0440\u0435\u0436\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u044b watchdog (off, automatic, required).<\/p>\n<\/li>\n<li>\n<p><code>device<\/code>: \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e watchdog.<\/p>\n<\/li>\n<li>\n<p><code>safety_margin<\/code>: t \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439 \u0441\u0431\u043e\u044f.<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0415\u0449\u0435 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u043d\u0444:<\/strong><\/p>\n<pre><code class=\"yaml\">scope: my_cluster namespace: \/db\/ name: node1  restapi:   listen: 0.0.0.0:8008   connect_address: 192.168.1.1:8008  etcd:   hosts: localhost:2379  bootstrap:   dcs:     ttl: 30     loop_wait: 10     retry_timeout: 10     maximum_lag_on_failover: 1048576   initdb:   - encoding: UTF8   - data-checksums   pg_hba:   - host replication replicator 127.0.0.1\/32 md5   - host all all 0.0.0.0\/0 md5  postgresql:   listen: 0.0.0.0:5432   connect_address: 192.168.1.1:5432   data_dir: \/var\/lib\/postgresql\/data   pgpass: \/tmp\/pgpass   authentication:     replication:       username: replicator       password: secret     superuser:       username: postgres       password: secret<\/code><\/pre>\n<h4>Patroni REST API   <\/h4>\n<p>Patroni REST API \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u0443\u0437\u043b\u0430, \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0440\u043e\u043b\u0435\u0439 \u043c\u0435\u0436\u0434\u0443 \u0443\u0437\u043b\u0430\u043c\u0438, \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0438 \u0442.\u0434. API \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c REST, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 HTTP \u043c\u0435\u0442\u043e\u0434\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a GET \u0438 POST, \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438.<\/p>\n<p>\u0421\u0430\u043c\u044b\u0439 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u2013 \u044d\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 GET \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u043a\u043e\u0440\u043d\u044e API. \u0412 \u043e\u0442\u0432\u0435\u0442\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 JSON, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0440\u043e\u043b\u044c \u0443\u0437\u043b\u0430, \u0432\u0435\u0440\u0441\u0438\u044e PostgreSQL, \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0438 \u0442.\u043f<\/p>\n<pre><code class=\"python\">import requests  response = requests.get('http:\/\/patroni-api-endpoint:8008\/') status_info = response.json()  print(status_info)<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c switchover \u0438 failover \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. \u0414\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f switchover, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c POST \u0437\u0430\u043f\u0440\u043e\u0441 \u043a <code>\/switchover<\/code> endpoint, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044f \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0443\u0437\u0435\u043b \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0440\u043e\u043b\u0438 \u043b\u0438\u0434\u0435\u0440\u0430:<\/p>\n<pre><code class=\"python\">response = requests.post(     'http:\/\/patroni-api-endpoint:8008\/switchover',     json={         \"leader\": \"current_leader_name\",         \"candidate\": \"target_replica_name\"     } )  print(response.json())<\/code><\/pre>\n<p>\u0414\u043b\u044f failover \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c, \u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043d\u0430 <code>\/failover<\/code> endpoint.<\/p>\n<p>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u043d\u0430 \u043b\u0435\u0442\u0443 \u2013 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c POST \u0437\u0430\u043f\u0440\u043e\u0441 \u043a <code>\/reload<\/code> endpoint \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0443\u0437\u043b\u043e\u0432:<\/p>\n<pre><code class=\"python\">response = requests.post('http:\/\/patroni-api-endpoint:8008\/reload') print(response.status_code)<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 endpoints \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a <code>\/history<\/code> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0438 failover \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, <code>\/config<\/code> \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0438 <code>\/cluster<\/code> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0432\u0441\u0435\u0445 \u0443\u0437\u043b\u0430\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430.<\/p>\n<h4>Bootstrap \u0440\u0435\u043f\u043b\u0438\u043a <\/h4>\n<p>Bootstrap \u0440\u0435\u043f\u043b\u0438\u043a \u0432 Patron \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0431\u0430\u0437\u043e\u0432\u044b\u0439 backup \u0441 \u043c\u0430\u0441\u0442\u0435\u0440\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e backup (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>pg_basebackup<\/code> \u0438\u043b\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0440\u043e\u0434\u0435 Barman, WAL-E, WAL-G), \u0438\u043b\u0438 \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u0438.<\/p>\n<p>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f Patroni \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 bootstrap. \u041f\u0440\u0438\u043c\u0435\u0440 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0434\u043b\u044f <code>patroni.yml<\/code>:<\/p>\n<pre><code class=\"yaml\">bootstrap:   method: pg_basebackup   pg_basebackup:     command: pg_basebackup -h master_host -D \/var\/lib\/postgresql\/data\/pgdata -U replicator -vP -W     retries: 5     retry_timeout: 10<\/code><\/pre>\n<p>\u0424\u0430\u0439\u043b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 bootstrap, \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e backup, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b <code>initdb<\/code> \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 <code>pg_hba<\/code> \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0438 \u0443\u0447\u0435\u0442\u043a\u0443 \u044e\u0437\u0435\u0440\u0430.<\/p>\n<p>Patroni \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432 bootstrap, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u0444\u0438\u0447\u0438:<\/p>\n<ul>\n<li>\n<p><strong>pg_basebackup<\/strong>: \u0441\u0442\u0430\u043d\u0434. \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 PostgreSQL \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e backup. \u041f\u0440\u043e\u0441\u0442\u043e \u0438 \u043d\u0430\u0434\u0435\u0436\u043d\u043e, \u043d\u043e \u043d\u0435 \u043e\u0447 \u0431\u044b\u0441\u0442\u0440\u043e<\/p>\n<\/li>\n<li>\n<p><strong>WAL-E\/WAL-G<\/strong>: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u0438\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0440\u0435\u043f\u043b\u0438\u043a\u0438, \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 backup, \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0445\u0441\u044f \u0432 \u043e\u0431\u043b\u0430\u0447\u043d\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435. <\/p>\n<\/li>\n<li>\n<p><strong>Barman<\/strong>: \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f backup \u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f PostgreSQL, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0441 Patroni \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0435\u043f\u043b\u0438\u043a.<\/p>\n<\/li>\n<li>\n<p><strong>Clone from replica<\/strong>: \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0440\u0435\u043f\u043b\u0438\u043a\u0443<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f WAL-E \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 bootstrap:<\/p>\n<pre><code class=\"yaml\">bootstrap:   method: wal_e   wal_e:     command: wal-e backup-fetch \/var\/lib\/postgresql\/data\/pgdata LATEST     envdir: \/etc\/wal-e.d\/env     recovery_conf:       restore_command: wal-e wal-fetch \"%f\" \"%p\"<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0444\u0438\u0433 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 WAL-E \u0434\u043b\u044f \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e backup \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 <code>restore_command<\/code> \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f WAL \u0444\u0430\u0439\u043b\u043e\u0432.<\/p>\n<hr\/>\n<p><em>\u0412 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0445\u043e\u0447\u0443 \u043d\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0443 \u043c\u043e\u0438\u0445 \u0434\u0440\u0443\u0437\u0435\u0439 \u0438\u0437 <\/em><a href=\"https:\/\/otus.pw\/AYZD\/\"><em>OTUS<\/em><\/a><em> \u0435\u0441\u0442\u044c \u0440\u044f\u0434 \u043a\u0443\u0440\u0441\u043e\u0432 \u043f\u043e \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435, \u0433\u0434\u0435 \u043f\u0440\u0435\u043f\u043e\u0434\u0430\u044e\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443\u044e\u0449\u0438\u0435 \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u044b \u043e\u0442\u0440\u0430\u0441\u043b\u0438. <\/em><a href=\"https:\/\/otus.pw\/AYZD\/\"><em>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435<\/em><\/a><em>.<\/em><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/797135\/\"> https:\/\/habr.com\/ru\/articles\/797135\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-369580","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/369580","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=369580"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/369580\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=369580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=369580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=369580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}