{"id":300418,"date":"2020-03-19T21:00:14","date_gmt":"2020-03-19T21:00:14","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=300418"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=300418","title":{"rendered":"DBA: \u0433\u0440\u0430\u043c\u043e\u0442\u043d\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u044b"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/tensor\/blog\/492464\/\">\u041f\u0440\u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043d\u0430\u0431\u043e\u0440\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0440\u0430\u0437\u043d\u044b\u0435 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/ETL\">ETL-\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b<\/a>: \u0438\u043c\u043f\u043e\u0440\u0442\u044b, \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438 \u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c) \u0447\u0430\u0441\u0442\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c <b>\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u00ab\u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c\u00bb, \u0438 \u0441\u0440\u0430\u0437\u0443 \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c<\/b> \u0447\u0442\u043e-\u0442\u043e \u043e\u0431\u044a\u0435\u043c\u043d\u043e\u0435.<\/p>\n<p>  \u0422\u0438\u043f\u043e\u0432\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0437\u0432\u0443\u0447\u0438\u0442 \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a: <i>\u00ab\u0412\u043e\u0442 \u0442\u0443\u0442 <a href=\"https:\/\/sbis.ru\/accounting\">\u0431\u0443\u0445\u0433\u0430\u043b\u0442\u0435\u0440\u0438\u044f \u0432\u044b\u0433\u0440\u0443\u0437\u0438\u043b\u0430 \u0438\u0437 \u043a\u043b\u0438\u0435\u043d\u0442-\u0431\u0430\u043d\u043a\u0430<\/a> \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u0432\u0448\u0438\u0435 \u043e\u043f\u043b\u0430\u0442\u044b, \u043d\u0430\u0434\u043e \u0438\u0445 \u0431\u044b\u0441\u0442\u0440\u0435\u043d\u044c\u043a\u043e \u0432\u043a\u0430\u0447\u0430\u0442\u044c \u043d\u0430 \u0441\u0430\u0439\u0442 \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u043a \u0441\u0447\u0435\u0442\u0430\u043c\u00bb<\/i>.<\/p>\n<p>  \u041d\u043e \u043a\u043e\u0433\u0434\u0430 \u043e\u0431\u044a\u0435\u043c \u044d\u0442\u043e\u0433\u043e \u00ab\u0447\u0435\u0433\u043e-\u0442\u043e\u00bb \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0438\u0437\u043c\u0435\u0440\u044f\u0442\u044c\u0441\u044f \u0441\u043e\u0442\u043d\u044f\u043c\u0438 \u043c\u0435\u0433\u0430\u0431\u0430\u0439\u0442, \u0430 \u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u0430\u0437\u043e\u0439 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 24&#215;7, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e side-\u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0440\u0442\u0438\u0442\u044c \u0432\u0430\u043c \u0436\u0438\u0437\u043d\u044c.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/tl\/g3\/ff\/tlg3ffjptyayqlu-5k06oonr_vi.png\"><br \/>  \u0427\u0442\u043e\u0431\u044b \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u0441 \u043d\u0438\u043c\u0438 \u0432 PostgreSQL (\u0434\u0430 \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043d\u0435\u043c), \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u0441\u0435 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0438 \u0441 \u043c\u0435\u043d\u044c\u0448\u0438\u043c \u0440\u0430\u0441\u0445\u043e\u0434\u043e\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>1. \u041a\u0443\u0434\u0430 \u0433\u0440\u0443\u0437\u0438\u0442\u044c?<\/h2>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c\u0441\u044f, \u043a\u0443\u0434\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043b\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u00ab\u043e\u0442\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0438\u0442\u044c\u00bb.<\/p>\n<h3>1.1. \u0412\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b (TEMPORARY TABLE)<\/h3>\n<p>  \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0434\u043b\u044f PostgreSQL \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u2014 \u044d\u0442\u043e \u0442\u0430\u043a\u0438\u0435 \u0436\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043a\u0430\u043a \u0438 \u043b\u044e\u0431\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u0432\u0435\u0440\u043d\u044b \u0441\u0443\u0435\u0432\u0435\u0440\u0438\u044f \u0442\u0438\u043f\u0430 <i><b>\u00ab\u0442\u0430\u043c \u0432\u0441\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u0430 \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u043a\u043e\u043d\u0447\u0438\u0442\u044c\u0441\u044f\u00bb<\/b><\/i>. \u041d\u043e \u0435\u0441\u0442\u044c \u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043e\u0442\u043b\u0438\u0447\u0438\u0439.<\/p>\n<h4>\u0421\u0432\u043e\u0439 \u00ab\u043d\u0435\u0439\u043c\u0441\u043f\u0435\u0439\u0441\u00bb \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0411\u0414<\/h4>\n<p>  \u0415\u0441\u043b\u0438 \u0434\u0432\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c <code>CREATE TABLE x<\/code>, \u0442\u043e \u043a\u0442\u043e-\u0442\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442 <b>\u043e\u0448\u0438\u0431\u043a\u0443 \u043d\u0435\u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/b> \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0411\u0414.<\/p>\n<p>  \u0410 \u0432\u043e\u0442 \u0435\u0441\u043b\u0438 \u043e\u0431\u0430 \u043f\u043e\u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c <code>CREATE <b>TEMPORARY<\/b> TABLE x<\/code>, \u0442\u043e \u043e\u0431\u0430 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u044e\u0442, \u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u043b\u0443\u0447\u0438\u0442 <b>\u0441\u0432\u043e\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440<\/b> \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u0418 \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0431\u0449\u0435\u0433\u043e \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.<\/p>\n<h4>\u00ab\u0421\u0430\u043c\u043e\u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435\u00bb \u043f\u0440\u0438 disconnect<\/h4>\n<p>  \u041f\u0440\u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u00ab\u0432\u0440\u0443\u0447\u043d\u0443\u044e\u00bb \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c <code>DROP TABLE x<\/code> \u0441\u043c\u044b\u0441\u043b\u0430 \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e, \u043a\u0440\u043e\u043c\u0435\u2026<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0435 \u0447\u0435\u0440\u0435\u0437 <b>pgbouncer \u0432 transaction mode<\/b>, \u0442\u043e \u0431\u0430\u0437\u0430-\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0432\u0441\u0435 \u0435\u0449\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u043e, \u0438 \u0432 \u043d\u0435\u043c-\u0442\u043e \u044d\u0442\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442.<\/p>\n<p>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0435\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e, \u0443\u0436\u0435 \u0438\u0437 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a pgbouncer, \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0435. \u041d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c <code>CREATE TEMPORARY TABLE <b>IF NOT EXISTS<\/b> x<\/code>.<\/p>\n<p>  \u041f\u0440\u0430\u0432\u0434\u0430, \u043b\u0443\u0447\u0448\u0435 \u0442\u0430\u043a \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0437\u0430\u0442\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u00ab\u0432\u043d\u0435\u0437\u0430\u043f\u043d\u043e\u00bb \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u0442\u0430\u043c, \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0435\u0441\u044f \u043e\u0442 \u00ab\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430\u00bb \u0434\u0430\u043d\u043d\u044b\u0435. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0443\u0447\u0448\u0435 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c-\u0442\u0430\u043a\u0438 \u043c\u0430\u043d\u0443\u0430\u043b, \u0438 \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u043f\u0438\u0441\u0430\u0442\u044c <code>ON COMMIT <b>DROP<\/b><\/code> \u2014 \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0431\u0443\u0434\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0430.<\/p>\n<h4>\u041d\u0435-\u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f<\/h4>\n<p>  \u0412 \u0441\u0438\u043b\u0443 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044e, \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043d\u0435 \u0440\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u0443\u044e\u0442\u0441\u044f. \u0417\u0430\u0442\u043e <b>\u044d\u0442\u043e \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u0432\u043e\u0439\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445<\/b> \u0432 heap + WAL, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 INSERT\/UPDATE\/DELETE \u0432 \u043d\u0435\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435.<\/p>\n<p>  \u041d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u2014 \u044d\u0442\u043e \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u00ab\u043f\u043e\u0447\u0442\u0438 \u043e\u0431\u044b\u0447\u043d\u0430\u044f\u00bb \u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u0442\u043e \u0438 \u043d\u0430 \u0440\u0435\u043f\u043b\u0438\u043a\u0435 \u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f \u0442\u043e\u0436\u0435. \u041f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u043f\u043e\u043a\u0430, \u0445\u043e\u0442\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043f\u0430\u0442\u0447 \u0443\u0436\u0435 \u0434\u0430\u0432\u043d\u043e \u0445\u043e\u0434\u0438\u0442.<\/p>\n<h3>1.2. \u041d\u0435\u0436\u0443\u0440\u043d\u0430\u043b\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b (UNLOGGED TABLE)<\/h3>\n<p>  \u041d\u043e \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u0438\u0439 ETL-\u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, \u0430 \u0443 \u0432\u0430\u0441 \u0442\u0430\u043a\u0438 <b>pgbouncer \u0432 transaction mode<\/b>?..<\/p>\n<p>  \u0418\u043b\u0438 \u043f\u043e\u0442\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u043b\u0438\u043a, \u0447\u0442\u043e <b>\u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f<\/b> \u0441 \u0411\u0414 (\u0447\u0438\u0442\u0430\u0439, \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043d\u0430 CPU)?..<\/p>\n<p>  \u0418\u043b\u0438 \u0447\u0430\u0441\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0438\u0434\u0443\u0442 <b>\u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e<\/b> \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u0430\u0445?..<\/p>\n<p>  \u0422\u0443\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u2014 <b>\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0435-\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443<\/b>. \u041a\u0430\u043b\u0430\u043c\u0431\u0443\u0440, \u0430\u0433\u0430. \u0422\u043e \u0435\u0441\u0442\u044c:<\/p>\n<ul>\n<li>\u0441\u043e\u0437\u0434\u0430\u043b \u00ab\u0441\u0432\u043e\u0438\u00bb \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e-\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 \u0438\u043c\u0435\u043d\u0430\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u043d\u0438 \u0441 \u043a\u0435\u043c \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u044c\u0441\u044f<\/li>\n<li><b>Extract<\/b>: \u0437\u0430\u043b\u0438\u043b \u0432 \u043d\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430<\/li>\n<li><b>Transform<\/b>: \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043b, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043b \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u043f\u043e\u043b\u044f<\/li>\n<li><b>Load<\/b>: \u043f\u0435\u0440\u0435\u043b\u0438\u043b \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0446\u0435\u043b\u0435\u0432\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/li>\n<li>\u0443\u0434\u0430\u043b\u0438\u043b \u00ab\u0441\u0432\u043e\u0438\u00bb \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/li>\n<\/ul>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u2014 \u043b\u043e\u0436\u043a\u0430 \u0434\u0435\u0433\u0442\u044f. \u041f\u043e \u0441\u0443\u0442\u0438, <b>\u0432\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0432 PostgreSQL \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0434\u0432\u0430\u0436\u0434\u044b<\/b> \u2014 <a href=\"https:\/\/habr.com\/ru\/company\/postgrespro\/blog\/461523\/\">\u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432 WAL<\/a>, \u043f\u043e\u0442\u043e\u043c \u0443\u0436\u0435 \u0432 \u0442\u0435\u043b\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b\/\u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432. \u0412\u0441\u0435 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 ACID \u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 <code>COMMIT<\/code>&#8216;\u043d\u0443\u0442\u044b\u043c\u0438 \u0438 <code>ROLLBACK<\/code>&#8216;\u043d\u0443\u0442\u044b\u043c\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u043c\u0438.<\/p>\n<p>  \u041d\u043e \u043d\u0430\u043c-\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e! \u0423 \u043d\u0430\u0441 \u0432\u0435\u0441\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 <b>\u0438\u043b\u0438 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043f\u0440\u043e\u0448\u0435\u043b, \u0438\u043b\u0438 \u043d\u0435\u0442<\/b>. \u041d\u0435\u0432\u0430\u0436\u043d\u043e, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432 \u043d\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0445 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u2014 \u043d\u0430\u043c \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u00ab\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u044b\u00bb, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0433\u0434\u0435 \u043e\u043d\u0430 \u0431\u044b\u043b\u0430.<\/p>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 PostgreSQL \u0435\u0449\u0435 \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 9.1 \u0432\u043d\u0435\u0434\u0440\u0438\u043b\u0438 \u0442\u0430\u043a\u0443\u044e \u0448\u0442\u0443\u043a\u0443 \u043a\u0430\u043a <a href=\"https:\/\/postgrespro.ru\/docs\/postgresql\/12\/sql-createtable#SQL-CREATETABLE-UNLOGGED\">\u043d\u0435\u0436\u0443\u0440\u043d\u0430\u043b\u0438\u0440\u0443\u0435\u043c\u044b\u0435 (UNLOGGED) \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/a>:  <\/p>\n<blockquote><p>\u0421 \u044d\u0442\u0438\u043c \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u043a\u0430\u043a \u043d\u0435\u0436\u0443\u0440\u043d\u0430\u043b\u0438\u0440\u0443\u0435\u043c\u0430\u044f. \u0414\u0430\u043d\u043d\u044b\u0435, \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u0432 \u043d\u0435\u0436\u0443\u0440\u043d\u0430\u043b\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442 \u0447\u0435\u0440\u0435\u0437 \u0436\u0443\u0440\u043d\u0430\u043b \u043f\u0440\u0435\u0434\u0437\u0430\u043f\u0438\u0441\u0438 (\u0441\u043c. \u0413\u043b\u0430\u0432\u0443 29), \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0447\u0435\u0433\u043e \u0442\u0430\u043a\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <b>\u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043e\u0431\u044b\u0447\u043d\u044b\u0445<\/b>. \u041e\u0434\u043d\u0430\u043a\u043e, \u043e\u043d\u0438 \u043d\u0435 \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u044b \u043e\u0442 \u0441\u0431\u043e\u044f; \u043f\u0440\u0438 \u0441\u0431\u043e\u0435 \u0438\u043b\u0438 \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e\u043c \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0435\u0436\u0443\u0440\u043d\u0430\u043b\u0438\u0440\u0443\u0435\u043c\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 <b>\u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0443\u0441\u0435\u043a\u0430\u0435\u0442\u0441\u044f<\/b>. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043d\u0435\u0436\u0443\u0440\u043d\u0430\u043b\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <b>\u043d\u0435 \u0440\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f<\/b> \u043d\u0430 \u0432\u0435\u0434\u043e\u043c\u044b\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u044b. \u041b\u044e\u0431\u044b\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u0434\u043b\u044f \u043d\u0435\u0436\u0443\u0440\u043d\u0430\u043b\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043d\u0435\u0436\u0443\u0440\u043d\u0430\u043b\u0438\u0440\u0443\u0435\u043c\u044b\u043c\u0438.<\/p><\/blockquote>\n<p>\u041a\u043e\u0440\u043e\u0447\u0435, <b>\u0431\u0443\u0434\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435<\/b>, \u043d\u043e \u0435\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u0411\u0414 \u00ab\u0443\u043f\u0430\u0434\u0435\u0442\u00bb \u2014 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u043e. \u041d\u043e \u0447\u0430\u0441\u0442\u043e \u043b\u0438 \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u0438 \u0443\u043c\u0435\u0435\u0442 \u043b\u0438 \u0432\u0430\u0448 ETL-\u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u044d\u0442\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0434\u043e\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u00ab\u0441 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u044b\u00bb \u043f\u043e\u0441\u043b\u0435 \u00ab\u043e\u0436\u0438\u0432\u043b\u0435\u043d\u0438\u044f\u00bb \u0411\u0414?..<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0442\u0430\u043a\u0438 \u043d\u0435\u0442, \u0438 \u043a\u0435\u0439\u0441 \u0432\u044b\u0448\u0435 \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0432\u0430\u0448 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code>UNLOGGED<\/code>, \u043d\u043e \u043d\u0438\u043a\u043e\u0433\u0434\u0430 <b>\u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0439\u0442\u0435 \u044d\u0442\u043e\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445<\/b>, \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u0430\u043c \u0434\u043e\u0440\u043e\u0433\u0438.<\/p>\n<h3>1.3. ON COMMIT { DELETE ROWS | DROP }<\/h3>\n<p>  \u042d\u0442\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0437\u0430\u0434\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438.<\/p>\n<p>  \u041f\u0440\u043e <code>ON COMMIT <b>DROP<\/b><\/code> \u044f \u0443\u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0432\u044b\u0448\u0435, \u043e\u043d \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 <code>DROP TABLE<\/code>, \u0430 \u0432\u043e\u0442 \u0441 <code>ON COMMIT <b>DELETE ROWS<\/b><\/code> \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435 \u2014 \u0442\u0443\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f <code>TRUNCATE TABLE<\/code>.<\/p>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u0441\u044f \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u0430\u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0440\u043e\u0432\u043d\u043e \u0442\u0430\u043a\u0430\u044f \u0436\u0435, \u043a\u0430\u043a \u0438 \u0443 \u043e\u0431\u044b\u0447\u043d\u043e\u0439, \u0442\u043e <b>\u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435-\u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0441\u0438\u043b\u044c\u043d\u043e\u043c\u0443 \u00ab\u0440\u0430\u0437\u0431\u0443\u0445\u0430\u043d\u0438\u044e\u00bb \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446<\/b> pg_class, pg_attribute, pg_attrdef, pg_depend,\u2026<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u043e\u0440\u043a\u0435\u0440 \u043d\u0430 \u043f\u0440\u044f\u043c\u043e\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438 \u0441 \u0411\u0414, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0430\u0436\u0434\u0443\u044e \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043d\u043e\u0432\u0443\u044e \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e, \u0441\u043e\u0437\u0434\u0430\u0435\u0442, \u043d\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442, \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443\u2026 \u041c\u0443\u0441\u043e\u0440\u0430 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 \u043d\u0430\u043a\u043e\u043f\u0438\u0442\u0441\u044f \u0432 \u0438\u0437\u0431\u044b\u0442\u043a\u0435, \u0430 \u044d\u0442\u043e \u043b\u0438\u0448\u043d\u0438\u0435 \u0442\u043e\u0440\u043c\u043e\u0437\u0430 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u0412 \u043e\u0431\u0449\u0435\u043c, \u043d\u0435 \u043d\u0430\u0434\u043e \u0442\u0430\u043a! \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 <code>CREATE TEMPORARY TABLE x ... ON COMMIT DELETE ROWS<\/code> \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0437\u0430 \u0446\u0438\u043a\u043b \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 \u2014 \u0442\u043e\u0433\u0434\u0430 \u043a \u043d\u0430\u0447\u0430\u043b\u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u043d\u043e\u0432\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0443\u0436\u0435 <b>\u0431\u0443\u0434\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c<\/b> (\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u043c \u0432\u044b\u0437\u043e\u0432 <code>CREATE<\/code>), \u043d\u043e <b>\u0431\u0443\u0434\u0435\u0442 \u043f\u0443\u0441\u0442\u043e\u0439<\/b>, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f <code>TRUNCATE<\/code> (\u0435\u0433\u043e \u0432\u044b\u0437\u043e\u0432 \u043c\u044b \u0442\u043e\u0436\u0435 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u043b\u0438) \u043f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438.<\/p>\n<h3>1.4. LIKE\u2026 INCLUDING &#8230;<\/h3>\n<p>  \u042f \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u043b \u0432 \u043d\u0430\u0447\u0430\u043b\u0435, \u0447\u0442\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0445 use case \u0434\u043b\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u2014 \u044d\u0442\u043e \u0440\u0430\u0437\u043d\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0438\u043c\u043f\u043e\u0440\u0442\u044b \u2014 \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0443\u0441\u0442\u0430\u043b\u043e \u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0438\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u043b\u0435\u0439 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0435\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439\u2026<\/p>\n<p>  \u041d\u043e \u043b\u0435\u043d\u044c \u2014 \u0434\u0432\u0438\u0433\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u0430! \u041f\u043e\u044d\u0442\u043e\u043c\u0443 <b>\u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u00ab\u043f\u043e \u043e\u0431\u0440\u0430\u0437\u0446\u0443\u00bb<\/b> \u043c\u043e\u0436\u043d\u043e \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435:<\/p>\n<pre><code class=\"sql\">CREATE TEMPORARY TABLE import_table(   LIKE target_table );<\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430\u0433\u0435\u043d\u0435\u0440\u0438\u0442\u044c \u043f\u043e\u0442\u043e\u043c \u0432 \u044d\u0442\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043c\u043e\u0436\u043d\u043e \u0432\u0435\u0441\u044c\u043c\u0430 \u043c\u043d\u043e\u0433\u043e \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u043f\u043e\u0438\u0441\u043a\u0438 \u043f\u043e \u043d\u0435\u0439 \u0441\u0442\u0430\u043d\u0443\u0442 \u043d\u0438 \u0440\u0430\u0437\u0443 \u043d\u0435 \u0431\u044b\u0441\u0442\u0440\u044b\u043c\u0438. \u041d\u043e \u043f\u0440\u043e\u0442\u0438\u0432 \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u2014 \u0438\u043d\u0434\u0435\u043a\u0441\u044b! \u0418, \u0434\u0430, <b>\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0442\u043e\u0436\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b<\/b>.<\/p>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443, \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e, \u043d\u0443\u0436\u043d\u044b\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c\u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c <code>LIKE target_table <b>INCLUDING INDEXES<\/b><\/code>.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u044b \u0435\u0449\u0435 \u0438 <code>DEFAULT<\/code>-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430), \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <code>LIKE target_table <b>INCLUDING DEFAULTS<\/b><\/code>. \u041d\u0443 \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u2014 <code>LIKE target_table <b>INCLUDING ALL<\/b><\/code> \u2014 \u0441\u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0434\u0435\u0444\u043e\u043b\u0442\u044b, \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u043a\u043e\u043d\u0441\u0442\u0440\u0435\u0439\u043d\u0442\u044b,\u2026<\/p>\n<p>  \u041d\u043e \u0442\u0443\u0442 \u0443\u0436\u0435 \u043d\u0430\u0434\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0438 <b>\u0438\u043c\u043f\u043e\u0440\u0442-\u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441\u0440\u0430\u0437\u0443 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c\u0438, \u0442\u043e \u0437\u0430\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u043b\u044c\u0448\u0435<\/b>, \u0447\u0435\u043c \u0435\u0441\u043b\u0438 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u0441\u0435 \u0437\u0430\u043b\u0438\u0442\u044c, \u0430 \u0443\u0436\u0435 \u043f\u043e\u0442\u043e\u043c \u043d\u0430\u043a\u0430\u0442\u0438\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u2014 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 <a href=\"https:\/\/postgrespro.ru\/docs\/postgresql\/12\/app-pgdump\">pg_dump<\/a>.<\/p>\n<p>  \u0412 \u043e\u0431\u0449\u0435\u043c, <a href=\"https:\/\/postgrespro.ru\/docs\/postgresql\/12\/sql-createtable\">RTFM<\/a>!<\/p>\n<h2>2. \u041a\u0430\u043a \u043f\u0438\u0441\u0430\u0442\u044c?<\/h2>\n<p>  \u0421\u043a\u0430\u0436\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code><a href=\"https:\/\/postgrespro.ru\/docs\/postgresql\/12\/sql-copy\">COPY<\/a><\/code>-\u043f\u043e\u0442\u043e\u043a \u0432\u043c\u0435\u0441\u0442\u043e \u00ab\u043f\u0430\u0447\u043a\u0438\u00bb <code>INSERT<\/code>, <a href=\"https:\/\/www.citusdata.com\/blog\/2017\/11\/08\/faster-bulk-loading-in-postgresql-with-copy\/\">\u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435 \u0432 \u0440\u0430\u0437\u044b<\/a>. \u041c\u043e\u0436\u043d\u043e \u0434\u0430\u0436\u0435 \u043f\u0440\u044f\u043c\u043e \u0438\u0437 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430.<\/p>\n<h2>3. \u041a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c?<\/h2>\n<p>  \u0418\u0442\u0430\u043a, \u043f\u0443\u0441\u0442\u044c \u043d\u0430\u0448\u0430 \u0432\u0432\u043e\u0434\u043d\u0430\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<ul>\n<li>\u0443 \u0432\u0430\u0441 \u0432 \u0431\u0430\u0437\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0430 \u0441 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043d\u0430 <b>1M \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/b><\/li>\n<li>\u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u0435\u0442 \u0432\u0430\u043c \u043d\u043e\u0432\u044b\u0439 <b>\u043f\u043e\u043b\u043d\u044b\u0439 \u00ab\u043e\u0431\u0440\u0430\u0437\u00bb<\/b><\/li>\n<li>\u043f\u043e \u043e\u043f\u044b\u0442\u0443 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u043e\u0442 \u0440\u0430\u0437\u0430 \u043a \u0440\u0430\u0437\u0443 <b>\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 10K \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/b><\/li>\n<\/ul>\n<p>  \u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/www.gnivc.ru\/technical_support\/classifiers_reference\/kladr\/\">\u0431\u0430\u0437\u0430 \u041a\u041b\u0410\u0414\u0420<\/a> \u2014 \u0432\u0441\u0435\u0433\u043e \u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u043c\u043d\u043e\u0433\u043e, \u043d\u043e \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u043d\u0435\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 (\u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0439 \u043d\u0430\u0441\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u043f\u0443\u043d\u043a\u0442\u043e\u0432, \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0443\u043b\u0438\u0446, \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0439 \u043d\u043e\u0432\u044b\u0445 \u0434\u043e\u043c\u043e\u0432) \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0434\u0430\u0436\u0435 \u0432 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0435 \u0432\u0441\u0435\u0439 \u0441\u0442\u0440\u0430\u043d\u044b.<\/p>\n<h3>3.1. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u043b\u043d\u043e\u0439 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438<\/h3>\n<p>  \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0447\u0442\u043e \u0432\u0430\u043c \u0434\u0430\u0436\u0435 \u0440\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u0432\u0438\u0434, \u0442\u043e \u0435\u0441\u0442\u044c:<\/p>\n<ul>\n<li><b>\u0443\u0434\u0430\u043b\u0438\u0442\u044c<\/b> \u0432\u0441\u0435, \u0447\u0435\u0433\u043e \u0443\u0436\u0435 \u043d\u0435\u0442<\/li>\n<li><b>\u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c<\/b> \u0432\u0441\u0435, \u0447\u0442\u043e \u0443\u0436\u0435 \u0431\u044b\u043b\u043e, \u0438 \u043d\u0430\u0434\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c<\/li>\n<li><b>\u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c<\/b> \u0432\u0441\u0435, \u0447\u0435\u0433\u043e \u0435\u0449\u0435 \u043d\u0435 \u0431\u044b\u043b\u043e<\/li>\n<\/ul>\n<p>  \u041f\u043e\u0447\u0435\u043c\u0443 \u0438\u043c\u0435\u043d\u043d\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0441\u0442\u043e\u0438\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432\u044b\u0440\u0430\u0441\u0442\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e (<a href=\"https:\/\/habr.com\/ru\/company\/tensor\/blog\/491366\/\">\u043f\u043e\u043c\u043d\u0438 \u043f\u0440\u043e MVCC!<\/a>).<\/p>\n<h4>DELETE FROM dst<\/h4>\n<p>  \u041d\u0435\u0442, \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0432\u0441\u0435\u0433\u043e \u0434\u0432\u0443\u043c\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c\u0438:<\/p>\n<ul>\n<li><b>\u0443\u0434\u0430\u043b\u0438\u0442\u044c<\/b> (<code>DELETE<\/code>) \u0432\u043e\u043e\u0431\u0449\u0435 \u0432\u0441\u0435<\/li>\n<li><b>\u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c<\/b> \u0432\u0441\u0435 \u0438\u0437 \u043d\u043e\u0432\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0437\u0430<\/li>\n<\/ul>\n<p>  \u041d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f MVCC, <b>\u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u0441\u044f \u0440\u043e\u0432\u043d\u043e \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430<\/b>! \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c +1M \u043e\u0431\u0440\u0430\u0437\u043e\u0432 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0438\u0437-\u0437\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f 10K \u2014 \u0442\u0430\u043a \u0441\u0435\u0431\u0435 \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u2026<\/p>\n<h4>TRUNCATE dst<\/h4>\n<p>  \u0411\u043e\u043b\u0435\u0435 \u043e\u043f\u044b\u0442\u043d\u044b\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u044e \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0443 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0435\u0448\u0435\u0432\u043e \u0437\u0430\u0447\u0438\u0441\u0442\u0438\u0442\u044c:<\/p>\n<ul>\n<li><b>\u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c<\/b> (<code>TRUNCATE<\/code>) \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0446\u0435\u043b\u0438\u043a\u043e\u043c<\/li>\n<li><b>\u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c<\/b> \u0432\u0441\u0435 \u0438\u0437 \u043d\u043e\u0432\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0437\u0430<\/li>\n<\/ul>\n<p>  \u041c\u0435\u0442\u043e\u0434 \u0434\u0435\u0439\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439, <a href=\"https:\/\/habr.com\/ru\/company\/tensor\/blog\/481866\/\">\u0438\u043d\u043e\u0433\u0434\u0430 \u0432\u043f\u043e\u043b\u043d\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c<\/a>, \u043d\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u0437\u0430\u0434\u0430\u0447\u0430\u2026 \u0412\u043b\u0438\u0432\u0430\u0442\u044c 1M \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u043e-\u043e-\u043e\u043b\u0433\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043f\u0443\u0441\u0442\u043e\u0439 \u043d\u0430 \u0432\u0441\u0435 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f (\u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u0431\u0435\u0437 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0432 \u0435\u0434\u0438\u043d\u0443\u044e \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e) \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0441\u0435\u0431\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u044c.<\/p>\n<p>  \u0410 \u0437\u043d\u0430\u0447\u0438\u0442:<\/p>\n<ul>\n<li>\u0443 \u043d\u0430\u0441 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f <b>\u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f<\/b><\/li>\n<li><code>TRUNCATE<\/code> \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442 <b>AccessExclusive<\/b>-\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443<\/li>\n<li>\u043c\u044b \u0434\u043e\u043b\u0433\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u0432\u0441\u0442\u0430\u0432\u043a\u0443, \u0430 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0432 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f <b>\u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0434\u0430\u0436\u0435 <code>SELECT<\/code><\/b><\/li>\n<\/ul>\n<p>  \u0427\u0435-\u0442\u043e \u043d\u0435\u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f\u2026<\/p>\n<h4>ALTER TABLE\u2026 RENAME\u2026 \/ DROP TABLE &#8230;<\/h4>\n<p>  \u041a\u0430\u043a \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 \u0437\u0430\u043b\u0438\u0442\u044c \u0432\u0441\u0435 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u043d\u043e\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043c\u0435\u0441\u0442\u043e \u0441\u0442\u0430\u0440\u043e\u0439. \u041f\u0430\u0440\u0430 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u044b\u0445 \u043c\u0435\u043b\u043e\u0447\u0435\u0439:<\/p>\n<ul>\n<li>\u0442\u0430\u043a\u0438 \u0442\u043e\u0436\u0435 <b>AccessExclusive<\/b>, \u0445\u043e\u0442\u044c \u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/li>\n<li>\u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u043f\u043b\u0430\u043d\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432\/\u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, <a href=\"https:\/\/habr.com\/ru\/company\/tensor\/blog\/479656\/\">\u043d\u0430\u0434\u043e \u0433\u043e\u043d\u044f\u0442\u044c ANALYZE<\/a><\/li>\n<li><b>\u043b\u043e\u043c\u0430\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0438<\/b> (FK) \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0443<\/li>\n<\/ul>\n<p>  \u0411\u044b\u043b WIP-\u043f\u0430\u0442\u0447 \u043e\u0442 Simon Riggs, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u043b \u0441\u0434\u0435\u043b\u0430\u0442\u044c <code>ALTER<\/code>-\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043f\u043e\u0434\u043c\u0435\u043d\u044b \u0442\u0435\u043b\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043d\u0430 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435, \u043d\u0435 \u0442\u0440\u043e\u0433\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0438 FK, \u043d\u043e \u043d\u0435 \u0441\u043e\u0431\u0440\u0430\u043b \u043a\u0432\u043e\u0440\u0443\u043c\u0430.<\/p>\n<h4>DELETE, UPDATE, INSERT<\/h4>\n<p>  \u0418\u0442\u0430\u043a, \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0435\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u0438\u0437 \u0442\u0440\u0435\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439. \u041f\u043e\u0447\u0442\u0438 \u0442\u0440\u0435\u0445\u2026 \u041a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e?<\/p>\n<pre><code class=\"sql\">-- \u0432\u0441\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0432\u0438\u0434\u0435\u043b &quot;\u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0445&quot; \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 BEGIN;  -- \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 CREATE TEMPORARY TABLE tmp(   LIKE dst INCLUDING INDEXES -- \u043f\u043e \u043e\u0431\u0440\u0430\u0437\u0443 \u0438 \u043f\u043e\u0434\u043e\u0431\u0438\u044e, \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c\u0438 ) ON COMMIT DROP; -- \u0437\u0430 \u0440\u0430\u043c\u043a\u0430\u043c\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u043e\u043d\u0430 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u0430  -- \u0431\u044b\u0441\u0442\u0440\u043e-\u0431\u044b\u0441\u0442\u0440\u043e \u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u0440\u0430\u0437 \u0447\u0435\u0440\u0435\u0437 COPY COPY tmp FROM STDIN; -- ... -- \\.  -- \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 DELETE FROM   dst D USING   dst X LEFT JOIN   tmp Y     USING(pk1, pk2) -- \u043f\u043e\u043b\u044f \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 WHERE   (D.pk1, D.pk2) = (X.pk1, X.pk2) AND   Y IS NOT DISTINCT FROM NULL; -- &quot;\u0430\u043d\u0442\u0438\u0434\u0436\u043e\u0439\u043d&quot;  -- \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0435\u0441\u044f UPDATE   dst D SET   (f1, f2, f3) = (T.f1, T.f2, T.f3) FROM   tmp T WHERE   (D.pk1, D.pk2) = (T.pk1, T.pk2) AND   (D.f1, D.f2, D.f3) IS DISTINCT FROM (T.f1, T.f2, T.f3); -- \u043d\u0435\u0437\u0430\u0447\u0435\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0435  -- \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 INSERT INTO   dst SELECT   T.* FROM   tmp T LEFT JOIN   dst D     USING(pk1, pk2) WHERE   D IS NOT DISTINCT FROM NULL;  COMMIT; <\/code><\/pre>\n<p>  <\/p>\n<h3>3.2. \u041f\u043e\u0441\u0442\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u043c\u043f\u043e\u0440\u0442\u0430<\/h3>\n<p>  \u0412 \u0442\u043e\u043c \u0436\u0435 \u0441\u0430\u043c\u043e\u043c \u041a\u041b\u0410\u0414\u0420\u0435 \u0432\u0441\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0432\u0448\u0438\u0435\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0433\u043d\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0441\u0442\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u2014 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c, \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0441\u043b\u043e\u0432\u0430, \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043d\u0443\u0436\u043d\u044b\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u043c. \u041d\u043e \u043a\u0430\u043a \u0443\u0437\u043d\u0430\u0442\u044c \u2014 <b>\u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u043b\u043e\u0441\u044c<\/b>, \u043d\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u043e\u0434 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438, \u0432 \u0438\u0434\u0435\u0430\u043b\u0435, \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0442\u0440\u043e\u0433\u0430\u044f \u0435\u0433\u043e?<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0443 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0431\u0435\u0440\u0435\u0442 \u0434\u043b\u044f \u043d\u0430\u0441 \u0432\u0441\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"sql\">-- \u0446\u0435\u043b\u0435\u0432\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b CREATE TABLE kladr(...); CREATE TABLE kladr_house(...);  -- \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u0438\u0441\u0442\u043e\u0440\u0438\u0435\u0439 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 CREATE TABLE kladr$log(   ro kladr, -- \u0442\u0443\u0442 \u043b\u0435\u0436\u0430\u0442 \u0446\u0435\u043b\u044b\u0435 \u043e\u0431\u0440\u0430\u0437\u044b \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0441\u0442\u0430\u0440\u043e\u0439\/\u043d\u043e\u0432\u043e\u0439   rn kladr );  CREATE TABLE kladr_house$log(   ro kladr_house,   rn kladr_house );  -- \u043e\u0431\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 CREATE OR REPLACE FUNCTION diff$log() RETURNS trigger AS $$ DECLARE   dst varchar = TG_TABLE_NAME || '$log';   stmt text = ''; BEGIN   -- \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0437\u0430\u043f\u0438\u0441\u0438   IF TG_OP = 'UPDATE' THEN     IF NEW IS NOT DISTINCT FROM OLD THEN       RETURN NEW;     END IF;   END IF;   -- \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044c \u043b\u043e\u0433\u0430   stmt = 'INSERT INTO ' || dst::text || '(ro,rn)VALUES(';   CASE TG_OP     WHEN 'INSERT' THEN       EXECUTE stmt || 'NULL,$1)' USING NEW;     WHEN 'UPDATE' THEN       EXECUTE stmt || '$1,$2)' USING OLD, NEW;     WHEN 'DELETE' THEN       EXECUTE stmt || '$1,NULL)' USING OLD;   END CASE;   RETURN NEW; END; $$ LANGUAGE plpgsql; <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u044b \u043d\u0430\u043b\u043e\u0436\u0438\u0442\u044c (\u0438\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 <code>ALTER TABLE ... ENABLE TRIGGER ...<\/code>):<\/p>\n<pre><code class=\"sql\">CREATE TRIGGER log   AFTER INSERT OR UPDATE OR DELETE   ON kladr     FOR EACH ROW       EXECUTE PROCEDURE diff$log();  CREATE TRIGGER log   AFTER INSERT OR UPDATE OR DELETE   ON kladr_house     FOR EACH ROW       EXECUTE PROCEDURE diff$log(); <\/code><\/pre>\n<p>  \u0410 \u043f\u043e\u0442\u043e\u043c \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0438\u0437 log-\u0442\u0430\u0431\u043b\u0438\u0446 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0432\u0441\u0435 \u043d\u0443\u0436\u043d\u044b\u0435 \u043d\u0430\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u043e\u0433\u043e\u043d\u044f\u0435\u043c \u043f\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c.<\/p>\n<h3>3.3. \u0418\u043c\u043f\u043e\u0440\u0442 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0431\u043e\u0440\u043e\u0432<\/h3>\n<p>  \u0412\u044b\u0448\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0438, \u043a\u043e\u0433\u0434\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0438 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a\u0430 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442. \u041d\u043e \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u0438\u0437 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0438\u043c\u0435\u0435\u0442 \u0444\u043e\u0440\u043c\u0430\u0442 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u043e\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0443 \u043d\u0430\u0441 \u0432 \u0431\u0430\u0437\u0435?<\/p>\n<p>  \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0438 \u0441\u0447\u0435\u0442\u043e\u0432 \u043f\u043e \u043d\u0438\u043c, \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u00ab\u043c\u043d\u043e\u0433\u0438\u0435-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443\u00bb:<\/p>\n<pre><code class=\"sql\">CREATE TABLE client(   client_id     serial       PRIMARY KEY , inn     varchar       UNIQUE , name     varchar );  CREATE TABLE invoice(   invoice_id     serial       PRIMARY KEY , client_id     integer       REFERENCES client(client_id) , number     varchar , dt     date , sum     numeric(32,2) );<\/code><\/pre>\n<p>  \u0410 \u0432\u043e\u0442 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u0438\u0437 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043d\u0430\u043c \u0432 \u0432\u0438\u0434\u0435 \u00ab\u0432\u0441\u0435 \u0432 \u043e\u0434\u043d\u043e\u043c\u00bb:<\/p>\n<pre><code class=\"sql\">CREATE TEMPORARY TABLE invoice_import(   client_inn     varchar , client_name     varchar , invoice_number     varchar , invoice_dt     date , invoice_sum     numeric(32,2) );<\/code><\/pre>\n<p>  \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c \u043c\u043e\u0433\u0443\u0442 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435, \u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u00ab\u0441\u0447\u0435\u0442\u00bb:<\/p>\n<pre><code class=\"plaintext\">0123456789;\u0412\u0430\u0441\u044f;A-01;2020-03-16;1000.00 9876543210;\u041f\u0435\u0442\u044f;A-02;2020-03-16;666.00 0123456789;\u0412\u0430\u0441\u044f;B-03;2020-03-16;9999.00 <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u043c \u043d\u0430\u0448\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u043e \u043f\u043e\u043c\u043d\u0438\u043c \u2014 <code>COPY<\/code> \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435!<\/p>\n<pre><code class=\"sql\">INSERT INTO invoice_import VALUES   ('0123456789', '\u0412\u0430\u0441\u044f', 'A-01', '2020-03-16', 1000.00) , ('9876543210', '\u041f\u0435\u0442\u044f', 'A-02', '2020-03-16', 666.00) , ('0123456789', '\u0412\u0430\u0441\u044f', 'B-03', '2020-03-16', 9999.00);<\/code><\/pre>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u044b\u0434\u0435\u043b\u0438\u043c \u0442\u0435 \u00ab\u0440\u0430\u0437\u0440\u0435\u0437\u044b\u00bb, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0448\u0438 \u00ab\u0444\u0430\u043a\u0442\u044b\u00bb \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0447\u0435\u0442\u0430 \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432:<\/p>\n<pre><code class=\"sql\">CREATE TEMPORARY TABLE client_import AS SELECT DISTINCT ON(client_inn) -- \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e SELECT DISTINCT, \u0435\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u0432\u0435\u0434\u043e\u043c\u043e \u043d\u0435\u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0438\u0432\u044b   client_inn inn , client_name &quot;name&quot; FROM   invoice_import;<\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0441\u0447\u0435\u0442\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0441 ID \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432, \u043d\u0430\u043c \u044d\u0442\u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u043d\u0430\u0434\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u0437\u043d\u0430\u0442\u044c \u0438\u043b\u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u043e\u0434 \u043d\u0438\u0445 \u043f\u043e\u043b\u044f:<\/p>\n<pre><code class=\"sql\">ALTER TABLE invoice_import ADD COLUMN client_id integer; ALTER TABLE client_import ADD COLUMN client_id integer;<\/code><\/pre>\n<p>  \u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c \u0432\u044b\u0448\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u043e\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u2014 \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0438 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u0432\u0435\u0434\u044c \u0438\u043c\u043f\u043e\u0440\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0443 \u043d\u0430\u0441 \u00abappend-only\u00bb:<\/p>\n<pre><code class=\"sql\">-- \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 ID \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 UPDATE   client_import T SET   client_id = D.client_id FROM   client D WHERE   T.inn = D.inn; -- unique key  -- \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0432\u0448\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0438\u0445 ID WITH ins AS (   INSERT INTO client(     inn   , name   )   SELECT     inn   , name   FROM     client_import   WHERE     client_id IS NULL -- \u0435\u0441\u043b\u0438 ID \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0441\u044f   RETURNING * ) UPDATE   client_import T SET   client_id = D.client_id FROM   ins D WHERE   T.inn = D.inn; -- unique key  -- \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c ID \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0443 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0441\u0447\u0435\u0442\u043e\u0432 UPDATE   invoice_import T SET   client_id = D.client_id FROM   client_import D WHERE   T.client_inn = D.inn; -- \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0439 \u043a\u043b\u044e\u0447 <\/code><\/pre>\n<p>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432\u0441\u0435 \u2014 \u0432 <code>invoice_import<\/code> \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u043f\u043e\u043b\u0435 \u0441\u0432\u044f\u0437\u0438 <code>client_id<\/code>, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u0438 \u0432\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0447\u0435\u0442.<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/tensor\/blog\/492464\/\"> https:\/\/habr.com\/ru\/company\/tensor\/blog\/492464\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/tensor\/blog\/492464\/\">\u041f\u0440\u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043d\u0430\u0431\u043e\u0440\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0440\u0430\u0437\u043d\u044b\u0435 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/ETL\">ETL-\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b<\/a>: \u0438\u043c\u043f\u043e\u0440\u0442\u044b, \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438 \u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c) \u0447\u0430\u0441\u0442\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c <b>\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u00ab\u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c\u00bb, \u0438 \u0441\u0440\u0430\u0437\u0443 \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c<\/b> \u0447\u0442\u043e-\u0442\u043e \u043e\u0431\u044a\u0435\u043c\u043d\u043e\u0435.<\/p>\n<p>  \u0422\u0438\u043f\u043e\u0432\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0437\u0432\u0443\u0447\u0438\u0442 \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a: <i>\u00ab\u0412\u043e\u0442 \u0442\u0443\u0442 <a href=\"https:\/\/sbis.ru\/accounting\">\u0431\u0443\u0445\u0433\u0430\u043b\u0442\u0435\u0440\u0438\u044f \u0432\u044b\u0433\u0440\u0443\u0437\u0438\u043b\u0430 \u0438\u0437 \u043a\u043b\u0438\u0435\u043d\u0442-\u0431\u0430\u043d\u043a\u0430<\/a> \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u0432\u0448\u0438\u0435 \u043e\u043f\u043b\u0430\u0442\u044b, \u043d\u0430\u0434\u043e \u0438\u0445 \u0431\u044b\u0441\u0442\u0440\u0435\u043d\u044c\u043a\u043e \u0432\u043a\u0430\u0447\u0430\u0442\u044c \u043d\u0430 \u0441\u0430\u0439\u0442 \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u043a \u0441\u0447\u0435\u0442\u0430\u043c\u00bb<\/i>.<\/p>\n<p>  \u041d\u043e \u043a\u043e\u0433\u0434\u0430 \u043e\u0431\u044a\u0435\u043c \u044d\u0442\u043e\u0433\u043e \u00ab\u0447\u0435\u0433\u043e-\u0442\u043e\u00bb \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0438\u0437\u043c\u0435\u0440\u044f\u0442\u044c\u0441\u044f \u0441\u043e\u0442\u043d\u044f\u043c\u0438 \u043c\u0435\u0433\u0430\u0431\u0430\u0439\u0442, \u0430 \u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u0430\u0437\u043e\u0439 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 24&#215;7, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e side-\u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0440\u0442\u0438\u0442\u044c \u0432\u0430\u043c \u0436\u0438\u0437\u043d\u044c.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/tl\/g3\/ff\/tlg3ffjptyayqlu-5k06oonr_vi.png\"><br \/>  \u0427\u0442\u043e\u0431\u044b \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u0441 \u043d\u0438\u043c\u0438 \u0432 PostgreSQL (\u0434\u0430 \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043d\u0435\u043c), \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u0441\u0435 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0438 \u0441 \u043c\u0435\u043d\u044c\u0448\u0438\u043c \u0440\u0430\u0441\u0445\u043e\u0434\u043e\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.  <\/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-300418","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/300418","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=300418"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/300418\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=300418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=300418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=300418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}