{"id":303358,"date":"2020-05-11T09:00:20","date_gmt":"2020-05-11T09:00:20","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=303358"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=303358","title":{"rendered":"\u0420\u0435\u0446\u0435\u043f\u0442\u044b PostgreSQL: auto-failover \u0438 auto-rejoin \u0432 docker swarm"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/498132\/\">\u0414\u043b\u044f \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0438\u044f auto-failover \u0438 auto-rejoin \u0432 docker swarm \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f <a href=\"https:\/\/www.docker.com\" rel=\"nofollow\">docker<\/a>, <a href=\"https:\/\/www.postgresql.org\" rel=\"nofollow\">postgres<\/a>, <a href=\"https:\/\/repmgr.org\" rel=\"nofollow\">repmgr<\/a>, <a href=\"https:\/\/www.pgbouncer.org\" rel=\"nofollow\">pgbouncer<\/a>, <a href=\"http:\/\/smarden.org\/runit\" rel=\"nofollow\">runit<\/a> \u0438 <a href=\"https:\/\/www.gluster.org\" rel=\"nofollow\">gluster<\/a>. \u041c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <a href=\"https:\/\/hub.docker.com\/r\/rekgrpth\/repmgr\" rel=\"nofollow\">\u0433\u043e\u0442\u043e\u0432\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/a>.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430 \u0434\u0432\u0443\u0445 \u0445\u043e\u0441\u0442\u0430\u0445 (\u043b\u0443\u0447\u0448\u0435 \u0436\u0435\u043b\u0435\u0437\u043d\u044b\u0445) docker1 \u0438 docker2 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0443\u0435\u043c docker swarm \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0430 \u0431\u044b\u043b\u0438 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430\u043c\u0438.<br \/>  \u0422\u0430\u043a\u0436\u0435, \u043d\u0430 \u043e\u0431\u0430 \u0445\u043e\u0441\u0442\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u0443\u044e \u0444\u0430\u0439\u043b\u043e\u0432\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 glusterfs \u0438 \u043f\u043e\u0434\u043c\u043e\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e \u043d\u0430 \u043e\u0431\u043e\u0438\u0445 \u0445\u043e\u0441\u0442\u0430\u0445 \u0432 fstab \u0442\u0430\u043a <\/p>\n<pre><code class=\"bash\">localhost:\/gfs \/mnt\/gfs glusterfs defaults,_netdev,backupvolfile-server=localhost 0 0<\/code><\/pre>\n<p>  \u041f\u043e\u0442\u043e\u043c \u043d\u0430 \u043e\u0431\u043e\u0438\u0445 \u0445\u043e\u0441\u0442\u0430\u0445 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0440\u0430\u0437\u0434\u0435\u043b <\/p>\n<pre><code class=\"bash\">docker volume create repmgr<\/code><\/pre>\n<p> \u0438 \u0441\u0435\u0442\u044c <\/p>\n<pre><code class=\"bash\">docker network create --attachable --driver overlay docker<\/code><\/pre>\n<p>  \u0417\u0430\u0442\u0435\u043c \u0441\u043e\u0431\u0435\u0440\u0451\u043c \u043e\u0431\u0440\u0430\u0437 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u043e\u043a\u0435\u0440-\u0444\u0430\u0439\u043b\u0430  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">Dockerfile<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">FROM alpine RUN set -ex \\     &amp;&amp; apk add --no-cache --repository http:\/\/dl-cdn.alpinelinux.org\/alpine\/edge\/testing --virtual .locales-rundeps \\         musl-locales \\ # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043c \u043b\u043e\u043a\u0430\u043b\u0438 (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c, \u043d\u043e \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u044b \u043f\u0443\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442)     &amp;&amp; apk add --no-cache --virtual .postgresql-rundeps \\         openssh-client \\ # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c ssh-\u043a\u043b\u0438\u0435\u043d\u0442\u0430 (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c, \u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043b\u044e\u0447\u0435\u0439)         openssh-server \\ # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c ssh-\u0441\u0435\u0440\u0432\u0435\u0440 (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c, \u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f switchover)         pgbouncer \\ # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a         postgresql \\ # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0431\u0430\u0437\u0443         postgresql-contrib \\ # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c, \u043d\u043e \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u044b \u043f\u0443\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442)         repmgr \\ # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c repmgr         repmgr-daemon \\ # \u0438 \u0441\u0435\u0440\u0432\u0438\u0441 \u0434\u043b\u044f \u043d\u0435\u0433\u043e         rsync \\ # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440 (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c, \u043d\u043e \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u044b \u043f\u0443\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442)         runit \\ # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043b\u0451\u0433\u043a\u0438\u0439 \u0441\u0443\u043f\u0435\u0440\u0432\u0438\u0437\u043e\u0440         shadow \\ # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438         tzdata \\ # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u043e\u043d\u044b (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c, \u043d\u043e \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u044b \u043f\u0443\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442)     &amp;&amp; echo done ADD bin \/usr\/local\/bin # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u044b ADD service \/etc\/service # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0434\u043b\u044f \u0441\u0443\u043f\u0435\u0440\u0432\u0438\u0437\u043e\u0440\u0430 CMD [ &quot;runsvdir&quot;, &quot;\/etc\/service&quot; ] # \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0441\u0443\u043f\u0435\u0440\u0432\u0438\u0437\u043e\u0440 ENTRYPOINT [ &quot;docker_entrypoint.sh&quot; ] # \u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u0432\u0445\u043e\u0434\u0430 ENV HOME=\/var\/lib\/postgresql ENV GROUP=postgres \\     PGDATA=&quot;${HOME}\/pg_data&quot; \\     USER=postgres VOLUME &quot;${HOME}&quot; WORKDIR &quot;${HOME}&quot; RUN set -ex \\     &amp;&amp; sed -i -e 's|#PasswordAuthentication yes|PasswordAuthentication no|g' \/etc\/ssh\/sshd_config \\ # \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u043c \u0432\u0445\u043e\u0434 \u043f\u043e \u043f\u0430\u0440\u043e\u043b\u044e     &amp;&amp; sed -i -e 's|#   StrictHostKeyChecking ask|   StrictHostKeyChecking no|g' \/etc\/ssh\/ssh_config \\ # \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c     &amp;&amp; echo &quot;   UserKnownHostsFile=\/dev\/null&quot; &gt;&gt;\/etc\/ssh\/ssh_config \\ # \u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0438\u043a\u0443\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c     &amp;&amp; sed -i -e 's|postgres:!:|postgres::|g' \/etc\/shadow \\ # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0432\u0445\u043e\u0434 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0431\u0430\u0437\u044b     &amp;&amp; chmod -R 0755 \/etc\/service \/usr\/local\/bin \\     &amp;&amp; echo done<\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0443 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0445\u043e\u0441\u0442\u0435 <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">service1.sh<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">docker service create \\     --constraint node.hostname==docker1 \\ # \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u0445\u043e\u0441\u0442\u0435     --env GROUP_ID=&quot;$(id -g)&quot; \\ # \u0437\u0430\u0434\u0430\u0451\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0433\u0440\u0443\u043f\u043f\u044b (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c \u0438 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430)     --env LANG=ru_RU.UTF-8 \\ # \u0437\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0443 (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c, \u043d\u043e \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u044b \u043f\u0443\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442)     --env TZ=Asia\/Yekaterinburg \\ # \u0437\u0430\u0434\u0430\u0451\u043c \u0437\u043e\u043d\u0443 (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c, \u043d\u043e \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u044b \u043f\u0443\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442)     --env USER_ID=&quot;$(id -u)&quot; \\ # \u0437\u0430\u0434\u0430\u0451\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c \u0438 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430)     --hostname tasks.repmgr1 \\ # \u0437\u0430\u0434\u0430\u0451\u043c \u0445\u043e\u0441\u0442     --mount type=bind,source=\/etc\/certs,destination=\/etc\/certs,readonly \\ # \u043c\u043e\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u0430\u043f\u043a\u0443 \u0441 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430\u043c\u0438 (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c, \u043d\u043e \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u044b \u043f\u0443\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442)     --mount type=bind,source=\/mnt\/gfs\/repmgr,destination=\/var\/lib\/postgresql\/gfs \\ # \u043c\u043e\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u0443\u044e \u0444\u0430\u0439\u043b\u043e\u0432\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443     --mount type=volume,source=repmgr,destination=\/var\/lib\/postgresql \\ # \u043c\u043e\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b     --name repmgr1 \\ # \u0437\u0430\u0434\u0430\u0451\u043c \u0438\u043c\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430     --network name=docker \\ # \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0435\u0442\u044c     --publish target=5432,published=5432,mode=host \\ # \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u043c \u043f\u043e\u0440\u0442\u044b \u0431\u0430\u0437\u044b     --publish target=5433,published=5433,mode=host \\ # \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u043c \u043f\u043e\u0440\u0442\u044b \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430     --replicas-max-per-node 1 \\ # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043a\u043e\u043d\u0435\u0439\u043d\u0435\u0440 \u043d\u0430 \u0445\u043e\u0441\u0442\u0435     rekgrpth\/repmgr # \u0431\u0435\u0440\u0451\u043c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043e\u0431\u0440\u0430\u0437 <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u041d\u0430 \u0432\u0442\u043e\u0440\u043e\u043c \u0445\u043e\u0441\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0442\u0430\u043a\u0436\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043c\u0435\u0441\u0442\u043e docker1 \u043f\u0438\u0448\u0435\u043c docker2 \u0438 \u0432\u043c\u0435\u0441\u0442\u043e repmgr1 \u043f\u0438\u0448\u0435\u043c repmgr2  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0415\u0441\u043b\u0438 \u043d\u0430\u0443\u0447\u0438\u0442\u044c docker \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u0442\u044c hostname \u043a\u043e\u043d\u0435\u0439\u0435\u0440\u043e\u0432<\/b>                         <\/p>\n<div class=\"spoiler_text\"><a href=\"https:\/\/github.com\/moby\/libnetwork\/issues\/2549\" rel=\"nofollow\">\u0442\u0430\u043a<\/a>, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u0441\u0435\u0440\u0432\u0438\u0441 \u0441\u0440\u0430\u0437\u0443 \u043d\u0430 \u043e\u0431\u043e\u0438\u0445 \u0445\u043e\u0441\u0442\u0430\u0445<\/p>\n<pre><code class=\"bash\">docker service create \\     --env GROUP_ID=&quot;$(id -g)&quot; \\ # \u0437\u0430\u0434\u0430\u0451\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0433\u0440\u0443\u043f\u043f\u044b (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c \u0438 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430)     --env LANG=ru_RU.UTF-8 \\ # \u0437\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0443 (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c, \u043d\u043e \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u044b \u043f\u0443\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442)     --env TZ=Asia\/Yekaterinburg \\ # \u0437\u0430\u0434\u0430\u0451\u043c \u0437\u043e\u043d\u0443 (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c, \u043d\u043e \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u044b \u043f\u0443\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442)     --env USER_ID=&quot;$(id -u)&quot; \\ # \u0437\u0430\u0434\u0430\u0451\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c \u0438 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430)     --hostname repmgr-{{.Node.Hostname}} \\ # \u0437\u0430\u0434\u0430\u0451\u043c \u0445\u043e\u0441\u0442     --mode global \\ # \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0443 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0445\u043e\u0441\u0442\u0435     --mount type=bind,source=\/etc\/certs,destination=\/etc\/certs,readonly \\ # \u043c\u043e\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u0430\u043f\u043a\u0443 \u0441 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430\u043c\u0438 (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c, \u043d\u043e \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u044b \u043f\u0443\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442)     --mount type=bind,source=\/mnt\/gfs\/repmgr,destination=\/var\/lib\/postgresql\/gfs \\ # \u043c\u043e\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u0443\u044e \u0444\u0430\u0439\u043b\u043e\u0432\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443     --mount type=volume,source=repmgr,destination=\/var\/lib\/postgresql \\ # \u043c\u043e\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b     --name repmgr \\ # \u0437\u0430\u0434\u0430\u0451\u043c \u0438\u043c\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430     --network name=docker \\ # \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0435\u0442\u044c     --publish target=5432,published=5432,mode=host \\ # \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u043c \u043f\u043e\u0440\u0442\u044b \u0431\u0430\u0437\u044b     --publish target=5433,published=5433,mode=host \\ # \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u043c \u043f\u043e\u0440\u0442\u044b \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430     rekgrpth\/repmgr # \u0431\u0435\u0440\u0451\u043c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043e\u0431\u0440\u0430\u0437 <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0418\u0442\u0430\u043a, \u0432\u0445\u043e\u0434 \u0432 \u043a\u043e\u043d\u0435\u0439\u043d\u0435\u0440 <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/usr\/local\/bin\/docker_entrypoint.sh<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 set -ex if [ -n &quot;$GROUP&quot; ] &amp;&amp; [ -n &quot;$GROUP_ID&quot; ] &amp;&amp; [ &quot;$GROUP_ID&quot; != &quot;$(id -g &quot;$GROUP&quot;)&quot; ]; then # \u0435\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u0430 \u0438 \u0437\u0430\u0434\u0430\u043d \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0433\u0440\u0443\u043f\u043f\u044b \u0438 \u043e\u043d \u0434\u0440\u0443\u0433\u043e\u0439, \u0442\u043e     groupmod --gid &quot;$GROUP_ID&quot; &quot;$GROUP&quot; # \u0437\u0430\u043c\u0435\u043d\u0438\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0433\u0440\u0443\u043f\u043f\u044b     chgrp &quot;$GROUP_ID&quot; &quot;$HOME&quot; # \u0438 \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u0433\u0440\u0443\u043f\u043f\u0443 \u0443 \u0434\u043e\u043c\u0430\u0448\u043d\u0435\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 fi if [ -n &quot;$USER&quot; ] &amp;&amp; [ -n &quot;$USER_ID&quot; ] &amp;&amp; [ &quot;$USER_ID&quot; != &quot;$(id -u &quot;$USER&quot;)&quot; ]; then # \u0435\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438 \u0437\u0430\u0434\u0430\u043d \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043e\u043d \u0434\u0440\u0443\u0433\u043e\u0439, \u0442\u043e     usermod --uid &quot;$USER_ID&quot; &quot;$USER&quot; # \u0437\u0430\u043c\u0435\u043d\u0438\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f     chown &quot;$USER_ID&quot; &quot;$HOME&quot; # \u0438 \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0443 \u0434\u043e\u043c\u0430\u0448\u043d\u0435\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 fi exec &quot;$@&quot; # \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443<\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0421\u0443\u043f\u0435\u0440\u0432\u0438\u0437\u043e\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">1) \/etc\/service\/ssh<\/b>                         <\/p>\n<div class=\"spoiler_text\">\u042d\u0442\u043e\u0442 \u0441\u0435\u0440\u0432\u0438\u0441 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c, \u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f switchover. \u0421\u0443\u043f\u0435\u0440\u0432\u0438\u0437\u043e\u0440 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0444\u0430\u0439\u043b  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/etc\/service\/ssh\/run<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 realpath &quot;$0&quot; set -ex ssh-keygen -A # \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u044e\u0447\u0438 \u0445\u043e\u0441\u0442\u0430 exec \/usr\/sbin\/sshd -D -e # \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c ssh-\u0441\u0435\u0440\u0432\u0435\u0440 <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0422\u0430\u043a\u0436\u0435, \u0441\u0443\u043f\u0435\u0440\u0432\u0438\u0437\u043e\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043b\u043e\u0433\u0435\u0440 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c, \u043d\u043e \u0442\u0430\u043a \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0442\u044c \u043b\u043e\u0433\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432) <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/etc\/service\/ssh\/log\/run<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 exec sed 's|^|ssh: |' <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">2) \/etc\/service\/postgres<\/b>                         <\/p>\n<div class=\"spoiler_text\">\u0421\u0443\u043f\u0435\u0440\u0432\u0438\u0437\u043e\u0440 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0444\u0430\u0439\u043b  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/etc\/service\/postgres\/run<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 install -d -m 0750 -o &quot;$USER&quot; -g &quot;$GROUP&quot; &quot;$PGDATA&quot; # \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0434\u043e\u043c\u0430\u0448\u043d\u044e\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0431\u0430\u0437\u044b install -d -m 1775 -o &quot;$USER&quot; -g &quot;$GROUP&quot; \/run\/postgresql \/var\/log\/postgresql # \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0438 \u043b\u043e\u0433\u043e\u0432 rm -f \/run\/postgresql\/postgres.run # \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0444\u0430\u0439\u043b \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 realpath &quot;$0&quot; set -ex chmod 755 supervise chown &quot;$USER&quot;:&quot;$GROUP&quot; supervise\/ok supervise\/control supervise\/status # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e rm -f &quot;$PGDATA\/postmaster.pid&quot; # \u0443\u0434\u0430\u043b\u044f\u0435\u043c pid primary=&quot;$(test -f &quot;$HOME\/gfs\/primary&quot; &amp;&amp; cat &quot;$HOME\/gfs\/primary&quot;)&quot; # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043c\u044f \u0445\u043e\u0441\u0442\u0430 \u043c\u0430\u0441\u0442\u0435\u0440\u0430 test -n &quot;$primary&quot; || echo -n &quot;$(hostname)&quot; &gt;&quot;$HOME\/gfs\/primary&quot; # \u0435\u0441\u043b\u0438 \u043c\u0430\u0441\u0442\u0435\u0440 \u043d\u0435 \u0437\u0430\u0434\u0430\u043d, \u0442\u043e \u043c\u0430\u0441\u0442\u0435\u0440 - \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0445\u043e\u0441\u0442 primary=&quot;$(test -f &quot;$HOME\/gfs\/primary&quot; &amp;&amp; cat &quot;$HOME\/gfs\/primary&quot;)&quot; # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043c\u044f \u0445\u043e\u0441\u0442\u0430 \u043c\u0430\u0441\u0442\u0435\u0440\u0430 test -n &quot;$primary&quot; # \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u0430\u0441\u0442\u0435\u0440 \u0437\u0430\u0434\u0430\u043d chown &quot;$USER&quot;:&quot;$GROUP&quot; &quot;$HOME\/gfs\/primary&quot; # \u043f\u0440\u0430\u0432\u0438\u043c \u043f\u0440\u0430\u0432\u0430 if [ &quot;$primary&quot; != &quot;$(hostname)&quot; ]; then # \u0435\u0441\u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0445\u043e\u0441\u0442 \u043d\u0435 \u043c\u0430\u0441\u0442\u0435\u0440, \u0442\u043e     test -d &quot;$PGDATA\/base&quot; || \/etc\/service\/postgres\/standby # \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0431\u0430\u0437\u044b - \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0435\u0451     test -f &quot;$PGDATA\/standby.signal&quot; || \/etc\/service\/postgres\/rejoin # \u0435\u0441\u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0445\u043e\u0441\u0442 \u0440\u0430\u043d\u044c\u0448\u0435 \u0431\u044b\u043b \u043c\u0430\u0441\u0442\u0435\u0440\u043e\u043c, \u0442\u043e \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0435\u0433\u043e \u043d\u0430 \u043d\u043e\u0432\u044b\u0439 \u043c\u0430\u0441\u0442\u0435\u0440 else # \u0438\u043d\u0430\u0447\u0435 (\u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0445\u043e\u0441\u0442 - \u043c\u0430\u0441\u0442\u0435\u0440)     test -d &quot;$PGDATA\/base&quot; || \/etc\/service\/postgres\/primary # \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0431\u0430\u0437\u044b - \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0435\u0451 fi test -d &quot;$PGDATA\/base&quot; # \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0435\u0441\u0442\u044c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f \u0431\u0430\u0437\u044b exec chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; -L \/run\/postgresql\/postgres.run postmaster # \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0431\u0430\u0437\u0443 <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0422\u0430\u043a\u0436\u0435, \u0441\u0443\u043f\u0435\u0440\u0432\u0438\u0437\u043e\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043b\u043e\u0433\u0435\u0440 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c, \u043d\u043e \u0442\u0430\u043a \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0442\u044c \u043b\u043e\u0433\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432) <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/etc\/service\/postgres\/log\/run<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 exec sed 's|^|postgres: |' <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0431\u0430\u0437\u044b \u043d\u0435 \u043c\u0430\u0441\u0442\u0435\u0440\u0430 \u0442\u0430\u043a <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/etc\/service\/postgres\/standby<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 realpath &quot;$0&quot; set -ex chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; \/etc\/service\/repmgr\/conf # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0434\u043b\u044f repmgr primary=&quot;$(test -f &quot;$HOME\/gfs\/primary&quot; &amp;&amp; cat &quot;$HOME\/gfs\/primary&quot;)&quot; # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043c\u044f \u0445\u043e\u0441\u0442\u0430 \u043c\u0430\u0441\u0442\u0435\u0440\u0430 test -n &quot;$primary&quot; # \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u043c\u0430\u0441\u0442\u0435\u0440 \u0437\u0430\u0434\u0430\u043d chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; repmgr standby clone --config-file=&quot;$HOME\/repmgr.conf&quot; --verbose --fast-checkpoint --dbname=&quot;host=$primary user=repmgr dbname=repmgr connect_timeout=2&quot; # \u043a\u043b\u043e\u043d\u0438\u0440\u0443\u0435\u043c \u0431\u0430\u0437\u0443 \u0438\u0437 \u043c\u0430\u0441\u0442\u0435\u0440\u0430 <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u041f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0441\u0442\u0430\u0440\u044b\u0439 \u043c\u0430\u0441\u0442\u0435\u0440 \u043d\u0430 \u043d\u043e\u0432\u044b\u0439 \u0442\u0430\u043a <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/etc\/service\/postgres\/rejoin<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 realpath &quot;$0&quot; set -ex primary=&quot;$(test -f &quot;$HOME\/gfs\/primary&quot; &amp;&amp; cat &quot;$HOME\/gfs\/primary&quot;)&quot; # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043c\u044f \u0445\u043e\u0441\u0442\u0430 \u043c\u0430\u0441\u0442\u0435\u0440\u0430 test -n &quot;$primary&quot; # \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u043c\u0430\u0441\u0442\u0435\u0440 \u0437\u0430\u0434\u0430\u043d chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; pg_ctl --options=&quot;-c listen_addresses=''&quot; --wait start # \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0431\u0430\u0437\u0443 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e (\u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f pg_rewind) chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; pg_ctl --wait --mode=fast stop # \u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0431\u0430\u0437\u0443 (\u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f pg_rewind) chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; repmgr node rejoin --config-file=&quot;$HOME\/repmgr.conf&quot; --verbose --force-rewind --no-wait --dbname=&quot;host=$primary user=repmgr dbname=repmgr connect_timeout=2&quot; || mv -f &quot;$PGDATA&quot; &quot;${PGDATA}_$(date &quot;+%F %T&quot;)&quot; # \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0431\u0430\u0437\u0443 \u043d\u0430 \u043d\u043e\u0432\u044b\u0439 \u043c\u0430\u0441\u0442\u0435\u0440 (\u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0443\u0434\u0430\u0447\u0438 - \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0431\u0430\u0437\u0443 \u0438 \u0431\u0443\u0434\u0435\u043c \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437 \u043c\u0430\u0441\u0442\u0435\u0440\u0430) <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0431\u0430\u0437\u044b \u043c\u0430\u0441\u0442\u0435\u0440\u0430 \u0442\u0430\u043a <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/etc\/service\/postgres\/primary<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 realpath &quot;$0&quot; set -ex \/etc\/service\/postgres\/init # \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0431\u0430\u0437\u0443 \/etc\/service\/repmgr\/init # \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c repmgr <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0431\u0430\u0437\u0443 \u0442\u0430\u043a <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/etc\/service\/postgres\/init<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 realpath &quot;$0&quot; set -ex cd &quot;$PGDATA&quot; &amp;&amp; chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; initdb # \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0431\u0430\u0437\u0443 chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; \/etc\/service\/postgres\/conf # \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0431\u0430\u0437\u044b chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; \/etc\/service\/postgres\/hba # \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0444\u0430\u0439\u043b \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u0432 <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0414\u043e\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0431\u0430\u0437\u044b \u0442\u0430\u043a <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/etc\/service\/postgres\/conf<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 realpath &quot;$0&quot; set -ex cat &gt;&gt;&quot;$PGDATA\/postgresql.conf&quot; &lt;&lt;EOF  archive_command = '\/bin\/true' # \u0444\u0435\u0439\u043a\u043e\u0432\u0430\u044f \u0430\u0440\u0445\u0438\u0432\u0430\u0446\u0438\u044f archive_mode = on # \u043d\u043e \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0430 datestyle = 'iso, dmy' # \u0437\u0430\u0434\u0430\u0451\u043c \u0441\u0442\u0438\u043b\u044c \u0434\u0430\u0442\u044b listen_addresses = '*' # \u0441\u043b\u0443\u0448\u0430\u0435\u043c \u0432\u0441\u0451 max_logical_replication_workers = 0 # \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044e max_sync_workers_per_subscription = 0 # \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044e ssl_ca_file = '\/etc\/certs\/ca.pem' # \u0437\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 ssl_cert_file = '\/etc\/certs\/cert.pem' # \u0437\u0430\u0434\u0430\u0451\u043c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 ssl_key_file = '\/etc\/certs\/key.pem' # \u0437\u0430\u0434\u0430\u0451\u043c \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 ssl = on # \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c ssl EOF <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0414\u043e\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0444\u0430\u0439\u043b \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u0432 \u0442\u0430\u043a <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/etc\/service\/postgres\/hba<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 realpath &quot;$0&quot; set -ex echo &gt;&gt;&quot;$PGDATA\/pg_hba.conf&quot; ip -o -f inet addr show | awk '\/scope global\/ {print $4}' | sed -E 's|.\\d+\/|.0\/|' | while read -r net; do # \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439     echo &quot;host all all $net trust&quot; # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0432\u0441\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f done &gt;&gt;&quot;$PGDATA\/pg_hba.conf&quot; <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">3) \/etc\/service\/repmgr<\/b>                         <\/p>\n<div class=\"spoiler_text\">\u0421\u0443\u043f\u0435\u0440\u0432\u0438\u0437\u043e\u0440 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0444\u0430\u0439\u043b <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/etc\/service\/repmgr\/run<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 install -d -m 1775 -o &quot;$USER&quot; -g &quot;$GROUP&quot; \/run\/postgresql # \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 rm -f \/run\/postgresql\/repmgr.run # \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0444\u0430\u0439\u043b \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 test -f \/run\/postgresql\/postgres.run || exit $? # \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0437\u0430\u043f\u0443\u0449\u0435\u043d \u0441\u0435\u0440\u0432\u0438\u0441 \u0431\u0430\u0437\u044b realpath &quot;$0&quot; set -ex chmod 755 supervise chown &quot;$USER&quot;:&quot;$GROUP&quot; supervise\/ok supervise\/control supervise\/status # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; pg_ctl status # \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0437\u0430\u043f\u0443\u0449\u0435\u043d \u0431\u0430\u0437\u0430 primary=&quot;$(test -f &quot;$HOME\/gfs\/primary&quot; &amp;&amp; cat &quot;$HOME\/gfs\/primary&quot;)&quot; # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043c\u044f \u0445\u043e\u0441\u0442\u0430 \u043c\u0430\u0441\u0442\u0435\u0440\u0430 test -n &quot;$primary&quot; # \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u043c\u0430\u0441\u0442\u0435\u0440 \u0437\u0430\u0434\u0430\u043d if [ &quot;$primary&quot; != &quot;$(hostname)&quot; ]; then # \u0435\u0441\u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0445\u043e\u0441\u0442 \u043d\u0435 \u043c\u0430\u0441\u0442\u0435\u0440, \u0442\u043e     test -f &quot;$HOME\/repmgr.conf&quot; || \/etc\/service\/repmgr\/standby # \u0435\u0441\u043b\u0438 \u043d\u0435 \u0437\u0430\u0434\u0430\u043d\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f, \u0442\u043e \u0437\u0430\u0434\u0430\u0451\u043c \u0435\u0451     chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; repmgr standby register --config-file=&quot;$HOME\/repmgr.conf&quot; --verbose --force # \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043a\u0430\u043a \u043d\u0435 \u043c\u0430\u0441\u0442\u0435\u0440 else # \u0438\u043d\u0430\u0447\u0435 (\u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0445\u043e\u0441\u0442 - \u043c\u0430\u0441\u0442\u0435\u0440)     test -f &quot;$HOME\/repmgr.conf&quot; || \/etc\/service\/repmgr\/primary # \u0435\u0441\u043b\u0438 \u043d\u0435 \u0437\u0430\u0434\u0430\u043d\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f, \u0442\u043e \u0437\u0430\u0434\u0430\u0451\u043c \u0435\u0451     test ! -f &quot;$PGDATA\/standby.signal&quot; || \/etc\/service\/repmgr\/promote # \u0435\u0441\u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0445\u043e\u0441\u0442 \u0440\u0430\u043d\u044c\u0448\u0435 \u0431\u044b\u043b \u043d\u0435 \u043c\u0430\u0441\u0442\u0435\u0440\u043e\u043c, \u0442\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u043c\u0430\u0441\u0442\u0435\u0440     chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; repmgr primary register --config-file=&quot;$HOME\/repmgr.conf&quot; --verbose --force # \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043a\u0430\u043a \u043c\u0430\u0441\u0442\u0435\u0440 fi exec chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; -L \/run\/postgresql\/repmgr.run repmgrd --config-file=&quot;$HOME\/repmgr.conf&quot; --verbose --daemonize=false # \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441 repmgr <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0422\u0430\u043a\u0436\u0435, \u0441\u0443\u043f\u0435\u0440\u0432\u0438\u0437\u043e\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043b\u043e\u0433\u0435\u0440 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 (\u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c, \u043d\u043e \u0442\u0430\u043a \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0442\u044c \u043b\u043e\u0433\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432) <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/etc\/service\/repmgr\/log\/run<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 exec sed 's|^|repmgr: |' <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0417\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u043d\u0435 \u043c\u0430\u0441\u0442\u0435\u0440\u0430 \u0442\u0430\u043a <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/etc\/service\/repmgr\/standby<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 realpath &quot;$0&quot; set -ex chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; \/etc\/service\/repmgr\/conf # \u0437\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0417\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u043c\u0430\u0441\u0442\u0435\u0440\u0430 \u0442\u0430\u043a <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/etc\/service\/repmgr\/primary<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 realpath &quot;$0&quot; set -ex chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; createuser --superuser repmgr # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; createdb repmgr --owner=repmgr # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0431\u0430\u0437\u0443 chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; \/etc\/service\/repmgr\/conf # \u0437\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u041f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043d\u0435 \u043c\u0430\u0441\u0442\u0435\u0440 \u0432 \u043c\u0430\u0441\u0442\u0435\u0440 \u0442\u0430\u043a <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/etc\/service\/repmgr\/promote<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 realpath &quot;$0&quot; set -ex chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; repmgr standby promote --config-file=&quot;$HOME\/repmgr.conf&quot; --verbose # \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043d\u0435 \u043c\u0430\u0441\u0442\u0435\u0440 \u0432 \u043c\u0430\u0441\u0442\u0435\u0440 <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0417\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0442\u0430\u043a <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/etc\/service\/repmgr\/conf<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 realpath &quot;$0&quot; set -ex cat &gt;&quot;$HOME\/repmgr.conf&quot; &lt;&lt;EOF conninfo='host=$(hostname) user=repmgr dbname=repmgr connect_timeout=2' # \u0437\u0430\u0434\u0430\u0451\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 data_directory='$(echo -n &quot;$PGDATA&quot;)' # \u0437\u0430\u0434\u0430\u0451\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0431\u0430\u0437\u044b event_notification_command='\/etc\/service\/repmgr\/event &quot;%n&quot; &quot;%e&quot; &quot;%s&quot; &quot;%t&quot; &quot;%d&quot;' # \u0437\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 failover='automatic' # \u0437\u0430\u0434\u0430\u0451\u043c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 failover failover_validation_command='\/etc\/service\/repmgr\/valid &quot;%n&quot; &quot;%a&quot;' # \u0437\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 follow_command='repmgr standby follow --config-file=&quot;$(echo -n &quot;$HOME&quot;)\/repmgr.conf&quot; --wait --upstream-node-id=%n' # \u0437\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f node_id=$(hostname | grep -oE '\\d+') # \u0437\u0430\u0434\u0430\u0451\u043c \u043d\u043e\u043c\u0435\u0440 \u0443\u0437\u043b\u0430 node_name='$(hostname)' # \u0437\u0430\u0434\u0430\u0451\u043c \u0438\u043c\u044f \u0443\u0437\u043b\u0430 promote_command='repmgr standby promote --config-file=&quot;$(echo -n &quot;$HOME&quot;)\/repmgr.conf&quot;' # \u0437\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043f\u0440\u043e\u043c\u043e\u0442\u043a\u0438 repmgrd_service_start_command='sv start repmgr' # \u0437\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 repmgrd_service_stop_command='sv force-stop repmgr' # \u0437\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 service_promote_command='pg_ctl --wait promote' # \u0437\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043f\u0440\u043e\u043c\u043e\u0442\u043a\u0438 \u0431\u0430\u0437\u044b service_reload_command='sv reload postgres' # \u0437\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0431\u0430\u0437\u044b service_restart_command='sv force-restart postgres' # \u0437\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0431\u0430\u0437\u044b service_start_command='sv start postgres' # \u0437\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0431\u0430\u0437\u044b service_stop_command='sv force-stop postgres' # \u0437\u0430\u0434\u0430\u0451\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0431\u0430\u0437\u044b ssh_options='-q -o ConnectTimeout=10' # \u0437\u0430\u0434\u0430\u0451\u043c \u043e\u043f\u0446\u0438\u0438 ssl standby_disconnect_on_failover=true # \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043f\u0440\u0438 failover use_replication_slots=true # \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043b\u043e\u0442\u044b \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438 EOF <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c repmgr \u0442\u0430\u043a <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/etc\/service\/repmgr\/init<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 realpath &quot;$0&quot; set -ex chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; \/etc\/service\/repmgr\/hba # \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0444\u0430\u0439\u043b \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0431\u0430\u0437\u044b chpst -u &quot;$USER&quot;:&quot;$GROUP&quot; cat &gt;&gt;&quot;$PGDATA\/postgresql.conf&quot; &lt;&lt;EOF # \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0431\u0430\u0437\u044b  hot_standby = on # \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0433\u043e\u0440\u044f\u0447\u0438\u0439 \u0440\u0435\u0437\u0435\u0440\u0432 max_replication_slots = 10 # \u0437\u0430\u0434\u0430\u0451\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0442\u043e\u0432 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438 max_wal_senders = 10 # \u0437\u0430\u0434\u0430\u0451\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0449\u0438\u043a\u043e\u0432 shared_preload_libraries = 'repmgr' # \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c repmgr wal_level = 'hot_standby' # \u0437\u0430\u0434\u0430\u0451\u043c \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0433\u043e\u0440\u044f\u0447\u0438\u0439 \u0440\u0435\u0437\u0435\u0440\u0432 wal_log_hints = on # \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 \u0434\u043b\u044f pg_rewind EOF <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0414\u043e\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0444\u0430\u0439\u043b \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0431\u0430\u0437\u044b \u0442\u0430\u043a <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\/etc\/service\/repmgr\/hba<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">#!\/bin\/sh  exec 2&gt;&amp;1 realpath &quot;$0&quot; set -ex echo &gt;&gt;&quot;$PGDATA\/pg_hba.conf&quot; ip -o -f inet addr show | awk '\/scope global\/ {print $4}' | sed -E 's|.\\d+\/|.0\/|' | while read -r net; do # \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439     echo &quot;host replication repmgr $net trust&quot; # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044e \u0434\u043b\u044f repmgr     echo &quot;host repmgr repmgr $net trust&quot; # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c repmgr \u0434\u043b\u044f repmgr done &gt;&gt;&quot;$PGDATA\/pg_hba.conf&quot; cat &gt;&gt;&quot;$PGDATA\/pg_hba.conf&quot; &lt;&lt;EOF  local replication repmgr trust # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044e \u0434\u043b\u044f repmgr host replication repmgr 127.0.0.1\/32 trust # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044e \u0434\u043b\u044f repmgr host replication repmgr ::1\/128 trust # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044e \u0434\u043b\u044f repmgr  local repmgr repmgr trust # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c repmgr \u0434\u043b\u044f repmgr host repmgr repmgr 127.0.0.1\/32 trust # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c repmgr \u0434\u043b\u044f repmgr host repmgr repmgr ::1\/128 trust # \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c repmgr \u0434\u043b\u044f repmgr EOF <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  <\/div>\n<\/p><\/div>\n<\/div>\n<p> \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\/post\/498132\/\"> https:\/\/habr.com\/ru\/post\/498132\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/498132\/\">\u0414\u043b\u044f \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0438\u044f auto-failover \u0438 auto-rejoin \u0432 docker swarm \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f <a href=\"https:\/\/www.docker.com\" rel=\"nofollow\">docker<\/a>, <a href=\"https:\/\/www.postgresql.org\" rel=\"nofollow\">postgres<\/a>, <a href=\"https:\/\/repmgr.org\" rel=\"nofollow\">repmgr<\/a>, <a href=\"https:\/\/www.pgbouncer.org\" rel=\"nofollow\">pgbouncer<\/a>, <a href=\"http:\/\/smarden.org\/runit\" rel=\"nofollow\">runit<\/a> \u0438 <a href=\"https:\/\/www.gluster.org\" rel=\"nofollow\">gluster<\/a>. \u041c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <a href=\"https:\/\/hub.docker.com\/r\/rekgrpth\/repmgr\" rel=\"nofollow\">\u0433\u043e\u0442\u043e\u0432\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/a>.  <\/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-303358","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/303358","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=303358"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/303358\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=303358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=303358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=303358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}