{"id":282761,"date":"2016-12-20T12:55:05","date_gmt":"2016-12-20T09:55:05","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=282761"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=282761","title":{"rendered":"\u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 ClickHouse, \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044f\u043c\u0438 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u0437 PHP \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440"},"content":{"rendered":"<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 <a href=\"https:\/\/habrahabr.ru\/company\/smi2\/blog\/314558\/\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u043b\u0438\u0441\u044c \u0441\u0432\u043e\u0438\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0421\u0423\u0411\u0414 ClickHouse \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 <a href=\"https:\/\/smi2.net\/\">\u0421\u041c\u04182<\/a>. \u0412 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0437\u0430\u0442\u0440\u043e\u043d\u0435\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u0431\u044a\u0435\u043c\u0430 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0440\u043e\u0441\u0442\u043e\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u043a\u043e\u0433\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u0443\u0436\u0435 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0422\u0430\u043a\u0436\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c \u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u043e\u043c \u043d\u0430\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0435 \u0434\u043b\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Data_definition_language\">DDL<\/a>-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 ClickHouse-\u043a\u043b\u0430\u0441\u0442\u0435\u0440.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/d0d\/766\/d01\/d0d766d019724159bc0896bcafad3da5.png\" alt=\"\u0414\u0432\u0430 \u0448\u0430\u0440\u0434\u0430 \u043f\u043e \u0434\u0432\u0435 \u0440\u0435\u043f\u043b\u0438\u043a\u0438\"\/><\/p>\n<p>  <a name=\"habracut\"><\/a>  <\/p>\n<p><a href=\"https:\/\/clickhouse.yandex\/\">ClickHouse<\/a> \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u0445, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0434\u0430\u0442\u0430-\u0446\u0435\u043d\u0442\u0440\u0430\u0445. \u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0421\u0423\u0411\u0414 \u043b\u0438\u043d\u0435\u0439\u043d\u043e \u0434\u043e \u0441\u043e\u0442\u0435\u043d \u0443\u0437\u043b\u043e\u0432. \u0422\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/metrika.yandex.ru\/\">\u042f\u043d\u0434\u0435\u043a\u0441.\u041c\u0435\u0442\u0440\u0438\u043a\u0430<\/a> \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u2014 \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440 \u0438\u0437 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c 400 \u0443\u0437\u043b\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>ClickHouse \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044e &quot;\u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438&quot;, \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0433\u0438\u0431\u043a\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u0414\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f <a href=\"https:\/\/zookeeper.apache.org\/\">Apache ZooKeeper<\/a> (\u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u044e 3.4.5+). \u0414\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c ZK-\u043a\u043b\u0430\u0441\u0442\u0435\u0440 (\u0430\u043d\u0441\u0430\u043c\u0431\u043b\u044c) \u0438\u0437 5 \u0443\u0437\u043b\u043e\u0432. \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u043d\u0435\u0447\u0435\u0442\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e ZK-\u0443\u0437\u043b\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 3 \u0438\u043b\u0438 5), \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043a\u0432\u043e\u0440\u0443\u043c. \u0422\u0430\u043a\u0436\u0435 \u043e\u0442\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e ZK \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445 SELECT, \u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 ALTER-\u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0440\u0435\u043f\u043b\u0438\u043a. <\/p>\n<p>  <\/p>\n<h2 id=\"shardirovanie\">\u0428\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0428\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 ClickHouse \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043f\u043e\u0440\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c (\u0447\u0438\u0442\u0430\u0442\u044c) \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u0432\u0441\u0435\u0445 \u0443\u0437\u043b\u0430\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044f throughput \u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u044f latency. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u0441 GROUP BY ClickHouse \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0445 \u0443\u0437\u043b\u0430\u0445 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0441\u0442 \u0443\u0437\u043b\u0443-\u0438\u043d\u0438\u0446\u0438\u0430\u0442\u043e\u0440\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0433\u0434\u0435 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u044b.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0434\u0432\u0438\u0436\u043e\u043a <a href=\"https:\/\/clickhouse.yandex\/reference_ru.html#Distributed\">Distributed<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u0445\u0440\u0430\u043d\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0435, \u0430 \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0435\u0442 SELECT-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b (\u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u043f\u043e\u0440\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445) \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0417\u0430\u043f\u0438\u0441\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0448\u0430\u0440\u0434\u044b \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0432 \u0434\u0432\u0443\u0445 \u0440\u0435\u0436\u0438\u043c\u0430\u0445: 1) \u0447\u0435\u0440\u0435\u0437 Distributed-\u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043b\u0438 2) \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0430\u043b\u0435\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u0447\u0435\u0440\u0435\u0437 Distributed-\u0442\u0430\u0431\u043b\u0438\u0446\u0443. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u0438 \u0440\u0435\u0436\u0438\u043c\u044b \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e. <\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 Distributed-\u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043f\u043e \u043a\u043b\u044e\u0447\u0443 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0412 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043b\u044e\u0447\u043e\u043c \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u0442. \u0435. \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <a href=\"https:\/\/clickhouse.yandex\/reference_ru.html#rand\">rand()<\/a>. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0430 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0431\u0440\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0445\u0435\u0448-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0442 \u043f\u043e\u043b\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442, \u0441 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043d\u0430\u0431\u043e\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0448\u0430\u0440\u0434\u0435, \u0430 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u2014 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0440\u043e\u0432\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u0430\u043a\u0438\u0445 \u043d\u0430\u0431\u043e\u0440\u043e\u0432 \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u0448\u0430\u0440\u0434\u0430\u043c \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0441\u0435\u0441\u0441\u0438\u0438 (sess_id) \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043a\u0430\u0437\u044b \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0448\u0430\u0440\u0434\u0435, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u0435\u0441\u0441\u0438\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e \u043f\u043e \u0432\u0441\u0435\u043c \u0448\u0430\u0440\u0434\u0430\u043c \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435 (\u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f sess_id \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435). \u041a\u043b\u044e\u0447 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c \u0438\u043b\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u043c. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0443\u044e \u0445\u0435\u0448\u0438\u0440\u0443\u044e\u0449\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <a href=\"https:\/\/clickhouse.yandex\/reference_ru.html#cityHash64\">cityHash64<\/a>. \u0412 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u043d\u0430 \u043e\u0434\u0438\u043d \u0438\u0437 \u0443\u0437\u043b\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u043f\u043e \u043a\u043b\u044e\u0447\u0443 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0443\u0436\u043d\u044b\u0435 \u0448\u0430\u0440\u0434\u044b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044f, \u043e\u0434\u043d\u0430\u043a\u043e, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0442\u0440\u0430\u0444\u0438\u043a.<\/p>\n<p>  <\/p>\n<p>\u0411\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0432\u043d\u0435 ClickHouse \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0439 \u0448\u0430\u0440\u0434 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443. \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0434\u0435\u0441\u044c \u043e\u0431\u0443\u0441\u043b\u043e\u0432\u043b\u0435\u043d\u0430 \u0442\u0435\u043c, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0443\u0437\u043b\u043e\u0432-\u0448\u0430\u0440\u0434\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0437\u0430\u043f\u0438\u0441\u044c \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439, \u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0448\u0430\u0440\u0434\u0430) \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u0438\u043c.<\/p>\n<p>  <\/p>\n<h2 id=\"replikaciya\">\u0420\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f<\/h2>\n<p>  <\/p>\n<p>ClickHouse \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 <a href=\"https:\/\/clickhouse.yandex\/reference_ru.html#\u0420\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f%20\u0434\u0430\u043d\u043d\u044b\u0445\">\u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044e<\/a> \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0445. \u0414\u043b\u044f \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0432\u0438\u0436\u043a\u0438 MergeTree-\u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u0430:<\/p>\n<p>  <\/p>\n<ul>\n<li>ReplicatedMergeTree<\/li>\n<li>ReplicatedCollapsingMergeTree<\/li>\n<li>ReplicatedAggregatingMergeTree<\/li>\n<li>ReplicatedSummingMergeTree<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0420\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043b\u0430\u0441\u0442\u0435\u0440 \u0438\u0437 6 \u0443\u0437\u043b\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c 3 \u0448\u0430\u0440\u0434\u0430 \u043f\u043e 2 \u0440\u0435\u043f\u043b\u0438\u043a\u0438. \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446.<\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u043f\u0438\u0441\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0432 \u043b\u044e\u0431\u0443\u044e \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446-\u0440\u0435\u043f\u043b\u0438\u043a, ClickHouse \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 \u0432\u0441\u0435\u043c\u0438 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<h2 id=\"primery-konfiguracii-clickhouse-klastera\">\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 ClickHouse-\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430<\/h2>\n<p>  <\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0443\u0437\u043b\u043e\u0432: <code>ch63.smi2, ch64.smi2, ch65.smi2, ch66.smi2<\/code>. \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 <em>\/etc\/clickhouse-server\/config.xml<\/em>.<\/p>\n<p>  <\/p>\n<h3 id=\"odin-shard-i-chetyre-repliki\">\u041e\u0434\u0438\u043d \u0448\u0430\u0440\u0434 \u0438 \u0447\u0435\u0442\u044b\u0440\u0435 \u0440\u0435\u043f\u043b\u0438\u043a\u0438<\/h3>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/24c\/291\/fcd\/24c291fcda9943d2b6f416fec8b6eefc.png\" alt=\"\u041e\u0434\u0438\u043d \u0448\u0430\u0440\u0434 \u0438 \u0447\u0435\u0442\u044b\u0440\u0435 \u0440\u0435\u043f\u043b\u0438\u043a\u0438\"\/><\/p>\n<p>  <\/p>\n<pre><code class=\"xml\">&lt;remote_servers&gt;     &lt;!-- One shard, four replicas --&gt;     &lt;repikator&gt;        &lt;shard&gt;            &lt;!-- replica 01_01 --&gt;            &lt;replica&gt;                &lt;host&gt;ch63.smi2&lt;\/host&gt;            &lt;\/replica&gt;             &lt;!-- replica 01_02 --&gt;            &lt;replica&gt;                &lt;host&gt;ch64.smi2&lt;\/host&gt;            &lt;\/replica&gt;             &lt;!-- replica 01_03 --&gt;            &lt;replica&gt;                &lt;host&gt;ch65.smi2&lt;\/host&gt;            &lt;\/replica&gt;             &lt;!-- replica 01_04 --&gt;            &lt;replica&gt;                &lt;host&gt;ch66.smi2&lt;\/host&gt;            &lt;\/replica&gt;        &lt;\/shard&gt;     &lt;\/repikator&gt; &lt;\/remote_servers&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u0445\u0435\u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/352\/b8d\/314\/352b8d314e574ba9aa54350715f47697.png\" alt=\"\u0421\u0445\u0435\u043c\u0430\"\/><\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">CREATE DATABASE IF NOT EXISTS dbrepikator ;  CREATE TABLE IF NOT EXISTS dbrepikator.anysumming_repl_sharded (     event_date Date DEFAULT toDate(event_time),     event_time DateTime DEFAULT now(),     body_id Int32,     views Int32 ) ENGINE = ReplicatedSummingMergeTree('\/clickhouse\/tables\/{repikator_replica}\/dbrepikator\/anysumming_repl_sharded', '{replica}', event_date, (event_date, event_time, body_id), 8192) ;  CREATE TABLE IF NOT EXISTS  dbrepikator.anysumming_repl AS dbrepikator.anysumming_repl_sharded       ENGINE = Distributed( repikator, dbrepikator, anysumming_repl_sharded , rand() )<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u0434\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0437\u0430\u0434\u0430\u0447 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u043f\u0438\u0439 \u0434\u0430\u043d\u043d\u044b\u0445.<\/li>\n<li>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0442\u043e\u043b\u044c\u043a\u043e 1 \u0448\u0430\u0440\u0434, SELECT-\u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0443\u0437\u043b\u0430\u0445.<\/li>\n<li>\u0422\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u043d\u0430 \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e\u0435 \u0440\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 \u0432\u0441\u0435\u043c\u0438 \u0443\u0437\u043b\u0430\u043c\u0438.<\/li>\n<\/ul>\n<p>  <\/p>\n<h3 id=\"chetyre-sharda-po-odnoy-replike\">\u0427\u0435\u0442\u044b\u0440\u0435 \u0448\u0430\u0440\u0434\u0430 \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u0435<\/h3>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/38f\/b5c\/3c5\/38fb5c3c51f64b7896c55b9c5d872478.png\" alt=\"\u0427\u0435\u0442\u044b\u0440\u0435 \u0448\u0430\u0440\u0434\u0430 \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u0435\"\/><\/p>\n<p>  <\/p>\n<pre><code class=\"xml\">&lt;remote_servers&gt;     &lt;!-- Four shards, one replica --&gt;     &lt;sharovara&gt;        &lt;!-- shard 01 --&gt;        &lt;shard&gt;            &lt;!-- replica 01_01 --&gt;            &lt;replica&gt;                &lt;host&gt;ch63.smi2&lt;\/host&gt;            &lt;\/replica&gt;        &lt;\/shard&gt;         &lt;!-- shard 02 --&gt;        &lt;shard&gt;            &lt;!-- replica 02_01 --&gt;            &lt;replica&gt;                &lt;host&gt;ch64.smi2&lt;\/host&gt;            &lt;\/replica&gt;        &lt;\/shard&gt;         &lt;!-- shard 03 --&gt;        &lt;shard&gt;            &lt;!-- replica 03_01 --&gt;            &lt;replica&gt;                &lt;host&gt;ch65.smi2&lt;\/host&gt;            &lt;\/replica&gt;        &lt;\/shard&gt;         &lt;!-- shard 04 --&gt;        &lt;shard&gt;            &lt;!-- replica 04_01 --&gt;            &lt;replica&gt;                &lt;host&gt;ch66.smi2&lt;\/host&gt;            &lt;\/replica&gt;        &lt;\/shard&gt;     &lt;\/sharovara&gt; &lt;\/remote_servers&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">CREATE DATABASE IF NOT EXISTS testshara  ; CREATE TABLE IF NOT EXISTS testshara.anysumming_sharded (     event_date Date DEFAULT toDate(event_time),     event_time DateTime DEFAULT now(),     body_id Int32,     views Int32 ) ENGINE = ReplicatedSummingMergeTree('\/clickhouse\/tables\/{sharovara_replica}\/sharovara\/anysumming_sharded_sharded', '{replica}', event_date, (event_date, event_time, body_id), 8192) ; CREATE TABLE IF NOT EXISTS  testshara.anysumming AS testshara.anysumming_sharded       ENGINE = Distributed( sharovara, testshara, anysumming_sharded , rand() )<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u0434\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 4 \u0448\u0430\u0440\u0434\u0430, SELECT-\u0437\u0430\u043f\u0440\u043e\u0441 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u043d\u0430 \u0432\u0441\u0435\u0445 \u0443\u0437\u043b\u0430\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u041d\u0430\u0438\u043c\u0435\u043d\u0435\u0435 \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 (\u043f\u043e\u0442\u0435\u0440\u044f \u0443\u0437\u043b\u0430 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043f\u043e\u0442\u0435\u0440\u0435 \u043f\u043e\u0440\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445).<\/li>\n<\/ul>\n<p>  <\/p>\n<h3 id=\"dva-sharda-po-dve-repliki\">\u0414\u0432\u0430 \u0448\u0430\u0440\u0434\u0430 \u043f\u043e \u0434\u0432\u0435 \u0440\u0435\u043f\u043b\u0438\u043a\u0438<\/h3>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/d0d\/766\/d01\/d0d766d019724159bc0896bcafad3da5.png\" alt=\"\u0414\u0432\u0430 \u0448\u0430\u0440\u0434\u0430 \u043f\u043e \u0434\u0432\u0435 \u0440\u0435\u043f\u043b\u0438\u043a\u0438\"\/><\/p>\n<p>  <\/p>\n<pre><code class=\"xml\">&lt;remote_servers&gt;     &lt;!-- Two shards, two replica --&gt;     &lt;pulse&gt;         &lt;!-- shard 01 --&gt;        &lt;shard&gt;            &lt;!-- replica 01_01 --&gt;            &lt;replica&gt;                &lt;host&gt;ch63.smi2&lt;\/host&gt;            &lt;\/replica&gt;             &lt;!-- replica 01_02 --&gt;            &lt;replica&gt;                &lt;host&gt;ch64.smi2&lt;\/host&gt;            &lt;\/replica&gt;        &lt;\/shard&gt;         &lt;!-- shard 02 --&gt;        &lt;shard&gt;            &lt;!-- replica 02_01 --&gt;            &lt;replica&gt;                &lt;host&gt;ch65.smi2&lt;\/host&gt;            &lt;\/replica&gt;             &lt;!-- replica 02_02 --&gt;            &lt;replica&gt;                &lt;host&gt;ch66.smi2&lt;\/host&gt;            &lt;\/replica&gt;        &lt;\/shard&gt;     &lt;\/pulse&gt; &lt;\/remote_servers&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">CREATE DATABASE IF NOT EXISTS dbpulse  ;  CREATE TABLE IF NOT EXISTS dbpulse.normal_summing_sharded (     event_date Date DEFAULT toDate(event_time),     event_time DateTime DEFAULT now(),     body_id Int32,     views Int32 ) ENGINE = ReplicatedSummingMergeTree('\/clickhouse\/tables\/{pulse_replica}\/pulse\/normal_summing_sharded', '{replica}', event_date, (event_date, event_time, body_id), 8192) ;  CREATE TABLE IF NOT EXISTS  dbpulse.normal_summing AS dbpulse.normal_summing_sharded       ENGINE = Distributed( pulse, dbpulse, normal_summing_sharded , rand() )<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0432\u043e\u043f\u043b\u043e\u0449\u0430\u0435\u0442 \u043b\u0443\u0447\u0448\u0438\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 2 \u0448\u0430\u0440\u0434\u0430, SELECT-\u0437\u0430\u043f\u0440\u043e\u0441 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u0448\u0430\u0440\u0434\u043e\u0432 \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435.<\/li>\n<li>\u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 (\u043f\u043e\u0442\u0435\u0440\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0443\u0437\u043b\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043f\u043e\u0442\u0435\u0440\u0435 \u043f\u043e\u0440\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445).<\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"primer-konfiguracii-klasterov-v-ansible\">\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0432 ansible<\/h2>\n<p>  <\/p>\n<p>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0432 <a href=\"http:\/\/docs.ansible.com\/ansible\/index.html\">ansible<\/a> \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code>- name: &quot;pulse&quot;    shards:      - { name: &quot;01&quot;, replicas: [&quot;ch63.smi2&quot;, &quot;ch64.smi2&quot;]}      - { name: &quot;02&quot;, replicas: [&quot;ch65.smi2&quot;, &quot;ch66.smi2&quot;]}  - name: &quot;sharovara&quot;    shards:      - { name: &quot;01&quot;, replicas: [&quot;ch63.smi2&quot;]}      - { name: &quot;02&quot;, replicas: [&quot;ch64.smi2&quot;]}      - { name: &quot;03&quot;, replicas: [&quot;ch65.smi2&quot;]}      - { name: &quot;04&quot;, replicas: [&quot;ch66.smi2&quot;]}  - name: &quot;repikator&quot;    shards:      - { name: &quot;01&quot;, replicas: [&quot;ch63.smi2&quot;, &quot;ch64.smi2&quot;,&quot;ch65.smi2&quot;, &quot;ch66.smi2&quot;]}<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"php-drayver-dlya-raboty-s-clickhouse-klasterom\">PHP-\u0434\u0440\u0430\u0439\u0432\u0435\u0440 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 ClickHouse-\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u043c<\/h2>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 <a href=\"https:\/\/habrahabr.ru\/company\/smi2\/blog\/314558\/\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u044b \u0443\u0436\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0438 \u043e \u043d\u0430\u0448\u0435\u043c open-source <a href=\"https:\/\/github.com\/smi2\/phpClickHouse\">PHP-\u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0435<\/a> \u0434\u043b\u044f ClickHouse.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0437\u043b\u043e\u0432 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043c, \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u043c \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u044b\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 DDL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 ClickHouse-\u043a\u043b\u0430\u0441\u0442\u0435\u0440. \u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043a\u0440\u0430\u0442\u043a\u043e \u043e\u043f\u0438\u0448\u0435\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0435\u0433\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 <code>ClickHouseDB\\Cluster<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">$cl = new ClickHouseDB\\Cluster(  ['host'=&gt;'allclickhouse.smi2','port'=&gt;'8123','username'=&gt;'x','password'=&gt;'x'] ); <\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 DNS-\u0437\u0430\u043f\u0438\u0441\u0438 <code>allclickhouse.smi2<\/code> \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u044b IP-\u0430\u0434\u0440\u0435\u0441\u0430 \u0432\u0441\u0435\u0445 \u0443\u0437\u043b\u043e\u0432: <code>ch63.smi2, ch64.smi2, ch65.smi2, ch66.smi2<\/code>, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c <a href=\"https:\/\/en.wikipedia.org\/wiki\/Round-robin_DNS\">Round-robin DNS<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0414\u0440\u0430\u0439\u0432\u0435\u0440 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 ping-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439 \u0432 DNS-\u0437\u0430\u043f\u0438\u0441\u0438.<\/p>\n<p>  <\/p>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a\u043e \u0432\u0441\u0435\u043c \u0443\u0437\u043b\u0430\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\"> $cl-&gt;setScanTimeOut(2.5); \/\/ 2500 ms <\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0440\u0435\u043f\u043b\u0438\u043a \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">if (!$cl-&gt;isReplicasIsOk()) {    throw new Exception('Replica state is bad , error='.$cl-&gt;getError()); } <\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 ClickHouse-\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442\u0441\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0443\u0437\u043b\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0432 DNS-\u0437\u0430\u043f\u0438\u0441\u0438.<\/li>\n<li>\u041d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/clickhouse.yandex\/reference_ru.html#system.replicas\">SQL-\u0437\u0430\u043f\u0440\u043e\u0441<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0440\u0435\u043f\u043b\u0438\u043a ClickHouse-\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0430, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0432\u044b\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 <code>log_max_index, log_pointer, total_replicas, active_replicas<\/code>, \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 ZK-\u043a\u043b\u0430\u0441\u0442\u0435\u0440. <\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043e\u0431\u043b\u0435\u0433\u0447\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u043b\u0430\u0433: <\/p>\n<p>  <\/p>\n<pre><code class=\"php\"> $cl-&gt;setSoftCheck(true); <\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0432\u0441\u0435\u0445 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">print_r($cl-&gt;getClusterList()); \/\/ result \/\/    [0] =&gt; pulse \/\/    [1] =&gt; repikator \/\/    [2] =&gt; sharovara<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u0432\u044b\u0448\u0435, \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\"> foreach (['pulse','repikator','sharovara'] as $name) {    print_r($cl-&gt;getClusterNodes($name));    echo &quot;&gt; $name , count shard   = &quot;.$cl-&gt;getClusterCountShard($name).&quot; ; count replica = &quot;.$cl-&gt;getClusterCountReplica($name).&quot;\\n&quot;; }  \/\/\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: \/\/&gt;  pulse , count shard = 2 ; count replica = 2 \/\/&gt;  repikator , count shard = 1 ; count replica = 4 \/\/&gt;  sharovara , count shard = 4 ; count replica = 1 <\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0443\u0437\u043b\u043e\u0432 \u043f\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0438\u043b\u0438 \u0438\u0437 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\"> $nodes=$cl-&gt;getNodesByTable('sharovara.body_views_sharded');  $nodes=$cl-&gt;getClusterNodes('sharovara'); <\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438\u043b\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u0432\u0441\u0435\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u0447\u0435\u0440\u0435\u0437 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">foreach ($nodes as $node) {    echo &quot;$node &gt; \\n&quot;;    print_r($cl-&gt;client($node)-&gt;tableSize('test_sharded'));    print_r($cl-&gt;client($node)-&gt;tablesSize()); }  \/\/ \u0423\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f $cl-&gt;getSizeTable('dbName.tableName'); <\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0442\u0430\u0431\u043b\u0438\u0446 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">$cl-&gt;getTables()<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043b\u0438\u0434\u0435\u0440\u0430 \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\"> $cl-&gt;getMasterNodeForTable('dbName.tableName') \/\/ \u041b\u0438\u0434\u0435\u0440 \u0438\u043c\u0435\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0444\u043b\u0430\u0433 is_leader=1 <\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0430\u043f\u0440\u043e\u0441\u044b, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435\u043c \u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u0443\u0437\u0435\u043b \u0441 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u043c \u0444\u043b\u0430\u0433\u043e\u043c <code>is_leader<\/code>. <\/p>\n<p>  <\/p>\n<p>\u041e\u0447\u0438\u0441\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">$cl-&gt;truncateTable('dbName.tableName')`<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"instrument-migracii-ddl-zaprosov\">\u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 DDL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/h2>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 DDL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0434\u043b\u044f \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0421\u0423\u0411\u0414 \u0432 \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <a href=\"http:\/\/www.mybatis.org\/migrations\/\">MyBatis Migrations<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041e\u0431 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0445 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u043d\u0430 \u0425\u0430\u0431\u0440\u0435 \u0443\u0436\u0435 \u043f\u0438\u0441\u0430\u043b\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/habrahabr.ru\/post\/121265\/\">\u0412\u0435\u0440\u0441\u0438\u043e\u043d\u043d\u0430\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445: \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b<\/a><\/li>\n<li><a href=\"https:\/\/habrahabr.ru\/post\/315254\/\">\u041f\u0440\u043e\u0441\u0442\u044b\u0435 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0441 PHPixie Migrate<\/a><\/li>\n<li><a href=\"https:\/\/habrahabr.ru\/post\/129290\/\">\u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430\u043c\u0438 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 MyBatis Scheme Migration Extended<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 ClickHouse-\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u043c \u043d\u0430\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0441\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 ClickHouse \u0438\u043c\u0435\u0435\u0442 \u0440\u044f\u0434 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 (\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439) \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 DDL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438. <a href=\"https:\/\/clickhouse.yandex\/reference_ru.html#\u0420\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f%20\u0434\u0430\u043d\u043d\u044b\u0445\">\u0426\u0438\u0442\u0430\u0442\u0430<\/a>:<\/p>\n<p>  <\/p>\n<blockquote><p>\u0420\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u0443\u044e\u0442\u0441\u044f INSERT, ALTER (\u0441\u043c. \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0432 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 ALTER). \u0420\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0441\u0436\u0430\u0442\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0430 \u043d\u0435 \u0442\u0435\u043a\u0441\u0442\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0417\u0430\u043f\u0440\u043e\u0441\u044b CREATE, DROP, ATTACH, DETACH, RENAME \u043d\u0435 \u0440\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u2014 \u0442\u043e \u0435\u0441\u0442\u044c, \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0443. \u0417\u0430\u043f\u0440\u043e\u0441 CREATE TABLE \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043d\u043e\u0432\u0443\u044e \u0440\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u0443\u0435\u043c\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043d\u0430 \u0442\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u0433\u0434\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441; \u0430 \u0435\u0441\u043b\u0438 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 \u0442\u0430\u043a\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u2014 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u043e\u0432\u0443\u044e \u0440\u0435\u043f\u043b\u0438\u043a\u0443. \u0417\u0430\u043f\u0440\u043e\u0441 DROP TABLE \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u0440\u0435\u043f\u043b\u0438\u043a\u0443, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u0443\u044e \u043d\u0430 \u0442\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u0433\u0434\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441. \u0417\u0430\u043f\u0440\u043e\u0441 RENAME \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u0442 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043d\u0430 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0440\u0435\u043f\u043b\u0438\u043a \u2014 \u0442\u043e \u0435\u0441\u0442\u044c, \u0440\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0445 \u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u0440\u0430\u0437\u043d\u043e\u043c\u0443.<\/p><\/blockquote>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 ClickHouse \u0443\u0436\u0435 \u0430\u043d\u043e\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043b\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0432 \u044d\u0442\u043e\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438, \u043d\u043e \u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0435\u0448\u0430\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u043c. \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 <a href=\"https:\/\/github.com\/smi2\/phpMigrationsClickhouse\">phpMigrationsClickhouse<\/a> \u0434\u043b\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 DDL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 ClickHouse-\u043a\u043b\u0430\u0441\u0442\u0435\u0440. \u0418 \u0432 \u043d\u0430\u0448\u0438\u0445 \u043f\u043b\u0430\u043d\u0430\u0445 \u2014 \u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c <em>phpMigrationsClickhouse<\/em> \u043e\u0442 \u044f\u0437\u044b\u043a\u0430 PHP.<\/p>\n<p>  <\/p>\n<p>\u041e\u043f\u0438\u0448\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439\u0441\u044f \u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432 <em>phpMigrationsClickhouse<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043d\u0430 \u043b\u044e\u0431\u043e\u043c \u0434\u0440\u0443\u0433\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043f\u043e \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0432 <em>phpMigrationsClickhouse<\/em> \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437: <\/p>\n<p>  <\/p>\n<ul>\n<li>SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043a\u0430\u0442\u0438\u0442\u044c \u0438 \u043e\u0442\u043a\u0430\u0442\u0438\u0442\u044c \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438; <\/li>\n<li>\u0438\u043c\u0435\u043d\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c PHP-\u0444\u0430\u0439\u043b, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434: <\/p>\n<p>  <\/p>\n<pre><code class=\"php\">$cluster_name = 'pulse';  $mclq = new \\ClickHouseDB\\Cluster\\Migration($cluster_name); $mclq-&gt;setTimeout(100);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043a\u0430\u0442\u0438\u0442\u044c: <\/p>\n<p>  <\/p>\n<pre><code class=\"php\">$mclq-&gt;addSqlUpdate(&quot; CREATE DATABASE IF NOT EXISTS dbpulse  &quot;);  $mclq-&gt;addSqlUpdate(&quot;    CREATE TABLE IF NOT EXISTS dbpulse.normal_summing_sharded (      event_date Date DEFAULT toDate(event_time),      event_time DateTime DEFAULT now(),      body_id Int32,      views Int32  ) ENGINE = ReplicatedSummingMergeTree('\/clickhouse\/tables\/{pulse_replica}\/pulse\/normal_summing_sharded', '{replica}', event_date, (event_date, event_time, body_id), 8192)  &quot;); <\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0442\u043a\u0430\u0442\u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438: <\/p>\n<p>  <\/p>\n<pre><code class=\"php\">$mclq-&gt;addSqlDowngrade(' DROP TABLE IF EXISTS dbpulse.normal_summing_sharded ');   $mclq-&gt;addSqlDowngrade(' DROP DATABASE IF EXISTS dbpulse  '); <\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 2 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u043d\u0430\u043a\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0439:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u043e\u0434\u0438\u043d \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0443;<\/li>\n<li>\u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0432\u0441\u0435\u0445 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u043e\u0434\u0438\u043d \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0443.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 downgrade-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u0432\u0441\u0435 \u0443\u0437\u043b\u044b, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u0436\u0435 \u0431\u044b\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u044b upgrade-\u0437\u0430\u043f\u0440\u043e\u0441\u044b;<\/li>\n<li>\u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0434 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 upgrade-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430;<\/li>\n<li>\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 downgrade-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u0432\u0441\u0435\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043a\u0438.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043e\u0448\u0438\u0431\u043a\u0430 timeout \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f;<\/li>\n<li>\u043e\u0448\u0438\u0431\u043a\u0430 \u0441\u0432\u044f\u0437\u0438 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b PHP-\u043a\u043e\u0434\u0430 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\"> \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 IP-\u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u0443\u0437\u043b\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 $node_hosts=$this-&gt;getClusterNodes($migration-&gt;getClusterName()); \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 downgrade-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 $sql_down=$migration-&gt;getSqlDowngrade(); \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 upgrade-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 $sql_up=$migration-&gt;getSqlUpdate();  \/\/ \u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 upgrade-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b \u0438, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 downgrade-\u0437\u0430\u043f\u0440\u043e\u0441\u0430  $need_undo=false; $undo_ip=[];  foreach ($sql_up as $s_u) {     foreach ($node_hosts as $node) {         \/\/ \u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 upgrade-\u0437\u0430\u043f\u0440\u043e\u0441\u0430         $state=$this-&gt;client($node)-&gt;write($s_u);          if ($state-&gt;isError()) {             $need_undo = true;         } else {             \/\/ OK         }          if ($need_undo) {             \/\/ \u0424\u0438\u043a\u0441\u0430\u0446\u0438\u044f \u0443\u0437\u043b\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u0433\u0434\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430               $undo_ip[$node]=1;             break;         }     } }  \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f upgrade-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u0432\u0441\u0435\u0445 \u0443\u0437\u043b\u0430\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 if (!$need_undo) {     return true; \/\/ OK }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043d\u0430 \u0432\u0441\u0435 \u0443\u0437\u043b\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 downgrade-\u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">foreach ($node_hosts as $node) {     foreach ($sql_down as $s_u) {         try{             $st=$this-&gt;client($node)-&gt;write($s_u);         } catch (Exception $E) {             \/\/ \u041e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 downgrade-\u0437\u0430\u043f\u0440\u043e\u0441\u0430          }     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0446\u0438\u043a\u043b \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432, \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043d\u044b\u0445 \u043d\u0430\u0448\u0435\u043c\u0443 \u043e\u043f\u044b\u0442\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 ClickHouse.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u044b \u0445\u043e\u0442\u0435\u043b\u0438 \u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043e\u043f\u0440\u043e\u0441.<\/p>\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:\/\/habrahabr.ru\/post\/317682\/\"> https:\/\/habrahabr.ru\/post\/317682\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 <a href=\"https:\/\/habrahabr.ru\/company\/smi2\/blog\/314558\/\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u043b\u0438\u0441\u044c \u0441\u0432\u043e\u0438\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0421\u0423\u0411\u0414 ClickHouse \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 <a href=\"https:\/\/smi2.net\/\">\u0421\u041c\u04182<\/a>. \u0412 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0437\u0430\u0442\u0440\u043e\u043d\u0435\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u0431\u044a\u0435\u043c\u0430 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0440\u043e\u0441\u0442\u043e\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u043a\u043e\u0433\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u0443\u0436\u0435 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0422\u0430\u043a\u0436\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c \u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u043e\u043c \u043d\u0430\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0435 \u0434\u043b\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Data_definition_language\">DDL<\/a>-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 ClickHouse-\u043a\u043b\u0430\u0441\u0442\u0435\u0440.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/d0d\/766\/d01\/d0d766d019724159bc0896bcafad3da5.png\" alt=\"\u0414\u0432\u0430 \u0448\u0430\u0440\u0434\u0430 \u043f\u043e \u0434\u0432\u0435 \u0440\u0435\u043f\u043b\u0438\u043a\u0438\"\/><\/p>\n<p>  <\/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-282761","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/282761","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=282761"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/282761\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=282761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=282761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=282761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}