{"id":310904,"date":"2020-10-03T09:00:16","date_gmt":"2020-10-03T09:00:16","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=310904"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=310904","title":{"rendered":"\u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u043c\u0435\u0441\u0442\u0430 \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430\u0445"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/517558\/\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442 \u0425\u0430\u0431\u0440\u043e\u0432\u0447\u0430\u043d\u0435!!<\/p>\n<p>\u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u044b &#8212; \u044d\u0442\u043e \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u0438\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432. \u0410 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435  \u0432\u0441\u0435 \u043d\u043e\u0432\u044b\u0445  \u0438 \u043d\u043e\u0432\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043c\u0435\u0441\u0442\u0430 \u043d\u0430 \u0434\u0438\u0441\u043a\u0430\u0445. <\/p>\n<p>\u0414\u0430, \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435  \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0447\u0438\u0441\u0442\u043a\u0438 \u0441\u0430\u043c\u044b\u0445 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 \u043f\u0435\u0440\u0438\u043e\u0434\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0446\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u0438  \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0442 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u043c\u043e\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0441\u0442\u0430. \u041d\u043e \u0435\u0441\u043b\u0438 \u0440\u0435\u0447\u044c \u0438\u0434\u0435\u0442 \u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u043e\u0434\u0440\u043e \u043d\u0430\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0441\u0451 \u043d\u043e\u0432\u044b\u0435 &#171;\u0431\u043e\u043b\u044c\u0448\u0438\u0435&#187; \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0445 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e \u0432\u043e\u043f\u0440\u043e\u0441 \u043c\u0435\u0441\u0442\u0430 \u0432 DWH \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0440\u0435\u0431\u0440\u043e\u043c.  \u0418  \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 &#171;\u0410 \u043a\u0443\u0434\u0430 \u0436\u0435 \u0443\u0448\u043b\u043e \u043c\u0435\u0441\u0442\u043e?&#187;,  &#171;\u0427\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c?&#187; \u0438\u043b\u0438 &#171;\u041a\u0430\u043a \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u0442\u044c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0443 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430?&#187; \u0421\u0438\u0441\u0442\u0435\u043c\u044b \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u043d\u0430 \u043f\u043e\u0434\u043e\u0431\u0438\u0435 ZABBIX \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u0445\u043d\u0435\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u0434\u0438\u0441\u043a\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430  \u043d\u0430 \u043f\u043e\u043b\u043a\u0435 \u043d\u043e \u043d\u0435 \u0434\u0430\u044e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438  \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0440\u043e\u0441\u0442 \u0441\u0430\u043c\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0431\u0430\u0437\u0435. <\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u043c \u043b\u0430\u0439\u0444\u0445\u0430\u043a\u043e\u043c \u043a\u0430\u043a \u043b\u0435\u0433\u043a\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0442\u0430\u0431\u043b\u0438\u0446 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 MS SQL \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0430\u0437\u044b. \u042d\u0442\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u043a\u0443\u0447\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c &#171;\u041a\u0443\u0434\u0430 \u0436\u0435 \u0443\u0448\u043b\u043e \u0432\u0441\u0435 \u043c\u0435\u0441\u0442\u043e \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435?&#187;. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c  \u0438 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0431\u0430\u0437\u0430\u0445 (Oracle, PostgreSQL \u0438 \u0442.\u0434.) \u0441 \u0442\u043e\u0439 \u043b\u0438\u0448\u044c \u0440\u0430\u0437\u043d\u0438\u0446\u0435\u0439, \u0447\u0442\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u0431\u0443\u0434\u0443\u0442 \u0434\u0440\u0443\u0433\u0438\u0435. <\/p>\n<p>\u041d\u0438\u0436\u0435  \u043e\u043f\u0438\u0441\u0430\u043d \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u043b\u0430\u043d \u0438 \u043d\u0430\u0431\u043e\u0440 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 MS SQL  \u0447\u0442\u043e\u0431\u044b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u043c\u0435\u0441\u0442\u0430:<\/p>\n<p>\u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0433\u043b\u0430\u043c\u0435\u043d\u0442\u043d\u043e\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u0435 , \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u043e.<\/p>\n<p><strong>1)<\/strong> \u041d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u0448\u0430\u0433\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0438 \u0441\u0447\u0435\u0442\u0447\u0438\u043a. \u0412 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f  \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u0430\u044f  \u0438\u0441\u0442\u043e\u0440\u0438\u044f  \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<pre><code class=\"sql\">CREATE SEQUENCE prm.sq_etl_log_1   AS bigint  START WITH 1  INCREMENT BY 1    CREATE TABLE prm.dwh_size_of_tables( \tddate date NULL,\t\t\t\t\t\t\t--\u0414\u0430\u0442\u0430  \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \trun_id numeric(14, 0) NOT NULL,\t--ID \u0417\u0430\u043f\u0443\u0441\u043a\u0430 \u0441\u0431\u043e\u0440\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438, \u0421\u0447\u0435\u0442\u0447\u0438\u043a \tdb_name varchar(20) NOT NULL,\t--\u0411\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \tschema_name sysname NOT NULL,\t--\u0421\u0445\u0435\u043c\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \ttable_name sysname NOT NULL,\t--\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \trow_count bigint NULL,\t\t\t\t--\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \treserved_KB bigint NULL,\t\t\t--\u041e\u0449\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u0431\u043b\u0438\u0446\u044b  \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0438\u043d\u0434\u0435\u0441\u0430\u043c\u0438 \tdata_KB bigint NULL,\t\t\t\t\t--\u0420\u0430\u0437\u043c\u0435\u0440 \u0441\u0430\u043c\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435  \tindex_size_KB bigint NULL,\t\t--\u0420\u0430\u0437\u043c\u0435\u0440 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \tunused_KB bigint NULL\t\t\t\t\t--\u043d\u0435\u0438\u0441\u043f\u0440\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e ) <\/code><\/pre>\n<p><strong>2) <\/strong>\u0414\u0430\u043b\u0435\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e  \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u043a\u043e\u0442\u043e\u0440\u0430\u044f  \u0431\u0443\u0434\u0435\u0442 \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043f\u043e-\u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e.  \u042d\u0442\u0443 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u043e\u0435  \u0437\u0430\u0434\u0430\u043d\u0438\u0435  \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430. \u041e\u043d\u0430 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0441\u0440\u0435\u0437  \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u0442\u0430\u0431\u043b\u0438\u0446 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0434\u0435\u043d\u044c.<\/p>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043d\u0438\u0436\u0435:<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u0438\u043f\u0442 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">USE [LEMON] GO  CREATE  PROCEDURE  [prm].[load_etl_log] AS declare  @run_id int BEGIN  --\u0415\u0441\u043b\u0438 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0431\u044b\u043b \u0437\u0430\u043f\u0443\u0441\u043a \u043e\u0447\u0438\u0449\u0430\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u044e\u0443\u044e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043b\u0438\u0432\u0430\u0435\u043c delete from lemon.prm.dwh_size_of_tables where ddate = cast(getdate() as date);  --\u0414\u043b\u044f \u0441\u0442\u0440\u0430\u044b\u0445 \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432  \u0445\u0440\u0430\u043d\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043d\u0430\u0447\u0430\u043b\u043e \u0438 \u043d\u0430 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0443 \u043c\u0435\u0441\u044f\u0446\u0430 delete from  lemon.prm.dwh_size_of_tables where (DATEPART(day, ddate)not in (1,15) and ddate &lt; dateadd(month ,-2, getdate()))   DECLARE @SQL_text varchar(max),@SQL_text_final varchar(max); ;   set @SQL_text=   ' USE {SCHEMA_FOR_REPLACE};   insert into  lemon.prm.dwh_size_of_tables SELECT   \tcast(getdate() as date) date_time, \t'''+ convert(nvarchar , @run_id  ) +''' run_id , \t''{SCHEMA_FOR_REPLACE}'' db_name, \ta3.name AS schema_name \t,--\u0421\u0445\u0435\u043c\u0430 \ta2.name AS table_name \t,--\u0418\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \ta1.rows AS row_count \t,--\u0427\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \t(a1.reserved + ISNULL(a4.reserved, 0)) * 8 AS reserved_KB \t,--\u0417\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043e (\u041a\u0411)\t \ta1.data * 8 AS data_KB \t,--\u0414\u0430\u043d\u043d\u044b\u0435 (\u041a\u0411) \t( \t\tCASE  \t\t\tWHEN (a1.used + ISNULL(a4.used, 0)) &gt; a1.data \t\t\t\tTHEN (a1.used + ISNULL(a4.used, 0)) - a1.data \t\t\tELSE 0 \t\t\tEND \t\t) * 8 AS index_size_KB \t,--\u0418\u043d\u0434\u0435\u043a\u0441\u044b (\u041a\u0411) \t( \t\tCASE  \t\t\tWHEN (a1.reserved + ISNULL(a4.reserved, 0)) &gt; a1.used \t\t\t\tTHEN (a1.reserved + ISNULL(a4.reserved, 0)) - a1.used \t\t\tELSE 0 \t\t\tEND \t\t) * 8 AS unused_KB --\u041d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f (\u041a\u0411) \t\t \tFROM ( \t\t\t\tSELECT ps.object_id \t\t\t\t\t,SUM(CASE  \t\t\t\t\t\t\tWHEN (ps.index_id &lt; 2) \t\t\t\t\t\t\t\tTHEN row_count \t\t\t\t\t\t\tELSE 0 \t\t\t\t\t\t\tEND) AS [rows] \t\t\t\t\t,SUM(ps.reserved_page_count) AS reserved \t\t\t\t\t,SUM(CASE  \t\t\t\t\t\t\tWHEN (ps.index_id &lt; 2) \t\t\t\t\t\t\t\tTHEN (ps.in_row_data_page_count + ps.lob_used_page_count + ps.row_overflow_used_page_count) \t\t\t\t\t\t\tELSE (ps.lob_used_page_count + ps.row_overflow_used_page_count) \t\t\t\t\t\t\tEND) AS data \t\t\t\t\t,SUM(ps.used_page_count) AS used \t\t\t\tFROM sys.dm_db_partition_stats ps \t\t\t\tWHERE ps.object_id NOT IN ( \t\t\t\t\t\tSELECT object_id \t\t\t\t\t\tFROM sys.tables \t\t\t\t\t\tWHERE is_memory_optimized = 1 \t\t\t\t\t\t) \t\t\t\tGROUP BY ps.object_id \t\t) AS a1 \tLEFT OUTER JOIN ( \t\t\t\tSELECT it.parent_id \t\t\t\t\t,SUM(ps.reserved_page_count) AS reserved \t\t\t\t\t,SUM(ps.used_page_count) AS used \t\t\t\tFROM sys.dm_db_partition_stats ps \t\t\t\tINNER JOIN sys.internal_tables it ON (it.object_id = ps.object_id) \t\t\t\tWHERE it.internal_type IN ( \t\t\t\t\t\t202 \t\t\t\t\t\t,204 \t\t\t\t\t\t) \t\t\t\tGROUP BY it.parent_id \t\t) AS a4 ON (a4.parent_id = a1.object_id) \tINNER JOIN sys.all_objects a2 ON (a1.object_id = a2.object_id) \tINNER JOIN sys.schemas a3 ON (a2.schema_id = a3.schema_id) \tWHERE a2.type &lt;&gt; N''S'' \t\tAND a2.type &lt;&gt; N''IT'' \t\t'; \t\t \t\t\tDECLARE @request_id nvarchar(36), @schema_for_replace nvarchar(100) \t \t\t\tDECLARE bki_cursor CURSOR FOR    \t\t\t\tSELECT name as schem     \t\t\t\tFROM    sys.databases \t\t\t\t--\u0417\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0431\u0430\u0437 \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \t\t\t\t\/*  where name  in ( \t\t\t\t\t'DWH','DWH_copy','VN','VN_test') --and name ='DWH' \t\t\t\t\t*\/ \t\t\tOPEN bki_cursor    \t\t\tFETCH NEXT FROM bki_cursor INTO @schema_for_replace  \t\t\tWHILE @@FETCH_STATUS = 0   \t\t\tBEGIN \t\t\t\tset @SQL_text_final = replace (@sql_text,'{SCHEMA_FOR_REPLACE}',@schema_for_replace);   \t\t\t\texecute (@SQL_text_final)  \t\t\tFETCH NEXT FROM bki_cursor INTO @schema_for_replace \t\t\tEND    \t \t\tCLOSE bki_cursor;   \t\tDEALLOCATE bki_cursor; END  <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u043e\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a04\/6a8\/4c4\/a046a84c4b8acbd786de566238b9f3eb.png\" width=\"1022\" height=\"549\"><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<p><strong>3)<\/strong> \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e \u043c\u0435\u0440\u0435 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f  \u0442\u0430\u0431\u043b\u0438\u0446\u044b <em>dwh_size_of_tables<\/em> \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443  \u043f\u043e-\u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e \u0438 \u043f\u043e \u0431\u0430\u0437\u0430\u043c. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u043c \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c \u043d\u0438\u0436\u0435.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043c\u0435\u0441\u0442\u0430 \u0432 DWH \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">--\u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043c\u0435\u0441\u0442\u0430  \u0432 DWH \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c select top 10 ddate -- [\u0414\u0430\u0442\u0430] \t\t,run_id -- \t\t,db_name --\u0411\u0414- \t\t,schema_name --\u0421\u0445\u0435\u043c\u0430 \t\t,table_name --\u0418\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \t\t,row_count --\u0427\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \t\t,round(cast(reserved_KB as float) \/1024\/1024,2) as  reserved_GB --\u0417\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043e (\u041a\u0411)\t \t\t,round(cast(data_KB as float) \/1024\/1024,2) as data_GB --\u0414\u0430\u043d\u043d\u044b\u0435 (\u041a\u0411) \t\t,round(cast(index_size_KB as float) \/1024\/1024,2) as index_size_GB --\u0418\u043d\u0434\u0435\u043a\u0441\u044b (\u041a\u0411) \t\t,round(cast(unused_KB as float) \/1024\/1024,2) as unused_GB--\u041d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f (\u041a\u0411)\t  from  lemon.prm.dwh_size_of_tables where ddate = cast(getdate() as date)-- and  db_name='DWH'  order by reserved_GB desc<\/code><\/pre>\n<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6b5\/88d\/a65\/6b588da65f6fd890573fea73144f30c5.png\" width=\"985\" height=\"299\"><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043c\u0435\u0441\u0442\u0430 \u0432 DWH \u043f\u043e \u0431\u0430\u0437\u0430\u043c <\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">--\u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043c\u0435\u0441\u0442\u0430  \u0432 DWH \u043f\u043e  \u0411\u0430\u0437\u0430\u043c  select ddate -- [\u0414\u0430\u0442\u0430] \t\t,run_id -- \t\t,db_name --\u0411\u0414- \t\t,round(cast(sum(reserved_KB) as float) \/1024\/1024,2) as  reserved_GB --\u0417\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043e (\u041a\u0411)\t \t\t,round(cast(sum(data_KB) as float) \/1024\/1024,2) as data_GB --\u0414\u0430\u043d\u043d\u044b\u0435 (\u041a\u0411) \t\t,round(cast(sum(index_size_KB) as float) \/1024\/1024,2) as index_size_GB --\u0418\u043d\u0434\u0435\u043a\u0441\u044b (\u041a\u0411) \t\t,round(cast(sum(unused_KB) as float) \/1024\/1024,2) as unused_GB--\u041d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f (\u041a\u0411)\t \t\t,sum(row_count) row_count--\u0427\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439  from  lemon.prm.dwh_size_of_tables where ddate = cast(getdate() as date)-- and  db_name='DWH'  group by   ddate,run_id,db_name order  by  ddate,run_id\t,sum(data_KB+index_size_KB) desc<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/123\/1b6\/06d\/1231b606d2dc824e2e145fdc71bd3518.png\" width=\"807\" height=\"348\"><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<p><strong>4) <\/strong>\u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c  \u0435\u0449\u0435 3 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0442 \u043d\u0430\u043c \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u043f\u043e \u0431\u0430\u0437\u0430\u043c \u0438 \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e. \u042d\u0442\u0438 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043d\u0435 \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438  \u0430 \u0434\u043b\u044f  \u043f\u043e\u043a\u0430\u0437\u0430 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0432 \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u043c \u0432\u0438\u0434\u0435. \u041f\u0440\u0438\u0447\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0432 \u043f\u0435\u0440\u0438\u043e\u0434 \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443, \u043e\u043d\u0430 \u043f\u043e-\u043a\u043e\u043b\u043e\u043d\u043e\u0447\u043d\u043e \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443. <\/p>\n<details class=\"spoiler\">\n<summary>\u0414\u043d\u0435\u0432\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043c\u0435\u0441\u0442\u0430  \u043f\u043e \u0431\u0430\u0437\u0430\u043c. \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u0435\u0440\u0438\u043e\u0434 \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043c\u043e\u0442\u0440\u0438\u043c<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">USE [LEMON] GO  \/****** Object:  StoredProcedure [prm].[dwh_daily_size_statistics]    Script Date: 02.09.2020 18:35:02 ******\/ SET ANSI_NULLS ON GO  SET QUOTED_IDENTIFIER ON GO  CREATE  procedure [prm].[dwh_daily_size_statistics]   @sdate date, @edate date AS BEGIN  \t--\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u0434\u043d\u0435\u0432\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \t\tdeclare   @str nvarchar(4000)\t\t \t\tset @str= \t\t\t\t stuff \t\t\t\t ( \t\t\t\t  (\t  \t\t\t\t\tselect  N','+ 'round(cast(sum(case when ddate =  cast('''+ cast( ddate as nvarchar)+'''as date)  then\treserved_KB\tend) as float) \/1024\/1024,0)  ['+ cast( ddate as nvarchar)+']'+char(10) \t\t\t\t\tfrom (  \t\t\t\t\t\tselect distinct ddate from  lemon.prm.dwh_size_of_tables \t\t\t\t\t\twhere ddate &gt;=@sdate and  ddate&lt;@edate \t\t\t\t\t\t) t \t\t\t\t\t order by t.ddate \t\t\t\t   for xml path('') \t\t\t\t  ,type \t\t\t\t  ).value('.','nvarchar(max)'), \t\t\t\t  1,0,'' \t\t\t\t )-- column_string  \t\t--print @str   \t\texec ('  \t\t select db_name --\u0411\u0414- \t\t \t\t\t\t'+@str+' \t\t from  lemon.prm.dwh_size_of_tables \t\t--where ddate = cast(getdate() as date) \t\t group by  db_name \t\t--order  by  db_name \t\t');   end ; GO   <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041c\u0435\u0441\u044f\u0447\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043c\u0435\u0441\u0442\u0430 \u043f\u043e \u0431\u0430\u0437\u0430\u043c. \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u0435\u0440\u0438\u043e\u0434 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0438.<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">USE [LEMON] GO  \/****** Object:  StoredProcedure [prm].[dwh_monthly_size_statistics]    Script Date: 02.09.2020 18:35:09 ******\/ SET ANSI_NULLS ON GO  SET QUOTED_IDENTIFIER ON GO    CREATE procedure [prm].[dwh_monthly_size_statistics]   @sdate date, @edate date AS begin  --\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u043c\u0435\u0441\u044f\u0447\u0443\u044e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 declare   @str2 nvarchar(4000)\t\t set @str2= \t\t stuff \t\t ( \t\t  (\t  \t\t\tselect  N','+ 'round(cast(sum(case when ddate =  cast('''+ cast( ddate as nvarchar)+'''as date)  then\treserved_KB\tend) as float) \/1024\/1024,0)  ['+  \t\t\tCAST(year( ddate) as nvarchar) +'_'+ CAST(month( ddate) as nvarchar) \t\t\t--cast( ddate as nvarchar) \t\t\t+']'+char(10) \t\t\tfrom (  \t\t\t\tselect distinct ddate from  lemon.prm.dwh_size_of_tables \t\t\t\twhere ddate &gt;=@sdate and  ddate&lt;@edate and day(ddate)=1 \t\t\t\t) t \t\t\t order by t.ddate \t\t   for xml path('') \t\t  ,type \t\t  ).value('.','nvarchar(max)'), \t\t  1,0,'' \t\t )  exec ('   select db_name --\u0411\u0414- \t\t--,table_name \t\t'+@str2+'  from  lemon.prm.dwh_size_of_tables --where ddate = cast(getdate() as date)  group by  db_name--,table_name order  by  db_name ');   end; GO   <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430  \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u0442\u0430\u0431\u043b\u0438\u0446<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">USE [LEMON] GO \/****** Object:  StoredProcedure [prm].[dwh_monthly_table_size_statistics]    Script Date: 02.09.2020 18:36:15 ******\/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO  ALTER procedure [prm].[dwh_monthly_table_size_statistics]   @sdate date, @edate date ,@db_name nvarchar(100) AS begin  --\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u043c\u0435\u0441\u044f\u0447\u0443\u044e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 declare   @str2 nvarchar(4000)\t\t set @str2= \t\t stuff \t\t ( \t\t  (\t  \t\t\tselect  N','+ 'round(cast(sum(case when ddate =  cast('''+ cast( ddate as nvarchar)+'''as date)  then\treserved_KB\tend) as float) \/1024\/1024,0)  ['+  \t\t\tCAST(year( ddate) as nvarchar) +'_'+ CAST(month( ddate) as nvarchar) \t\t\t--cast( ddate as nvarchar) \t\t\t+']'+char(10) \t\t\tfrom (  \t\t\t\tselect distinct ddate from  lemon.prm.dwh_size_of_tables \t\t\t\twhere ddate &gt;=@sdate and  ddate&lt;@edate and day(ddate)=1    \t\t\t\t) t \t\t\t order by t.ddate \t\t   for xml path('') \t\t  ,type \t\t  ).value('.','nvarchar(max)'), \t\t  1,0,'' \t\t )  declare @ORDER_DATE NVARCHAR(100)     SET @ORDER_DATE= convert(nvarchar, year( @edate)  ) +'_'+  convert(nvarchar, month( @edate) )    SELECT  @ORDER_DATE = convert(nvarchar, year( DDATE)  ) +'_'+  convert(nvarchar, month( DDATE) ) FROM ( \tselect MAX( ddate ) DDATE from  lemon.prm.dwh_size_of_tables \t\t\t\twhere ddate &gt;=@sdate and  ddate&lt;@edate and day(ddate)=1  \t\t\t\t) tt  ; declare @ddb_name nvarchar(100) set @ddb_name =  case when @db_name is null then '' else  ' and '+ 'db_name= '''+@db_name + '''' end   exec ('   select db_name --\u0411\u0414- \t\t,table_name \t\t'+@str2+'  from  lemon.prm.dwh_size_of_tables where 1=1  ' + @ddb_name  + '  -- ddate = cast(getdate() as date)  group by  db_name,table_name  order by  db_name,['+ @ORDER_DATE +'] desc ');   end;<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p><strong>5)<\/strong> \u0412 \u0438\u0442\u043e\u0433\u0435  \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438\u0441\u044c 3 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 : <\/p>\n<p>A) \u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f\/\u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f  \u0411\u0414 \u043f\u043e\u0434\u043d\u0435\u0432\u043d\u043e<\/p>\n<p>B) \u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f\/\u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f  \u0411\u0414 \u043f\u043e\u043c\u0435\u0441\u044f\u0447\u043d\u043e<\/p>\n<p>C) \u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f\/\u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f  \u0442\u0430\u0431\u043b\u0438\u0446 \u043f\u043e\u043c\u0435\u0441\u044f\u0447\u043d\u043e. \u041e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c  \u043f\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043a\u043e\u0433\u0434\u0430 \u043f\u043e \u043d\u0435\u0439 \u043f\u043e\u0448\u0435\u043b \u0440\u043e\u0441\u0442. <\/p>\n<p>\u0414\u0430 , \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u0435\u0441\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c PIVOT), \u043d\u043e \u044d\u0442\u0438 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0443\u0434\u043e\u0431\u043d\u044b \u0442\u0435\u043c, \u0447\u0442\u043e \u043e\u0434\u043d\u0430\u0436\u0434\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0432 \u0435\u0433\u043e, \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432, \u043a\u0430\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440,  \u043d\u0443\u0436\u043d\u044b\u0439 \u043f\u0435\u0440\u0438\u043e\u0434 \u0438\u0441\u0442\u043e\u0440\u0438\u0438.  <\/p>\n<pre><code class=\"sql\">--\u0414\u043d\u0435\u0432\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043c\u0435\u0441\u0442\u0430 \u043f\u043e \u0431\u0430\u0437\u0430\u043c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u0435\u0440\u0438\u043e\u0434  \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043c\u043e\u0442\u0440\u0438\u043c exec  LEMON.prm.dwh_daily_size_statistics @sdate ='2020-08-01', @edate ='2020-09-01'  --\u041c\u0435\u0441\u044f\u0447\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043c\u0435\u0441\u0442\u0430 \u043f\u043e \u0431\u0430\u0437\u0430\u043c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u0435\u0440\u0438\u043e\u0434  \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043c\u043e\u0442\u0440\u0438\u043c exec  LEMON.prm.dwh_monthly_size_statistics @sdate ='2020-03-01', @edate ='2020-09-01'  --\u041c\u0435\u0441\u044f\u0447\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043c\u0435\u0441\u0442\u0430 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 exec  LEMON.prm.dwh_monthly_table_size_statistics  \t\t\t  @sdate ='2020-02-01' \t\t\t, @edate ='2020-08-01' \t\t\t, @db_name ='DWH'--\u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c null \u0442\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u043e \u0432\u0441\u0435\u043c \u0431\u0430\u0437\u0430\u043c<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/929\/fd8\/837\/929fd883774531e0f91eb1a1cd3abcf8.png\" width=\"1077\" height=\"487\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435  \u0432\u044b\u0448\u0435 \u043f\u043e \u043d\u0435\u0439 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a\u0430\u044f \u0431\u0430\u0437\u0430 \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0435\u0437\u043a\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u0445.  \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e \u044d\u0442\u0438\u043c\u0438 \u0442\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430\u043c\u0438 \u043e\u0447\u0435\u043d\u044c \u0431\u044b\u0441\u0442\u0440\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 , \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438\u043b\u0438  \u0431\u0430\u0437\u0443 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u0447\u0430\u043b\u0430  \u0432 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u0438\u043b\u044c\u043d\u043e  \u0440\u0430\u0441\u0442\u0438. \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u043a\u043e\u0433\u0434\u0430  \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0442\u044b\u0441\u044f\u0447\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432,  \u0438 \u0440\u0443\u0447\u043d\u043e\u0439 \u043f\u043e\u0438\u0441\u043a \u0443\u0436\u0435 \u043d\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c.  <\/p>\n<p><strong><u>\u0412\u044b\u0432\u043e\u0434: <\/u><\/strong>\u041d\u0430\u0441\u0442\u0440\u043e\u0438\u0432 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0442\u0430\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043f\u043e \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0443 \u043c\u0435\u0441\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0436\u0438\u0437\u043d\u044c  \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c, \u0432 \u0447\u0430\u0441\u0442\u0438 \u043a\u0430\u0441\u0430\u044e\u0449\u0435\u0439\u0441\u044f \u0440\u043e\u0441\u0442\u0430 \u0431\u0430\u0437\u044b \u0438 \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u0432\u044b\u0440\u043e\u0441\u043b\u0438. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u044d\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043e \u043a\u0430\u043a\u0438\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u043c \u0438\u043b\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u0442\u0441\u044f \u0440\u043e\u0441\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u0430  \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0438 \u043b\u0435\u0433\u043a\u043e \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u0442\u044c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440,  \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430 \u0438\u043b\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0447\u0438\u0441\u0442\u043a\u0443  \u0442\u0430\u0431\u043b\u0438\u0446, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u0442\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0440\u043e\u0441\u0442.    <\/p>\n<p>\u041d\u0430  \u044d\u0442\u043e\u043c \u044f \u043f\u043e\u0436\u0430\u043b\u0443\u0439 \u0437\u0430\u043a\u0440\u0443\u0433\u043b\u044f\u044e\u0441\u044c \u0438 \u043d\u0430\u0434\u0435\u044e\u0441\u044c \u0447\u0442\u043e \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c. \u041e\u0441\u0442\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u0441\u0432\u043e\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0443 \u043a\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u043e  \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u043c\u0435\u0441\u0442\u0430 \u0432  \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430\u0445.  \u0411\u0443\u0434\u0443 \u0440\u0430\u0434 \u043b\u044e\u0431\u044b\u043c \u043e\u0442\u0437\u044b\u0432\u0430\u043c. <\/p>\n<p>P.S.  \u0412\u0441\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b  \u0432\u044b\u043b\u043e\u0436\u0435\u043d\u044b \u043d\u0430 GitHub \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u043d\u0438\u0436\u0435:<\/p>\n<p><a href=\"https:\/\/github.com\/michailo87\/MSSQL\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/michailo87\/MSSQL<\/a><\/p>\n<\/p>\n<p>\u0414\u043e \u0441\u043a\u043e\u0440\u044b\u0445 \u0432\u0441\u0442\u0440\u0435\u0447 !!<\/p>\n<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/517558\/\"> https:\/\/habr.com\/ru\/post\/517558\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/517558\/\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442 \u0425\u0430\u0431\u0440\u043e\u0432\u0447\u0430\u043d\u0435!!<\/p>\n<p>\u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u044b &#8212; \u044d\u0442\u043e \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u0438\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432. \u0410 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435  \u0432\u0441\u0435 \u043d\u043e\u0432\u044b\u0445  \u0438 \u043d\u043e\u0432\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043c\u0435\u0441\u0442\u0430 \u043d\u0430 \u0434\u0438\u0441\u043a\u0430\u0445. <\/p>\n<p>\u0414\u0430, \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435  \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0447\u0438\u0441\u0442\u043a\u0438 \u0441\u0430\u043c\u044b\u0445 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 \u043f\u0435\u0440\u0438\u043e\u0434\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0446\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u0438  \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0442 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u043c\u043e\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0441\u0442\u0430. \u041d\u043e \u0435\u0441\u043b\u0438 \u0440\u0435\u0447\u044c \u0438\u0434\u0435\u0442 \u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u043e\u0434\u0440\u043e \u043d\u0430\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0441\u0451 \u043d\u043e\u0432\u044b\u0435 &#171;\u0431\u043e\u043b\u044c\u0448\u0438\u0435&#187; \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0445 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e \u0432\u043e\u043f\u0440\u043e\u0441 \u043c\u0435\u0441\u0442\u0430 \u0432 DWH \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0440\u0435\u0431\u0440\u043e\u043c.  \u0418  \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 &#171;\u0410 \u043a\u0443\u0434\u0430 \u0436\u0435 \u0443\u0448\u043b\u043e \u043c\u0435\u0441\u0442\u043e?&#187;,  &#171;\u0427\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c?&#187; \u0438\u043b\u0438 &#171;\u041a\u0430\u043a \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u0442\u044c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0443 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430?&#187; \u0421\u0438\u0441\u0442\u0435\u043c\u044b \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u043d\u0430 \u043f\u043e\u0434\u043e\u0431\u0438\u0435 ZABBIX \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u0445\u043d\u0435\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u0434\u0438\u0441\u043a\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430  \u043d\u0430 \u043f\u043e\u043b\u043a\u0435 \u043d\u043e \u043d\u0435 \u0434\u0430\u044e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438  \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0440\u043e\u0441\u0442 \u0441\u0430\u043c\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0431\u0430\u0437\u0435. <\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u043c \u043b\u0430\u0439\u0444\u0445\u0430\u043a\u043e\u043c \u043a\u0430\u043a \u043b\u0435\u0433\u043a\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0442\u0430\u0431\u043b\u0438\u0446 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 MS SQL \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0430\u0437\u044b. \u042d\u0442\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u043a\u0443\u0447\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c &#171;\u041a\u0443\u0434\u0430 \u0436\u0435 \u0443\u0448\u043b\u043e \u0432\u0441\u0435 \u043c\u0435\u0441\u0442\u043e \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435?&#187;. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c  \u0438 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0431\u0430\u0437\u0430\u0445 (Oracle, PostgreSQL \u0438 \u0442.\u0434.) \u0441 \u0442\u043e\u0439 \u043b\u0438\u0448\u044c \u0440\u0430\u0437\u043d\u0438\u0446\u0435\u0439, \u0447\u0442\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u0431\u0443\u0434\u0443\u0442 \u0434\u0440\u0443\u0433\u0438\u0435. <\/p>\n<p>\u041d\u0438\u0436\u0435  \u043e\u043f\u0438\u0441\u0430\u043d \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u043b\u0430\u043d \u0438 \u043d\u0430\u0431\u043e\u0440 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 MS SQL  \u0447\u0442\u043e\u0431\u044b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u043c\u0435\u0441\u0442\u0430:<\/p>\n<p>\u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0433\u043b\u0430\u043c\u0435\u043d\u0442\u043d\u043e\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u0435 , \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u043e.<\/p>\n<p><strong>1)<\/strong> \u041d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u0448\u0430\u0433\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0438 \u0441\u0447\u0435\u0442\u0447\u0438\u043a. \u0412 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f  \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u0430\u044f  \u0438\u0441\u0442\u043e\u0440\u0438\u044f  \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<pre><code class=\"sql\">CREATE SEQUENCE prm.sq_etl_log_1   AS bigint  START WITH 1  INCREMENT BY 1    CREATE TABLE prm.dwh_size_of_tables( \tddate date NULL,\t\t\t\t\t\t\t--\u0414\u0430\u0442\u0430  \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \trun_id numeric(14, 0) NOT NULL,\t--ID \u0417\u0430\u043f\u0443\u0441\u043a\u0430 \u0441\u0431\u043e\u0440\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438, \u0421\u0447\u0435\u0442\u0447\u0438\u043a \tdb_name varchar(20) NOT NULL,\t--\u0411\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \tschema_name sysname NOT NULL,\t--\u0421\u0445\u0435\u043c\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \ttable_name sysname NOT NULL,\t--\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \trow_count bigint NULL,\t\t\t\t--\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \treserved_KB bigint NULL,\t\t\t--\u041e\u0449\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u0431\u043b\u0438\u0446\u044b  \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0438\u043d\u0434\u0435\u0441\u0430\u043c\u0438 \tdata_KB bigint NULL,\t\t\t\t\t--\u0420\u0430\u0437\u043c\u0435\u0440 \u0441\u0430\u043c\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435  \tindex_size_KB bigint NULL,\t\t--\u0420\u0430\u0437\u043c\u0435\u0440 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \tunused_KB bigint NULL\t\t\t\t\t--\u043d\u0435\u0438\u0441\u043f\u0440\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e ) <\/code><\/pre>\n<p><strong>2) <\/strong>\u0414\u0430\u043b\u0435\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e  \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u043a\u043e\u0442\u043e\u0440\u0430\u044f  \u0431\u0443\u0434\u0435\u0442 \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043f\u043e-\u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e.  \u042d\u0442\u0443 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u043e\u0435  \u0437\u0430\u0434\u0430\u043d\u0438\u0435  \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430. \u041e\u043d\u0430 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0441\u0440\u0435\u0437  \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u0442\u0430\u0431\u043b\u0438\u0446 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0434\u0435\u043d\u044c.<\/p>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043d\u0438\u0436\u0435:<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u0438\u043f\u0442 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">USE [LEMON] GO  CREATE  PROCEDURE  [prm].[load_etl_log] AS declare  @run_id int BEGIN  --\u0415\u0441\u043b\u0438 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0431\u044b\u043b \u0437\u0430\u043f\u0443\u0441\u043a \u043e\u0447\u0438\u0449\u0430\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u044e\u0443\u044e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043b\u0438\u0432\u0430\u0435\u043c delete from lemon.prm.dwh_size_of_tables where ddate = cast(getdate() as date);  --\u0414\u043b\u044f \u0441\u0442\u0440\u0430\u044b\u0445 \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432  \u0445\u0440\u0430\u043d\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043d\u0430\u0447\u0430\u043b\u043e \u0438 \u043d\u0430 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0443 \u043c\u0435\u0441\u044f\u0446\u0430 delete from  lemon.prm.dwh_size_of_tables where (DATEPART(day, ddate)not in (1,15) and ddate &lt; dateadd(month ,-2, getdate()))   DECLARE @SQL_text varchar(max),@SQL_text_final varchar(max); ;   set @SQL_text=   ' USE {SCHEMA_FOR_REPLACE};   insert into  lemon.prm.dwh_size_of_tables SELECT   \tcast(getdate() as date) date_time, \t'''+ convert(nvarchar , @run_id  ) +''' run_id , \t''{SCHEMA_FOR_REPLACE}'' db_name, \ta3.name AS schema_name \t,--\u0421\u0445\u0435\u043c\u0430 \ta2.name AS table_name \t,--\u0418\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \ta1.rows AS row_count \t,--\u0427\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \t(a1.reserved + ISNULL(a4.reserved, 0)) * 8 AS reserved_KB \t,--\u0417\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043e (\u041a\u0411)\t \ta1.data * 8 AS data_KB \t,--\u0414\u0430\u043d\u043d\u044b\u0435 (\u041a\u0411) \t( \t\tCASE  \t\t\tWHEN (a1.used + ISNULL(a4.used, 0)) &gt; a1.data \t\t\t\tTHEN (a1.used + ISNULL(a4.used, 0)) - a1.data \t\t\tELSE 0 \t\t\tEND \t\t) * 8 AS index_size_KB \t,--\u0418\u043d\u0434\u0435\u043a\u0441\u044b (\u041a\u0411) \t( \t\tCASE  \t\t\tWHEN (a1.reserved + ISNULL(a4.reserved, 0)) &gt; a1.used \t\t\t\tTHEN (a1.reserved + ISNULL(a4.reserved, 0)) - a1.used \t\t\tELSE 0 \t\t\tEND \t\t) * 8 AS unused_KB --\u041d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f (\u041a\u0411) \t\t \tFROM ( \t\t\t\tSELECT ps.object_id \t\t\t\t\t,SUM(CASE  \t\t\t\t\t\t\tWHEN (ps.index_id &lt; 2) \t\t\t\t\t\t\t\tTHEN row_count \t\t\t\t\t\t\tELSE 0 \t\t\t\t\t\t\tEND) AS [rows] \t\t\t\t\t,SUM(ps.reserved_page_count) AS reserved \t\t\t\t\t,SUM(CASE  \t\t\t\t\t\t\tWHEN (ps.index_id &lt; 2) \t\t\t\t\t\t\t\tTHEN (ps.in_row_data_page_count + ps.lob_used_page_count + ps.row_overflow_used_page_count) \t\t\t\t\t\t\tELSE (ps.lob_used_page_count + ps.row_overflow_used_page_count) \t\t\t\t\t\t\tEND) AS data \t\t\t\t\t,SUM(ps.used_page_count) AS used \t\t\t\tFROM sys.dm_db_partition_stats ps \t\t\t\tWHERE ps.object_id NOT IN ( \t\t\t\t\t\tSELECT object_id \t\t\t\t\t\tFROM sys.tables \t\t\t\t\t\tWHERE is_memory_optimized = 1 \t\t\t\t\t\t) \t\t\t\tGROUP BY ps.object_id \t\t) AS a1 \tLEFT OUTER JOIN ( \t\t\t\tSELECT it.parent_id \t\t\t\t\t,SUM(ps.reserved_page_count) AS reserved \t\t\t\t\t,SUM(ps.used_page_count) AS used \t\t\t\tFROM sys.dm_db_partition_stats ps \t\t\t\tINNER JOIN sys.internal_tables it ON (it.object_id = ps.object_id) \t\t\t\tWHERE it.internal_type IN ( \t\t\t\t\t\t202 \t\t\t\t\t\t,204 \t\t\t\t\t\t) \t\t\t\tGROUP BY it.parent_id \t\t) AS a4 ON (a4.parent_id = a1.object_id) \tINNER JOIN sys.all_objects a2 ON (a1.object_id = a2.object_id) \tINNER JOIN sys.schemas a3 ON (a2.schema_id = a3.schema_id) \tWHERE a2.type &lt;&gt; N''S'' \t\tAND a2.type &lt;&gt; N''IT'' \t\t'; \t\t \t\t\tDECLARE @request_id nvarchar(36), @schema_for_replace nvarchar(100) \t \t\t\tDECLARE bki_cursor CURSOR FOR    \t\t\t\tSELECT name as schem     \t\t\t\tFROM    sys.databases \t\t\t\t--\u0417\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0431\u0430\u0437 \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \t\t\t\t\/*  where name  in ( \t\t\t\t\t'DWH','DWH_copy','VN','VN_test') --and name ='DWH' \t\t\t\t\t*\/ \t\t\tOPEN bki_cursor    \t\t\tFETCH NEXT FROM bki_cursor INTO @schema_for_replace  \t\t\tWHILE @@FETCH_STATUS = 0   \t\t\tBEGIN \t\t\t\tset @SQL_text_final = replace (@sql_text,'{SCHEMA_FOR_REPLACE}',@schema_for_replace);   \t\t\t\texecute (@SQL_text_final)  \t\t\tFETCH NEXT FROM bki_cursor INTO @schema_for_replace \t\t\tEND    \t \t\tCLOSE bki_cursor;   \t\tDEALLOCATE bki_cursor; END  <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u043e\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<p><strong>3)<\/strong> \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e \u043c\u0435\u0440\u0435 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f  \u0442\u0430\u0431\u043b\u0438\u0446\u044b <em>dwh_size_of_tables<\/em> \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443  \u043f\u043e-\u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e \u0438 \u043f\u043e \u0431\u0430\u0437\u0430\u043c. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u043c \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c \u043d\u0438\u0436\u0435.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043c\u0435\u0441\u0442\u0430 \u0432 DWH \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">--\u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043c\u0435\u0441\u0442\u0430  \u0432 DWH \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c select top 10 ddate -- [\u0414\u0430\u0442\u0430] \t\t,run_id -- \t\t,db_name --\u0411\u0414- \t\t,schema_name --\u0421\u0445\u0435\u043c\u0430 \t\t,table_name --\u0418\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \t\t,row_count --\u0427\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \t\t,round(cast(reserved_KB as float) \/1024\/1024,2) as  reserved_GB --\u0417\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043e (\u041a\u0411)\t \t\t,round(cast(data_KB as float) \/1024\/1024,2) as data_GB --\u0414\u0430\u043d\u043d\u044b\u0435 (\u041a\u0411) \t\t,round(cast(index_size_KB as float) \/1024\/1024,2) as index_size_GB --\u0418\u043d\u0434\u0435\u043a\u0441\u044b (\u041a\u0411) \t\t,round(cast(unused_KB as float) \/1024\/1024,2) as unused_GB--\u041d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f (\u041a\u0411)\t  from  lemon.prm.dwh_size_of_tables where ddate = cast(getdate() as date)-- and  db_name='DWH'  order by reserved_GB desc<\/code><\/pre>\n<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043c\u0435\u0441\u0442\u0430 \u0432 DWH \u043f\u043e \u0431\u0430\u0437\u0430\u043c <\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">--\u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043c\u0435\u0441\u0442\u0430  \u0432 DWH \u043f\u043e  \u0411\u0430\u0437\u0430\u043c  select ddate -- [\u0414\u0430\u0442\u0430] \t\t,run_id -- \t\t,db_name --\u0411\u0414- \t\t,round(cast(sum(reserved_KB) as float) \/1024\/1024,2) as  reserved_GB --\u0417\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043e (\u041a\u0411)\t \t\t,round(cast(sum(data_KB) as float) \/1024\/1024,2) as data_GB --\u0414\u0430\u043d\u043d\u044b\u0435 (\u041a\u0411) \t\t,round(cast(sum(index_size_KB) as float) \/1024\/1024,2) as index_size_GB --\u0418\u043d\u0434\u0435\u043a\u0441\u044b (\u041a\u0411) \t\t,round(cast(sum(unused_KB) as float) \/1024\/1024,2) as unused_GB--\u041d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f (\u041a\u0411)\t \t\t,sum(row_count) row_count--\u0427\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439  from  lemon.prm.dwh_size_of_tables where ddate = cast(getdate() as date)-- and  db_name='DWH'  group by   ddate,run_id,db_name order  by  ddate,run_id\t,sum(data_KB+index_size_KB) desc<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<p><strong>4) <\/strong>\u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c  \u0435\u0449\u0435 3 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0442 \u043d\u0430\u043c \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u043f\u043e \u0431\u0430\u0437\u0430\u043c \u0438 \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u043e. \u042d\u0442\u0438 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043d\u0435 \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438  \u0430 \u0434\u043b\u044f  \u043f\u043e\u043a\u0430\u0437\u0430 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0432 \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u043c \u0432\u0438\u0434\u0435. \u041f\u0440\u0438\u0447\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0432 \u043f\u0435\u0440\u0438\u043e\u0434 \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443, \u043e\u043d\u0430 \u043f\u043e-\u043a\u043e\u043b\u043e\u043d\u043e\u0447\u043d\u043e \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443. <\/p>\n<details class=\"spoiler\">\n<summary>\u0414\u043d\u0435\u0432\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043c\u0435\u0441\u0442\u0430  \u043f\u043e \u0431\u0430\u0437\u0430\u043c. \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u0435\u0440\u0438\u043e\u0434 \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043c\u043e\u0442\u0440\u0438\u043c<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">USE [LEMON] GO  \/****** Object:  StoredProcedure [prm].[dwh_daily_size_statistics]    Script Date: 02.09.2020 18:35:02 ******\/ SET ANSI_NULLS ON GO  SET QUOTED_IDENTIFIER ON GO  CREATE  procedure [prm].[dwh_daily_size_statistics]   @sdate date, @edate date AS BEGIN  \t--\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u0434\u043d\u0435\u0432\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \t\tdeclare   @str nvarchar(4000)\t\t \t\tset @str= \t\t\t\t stuff \t\t\t\t ( \t\t\t\t  (\t  \t\t\t\t\tselect  N','+ 'round(cast(sum(case when ddate =  cast('''+ cast( ddate as nvarchar)+'''as date)  then\treserved_KB\tend) as float) \/1024\/1024,0)  ['+ cast( ddate as nvarchar)+']'+char(10) \t\t\t\t\tfrom (  \t\t\t\t\t\tselect distinct ddate from  lemon.prm.dwh_size_of_tables \t\t\t\t\t\twhere ddate &gt;=@sdate and  ddate&lt;@edate \t\t\t\t\t\t) t \t\t\t\t\t order by t.ddate \t\t\t\t   for xml path('') \t\t\t\t  ,type \t\t\t\t  ).value('.','nvarchar(max)'), \t\t\t\t  1,0,'' \t\t\t\t )-- column_string  \t\t--print @str   \t\texec ('  \t\t select db_name --\u0411\u0414- \t\t \t\t\t\t'+@str+' \t\t from  lemon.prm.dwh_size_of_tables \t\t--where ddate = cast(getdate() as date) \t\t group by  db_name \t\t--order  by  db_name \t\t');   end ; GO   <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041c\u0435\u0441\u044f\u0447\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043c\u0435\u0441\u0442\u0430 \u043f\u043e \u0431\u0430\u0437\u0430\u043c. \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u0435\u0440\u0438\u043e\u0434 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0438.<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">USE [LEMON] GO  \/****** Object:  StoredProcedure [prm].[dwh_monthly_size_statistics]    Script Date: 02.09.2020 18:35:09 ******\/ SET ANSI_NULLS ON GO  SET QUOTED_IDENTIFIER ON GO    CREATE procedure [prm].[dwh_monthly_size_statistics]   @sdate date, @edate date AS begin  --\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u043c\u0435\u0441\u044f\u0447\u0443\u044e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 declare   @str2 nvarchar(4000)\t\t set @str2= \t\t stuff \t\t ( \t\t  (\t  \t\t\tselect  N','+ 'round(cast(sum(case when ddate =  cast('''+ cast( ddate as nvarchar)+'''as date)  then\treserved_KB\tend) as float) \/1024\/1024,0)  ['+  \t\t\tCAST(year( ddate) as nvarchar) +'_'+ CAST(month( ddate) as nvarchar) \t\t\t--cast( ddate as nvarchar) \t\t\t+']'+char(10) \t\t\tfrom (  \t\t\t\tselect distinct ddate from  lemon.prm.dwh_size_of_tables \t\t\t\twhere ddate &gt;=@sdate and  ddate&lt;@edate and day(ddate)=1 \t\t\t\t) t \t\t\t order by t.ddate \t\t   for xml path('') \t\t  ,type \t\t  ).value('.','nvarchar(max)'), \t\t  1,0,'' \t\t )  exec ('   select db_name --\u0411\u0414- \t\t--,table_name \t\t'+@str2+'  from  lemon.prm.dwh_size_of_tables --where ddate = cast(getdate() as date)  group by  db_name--,table_name order  by  db_name ');   end; GO   <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430  \u0434\u043b\u044f<\/summary>\n<\/details>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-310904","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/310904","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=310904"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/310904\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=310904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=310904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=310904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}