{"id":351988,"date":"2024-05-20T21:59:51","date_gmt":"2024-05-20T21:59:51","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=351988"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-20T21:59:51","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=351988","title":{"rendered":"<span>\u041f\u043e\u0434\u043d\u0438\u043c\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440 PostgreSQL \u0432 Docker \u0438 Testcontainers<\/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<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0412 \u043e\u0434\u043d\u043e\u0439 \u0438\u0445 \u0441\u0432\u043e\u0438\u0445 <a href=\"https:\/\/habr.com\/ru\/articles\/578744\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439<\/a> \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c PostgreSQL \u0432 Docker. \u0422\u043e\u0433\u0434\u0430 \u0440\u0435\u0447\u044c \u0448\u043b\u0430 \u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u00ab\u0432\u0430\u043d\u0438\u043b\u044c\u043d\u044b\u0445\u00bb \u043e\u0431\u0440\u0430\u0437\u043e\u0432 Postgres \u0438 \u043f\u043e\u0434\u043d\u044f\u0442\u0438\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0445\u043e\u0441\u0442\u0430. \u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043a\u0430\u043a \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432, \u043d\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u043e\u0439 \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u0438 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f <a href=\"https:\/\/en.wikipedia.org\/wiki\/High-availability_cluster\" rel=\"noopener noreferrer nofollow\">\u0432\u044b\u0441\u043e\u043a\u043e\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435<\/a> (\u043e\u0442\u043a\u0430\u0437\u043e\u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u044b\u0435, \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435) \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 PostgreSQL.<\/p>\n<p>\u0422\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u043c\u0438\u043c\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0442\u043a\u0430\u0437\u043e\u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0441\u0442\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043f\u0435\u0440\u0435\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044f \u0447\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 primary \u0445\u043e\u0441\u0442\u0430 \u043d\u0430 \u0440\u0435\u043f\u043b\u0438\u043a\u0438. \u0412\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0431\u0443\u0434\u0443\u0442 \u0438\u0434\u0442\u0438 \u043d\u0430 primary \u0445\u043e\u0441\u0442.<\/p>\n<details class=\"spoiler\">\n<summary>\u0422\u0435\u0440\u043c\u0438\u043d\u043e\u043b\u043e\u0433\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435 \u043a\u0430\u0441\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043b\u043e\u0433\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>primary = master = \u043c\u0430\u0441\u0442\u0435\u0440-\u0445\u043e\u0441\u0442<\/p>\n<\/li>\n<li>\n<p>slave = standby = secondary = \u0440\u0435\u043f\u043b\u0438\u043a\u0430<\/p>\n<\/li>\n<li>\n<p>failover \u2014 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0433\u043e \u0445\u043e\u0441\u0442\u0430 (\u0440\u0435\u043f\u043b\u0438\u043a\u0438) \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 (\u043f\u0440\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438). \u0420\u0435\u043f\u043b\u0438\u043a\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u043c primary \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c.<\/p>\n<\/li>\n<li>\n<p>switchover \u2014 \u0440\u0443\u0447\u043d\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0430 primary \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u0445\u043e\u0441\u0442\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435.<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/af0\/5ae\/3a3\/af05ae3a3b26360973e05c2499c8dd3e.png\" alt=\"\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u043e\u0442\u0441\u044e\u0434\u0430\" title=\"\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u043e\u0442\u0441\u044e\u0434\u0430\" width=\"1024\" height=\"600\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/af0\/5ae\/3a3\/af05ae3a3b26360973e05c2499c8dd3e.png\"\/><\/p>\n<div><figcaption>\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 <a href=\"https:\/\/www.enterprisedb.com\/postgres-tutorials\/postgresql-replication-and-automatic-failover-tutorial\" rel=\"noopener noreferrer nofollow\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a><\/figcaption><\/div>\n<\/figure>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043b\u043e\u0433\u0438\u0438 <a href=\"https:\/\/cloud.google.com\/architecture\/architectures-high-availability-postgresql-clusters-compute-engine\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<\/div>\n<\/details>\n<p>\u0418\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 PostgreSQL \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 <a href=\"https:\/\/www.postgresql.org\/docs\/current\/high-availability.html\" rel=\"noopener noreferrer nofollow\">\u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c<\/a> \u0434\u043b\u044f \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f (promote) \u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u0432 primary \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0430\u0432\u0430\u0440\u0438\u0438, \u043d\u043e \u043d\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f HA-\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 (<strong>H<\/strong>igh <strong>A<\/strong>vailability). \u041d\u0430 \u0440\u044b\u043d\u043a\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0446\u0435\u043b\u044b\u0439 \u0440\u044f\u0434 \u0442\u0430\u043a\u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043e\u0442 \u0440\u0430\u0437\u043d\u044b\u0445 \u0432\u0435\u043d\u0434\u043e\u0440\u043e\u0432 (\u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c \u0442\u0435\u0440\u043c\u0438\u043d HA-\u0443\u0442\u0438\u043b\u0438\u0442\u044b). \u042f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/youtu.be\/sZjErOEaM9s\" rel=\"noopener noreferrer nofollow\">\u0432\u0438\u0434\u0435\u043e\u0434\u043e\u043a\u043b\u0430\u0434<\/a> \u0410\u043b\u0435\u043a\u0441\u0435\u044f \u041b\u0435\u0441\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u0434\u043b\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u043a\u0440\u0443\u0433\u043e\u0437\u043e\u0440\u0430 \u0432 \u044d\u0442\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438.<\/p>\n<p>\u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u0441\u0430\u043c\u044b\u043c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/habr.com\/ru\/post\/518216\/\" rel=\"noopener noreferrer nofollow\">Patroni<\/a>, \u043d\u043e \u044f \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/www.repmgr.org\/\" rel=\"noopener noreferrer nofollow\">repmgr<\/a> \u043e\u0442 EnterpriseDB. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u043b\u044f <strong>repmgr<\/strong> \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0435 <a href=\"https:\/\/github.com\/bitnami\/containers\/tree\/main\/bitnami\/postgresql-repmgr\" rel=\"noopener noreferrer nofollow\">\u043e\u0431\u0440\u0430\u0437\u044b \u043e\u0442 bitnami<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442\u0441\u044f.<\/p>\n<p>\u041e\u0442\u043a\u0430\u0437\u043e\u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0441\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435 PostgreSQL \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u0437\u0430 \u0441\u0447\u0451\u0442 <a href=\"https:\/\/www.postgresql.org\/docs\/15\/warm-standby.html#STREAMING-REPLICATION\" rel=\"noopener noreferrer nofollow\">WAL \u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u043e\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438<\/a>. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/selectel.ru\/blog\/tutorials\/how-to-set-up-replication-in-postgresql\/\" rel=\"noopener noreferrer nofollow\">\u0432 \u0431\u043b\u043e\u0433\u0435 Selectel<\/a>. \u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c: \u043b\u044e\u0431\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0435 \u043d\u0430 <strong>primary<\/strong>, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432 <strong>WAL<\/strong>, \u0430 \u043f\u043e\u0442\u043e\u043c \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e \u0441\u0435\u0442\u0438 \u043d\u0430 \u0440\u0435\u043f\u043b\u0438\u043a\u0443 \u0438 \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0442\u0430\u043c.\u00a0<\/p>\n<details class=\"spoiler\">\n<summary>\u041b\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e DML \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u043e\u0435 \u0432 \u0431\u043b\u043e\u043a <code>BEGIN\/ROLLBACK<\/code>, \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c: \u043e\u043d\u043e \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442 \u0432\u0438\u0434\u0438\u043c\u043e\u0433\u043e \u0432\u043d\u0435\u0448\u043d\u0435\u043c\u0443 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043c\u0435\u0434\u043b\u0438\u0442\u044c \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0443\u0440\u043e\u043d\u0438\u0442\u044c \u0432\u0430\u0448 \u043a\u043b\u0430\u0441\u0442\u0435\u0440 \u0411\u0414.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043d\u0430 100 \u0413\u0431\u0430\u0439\u0442; \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0431\u043d\u043e\u0432\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0443 \u0441\u0442\u0440\u043e\u043a \u0432 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u0427\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0439\u0442\u0438 \u043d\u0435 \u0442\u0430\u043a? \u041c\u043e\u0436\u0435\u0442 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u044c\u0441\u044f CPU \u0438\u043b\u0438 \u043c\u0435\u0441\u0442\u043e \u043d\u0430 \u0434\u0438\u0441\u043a\u0435 (MVCC \u0438 WAL), \u0437\u0430\u0431\u0438\u0442\u044c\u0441\u044f \u0441\u0435\u0442\u044c. \u0412 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043d\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440, \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0441\u0442\u0430\u0438\u0432\u0430\u0442\u044c \u0438, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0443. \u0421\u043d\u0430\u0440\u0443\u0436\u0438 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043a\u0430\u043a denial of service.<\/p>\n<p><strong><em>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u043b\u0438\u0431\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043d\u0430 \u0411\u0414, \u043f\u043e\u0434\u0443\u043c\u0430\u0439\u0442\u0435, \u043a \u0447\u0435\u043c\u0443 \u043e\u043d\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u0442.<\/em><\/strong><\/p>\n<\/div>\n<\/details>\n<h2>\u041a\u043b\u0430\u0441\u0442\u0435\u0440 \u0447\u0435\u0440\u0435\u0437 docker-compose<\/h2>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0434\u043d\u0438\u043c\u0435\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440 PostgreSQL \u0432 Docker \u0447\u0435\u0440\u0435\u0437 compose-\u0444\u0430\u0439\u043b. \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u043a\u043e\u0434\u044b, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e, <a href=\"https:\/\/github.com\/mfvanek\/useful-sql-scripts\/tree\/master\/running_pg_cluster_in_docker\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043d\u0430 GitHub<\/a>.<\/p>\n<p>\u041c\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 compose-\u0444\u0430\u0439\u043b\u0430 \u0431\u0430\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 <a href=\"https:\/\/github.com\/bitnami\/containers\/blob\/main\/bitnami\/postgresql-repmgr\/docker-compose.yml\" rel=\"noopener noreferrer nofollow\">\u0442\u0430\u043a\u043e\u0432\u043e\u043c<\/a> \u043e\u0442 <strong>bitnami<\/strong>. \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0447\u0435\u0440\u0435\u0437 <strong><em>postgres_exporter<\/em><\/strong>. \u0414\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0438\u0437 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0441 compose-\u0444\u0430\u0439\u043b\u043e\u043c:<\/p>\n<pre><code class=\"bash\">docker-compose --project-name=\"habr-pg-ha-14\" up -d<\/code><\/pre>\n<p>\u0418\u043c\u0435\u0439\u0442\u0435 \u0432 \u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f: \u043d\u0430 Linux \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u0430 macOS\/Windows \u0434\u043e\u043b\u044c\u0448\u0435. \u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 \u0434\u043b\u044f \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043e \u0434\u0432\u0443\u0445 \u043c\u0438\u043d\u0443\u0442.<\/p>\n<pre><code class=\"yaml\">version: \"3.9\" services:   pg-1:     container_name: postgres_1     image: docker.io\/bitnami\/postgresql-repmgr:14.9.0     ports:       - \"6432:5432\"     volumes:       - pg_1_data:\/bitnami\/postgresql       - .\/create_extensions.sql:\/docker-entrypoint-initdb.d\/create_extensions.sql:ro     environment:       - POSTGRESQL_POSTGRES_PASSWORD=adminpgpwd4habr       - POSTGRESQL_USERNAME=habrpguser       - POSTGRESQL_PASSWORD=pgpwd4habr       - POSTGRESQL_DATABASE=habrdb       - REPMGR_PASSWORD=repmgrpassword       - REPMGR_PRIMARY_HOST=pg-1       - REPMGR_PRIMARY_PORT=5432       - REPMGR_PARTNER_NODES=pg-1,pg-2:5432       - REPMGR_NODE_NAME=pg-1       - REPMGR_NODE_NETWORK_NAME=pg-1       - REPMGR_PORT_NUMBER=5432       - REPMGR_CONNECT_TIMEOUT=1       - REPMGR_RECONNECT_ATTEMPTS=2       - REPMGR_RECONNECT_INTERVAL=1       - REPMGR_MASTER_RESPONSE_TIMEOUT=5     restart: unless-stopped     networks:       - postgres-ha    pg-2:     container_name: postgres_2     image: docker.io\/bitnami\/postgresql-repmgr:14.9.0     ports:       - \"6433:5432\"     volumes:       - pg_2_data:\/bitnami\/postgresql       - .\/create_extensions.sql:\/docker-entrypoint-initdb.d\/create_extensions.sql:ro     environment:       - POSTGRESQL_POSTGRES_PASSWORD=adminpgpwd4habr       - POSTGRESQL_USERNAME=habrpguser       - POSTGRESQL_PASSWORD=pgpwd4habr       - POSTGRESQL_DATABASE=habrdb       - REPMGR_PASSWORD=repmgrpassword       - REPMGR_PRIMARY_HOST=pg-1       - REPMGR_PRIMARY_PORT=5432       - REPMGR_PARTNER_NODES=pg-1,pg-2:5432       - REPMGR_NODE_NAME=pg-2       - REPMGR_NODE_NETWORK_NAME=pg-2       - REPMGR_PORT_NUMBER=5432       - REPMGR_CONNECT_TIMEOUT=1       - REPMGR_RECONNECT_ATTEMPTS=2       - REPMGR_RECONNECT_INTERVAL=1       - REPMGR_MASTER_RESPONSE_TIMEOUT=5     restart: unless-stopped     networks:       - postgres-ha    pg_exporter-1:     container_name: pg_exporter_1     image: prometheuscommunity\/postgres-exporter:v0.11.1     command: --log.level=debug     environment:       DATA_SOURCE_URI: \"pg-1:5432\/habrdb?sslmode=disable\"       DATA_SOURCE_USER: habrpguser       DATA_SOURCE_PASS: pgpwd4habr       PG_EXPORTER_EXTEND_QUERY_PATH: \"\/etc\/postgres_exporter\/queries.yaml\"     volumes:       - .\/queries.yaml:\/etc\/postgres_exporter\/queries.yaml:ro     ports:       - \"9187:9187\"     networks:       - postgres-ha     restart: unless-stopped     depends_on:       - pg-1    pg_exporter-2:     container_name: pg_exporter_2     image: prometheuscommunity\/postgres-exporter:v0.11.1     command: --log.level=debug     environment:       DATA_SOURCE_URI: \"pg-2:5432\/habrdb?sslmode=disable\"       DATA_SOURCE_USER: habrpguser       DATA_SOURCE_PASS: pgpwd4habr       PG_EXPORTER_EXTEND_QUERY_PATH: \"\/etc\/postgres_exporter\/queries.yaml\"     volumes:       - .\/queries.yaml:\/etc\/postgres_exporter\/queries.yaml:ro     ports:       - \"9188:9187\"     networks:       - postgres-ha     restart: unless-stopped     depends_on:       - pg-2  networks:   postgres-ha:     driver: bridge  volumes:   pg_1_data:   pg_2_data: <\/code><\/pre>\n<h2>\u0418\u043d\u0438\u0446\u0438\u0438\u0440\u0443\u0435\u043c auto failover<\/h2>\n<p>\u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 <strong>repmgr<\/strong> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <strong><em>switchover<\/em><\/strong> \u2014 \u0440\u0443\u0447\u043d\u0430\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u0430\u044f \u0441\u043c\u0435\u043d\u0430 \u043c\u0430\u0441\u0442\u0435\u0440-\u0445\u043e\u0441\u0442\u0430 \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0432 \u043e\u0431\u0440\u0430\u0437\u0430\u0445 \u043e\u0442 <strong>bitnami<\/strong> \u044d\u0442\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f (\u0432 \u0441\u0442\u0430\u0440\u043e\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0431\u044b\u043b\u0430 <a href=\"https:\/\/github.com\/bitnami\/bitnami-docker-postgresql-repmgr\/issues\/51\" rel=\"noopener noreferrer nofollow\">issue<\/a> \u043d\u0430 \u044d\u0442\u043e, \u043d\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0443\u0434\u0430\u043b\u0435\u043d).<\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e <strong><em>failover<\/em><\/strong> \u0440\u0435\u0436\u0438\u043c. \u041a\u0430\u043a \u0435\u0433\u043e \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c? \u041f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0433\u0430\u0441\u0438\u0442\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0441 primary:<\/p>\n<pre><code class=\"bash\">docker stop postgres_1<\/code><\/pre>\n<p>\u0412 \u043b\u043e\u0433\u0430\u0445 \u043d\u0430 \u0440\u0435\u043f\u043b\u0438\u043a\u0435 \u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0442\u0438\u043f\u0430:<\/p>\n<pre><code>LOG:\u00a0 database system was not properly shut down; automatic recovery in progress \u2026 LOG:\u00a0 database system is ready to accept connections<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0431\u044b\u0432\u0448\u0430\u044f \u0440\u0435\u043f\u043b\u0438\u043a\u0430 \u0441\u0442\u0430\u043d\u0435\u0442 <strong><em>primary<\/em><\/strong> \u0438 \u0431\u0443\u0434\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u0430 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u0441\u0442\u0440\u043e\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u0445\u043e\u0441\u0442:<\/p>\n<pre><code class=\"bash\">docker start postgres_1<\/code><\/pre>\n<p>\u041e\u043d \u043f\u043e\u0434\u043d\u0438\u043c\u0435\u0442\u0441\u044f, \u0443\u0432\u0438\u0434\u0438\u0442, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043c\u0430\u0441\u0442\u0435\u0440, \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0440\u0435\u043f\u043b\u0438\u043a\u0430:<\/p>\n<pre><code>INFO\u00a0 ==> This node was acting as a primary before restart!  INFO\u00a0 ==> Current master is 'pg-2:5432'. Cloning\/rewinding it and acting as a standby node...  ...  LOG:\u00a0 database system is ready to accept read-only connections<\/code><\/pre>\n<h2>\u041a\u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441 primary?<\/h2>\n<p>\u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441: \u00ab\u041a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u044c, \u0432 \u043a\u0430\u043a\u043e\u0439 \u0440\u043e\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0445\u043e\u0441\u0442?\u00bb \u041e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u043d\u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code class=\"sql\">select case when pg_is_in_recovery() then 'secondary' else 'primary' end as host_status;<\/code><\/pre>\n<p>\u0418\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u0435\u0433\u043e \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0431\u0435\u0437 \u044f\u0432\u043d\u043e\u0433\u043e \u0432\u0445\u043e\u0434\u0430 \u0432 psql:<\/p>\n<pre><code class=\"bash\">psql -c \"select case when pg_is_in_recovery() then 'secondary' else 'primary' end as host_status;\" \"dbname=habrdb user=habrpguser password=pgpwd4habr\"<\/code><\/pre>\n<p>\u0410 \u0435\u0449\u0451 \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0438\u0437 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"bash\">docker exec postgres_1 psql -c \"select case when pg_is_in_recovery() then 'secondary' else 'primary' end as host_status;\" \"dbname=habrdb user=habrpguser password=pgpwd4habr\"<\/code><\/pre>\n<h2>\u041a\u043b\u0430\u0441\u0442\u0435\u0440 \u0432 Testcontainers<\/h2>\n<p>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 Continuous Integration (CI) \u2014 \u0434\u0432\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0441\u0438\u043b\u044c\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u041f\u041e. \u041a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u043a\u0430\u043a\u0438\u043c-\u043b\u0438\u0431\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u043c \u0438\u043b\u0438 \u0431\u0440\u043e\u043a\u0435\u0440\u043e\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u0443\u0434\u043e\u0431\u043d\u043e \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/habr.com\/ru\/companies\/jugru\/articles\/343298\/\" rel=\"noopener noreferrer nofollow\">Testcontainers<\/a>. \u0412 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <a href=\"https:\/\/github.com\/mfvanek\/pg-index-health\" rel=\"noopener noreferrer nofollow\">pg-index-health<\/a>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0441 open source \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e \u0438 \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u044e, \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043f\u043e \u0441\u0431\u043e\u0440\u0443 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043d\u0430 \u0432\u0441\u0435\u0445 \u0445\u043e\u0441\u0442\u0430\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430. \u0414\u043b\u044f \u0435\u0433\u043e \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0442\u0435\u0440 PostgreSQL \u0432 end-to-end \u0442\u0435\u0441\u0442\u0430\u0445.<\/p>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0432 <strong>Testcontainers<\/strong> \u043d\u0435 \u0431\u044b\u043b\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043e\u0431\u0451\u0440\u0442\u043a\u0443 <a href=\"https:\/\/github.com\/mfvanek\/pg-index-health\/blob\/c5d3aea8eee7d681bd5d3b8d3277995e822ebc45\/pg-index-health-testing\/src\/main\/java\/io\/github\/mfvanek\/pg\/testing\/PostgresBitnamiRepmgrContainer.java#L27\" rel=\"noopener noreferrer nofollow\">PostgresBitnamiRepmgrContainer<\/a> \u043d\u0430\u0434 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c <strong>JdbcDatabaseContainer<\/strong> \u0438 \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043b\u0438 \u0432\u0441\u0451 \u044d\u0442\u043e \u0432 <a href=\"https:\/\/github.com\/mfvanek\/pg-index-health\/blob\/c5d3aea8eee7d681bd5d3b8d3277995e822ebc45\/pg-index-health-testing\/src\/main\/java\/io\/github\/mfvanek\/pg\/testing\/PostgreSqlClusterWrapper.java#L41\" rel=\"noopener noreferrer nofollow\">PostgreSqlClusterWrapper<\/a>. \u0411\u043e\u043b\u044c\u0448\u043e\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0410\u043b\u0435\u043a\u0441\u0435\u044e <a class=\"mention\" href=\"\/users\/evreke\">@Evreke<\/a> \u0410\u043d\u0442\u0438\u043f\u0438\u043d\u0443 \u0437\u0430 \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043d\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443!<\/p>\n<p><strong>PostgreSqlClusterWrapper<\/strong> \u0443\u043c\u0435\u0435\u0442 \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0442\u044c \u0434\u0432\u0443\u0445\u043d\u043e\u0434\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440, \u0430 \u0442\u0430\u043a\u0436\u0435 \u00ab\u0433\u0430\u0441\u0438\u0442\u044c\u00bb \u043f\u0435\u0440\u0432\u044b\u0439 \u0445\u043e\u0441\u0442, \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c <strong><em>auto failover<\/em><\/strong>. Jar-\u043d\u0438\u043a \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0432 <a href=\"https:\/\/mvnrepository.com\/artifact\/io.github.mfvanek\/pg-index-health-testing\" rel=\"noopener noreferrer nofollow\">Maven Central<\/a>.<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u0442\u0430\u043b\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0430\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430: \u043f\u043e\u0434\u043d\u044f\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u0445\u043e\u0441\u0442, \u0437\u0430\u0442\u0435\u043c \u0432\u0442\u043e\u0440\u043e\u0439; \u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f, \u043f\u043e\u043a\u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u0445\u043e\u0441\u0442 \u0432\u043e\u0439\u0434\u0435\u0442 \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440 \u0438 \u043d\u0430\u0447\u043d\u0451\u0442 \u0441\u0442\u0440\u0438\u043c\u0438\u0442\u044c <strong>WAL<\/strong> \u0441 <strong>primary<\/strong>. \u0414\u043b\u044f \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 <code>LogMessageWaitStrategy<\/code> \u0438 <code>Awaitility<\/code>.<\/p>\n<p>\u0417\u0430\u0447\u0435\u043c <strong>PostgreSqlClusterWrapper<\/strong> \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432\u0430\u043c? \u0413\u043b\u0430\u0432\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u043d\u0435\u0448\u0442\u0430\u0442\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043d\u0430 \u0411\u0414: \u0441\u043c\u043e\u0436\u0435\u0442 \u043b\u0438 \u043e\u043d\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0440\u0438 \u0441\u043c\u0435\u043d\u0435 \u043c\u0430\u0441\u0442\u0435\u0440\u0430.<\/p>\n<h2>\u0422\u044e\u043d\u0438\u043d\u0433 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 JDBC \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430<\/h2>\n<p><a href=\"https:\/\/jdbc.postgresql.org\/documentation\/use\/\" rel=\"noopener noreferrer nofollow\">JDBC driver<\/a> \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0443\u044e \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0443 \u0438 \u0441\u0430\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043a \u043d\u043e\u0432\u043e\u043c\u0443 primary-\u0445\u043e\u0441\u0442\u0443, \u0435\u0441\u043b\u0438 \u0432 connection URL \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0441\u0442\u043e\u0432 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>jdbc:postgresql:\/\/localhost:32769,localhost:32770\/test_db?connectTimeout=1&amp;hostRecheckSeconds=2&amp;socketTimeout=600&amp;targetServerType=primary<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0434\u0432\u0430 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 \u0411\u0414 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0440\u0442\u0430\u0445: <code>localhost:32769<\/code> \u0438 <code>localhost:32770<\/code>, \u043d\u043e \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0432\u0430\u0436\u043d\u0435\u0435 \u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p><code>targetServerType=primary<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0430\u0441\u0442\u0435\u0440-\u0445\u043e\u0441\u0442 \u0411\u0414. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0447\u0442\u0435\u043d\u0438\u0435 \u0441 \u0440\u0435\u043f\u043b\u0438\u043a\u0438, \u0442\u043e \u0432\u0430\u043c \u043f\u043e\u0434\u043e\u0439\u0434\u0451\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 <code>targetServerType=secondary<\/code> \u0438\u043b\u0438 <code>targetServerType=preferSecondary<\/code>.<\/p>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>connectTimeout<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u043a\u0430\u043a \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u0436\u0434\u0430\u0442\u044c \u0434\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u0411\u0414. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u2014 10 \u0441\u0435\u043a\u0443\u043d\u0434. \u0423\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0430\u0433\u0440\u0435\u0441\u0441\u0438\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u0445\u043e\u0441\u0442\u044b \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u0438 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043a \u043d\u0438\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p>\u041e\u043f\u0446\u0438\u044f <code>hostRecheckSeconds<\/code> \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u043a\u0442\u043e \u0443 \u043d\u0430\u0441 \u0441\u0435\u0439\u0447\u0430\u0441 \u043c\u0430\u0441\u0442\u0435\u0440, \u0430 \u043a\u0442\u043e \u0440\u0435\u043f\u043b\u0438\u043a\u0430.<\/p>\n<p>\u0418, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, <code>socketTimeout<\/code> \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u0435\u043b\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0411\u0414. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u0430; \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0443\u0436\u043d\u043e \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0442\u044c \u043f\u043e\u0434 \u0432\u0430\u0448\u0438 \u043d\u0443\u0436\u0434\u044b.<\/p>\n<p>\u0411\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u043e, \u044d\u0442\u043e \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 JDBC \u0434\u0440\u0430\u0439\u0432\u0435\u0440, \u043d\u043e \u044d\u0442\u043e, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u043c\u0438\u043d\u0438\u043c\u0443\u043c.<\/p>\n<p>\u0412 \u043f\u0440\u043e\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0443\u043b \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u043a \u0411\u0414. \u041a\u0430\u0436\u0434\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f connection pool\u2019\u0430 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0445 \u0442\u043e\u043d\u043a\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f\u043c\u0438 \u0432 \u043f\u0443\u043b\u0435. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/miensol.pl\/database-timeouts\/\" rel=\"noopener noreferrer nofollow\">Database timeouts<\/a>. \u0414\u043b\u044f <strong>HikariCP<\/strong>, \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c <code>connectionTimeout<\/code> \u0438 <code>validationTimeout<\/code>:<\/p>\n<pre><code class=\"java\">import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource;  import javax.annotation.Nonnull;  import lombok.SneakyThrows; import lombok.experimental.UtilityClass; import org.postgresql.Driver;  @UtilityClass public class HikariDataSourceProvider {      @Nonnull     @SneakyThrows     public HikariDataSource getDataSource(@Nonnull final String jdbcUrl,                                           @Nonnull final String username,                                           @Nonnull final String password) {         final HikariConfig hikariConfig = new HikariConfig();         hikariConfig.setMaximumPoolSize(3);         hikariConfig.setConnectionTimeout(250L);         hikariConfig.setMaxLifetime(30_000L);         hikariConfig.setValidationTimeout(250L);         hikariConfig.setJdbcUrl(jdbcUrl);         hikariConfig.setUsername(username);         hikariConfig.setPassword(password);         hikariConfig.setDriverClassName(Driver.class.getCanonicalName());         return new HikariDataSource(hikariConfig);     } } <\/code><\/pre>\n<p>\u042f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b \u043f\u0430\u0440\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <strong>PostgreSqlClusterWrapper<\/strong>, \u0438 \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043b \u0438\u0445 \u043d\u0430 GitHub: <a href=\"https:\/\/github.com\/mfvanek\/java-experiments\/tree\/master\/console-app-example\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u043e\u0435<\/a> \u0438 <a href=\"https:\/\/github.com\/mfvanek\/java-experiments\/tree\/master\/spring-boot-app-example\" rel=\"noopener noreferrer nofollow\">spring-boot<\/a>. \u041f\u0443\u0441\u0442\u044c \u043e\u043d\u0438 \u0441\u0442\u0430\u043d\u0443\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0434\u043b\u044f \u0432\u0430\u0448\u0438\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432!<\/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\/754168\/\"> https:\/\/habr.com\/ru\/articles\/754168\/<\/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<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0412 \u043e\u0434\u043d\u043e\u0439 \u0438\u0445 \u0441\u0432\u043e\u0438\u0445 <a href=\"https:\/\/habr.com\/ru\/articles\/578744\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439<\/a> \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c PostgreSQL \u0432 Docker. \u0422\u043e\u0433\u0434\u0430 \u0440\u0435\u0447\u044c \u0448\u043b\u0430 \u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u00ab\u0432\u0430\u043d\u0438\u043b\u044c\u043d\u044b\u0445\u00bb \u043e\u0431\u0440\u0430\u0437\u043e\u0432 Postgres \u0438 \u043f\u043e\u0434\u043d\u044f\u0442\u0438\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0445\u043e\u0441\u0442\u0430. \u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043a\u0430\u043a \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432, \u043d\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u043e\u0439 \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u0438 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f <a href=\"https:\/\/en.wikipedia.org\/wiki\/High-availability_cluster\" rel=\"noopener noreferrer nofollow\">\u0432\u044b\u0441\u043e\u043a\u043e\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435<\/a> (\u043e\u0442\u043a\u0430\u0437\u043e\u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u044b\u0435, \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435) \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 PostgreSQL.<\/p>\n<p>\u0422\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u043c\u0438\u043c\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0442\u043a\u0430\u0437\u043e\u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0441\u0442\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043f\u0435\u0440\u0435\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044f \u0447\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 primary \u0445\u043e\u0441\u0442\u0430 \u043d\u0430 \u0440\u0435\u043f\u043b\u0438\u043a\u0438. \u0412\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0431\u0443\u0434\u0443\u0442 \u0438\u0434\u0442\u0438 \u043d\u0430 primary \u0445\u043e\u0441\u0442.<\/p>\n<details class=\"spoiler\">\n<summary>\u0422\u0435\u0440\u043c\u0438\u043d\u043e\u043b\u043e\u0433\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435 \u043a\u0430\u0441\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043b\u043e\u0433\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>primary = master = \u043c\u0430\u0441\u0442\u0435\u0440-\u0445\u043e\u0441\u0442<\/p>\n<\/li>\n<li>\n<p>slave = standby = secondary = \u0440\u0435\u043f\u043b\u0438\u043a\u0430<\/p>\n<\/li>\n<li>\n<p>failover \u2014 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0433\u043e \u0445\u043e\u0441\u0442\u0430 (\u0440\u0435\u043f\u043b\u0438\u043a\u0438) \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 (\u043f\u0440\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438). \u0420\u0435\u043f\u043b\u0438\u043a\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u043c primary \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c.<\/p>\n<\/li>\n<li>\n<p>switchover \u2014 \u0440\u0443\u0447\u043d\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0430 primary \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u0445\u043e\u0441\u0442\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435.<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\">\n<div><figcaption>\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 <a href=\"https:\/\/www.enterprisedb.com\/postgres-tutorials\/postgresql-replication-and-automatic-failover-tutorial\" rel=\"noopener noreferrer nofollow\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a><\/figcaption><\/div>\n<\/figure>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043b\u043e\u0433\u0438\u0438 <a href=\"https:\/\/cloud.google.com\/architecture\/architectures-high-availability-postgresql-clusters-compute-engine\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<\/div>\n<\/details>\n<p>\u0418\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 PostgreSQL \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 <a href=\"https:\/\/www.postgresql.org\/docs\/current\/high-availability.html\" rel=\"noopener noreferrer nofollow\">\u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c<\/a> \u0434\u043b\u044f \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f (promote) \u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u0432 primary \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0430\u0432\u0430\u0440\u0438\u0438, \u043d\u043e \u043d\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f HA-\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 (<strong>H<\/strong>igh <strong>A<\/strong>vailability). \u041d\u0430 \u0440\u044b\u043d\u043a\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0446\u0435\u043b\u044b\u0439 \u0440\u044f\u0434 \u0442\u0430\u043a\u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043e\u0442 \u0440\u0430\u0437\u043d\u044b\u0445 \u0432\u0435\u043d\u0434\u043e\u0440\u043e\u0432 (\u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c \u0442\u0435\u0440\u043c\u0438\u043d HA-\u0443\u0442\u0438\u043b\u0438\u0442\u044b). \u042f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/youtu.be\/sZjErOEaM9s\" rel=\"noopener noreferrer nofollow\">\u0432\u0438\u0434\u0435\u043e\u0434\u043e\u043a\u043b\u0430\u0434<\/a> \u0410\u043b\u0435\u043a\u0441\u0435\u044f \u041b\u0435\u0441\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u0434\u043b\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u043a\u0440\u0443\u0433\u043e\u0437\u043e\u0440\u0430 \u0432 \u044d\u0442\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438.<\/p>\n<p>\u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u0441\u0430\u043c\u044b\u043c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/habr.com\/ru\/post\/518216\/\" rel=\"noopener noreferrer nofollow\">Patroni<\/a>, \u043d\u043e \u044f \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/www.repmgr.org\/\" rel=\"noopener noreferrer nofollow\">repmgr<\/a> \u043e\u0442 EnterpriseDB. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u043b\u044f <strong>repmgr<\/strong> \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0435 <a href=\"https:\/\/github.com\/bitnami\/containers\/tree\/main\/bitnami\/postgresql-repmgr\" rel=\"noopener noreferrer nofollow\">\u043e\u0431\u0440\u0430\u0437\u044b \u043e\u0442 bitnami<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442\u0441\u044f.<\/p>\n<p>\u041e\u0442\u043a\u0430\u0437\u043e\u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0441\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435 PostgreSQL \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u0437\u0430 \u0441\u0447\u0451\u0442 <a href=\"https:\/\/www.postgresql.org\/docs\/15\/warm-standby.html#STREAMING-REPLICATION\" rel=\"noopener noreferrer nofollow\">WAL \u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u043e\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438<\/a>. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/selectel.ru\/blog\/tutorials\/how-to-set-up-replication-in-postgresql\/\" rel=\"noopener noreferrer nofollow\">\u0432 \u0431\u043b\u043e\u0433\u0435 Selectel<\/a>. \u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c: \u043b\u044e\u0431\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0435 \u043d\u0430 <strong>primary<\/strong>, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432 <strong>WAL<\/strong>, \u0430 \u043f\u043e\u0442\u043e\u043c \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e \u0441\u0435\u0442\u0438 \u043d\u0430 \u0440\u0435\u043f\u043b\u0438\u043a\u0443 \u0438 \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0442\u0430\u043c.\u00a0<\/p>\n<details class=\"spoiler\">\n<summary>\u041b\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e DML \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u043e\u0435 \u0432 \u0431\u043b\u043e\u043a <code>BEGIN\/ROLLBACK<\/code>, \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c: \u043e\u043d\u043e \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442 \u0432\u0438\u0434\u0438\u043c\u043e\u0433\u043e \u0432\u043d\u0435\u0448\u043d\u0435\u043c\u0443 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043c\u0435\u0434\u043b\u0438\u0442\u044c \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0443\u0440\u043e\u043d\u0438\u0442\u044c \u0432\u0430\u0448 \u043a\u043b\u0430\u0441\u0442\u0435\u0440 \u0411\u0414.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043d\u0430 100 \u0413\u0431\u0430\u0439\u0442; \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0431\u043d\u043e\u0432\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0443 \u0441\u0442\u0440\u043e\u043a \u0432 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u0427\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0439\u0442\u0438 \u043d\u0435 \u0442\u0430\u043a? \u041c\u043e\u0436\u0435\u0442 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u044c\u0441\u044f CPU \u0438\u043b\u0438 \u043c\u0435\u0441\u0442\u043e \u043d\u0430 \u0434\u0438\u0441\u043a\u0435 (MVCC \u0438 WAL), \u0437\u0430\u0431\u0438\u0442\u044c\u0441\u044f \u0441\u0435\u0442\u044c. \u0412 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043d\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440, \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0441\u0442\u0430\u0438\u0432\u0430\u0442\u044c \u0438, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0443. \u0421\u043d\u0430\u0440\u0443\u0436\u0438 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043a\u0430\u043a denial of service.<\/p>\n<p><strong><em>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u043b\u0438\u0431\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043d\u0430 \u0411\u0414, \u043f\u043e\u0434\u0443\u043c\u0430\u0439\u0442\u0435, \u043a \u0447\u0435\u043c\u0443 \u043e\u043d\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u0442.<\/em><\/strong><\/p>\n<\/div>\n<\/details>\n<h2>\u041a\u043b\u0430\u0441\u0442\u0435\u0440 \u0447\u0435\u0440\u0435\u0437 docker-compose<\/h2>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0434\u043d\u0438\u043c\u0435\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440 PostgreSQL \u0432 Docker \u0447\u0435\u0440\u0435\u0437 compose-\u0444\u0430\u0439\u043b. \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u043a\u043e\u0434\u044b, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e, <a href=\"https:\/\/github.com\/mfvanek\/useful-sql-scripts\/tree\/master\/running_pg_cluster_in_docker\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043d\u0430 GitHub<\/a>.<\/p>\n<p>\u041c\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 compose-\u0444\u0430\u0439\u043b\u0430 \u0431\u0430\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 <a href=\"https:\/\/github.com\/bitnami\/containers\/blob\/main\/bitnami\/postgresql-repmgr\/docker-compose.yml\" rel=\"noopener noreferrer nofollow\">\u0442\u0430\u043a\u043e\u0432\u043e\u043c<\/a> \u043e\u0442 <strong>bitnami<\/strong>. \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0447\u0435\u0440\u0435\u0437 <strong><em>postgres_exporter<\/em><\/strong>. \u0414\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0438\u0437 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0441 compose-\u0444\u0430\u0439\u043b\u043e\u043c:<\/p>\n<pre><code class=\"bash\">docker-compose --project-name=\"habr-pg-ha-14\" up -d<\/code><\/pre>\n<p>\u0418\u043c\u0435\u0439\u0442\u0435 \u0432 \u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f: \u043d\u0430 Linux \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u0430 macOS\/Windows \u0434\u043e\u043b\u044c\u0448\u0435. \u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 \u0434\u043b\u044f \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043e \u0434\u0432\u0443\u0445 \u043c\u0438\u043d\u0443\u0442.<\/p>\n<pre><code class=\"yaml\">version: \"3.9\" services:   pg-1:     container_name: postgres_1     image: docker.io\/bitnami\/postgresql-repmgr:14.9.0     ports:       - \"6432:5432\"     volumes:       - pg_1_data:\/bitnami\/postgresql       - .\/create_extensions.sql:\/docker-entrypoint-initdb.d\/create_extensions.sql:ro     environment:       - POSTGRESQL_POSTGRES_PASSWORD=adminpgpwd4habr       - POSTGRESQL_USERNAME=habrpguser       - POSTGRESQL_PASSWORD=pgpwd4habr       - POSTGRESQL_DATABASE=habrdb       - REPMGR_PASSWORD=repmgrpassword       - REPMGR_PRIMARY_HOST=pg-1       - REPMGR_PRIMARY_PORT=5432       - REPMGR_PARTNER_NODES=pg-1,pg-2:5432       - REPMGR_NODE_NAME=pg-1       - REPMGR_NODE_NETWORK_NAME=pg-1       - REPMGR_PORT_NUMBER=5432       - REPMGR_CONNECT_TIMEOUT=1       - REPMGR_RECONNECT_ATTEMPTS=2       - REPMGR_RECONNECT_INTERVAL=1       - REPMGR_MASTER_RESPONSE_TIMEOUT=5     restart: unless-stopped     networks:       - postgres-ha    pg-2:     container_name: postgres_2     image: docker.io\/bitnami\/postgresql-repmgr:14.9.0     ports:       - \"6433:5432\"     volumes:       - pg_2_data:\/bitnami\/postgresql       - .\/create_extensions.sql:\/docker-entrypoint-initdb.d\/create_extensions.sql:ro     environment:       - POSTGRESQL_POSTGRES_PASSWORD=adminpgpwd4habr       - POSTGRESQL_USERNAME=habrpguser       - POSTGRESQL_PASSWORD=pgpwd4habr       - POSTGRESQL_DATABASE=habrdb       - REPMGR_PASSWORD=repmgrpassword       - REPMGR_PRIMARY_HOST=pg-1       - REPMGR_PRIMARY_PORT=5432       - REPMGR_PARTNER_NODES=pg-1,pg-2:5432       - REPMGR_NODE_NAME=pg-2       - REPMGR_NODE_NETWORK_NAME=pg-2       - REPMGR_PORT_NUMBER=5432       - REPMGR_CONNECT_TIMEOUT=1       - REPMGR_RECONNECT_ATTEMPTS=2       - REPMGR_RECONNECT_INTERVAL=1       - REPMGR_MASTER_RESPONSE_TIMEOUT=5     restart: unless-stopped     networks:       - postgres-ha    pg_exporter-1:     container_name: pg_exporter_1     image: prometheuscommunity\/postgres-exporter:v0.11.1     command: --log.level=debug     environment:       DATA_SOURCE_URI: \"pg-1:5432\/habrdb?sslmode=disable\"       DATA_SOURCE_USER: habrpguser       DATA_SOURCE_PASS: pgpwd4habr       PG_EXPORTER_EXTEND_QUERY_PATH: \"\/etc\/postgres_exporter\/queries.yaml\"     volumes:       - .\/queries.yaml:\/etc\/postgres_exporter\/queries.yaml:ro     ports:       - \"9187:9187\"     networks:       - postgres-ha     restart: unless-stopped     depends_on:       - pg-1    pg_exporter-2:     container_name: pg_exporter_2     image: prometheuscommunity\/postgres-exporter:v0.11.1     command: --log.level=debug     environment:       DATA_SOURCE_URI: \"pg-2:5432\/habrdb?sslmode=disable\"       DATA_SOURCE_USER: habrpguser       DATA_SOURCE_PASS: pgpwd4habr       PG_EXPORTER_EXTEND_QUERY_PATH: \"\/etc\/postgres_exporter\/queries.yaml\"     volumes:       - .\/queries.yaml:\/etc\/postgres_exporter\/queries.yaml:ro     ports:       - \"9188:9187\"     networks:       - postgres-ha     restart: unless-stopped     depends_on:       - pg-2  networks:   postgres-ha:     driver: bridge  volumes:   pg_1_data:   pg_2_data: <\/code><\/pre>\n<h2>\u0418\u043d\u0438\u0446\u0438\u0438\u0440\u0443\u0435\u043c auto failover<\/h2>\n<p>\u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 <strong>repmgr<\/strong> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <strong><em>switchover<\/em><\/strong> \u2014 \u0440\u0443\u0447\u043d\u0430\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u0430\u044f \u0441\u043c\u0435\u043d\u0430 \u043c\u0430\u0441\u0442\u0435\u0440-\u0445\u043e\u0441\u0442\u0430 \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0432 \u043e\u0431\u0440\u0430\u0437\u0430\u0445 \u043e\u0442 <strong>bitnami<\/strong> \u044d\u0442\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f (\u0432 \u0441\u0442\u0430\u0440\u043e\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0431\u044b\u043b\u0430 <a href=\"https:\/\/github.com\/bitnami\/bitnami-docker-postgresql-repmgr\/issues\/51\" rel=\"noopener noreferrer nofollow\">issue<\/a> \u043d\u0430 \u044d\u0442\u043e, \u043d\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0443\u0434\u0430\u043b\u0435\u043d).<\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e <strong><em>failover<\/em><\/strong> \u0440\u0435\u0436\u0438\u043c. \u041a\u0430\u043a \u0435\u0433\u043e \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c? \u041f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0433\u0430\u0441\u0438\u0442\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0441 primary:<\/p>\n<pre><code class=\"bash\">docker stop postgres_1<\/code><\/pre>\n<p>\u0412 \u043b\u043e\u0433\u0430\u0445 \u043d\u0430 \u0440\u0435\u043f\u043b\u0438\u043a\u0435 \u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0442\u0438\u043f\u0430:<\/p>\n<pre><code>LOG:\u00a0 database system was not properly shut down; automatic recovery in progress \u2026 LOG:\u00a0 database system is ready to accept connections<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0431\u044b\u0432\u0448\u0430\u044f \u0440\u0435\u043f\u043b\u0438\u043a\u0430 \u0441\u0442\u0430\u043d\u0435\u0442 <strong><em>primary<\/em><\/strong> \u0438 \u0431\u0443\u0434\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u0430 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u0441\u0442\u0440\u043e\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u0445\u043e\u0441\u0442:<\/p>\n<pre><code class=\"bash\">docker start postgres_1<\/code><\/pre>\n<p>\u041e\u043d \u043f\u043e\u0434\u043d\u0438\u043c\u0435\u0442\u0441\u044f, \u0443\u0432\u0438\u0434\u0438\u0442, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043c\u0430\u0441\u0442\u0435\u0440, \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0440\u0435\u043f\u043b\u0438\u043a\u0430:<\/p>\n<pre><code>INFO\u00a0 ==> This node was acting as a primary before restart!  INFO\u00a0 ==> Current master is 'pg-2:5432'. Cloning\/rewinding it and acting as a standby node...  ...  LOG:\u00a0 database system is ready to accept read-only connections<\/code><\/pre>\n<h2>\u041a\u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441 primary?<\/h2>\n<p>\u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441: \u00ab\u041a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u044c, \u0432 \u043a\u0430\u043a\u043e\u0439 \u0440\u043e\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0445\u043e\u0441\u0442?\u00bb \u041e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u043d\u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code class=\"sql\">select case when pg_is_in_recovery() then 'secondary' else 'primary' end as host_status;<\/code><\/pre>\n<p>\u0418\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u0435\u0433\u043e \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0431\u0435\u0437 \u044f\u0432\u043d\u043e\u0433\u043e \u0432\u0445\u043e\u0434\u0430 \u0432 psql:<\/p>\n<pre><code class=\"bash\">psql -c \"select case when pg_is_in_recovery() then 'secondary' else 'primary' end as host_status;\" \"dbname=habrdb user=habrpguser password=pgpwd4habr\"<\/code><\/pre>\n<p>\u0410 \u0435\u0449\u0451 \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0438\u0437 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"bash\">docker exec postgres_1 psql -c \"select case when pg_is_in_recovery() then 'secondary' else 'primary' end as host_status;\" \"dbname=habrdb user=habrpguser password=pgpwd4habr\"<\/code><\/pre>\n<h2>\u041a\u043b\u0430\u0441\u0442\u0435\u0440 \u0432 Testcontainers<\/h2>\n<p>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 Continuous Integration (CI) \u2014 \u0434\u0432\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0441\u0438\u043b\u044c\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u041f\u041e. \u041a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u043a\u0430\u043a\u0438\u043c-\u043b\u0438\u0431\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u043c \u0438\u043b\u0438 \u0431\u0440\u043e\u043a\u0435\u0440\u043e\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u0443\u0434\u043e\u0431\u043d\u043e \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/habr.com\/ru\/companies\/jugru\/articles\/343298\/\" rel=\"noopener noreferrer nofollow\">Testcontainers<\/a>. \u0412 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <a href=\"https:\/\/github.com\/mfvanek\/pg-index-health\" rel=\"noopener noreferrer nofollow\">pg-index-health<\/a>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0441 open source \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e \u0438 \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u044e, \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043f\u043e \u0441\u0431\u043e\u0440\u0443 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043d\u0430 \u0432\u0441\u0435\u0445 \u0445\u043e\u0441\u0442\u0430\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430. \u0414\u043b\u044f \u0435\u0433\u043e \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0442\u0435\u0440 PostgreSQL \u0432 end-to-end \u0442\u0435\u0441\u0442\u0430\u0445.<\/p>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0432 <strong>Testcontainers<\/strong> \u043d\u0435 \u0431\u044b\u043b\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043e\u0431\u0451\u0440\u0442\u043a\u0443 <a href=\"https:\/\/github.com\/mfvanek\/pg-index-health\/blob\/c5d3aea8eee7d681bd5d3b8d3277995e822ebc45\/pg-index-health-testing\/src\/main\/java\/io\/github\/mfvanek\/pg\/testing\/PostgresBitnamiRepmgrContainer.java#L27\" rel=\"noopener noreferrer nofollow\">PostgresBitnamiRepmgrContainer<\/a> \u043d\u0430\u0434 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c <strong>JdbcDatabaseContainer<\/strong> \u0438 \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043b\u0438 \u0432\u0441\u0451 \u044d\u0442\u043e \u0432 <a href=\"https:\/\/github.com\/mfvanek\/pg-index-health\/blob\/c5d3aea8eee7d681bd5d3b8d3277995e822ebc45\/pg-index-health-testing\/src\/main\/java\/io\/github\/mfvanek\/pg\/testing\/PostgreSqlClusterWrapper.java#L41\" rel=\"noopener noreferrer nofollow\">PostgreSqlClusterWrapper<\/a>. \u0411\u043e\u043b\u044c\u0448\u043e\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0410\u043b\u0435\u043a\u0441\u0435\u044e <a class=\"mention\" href=\"\/users\/evreke\">@Evreke<\/a> \u0410\u043d\u0442\u0438\u043f\u0438\u043d\u0443 \u0437\u0430 \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043d\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443!<\/p>\n<p><strong>PostgreSqlClusterWrapper<\/strong> \u0443\u043c\u0435\u0435\u0442 \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0442\u044c \u0434\u0432\u0443\u0445\u043d\u043e\u0434\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440, \u0430 \u0442\u0430\u043a\u0436\u0435 \u00ab\u0433\u0430\u0441\u0438\u0442\u044c\u00bb \u043f\u0435\u0440\u0432\u044b\u0439 \u0445\u043e\u0441\u0442, \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c <strong><em>auto failover<\/em><\/strong>. Jar-\u043d\u0438\u043a \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0432 <a href=\"https:\/\/mvnrepository.com\/artifact\/io.github.mfvanek\/pg-index-health-testing\" rel=\"noopener noreferrer nofollow\">Maven Central<\/a>.<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u0442\u0430\u043b\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0430\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430: \u043f\u043e\u0434\u043d\u044f\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u0445\u043e\u0441\u0442, \u0437\u0430\u0442\u0435\u043c \u0432\u0442\u043e\u0440\u043e\u0439; \u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f, \u043f\u043e\u043a\u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u0445\u043e\u0441\u0442 \u0432\u043e\u0439\u0434\u0435\u0442 \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440 \u0438 \u043d\u0430\u0447\u043d\u0451\u0442 \u0441\u0442\u0440\u0438\u043c\u0438\u0442\u044c <strong>WAL<\/strong> \u0441 <strong>primary<\/strong>. \u0414\u043b\u044f \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 <code>LogMessageWaitStrategy<\/code> \u0438 <code>Awaitility<\/code>.<\/p>\n<p>\u0417\u0430\u0447\u0435\u043c <strong>PostgreSqlClusterWrapper<\/strong> \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432\u0430\u043c? \u0413\u043b\u0430\u0432\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u043d\u0435\u0448\u0442\u0430\u0442\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043d\u0430 \u0411\u0414: \u0441\u043c\u043e\u0436\u0435\u0442 \u043b\u0438 \u043e\u043d\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0440\u0438 \u0441\u043c\u0435\u043d\u0435 \u043c\u0430\u0441\u0442\u0435\u0440\u0430.<\/p>\n<h2>\u0422\u044e\u043d\u0438\u043d\u0433 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 JDBC \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430<\/h2>\n<p><a href=\"https:\/\/jdbc.postgresql.org\/documentation\/use\/\" rel=\"noopener noreferrer nofollow\">JDBC driver<\/a> \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0443\u044e \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0443 \u0438 \u0441\u0430\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043a \u043d\u043e\u0432\u043e\u043c\u0443 primary-\u0445\u043e\u0441\u0442\u0443, \u0435\u0441\u043b\u0438 \u0432 connection URL \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0441\u0442\u043e\u0432 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>jdbc:postgresql:\/\/localhost:32769,localhost:32770\/test_db?connectTimeout=1&amp;hostRecheckSeconds=2&amp;socketTimeout=600&amp;targetServerType=primary<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0434\u0432\u0430 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 \u0411\u0414 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0440\u0442\u0430\u0445: <code>localhost:32769<\/code> \u0438 <code>localhost:327<\/code><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-351988","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/351988","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=351988"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/351988\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=351988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=351988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=351988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}