{"id":32731,"date":"2019-10-31T21:48:38","date_gmt":"2019-10-31T18:48:38","guid":{"rendered":"https:\/\/prohoster.info\/blog\/vygruzka-loga-postgresql-s-oblaka-aws\/"},"modified":"2019-10-31T21:48:38","modified_gmt":"2019-10-31T18:48:38","slug":"vygruzka-loga-postgresql-s-oblaka-aws","status":"publish","type":"post","link":"https:\/\/prohoster.info\/de\/blog\/administrirovanie\/vygruzka-loga-postgresql-s-oblaka-aws","title":{"rendered":"Download des PostgreSQL-Logs aus der AWS-Cloud","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<p><i>\u0418\u043b\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0439 \u0442\u0435\u0442\u0440\u0438\u0441\u043e\u043b\u043e\u0433\u0438\u0438.<br \/>\n\u0412\u0441\u0451 \u043d\u043e\u0432\u043e\u0435- \u0445\u043e\u0440\u043e\u0448\u043e \u0437\u0430\u0431\u044b\u0442\u043e\u0435 \u0441\u0442\u0430\u0440\u043e\u0435.<br \/>\n<\/i>\u042d\u043f\u0438\u0433\u0440\u0430\u0444\u044b.<br \/>\n<img decoding=\"async\" alt=\"\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u043b\u043e\u0433\u0430 PostgreSQL \u0441 \u043e\u0431\u043b\u0430\u043a\u0430 AWS\" src=\"\/wp-content\/uploads\/2019\/04\/795dbfb9fdc67d0b32dd275600fda4fe.png\" style=\"display:block;margin: 0 auto;\" \/><br \/>\n<\/p>\n<h2>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p>\n\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b PostgreSQL \u0438\u0437 \u043e\u0431\u043b\u0430\u043a\u0430 AWS \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 Linux \u0445\u043e\u0441\u0442. \u041d\u0435 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043d\u043e, \u0441\u043a\u0430\u0436\u0435\u043c \u0442\u0430\u043a, \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439.<br \/>\n\u041f\u0435\u0440\u0438\u043e\u0434 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430 \u2014 5 \u043c\u0438\u043d\u0443\u0442.<br \/>\n\u041b\u043e\u0433-\u0444\u0430\u0439\u043b, \u0432 AWS, \u0440\u043e\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0447\u0430\u0441. <\/p>\n<h2>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b<\/h2>\n<p>\n\u0414\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430 \u043d\u0430 \u0445\u043e\u0441\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f bash-\u0441\u043a\u0440\u0438\u043f\u0442, \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 AWS API \u00ab<noindex><a rel=\"nofollow\" href=\"https:\/\/docs.aws.amazon.com\/cli\/latest\/reference\/rds\/download-db-log-file-portion.html\">aws rds download-db-log-file-portion<\/a><\/noindex>\u00bb. <\/p>\n<h3>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/h3>\n<p><\/p>\n<ul>\n<li> &#8212;db-instance-identifier: \u0418\u043c\u044f \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 \u0432 AWS;<\/li>\n<li> &#8212;log-file-name: \u0438\u043c\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430<\/li>\n<li> &#8212;max-item: \u041e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0445 \u0432 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<b>\u0420\u0430\u0437\u043c\u0435\u0440 \u043f\u043e\u0440\u0446\u0438\u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430.<\/b><\/li>\n<li> &#8212;starting-token: \u041c\u0435\u0442\u043a\u0430 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u043e\u0440\u0446\u0438\u0438<\/li>\n<\/ul>\n<p><noindex><a rel=\"nofollow\" name=\"habracut\"><\/a><\/noindex>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0437\u0430\u0434\u0430\u0447\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043b\u043e\u0433\u043e\u0432 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u043f\u043e \u0445\u043e\u0434\u0443 \u0440\u0430\u0431\u043e\u0442 \u043d\u0430\u0434 <noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/post\/444988\/\">\u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u043e\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 PostgreSQL.<\/a><\/noindex><\/p>\n<p>\u0414\u0430 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u2014 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u0434\u043b\u044f \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0438 \u0438 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u044f \u0432 \u0445\u043e\u0434\u0435 \u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<br \/>\n\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0443, \u0447\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u0432 \u0441\u0438\u043b\u0443 \u043e\u0431\u044b\u0434\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0443\u0436\u0435 \u0440\u0435\u0448\u0435\u043d\u0430. \u041d\u043e \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0433\u0443\u0433\u043b \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043d\u0435 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u0430\u043b, \u0430 \u0438\u0441\u043a\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0443\u0433\u043b\u0443\u0431\u043b\u0435\u043d\u043d\u043e \u043d\u0435 \u0431\u044b\u043b\u043e \u043e\u0441\u043e\u0431\u043e\u0433\u043e \u0436\u0435\u043b\u0430\u043d\u0438\u044f. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u043d\u0435\u043f\u043b\u043e\u0445\u0430\u044f \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0430.<\/p>\n<h2>\u0424\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p>\n\u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u044b. \u0413\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438, \u043b\u043e\u0433-\u0444\u0430\u0439\u043b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<br \/>\n<img decoding=\"async\" alt=\"\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u043b\u043e\u0433\u0430 PostgreSQL \u0441 \u043e\u0431\u043b\u0430\u043a\u0430 AWS\" src=\"\/wp-content\/uploads\/2019\/04\/0f46f89b8be74eef10da3f32e348c2b2.png\" style=\"display:block;margin: 0 auto;\" \/><br \/>\n<br \/>\n\u0423\u0436\u0435 \u0447\u0442\u043e-\u0442\u043e \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442? <b>\u041f\u0440\u0438 \u0447\u0451\u043c \u0442\u0443\u0442 \u00ab\u0442\u0435\u0442\u0440\u0438\u0441\u00bb? \u0410 \u0432\u043e\u0442, \u043f\u0440\u0438 \u0447\u0435\u043c.<\/b><br \/>\n\u0415\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0438\u0435 \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438 (\u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u0443\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u043d\u0443 \u0434\u043b\u0438\u043d\u0443), \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0441\u044f <b>\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0444\u0438\u0433\u0443\u0440\u044b \u0442\u0435\u0442\u0440\u0438\u0441\u0430:<\/b><\/p>\n<p><b>1)<\/b> \u0424\u0430\u0439\u043b \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c. \u0420\u0430\u0437\u043c\u0435\u0440 \u043f\u043e\u0440\u0446\u0438\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430:<br \/>\n<img decoding=\"async\" alt=\"\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u043b\u043e\u0433\u0430 PostgreSQL \u0441 \u043e\u0431\u043b\u0430\u043a\u0430 AWS\" src=\"\/wp-content\/uploads\/2019\/04\/42ff74392422a1adefe6f60e54868ea1.png\" style=\"display:block;margin: 0 auto;\" \/><br \/>\n<br \/>\n<b>2)<\/b> \u0424\u0430\u0439\u043b \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435. \u0420\u0430\u0437\u043c\u0435\u0440 \u043f\u043e\u0440\u0446\u0438\u0438 \u043c\u0435\u043d\u044c\u0448\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430:<br \/>\n<img decoding=\"async\" alt=\"\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u043b\u043e\u0433\u0430 PostgreSQL \u0441 \u043e\u0431\u043b\u0430\u043a\u0430 AWS\" src=\"\/wp-content\/uploads\/2019\/04\/da3ef62b6b506dce9463217e82bf602e.png\" style=\"display:block;margin: 0 auto;\" \/><br \/>\n<br \/>\n<b>3) <\/b>\u0424\u0430\u0439\u043b \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0438 \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435. \u0420\u0430\u0437\u043c\u0435\u0440 \u043f\u043e\u0440\u0446\u0438\u0438 \u043c\u0435\u043d\u044c\u0448\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043e\u0441\u0442\u0430\u0442\u043a\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430:<br \/>\n<img decoding=\"async\" alt=\"\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u043b\u043e\u0433\u0430 PostgreSQL \u0441 \u043e\u0431\u043b\u0430\u043a\u0430 AWS\" src=\"\/wp-content\/uploads\/2019\/04\/64d5c3a2dd1e2c45f415b5c0bb9dafe2.png\" style=\"display:block;margin: 0 auto;\" \/><br \/>\n<br \/>\n4) \u0424\u0430\u0439\u043b \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c. \u0420\u0430\u0437\u043c\u0435\u0440 \u043f\u043e\u0440\u0446\u0438\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043e\u0441\u0442\u0430\u0442\u043a\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430:<br \/>\n<img decoding=\"async\" alt=\"\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u043b\u043e\u0433\u0430 PostgreSQL \u0441 \u043e\u0431\u043b\u0430\u043a\u0430 AWS\" src=\"\/wp-content\/uploads\/2019\/04\/ff97ec201aacee18b9bd50259358f46d.png\" style=\"display:block;margin: 0 auto;\" \/><br \/>\n<br \/>\n<b>\u0417\u0430\u0434\u0430\u0447\u0430 \u2014 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a \u0438\u043b\u0438 \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c \u0432 \u0442\u0435\u0442\u0440\u0438\u0441, \u043d\u0430 \u043d\u043e\u0432\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435.<\/b><br \/>\n<img decoding=\"async\" alt=\"\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u043b\u043e\u0433\u0430 PostgreSQL \u0441 \u043e\u0431\u043b\u0430\u043a\u0430 AWS\" src=\"\/wp-content\/uploads\/2019\/04\/a7c71666a4fc9e4c84bc03de82c32382.png\" style=\"display:block;margin: 0 auto;\" \/><br \/>\n<\/p>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0438\u0435 \u043f\u043e \u0445\u043e\u0434\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p><\/p>\n<h3>1) \u0421\u043a\u043b\u0435\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0438\u0437 2-\u0445 \u043f\u043e\u0440\u0446\u0438\u0439<\/h3>\n<p>\n<img decoding=\"async\" alt=\"\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u043b\u043e\u0433\u0430 PostgreSQL \u0441 \u043e\u0431\u043b\u0430\u043a\u0430 AWS\" src=\"\/wp-content\/uploads\/2019\/04\/d7c77c8cbed90a89c00b233f51f64f3b.png\" style=\"display:block;margin: 0 auto;\" \/><br \/>\n\u0412 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043e\u0441\u043e\u0431\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u043e. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0438\u0437 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u0443\u0440\u0441\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<h2>\u041e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u043f\u043e\u0440\u0446\u0438\u0438<\/h2>\n<p>\n\u0410 \u0432\u043e\u0442 \u044d\u0442\u043e, \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435. <br \/>\n\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435 \u043c\u0435\u0442\u043a\u0438 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u043e\u0440\u0446\u0438\u0438:<\/p>\n<blockquote><p>As you already know the option &#8212;starting-token is used to specify where to start paginating. This option takes String values which would mean that if you try to add an offset value in front of the Next Token string, the option will not be taken into consideration as an offset.<\/p><\/blockquote>\n<p>\n\u0418 \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0447\u0438\u0442\u0430\u0442\u044c \u043a\u0443\u0441\u043a\u0430\u043c\u0438-\u043f\u043e\u0440\u0446\u0438\u044f\u043c\u0438.<br \/>\n\u0415\u0441\u043b\u0438 \u0447\u0438\u0442\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u043f\u043e\u0440\u0446\u0438\u044f\u043c\u0438, \u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0447\u0442\u0435\u043d\u0438\u0439 \u0431\u0443\u0434\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c, \u043d\u043e \u043e\u0431\u044a\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c.<br \/>\n\u0415\u0441\u043b\u0438 \u0447\u0438\u0442\u0430\u0442\u044c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u043c\u0438 \u043f\u043e\u0440\u0446\u0438\u044f\u043c\u0438, \u0442\u043e \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0447\u0442\u0435\u043d\u0438\u0439 \u0431\u0443\u0434\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c, \u043d\u043e \u0437\u0430\u0442\u043e \u043e\u0431\u044a\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c.<br \/>\n\u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0434\u043b\u044f \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0442\u0440\u0430\u0444\u0444\u0438\u043a\u0430 \u0438 \u0434\u043b\u044f \u043e\u0431\u0449\u0435\u0439 \u043a\u0440\u0430\u0441\u043e\u0442\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u043c\u0430\u0445\u0438\u0432\u0430\u044e\u0449\u0435\u0435 \u043d\u0430 \u043a\u043e\u0441\u0442\u044b\u043b\u044c.<\/p>\n<p>\u0414\u043b\u044f \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u0438, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430 \u0432 2-\u0445 \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u044b\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u0445. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0447\u0442\u0435\u043d\u0438\u0439 \u0432 \u043e\u0431\u043e\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043f\u043e\u0440\u0446\u0438\u0438.<\/p>\n<p><b>1) \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043c\u0430\u043b\u044b\u043c\u0438 \u043f\u043e\u0440\u0446\u0438\u044f\u043c\u0438:<\/b><br \/>\n<img decoding=\"async\" alt=\"\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u043b\u043e\u0433\u0430 PostgreSQL \u0441 \u043e\u0431\u043b\u0430\u043a\u0430 AWS\" src=\"\/wp-content\/uploads\/2019\/04\/8029996492f329a806953239f109c70b.png\" style=\"display:block;margin: 0 auto;\" \/><br \/>\n<br \/>\n<b>2) \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u043f\u043e\u0440\u0446\u0438\u044f\u043c\u0438:<\/b><br \/>\n<img decoding=\"async\" alt=\"\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u043b\u043e\u0433\u0430 PostgreSQL \u0441 \u043e\u0431\u043b\u0430\u043a\u0430 AWS\" src=\"\/wp-content\/uploads\/2019\/04\/5a09c387a33c2d04468892631d6cf44e.png\" style=\"display:block;margin: 0 auto;\" \/><br \/>\n<br \/>\n<b>\u041a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e, \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435-\u043f\u043e\u0441\u0440\u0435\u0434\u0438\u043d\u0435<\/b>. <br \/>\n\u0420\u0430\u0437\u043c\u0435\u0440 \u043f\u043e\u0440\u0446\u0438\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439, \u043d\u043e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0447\u0442\u0435\u043d\u0438\u044f, \u0440\u0430\u0437\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c, \u0434\u043b\u044f \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u043b\u0430 \u0447\u0442\u0435\u043d\u0438\u0439.<\/p>\n<p><b>\u041d\u0443\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c,<\/b> \u0447\u0442\u043e \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u043e\u0434\u0431\u043e\u0440\u0430 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u043f\u043e\u0440\u0446\u0438\u0438 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0440\u0435\u0448\u0435\u043d\u0430 \u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0439 \u043f\u0440\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0430. \u041c\u043e\u0436\u0435\u0442, \u0431\u044b\u0442\u044c, \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435.<\/p>\n<h2>\u041e\u0431\u0449\u0435\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p><\/p>\n<h3>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/h3>\n<p><\/p>\n<pre><code class=\"plaintext\">CREATE TABLE endpoint\n(\nid SERIAL ,\nhost text \n);\n\nTABLE database\n(\nid SERIAL , \n\u2026\nlast_aws_log_time text ,\nlast_aws_nexttoken text ,\naws_max_item_size integer \n);\nlast_aws_log_time \u2014 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043c\u0435\u0442\u043a\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 YYYY-MM-DD-HH24.\nlast_aws_nexttoken \u2014 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u0430\u044f \u043c\u0435\u0442\u043a\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0439 \u043f\u043e\u0440\u0446\u0438\u0438.\naws_max_item_size- \u044d\u043c\u043f\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043f\u0443\u0442\u0435\u043c, \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u043f\u043e\u0440\u0446\u0438\u0438.\n<\/code><\/pre>\n<h3>\u041f\u043e\u043b\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0441\u043a\u0440\u0438\u043f\u0442\u0430<\/h3>\n<p>\n<b class=\"spoiler_title\">download_aws_piece.sh<\/b><\/p>\n<pre><code class=\"plaintext\">#!\/bin\/bash\n#########################################################\n# download_aws_piece.sh\n# downloan piece of log from AWS\n# version HABR\n let min_item_size=1024\n let max_item_size=1048576\n let growth_factor=3\n let growth_counter=1\n let growth_counter_max=3\n\n echo $(date +%Y%m%d%H%M)':    download_aws_piece.sh:''STARTED'\n \n AWS_LOG_TIME=$1\n echo $(date +%Y%m%d%H%M)':    download_aws_piece.sh:AWS_LOG_TIME='$AWS_LOG_TIME\n  \n database_id=$2\n echo $(date +%Y%m%d%H%M)':    download_aws_piece.sh:database_id='$database_id\n RESULT_FILE=$3 \n  \n endpoint=`psql -h MONITOR_ENDPOINT.rds.amazonaws.com -U USER -d MONITOR_DATABASE_DATABASE -A -t -c \"select e.host from endpoint e join database d on e.id = d.endpoint_id where d.id = $database_id \"`\n echo $(date +%Y%m%d%H%M)':    download_aws_piece.sh:endpoint='$endpoint\n  \n db_instance=`echo $endpoint | awk -F\".\" '{print toupper($1)}'`\n \n echo $(date +%Y%m%d%H%M)':    download_aws_piece.sh:db_instance='$db_instance\n\n LOG_FILE=$RESULT_FILE'.tmp_log'\n TMP_FILE=$LOG_FILE'.tmp'\n TMP_MIDDLE=$LOG_FILE'.tmp_mid'  \n TMP_MIDDLE2=$LOG_FILE'.tmp_mid2'  \n  \n current_aws_log_time=`psql -h MONITOR_ENDPOINT.rds.amazonaws.com -U USER -d MONITOR_DATABASE -A -t -c \"select last_aws_log_time from database where id = $database_id \"`\n\n echo $(date +%Y%m%d%H%M)':      download_aws_piece.sh:current_aws_log_time='$current_aws_log_time\n  \n  if [[ $current_aws_log_time != $AWS_LOG_TIME  ]];\n  then\n    is_new_log='1'\n\tif ! psql -h MONITOR_ENDPOINT.rds.amazonaws.com -U USER -d MONITOR_DATABASE -v ON_ERROR_STOP=1 -A -t -q -c \"update database set last_aws_log_time = '$AWS_LOG_TIME' where id = $database_id \"\n\tthen\n\t  echo $(date +%Y%m%d%H%M)':    download_aws_piece.sh: FATAL_ERROR - update database set last_aws_log_time .'\n\t  exit 1\n\tfi\n  else\n    is_new_log='0'\n  fi\n  \n  echo $(date +%Y%m%d%H%M)':    download_aws_piece.sh:is_new_log='$is_new_log\n  \n  let last_aws_max_item_size=`psql -h MONITOR_ENDPOINT.rds.amazonaws.com -U USER -d MONITOR_DATABASE -A -t -c \"select aws_max_item_size from database where id = $database_id \"`\n  echo $(date +%Y%m%d%H%M)':    download_aws_piece.sh: last_aws_max_item_size='$last_aws_max_item_size\n  \n  let count=1\n  if [[ $is_new_log == '1' ]];\n  then    \n\techo $(date +%Y%m%d%H%M)':    download_aws_piece.sh: START DOWNLOADING OF NEW AWS LOG'\n\tif ! aws rds download-db-log-file-portion \n\t\t--max-items $last_aws_max_item_size \n\t\t--region REGION \n\t\t--db-instance-identifier  $db_instance \n\t\t--log-file-name error\/postgresql.log.$AWS_LOG_TIME &gt; $LOG_FILE\n\tthen\n\t\techo $(date +%Y%m%d%H%M)':    download_aws_piece.sh: FATAL_ERROR - Could not get log from AWS .'\n\t\texit 2\n\tfi  \t\n  else\n    next_token=`psql -h MONITOR_ENDPOINT.rds.amazonaws.com -U USER -d MONITOR_DATABASE -v ON_ERROR_STOP=1 -A -t -c \"select last_aws_nexttoken from database where id = $database_id \"`\n\t\n\tif [[ $next_token == '' ]];\n\tthen\n\t  next_token='0'\t  \n\tfi\n\t\n\techo $(date +%Y%m%d%H%M)':    download_aws_piece.sh: CONTINUE DOWNLOADING OF AWS LOG'\n\tif ! aws rds download-db-log-file-portion \n\t    --max-items $last_aws_max_item_size \n\t\t--starting-token $next_token \n\t\t--region REGION \n\t\t--db-instance-identifier  $db_instance \n\t\t--log-file-name error\/postgresql.log.$AWS_LOG_TIME &gt; $LOG_FILE\n\tthen\n\t\techo $(date +%Y%m%d%H%M)':    download_aws_piece.sh: FATAL_ERROR - Could not get log from AWS .'\n\t\texit 3\n\tfi       \n\t\n\tline_count=`cat  $LOG_FILE | wc -l`\n\tlet lines=$line_count-1\n\t  \n\ttail -$lines $LOG_FILE &gt; $TMP_MIDDLE \n\tmv -f $TMP_MIDDLE $LOG_FILE\n  fi\n  \n  next_token_str=`cat $LOG_FILE | grep NEXTTOKEN` \n  next_token=`echo $next_token_str | awk -F\" \" '{ print $2}' `\n  \n  grep -v NEXTTOKEN $LOG_FILE  &gt; $TMP_FILE \n  \n  if [[ $next_token == '' ]];\n  then\n\t  cp $TMP_FILE $RESULT_FILE\n\t  \n\t  echo $(date +%Y%m%d%H%M)':    download_aws_piece.sh:  NEXTTOKEN NOT FOUND - FINISH '\n\t  rm $LOG_FILE \n\t  rm $TMP_FILE\n\t  rm $TMP_MIDDLE\n          rm $TMP_MIDDLE2\t  \n\t  exit 0  \n  else\n\tpsql -h MONITOR_ENDPOINT.rds.amazonaws.com -U USER -d MONITOR_DATABASE -v ON_ERROR_STOP=1 -A -t -q -c \"update database set last_aws_nexttoken = '$next_token' where id = $database_id \"\n  fi\n  \n  first_str=`tail -1 $TMP_FILE`\n  \n  line_count=`cat  $TMP_FILE | wc -l`\n  let lines=$line_count-1    \n  \n  head -$lines $TMP_FILE  &gt; $RESULT_FILE\n\n###############################################\n# MAIN CIRCLE\n  let count=2\n  while [[ $next_token != '' ]];\n  do \n    echo $(date +%Y%m%d%H%M)':    download_aws_piece.sh: count='$count\n\t\n\techo $(date +%Y%m%d%H%M)':    download_aws_piece.sh: START DOWNLOADING OF AWS LOG'\n\tif ! aws rds download-db-log-file-portion \n             --max-items $last_aws_max_item_size \n             --starting-token $next_token \n             --region REGION \n             --db-instance-identifier  $db_instance \n             --log-file-name error\/postgresql.log.$AWS_LOG_TIME &gt; $LOG_FILE\n\tthen\n\t\techo $(date +%Y%m%d%H%M)':    download_aws_piece.sh: FATAL_ERROR - Could not get log from AWS .'\n\t\texit 4\n\tfi\n\n\tnext_token_str=`cat $LOG_FILE | grep NEXTTOKEN` \n\tnext_token=`echo $next_token_str | awk -F\" \" '{ print $2}' `\n\n\tTMP_FILE=$LOG_FILE'.tmp'\n\tgrep -v NEXTTOKEN $LOG_FILE  &gt; $TMP_FILE  \n\t\n\tlast_str=`head -1 $TMP_FILE`\n  \n    if [[ $next_token == '' ]];\n\tthen\n\t  concat_str=$first_str$last_str\n\t  \t  \n\t  echo $concat_str &gt;&gt; $RESULT_FILE\n\t\t \n\t  line_count=`cat  $TMP_FILE | wc -l`\n\t  let lines=$line_count-1\n\t  \n\t  tail -$lines $TMP_FILE &gt;&gt; $RESULT_FILE\n\t  \n\t  echo $(date +%Y%m%d%H%M)':    download_aws_piece.sh:  NEXTTOKEN NOT FOUND - FINISH '\n\t  rm $LOG_FILE \n\t  rm $TMP_FILE\n\t  rm $TMP_MIDDLE\n          rm $TMP_MIDDLE2\t  \n\t  exit 0  \n\tfi\n\t\n    if [[ $next_token != '' ]];\n\tthen\n\t\tlet growth_counter=$growth_counter+1\n\t\tif [[ $growth_counter -gt $growth_counter_max ]];\n\t\tthen\n\t\t\tlet last_aws_max_item_size=$last_aws_max_item_size*$growth_factor\n\t\t\tlet growth_counter=1\n\t\tfi\n\t\n\t\tif [[ $last_aws_max_item_size -gt $max_item_size ]]; \n\t\tthen\n\t\t\tlet last_aws_max_item_size=$max_item_size\n\t\tfi \n\n\t  psql -h MONITOR_ENDPOINT.rds.amazonaws.com -U USER -d MONITOR_DATABASE -A -t -q -c \"update database set last_aws_nexttoken = '$next_token' where id = $database_id \"\n\t  \n\t  concat_str=$first_str$last_str\n\t  \t  \n\t  echo $concat_str &gt;&gt; $RESULT_FILE\n\t\t \n\t  line_count=`cat  $TMP_FILE | wc -l`\n\t  let lines=$line_count-1\n\t  \n\t  #############################\n\t  #Get middle of file\n\t  head -$lines $TMP_FILE &gt; $TMP_MIDDLE\n\t  \n\t  line_count=`cat  $TMP_MIDDLE | wc -l`\n\t  let lines=$line_count-1\n\t  tail -$lines $TMP_MIDDLE &gt; $TMP_MIDDLE2\n\t  \n\t  cat $TMP_MIDDLE2 &gt;&gt; $RESULT_FILE\t  \n\t  \n\t  first_str=`tail -1 $TMP_FILE`\t  \n\tfi\n\t  \n    let count=$count+1\n\n  done\n#\n#################################################################\n\nexit 0  \n<\/code><\/pre>\n<p><\/p>\n<h3>\u0424\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u044f\u043c\u0438:<\/h3>\n<p>\n<b>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430:<\/b><\/p>\n<ul>\n<li> \u0412\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043c\u0435\u0442\u043a\u0430 \u0438\u043c\u0435\u043d\u0438 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 YYYY-MM-DD-HH24: AWS_LOG_TIME=<b>$1<\/b><\/li>\n<li> ID \u0411\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445: database_id=<b>$2<\/b><\/li>\n<li>\u0418\u043c\u044f \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430: RESULT_FILE=$3 <\/li>\n<\/ul>\n<p><b>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043c\u0435\u0442\u043a\u0443 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430:<\/b><\/p>\n<pre><code class=\"plaintext\">current_aws_log_time=`psql -h MONITOR_ENDPOINT.rds.amazonaws.com -U USER -d MONITOR_DATABASE -A -t -c \"select last_aws_log_time from database where id = $database_id \"`<\/code><\/pre>\n<p><b>\u0415\u0441\u043b\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043c\u0435\u0442\u043a\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0432\u0445\u043e\u0434\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u2014 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b:<\/b><\/p>\n<pre><code class=\"plaintext\">if [[ $current_aws_log_time != $AWS_LOG_TIME  ]];\n  then\n    is_new_log='1'\n\tif ! psql -h ENDPOINT.rds.amazonaws.com -U USER -d MONITOR_DATABASE -v ON_ERROR_STOP=1 -A -t -c \"update database set last_aws_log_time = '$AWS_LOG_TIME' where id = $database_id \"\n\tthen\n\t  echo '***download_aws_piece.sh -FATAL_ERROR - update database set last_aws_log_time .'\n\t  exit 1\n\tfi\n  else\n    is_new_log='0'\n  fi\n<\/code><\/pre>\n<p><b>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043a\u0438 nexttoken \u0438\u0437 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430:<\/b><\/p>\n<pre><code class=\"plaintext\">  next_token_str=`cat $LOG_FILE | grep NEXTTOKEN` \n  next_token=`echo $next_token_str | awk -F\" \" '{ print $2}' `\n<\/code><\/pre>\n<p>\u041f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u043c \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u043b\u0443\u0436\u0438\u0442 \u043f\u0443\u0441\u0442\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 nexttoken.<\/p>\n<p>\u0412 \u0446\u0438\u043a\u043b\u0435 \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043f\u043e\u0440\u0446\u0438\u0438 \u0444\u0430\u0439\u043b\u0430, \u043f\u043e\u043f\u0443\u0442\u043d\u043e, \u0441\u0446\u0435\u043f\u043b\u044f\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044f \u0440\u0430\u0437\u043c\u0435\u0440 \u043f\u043e\u0440\u0446\u0438\u0438:<br \/>\n<b class=\"spoiler_title\">\u0413\u043b\u0430\u0432\u043d\u044b\u0439 \u0446\u0438\u043a\u043b<\/b><\/p>\n<pre><code class=\"plaintext\"># MAIN CIRCLE\n  let count=2\n  while [[ $next_token != '' ]];\n  do \n    echo $(date +%Y%m%d%H%M)':    download_aws_piece.sh: count='$count\n\t\n\techo $(date +%Y%m%d%H%M)':    download_aws_piece.sh: START DOWNLOADING OF AWS LOG'\n\tif ! aws rds download-db-log-file-portion \n     --max-items $last_aws_max_item_size \n\t --starting-token $next_token \n     --region REGION \n     --db-instance-identifier  $db_instance \n     --log-file-name error\/postgresql.log.$AWS_LOG_TIME &gt; $LOG_FILE\n\tthen\n\t\techo $(date +%Y%m%d%H%M)':    download_aws_piece.sh: FATAL_ERROR - Could not get log from AWS .'\n\t\texit 4\n\tfi\n\n\tnext_token_str=`cat $LOG_FILE | grep NEXTTOKEN` \n\tnext_token=`echo $next_token_str | awk -F\" \" '{ print $2}' `\n\n\tTMP_FILE=$LOG_FILE'.tmp'\n\tgrep -v NEXTTOKEN $LOG_FILE  &gt; $TMP_FILE  \n\t\n\tlast_str=`head -1 $TMP_FILE`\n  \n    if [[ $next_token == '' ]];\n\tthen\n\t  concat_str=$first_str$last_str\n\t  \t  \n\t  echo $concat_str &gt;&gt; $RESULT_FILE\n\t\t \n\t  line_count=`cat  $TMP_FILE | wc -l`\n\t  let lines=$line_count-1\n\t  \n\t  tail -$lines $TMP_FILE &gt;&gt; $RESULT_FILE\n\t  \n\t  echo $(date +%Y%m%d%H%M)':    download_aws_piece.sh:  NEXTTOKEN NOT FOUND - FINISH '\n\t  rm $LOG_FILE \n\t  rm $TMP_FILE\n\t  rm $TMP_MIDDLE\n         rm $TMP_MIDDLE2\t  \n\t  exit 0  \n\tfi\n\t\n    if [[ $next_token != '' ]];\n\tthen\n\t\tlet growth_counter=$growth_counter+1\n\t\tif [[ $growth_counter -gt $growth_counter_max ]];\n\t\tthen\n\t\t\tlet last_aws_max_item_size=$last_aws_max_item_size*$growth_factor\n\t\t\tlet growth_counter=1\n\t\tfi\n\t\n\t\tif [[ $last_aws_max_item_size -gt $max_item_size ]]; \n\t\tthen\n\t\t\tlet last_aws_max_item_size=$max_item_size\n\t\tfi \n\n\t  psql -h MONITOR_ENDPOINT.rds.amazonaws.com -U USER -d MONITOR_DATABASE -A -t -q -c \"update database set last_aws_nexttoken = '$next_token' where id = $database_id \"\n\t  \n\t  concat_str=$first_str$last_str\n\t  \t  \n\t  echo $concat_str &gt;&gt; $RESULT_FILE\n\t\t \n\t  line_count=`cat  $TMP_FILE | wc -l`\n\t  let lines=$line_count-1\n\t  \n\t  #############################\n\t  #Get middle of file\n\t  head -$lines $TMP_FILE &gt; $TMP_MIDDLE\n\t  \n\t  line_count=`cat  $TMP_MIDDLE | wc -l`\n\t  let lines=$line_count-1\n\t  tail -$lines $TMP_MIDDLE &gt; $TMP_MIDDLE2\n\t  \n\t  cat $TMP_MIDDLE2 &gt;&gt; $RESULT_FILE\t  \n\t  \n\t  first_str=`tail -1 $TMP_FILE`\t  \n\tfi\n\t  \n    let count=$count+1\n\n  done\n<\/code><\/pre>\n<p><\/p>\n<h2>\u0427\u0442\u043e \u0436\u0435 \u0434\u0430\u043b\u044c\u0448\u0435 ?<\/h2>\n<p>\n\u0418\u0442\u0430\u043a, \u043f\u0435\u0440\u0432\u0430\u044f \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u2014 \u00ab\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043b\u043e\u0433-\u0444\u0430\u0439\u043b \u0441 \u043e\u0431\u043b\u0430\u043a\u0430\u00bb \u0440\u0435\u0448\u0435\u043d\u0430. \u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u043c \u043b\u043e\u0433\u043e\u043c? <br \/>\n\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u043b\u043e\u0433-\u0444\u0430\u0439\u043b \u0438 \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0438\u0437 \u043d\u0435\u0433\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u044b.<br \/>\n\u0417\u0430\u0434\u0430\u0447\u0430 \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u0430\u044f. \u041f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 bash-script \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f.<br \/>\n<b class=\"spoiler_title\">upload_log_query.sh<\/b><\/p>\n<pre><code class=\"plaintext\">#!\/bin\/bash\n#########################################################\n# upload_log_query.sh\n# Upload table table from dowloaded aws file \n# version HABR\n###########################################################  \necho 'TIMESTAMP:'$(date +%c)' Upload log_query table '\nsource_file=$1\necho 'source_file='$source_file\ndatabase_id=$2\necho 'database_id='$database_id\n\nbeginer=' '\nfirst_line='1'\nlet \"line_count=0\"\nsql_line=' '\nsql_flag=' '    \nspace=' '\ncat $source_file | while read line\ndo\n  line=\"$space$line\"\n\n  if [[ $first_line == \"1\" ]]; then\n    beginer=`echo $line | awk -F\" \" '{ print $1}' `\n    first_line='0'\n  fi\n\n  current_beginer=`echo $line | awk -F\" \" '{ print $1}' `\n\n  if [[ $current_beginer == $beginer ]]; then\n    if [[ $sql_flag == '1' ]]; then\n     sql_flag='0' \n     log_date=`echo $sql_line | awk -F\" \" '{ print $1}' `\n     log_time=`echo $sql_line | awk -F\" \" '{ print $2}' `\n     duration=`echo $sql_line | awk -F\" \" '{ print $5}' `\n\n     #replace ' to ''\n     sql_modline=`echo \"$sql_line\" | sed 's\/'''\/''''''\/g'`\n     sql_line=' '\n\n\t ################\n\t #PROCESSING OF THE SQL-SELECT IS HERE\n     if ! psql -h ENDPOINT.rds.amazonaws.com -U USER -d DATABASE -v ON_ERROR_STOP=1 -A -t -c \"select log_query('$ip_port',$database_id , '$log_date' , '$log_time' , '$duration' , '$sql_modline' )\" \n     then\n        echo 'FATAL_ERROR - log_query '\n        exit 1\n     fi\n\t ################\n\n    fi #if [[ $sql_flag == '1' ]]; then\n\n    let \"line_count=line_count+1\"\n\n    check=`echo $line | awk -F\" \" '{ print $8}' `\n    check_sql=${check^^}    \n\n    #echo 'check_sql='$check_sql\n    \n    if [[ $check_sql == 'SELECT' ]]; then\n     sql_flag='1'    \n     sql_line=\"$sql_line$line\"\n\t ip_port=`echo $sql_line | awk -F\":\" '{ print $4}' `\n    fi\n  else       \n\n    if [[ $sql_flag == '1' ]]; then\n      sql_line=\"$sql_line$line\"\n    fi   \n    \n  fi #if [[ $current_beginer == $beginer ]]; then\n\ndone\n<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u0438\u0437 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<p>\u0410 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e.<\/p>\n<p>\u0420\u0430\u0437\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430\u0434\u043e \u0433\u0434\u0435-\u0442\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 <b>log_query<\/b><\/p>\n<pre><code class=\"plaintext\">CREATE TABLE log_query\n(\n   id SERIAL ,\n   queryid bigint ,\n   query_md5hash text not null ,\n   database_id integer not null ,  \n   timepoint timestamp without time zone not null,\n   duration double precision not null ,\n   query text not null ,\n   explained_plan text[],\n   plan_md5hash text  , \n   explained_plan_wo_costs text[],\n   plan_hash_value text  ,\n   baseline_id integer ,\n   ip text ,\n   port text \n);\nALTER TABLE log_query ADD PRIMARY KEY (id);\nALTER TABLE log_query ADD CONSTRAINT queryid_timepoint_unique_key UNIQUE (queryid, timepoint );\nALTER TABLE log_query ADD CONSTRAINT query_md5hash_timepoint_unique_key UNIQUE (query_md5hash, timepoint );\n\nCREATE INDEX log_query_timepoint_idx ON log_query (timepoint);\nCREATE INDEX log_query_queryid_idx ON log_query (queryid);\nALTER TABLE log_query ADD CONSTRAINT database_id_fk FOREIGN KEY (database_id) REFERENCES database (id) ON DELETE CASCADE ;\n<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 <b>plpgsql <\/b>\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u00ab<b>log_query<\/b>\u00bb.<br \/>\n<b class=\"spoiler_title\">log_query.sql<\/b><\/p>\n<pre><code class=\"plaintext\">--log_query.sql\n--verison HABR\nCREATE OR REPLACE FUNCTION log_query( ip_port text ,log_database_id integer , log_date text , log_time text , duration text , sql_line text   ) RETURNS boolean AS $$\nDECLARE\n  result boolean ;\n  log_timepoint timestamp without time zone ;\n  log_duration double precision ; \n  pos integer ;\n  log_query text ;\n  activity_string text ;\n  log_md5hash text ;\n  log_explain_plan text[] ;\n  \n  log_planhash text ;\n  log_plan_wo_costs text[] ; \n  \n  database_rec record ;\n  \n  pg_stat_query text ; \n  test_log_query text ;\n  log_query_rec record;\n  found_flag boolean;\n  \n  pg_stat_history_rec record ;\n  port_start integer ;\n  port_end integer ;\n  client_ip text ;\n  client_port text ;\n  log_queryid bigint ;\n  log_query_text text ;\n  pg_stat_query_text text ; \nBEGIN\n  result = TRUE ;\n\n  RAISE NOTICE '***log_query';\n  \n  port_start = position('(' in ip_port);\n  port_end = position(')' in ip_port);\n  client_ip = substring( ip_port from 1 for port_start-1 );\n  client_port = substring( ip_port from port_start+1 for port_end-port_start-1 );\n\n  SELECT e.host , d.name , d.owner_pwd \n  INTO database_rec\n  FROM database d JOIN endpoint e ON e.id = d.endpoint_id\n  WHERE d.id = log_database_id ;\n  \n  log_timepoint = to_timestamp(log_date||' '||log_time,'YYYY-MM-DD HH24-MI-SS');\n  log_duration = duration:: double precision; \n\n  \n  pos = position ('SELECT' in UPPER(sql_line) );\n  log_query = substring( sql_line from pos for LENGTH(sql_line));\n  log_query = regexp_replace(log_query,' +',' ','g');\n  log_query = regexp_replace(log_query,';+','','g');\n  log_query = trim(trailing ' ' from log_query);\n \n\n  log_md5hash = md5( log_query::text );\n  \n  --Explain execution plan--\n  EXECUTE 'SELECT dblink_connect(''LINK1'',''host='||database_rec.host||' dbname='||database_rec.name||' user=DATABASE password='||database_rec.owner_pwd||' '')'; \n  \n  log_explain_plan = ARRAY ( SELECT * FROM dblink('LINK1', 'EXPLAIN '||log_query ) AS t (plan text) );\n  log_plan_wo_costs = ARRAY ( SELECT * FROM dblink('LINK1', 'EXPLAIN ( COSTS FALSE ) '||log_query ) AS t (plan text) );\n    \n  PERFORM dblink_disconnect('LINK1');\n  --------------------------\n  BEGIN\n\tINSERT INTO log_query\n\t(\n\t\tquery_md5hash ,\n\t\tdatabase_id , \n\t\ttimepoint ,\n\t\tduration ,\n\t\tquery ,\n\t\texplained_plan ,\n\t\tplan_md5hash , \n\t\texplained_plan_wo_costs , \n\t\tplan_hash_value , \n\t\tip , \n\t\tport\n\t) \n\tVALUES \n\t(\n\t\tlog_md5hash ,\n\t\tlog_database_id , \n\t\tlog_timepoint , \n\t\tlog_duration , \n\t\tlog_query ,\n\t\tlog_explain_plan , \n\t\tmd5(log_explain_plan::text) ,\n\t\tlog_plan_wo_costs , \n\t\tmd5(log_plan_wo_costs::text),\n\t\tclient_ip , \n\t\tclient_port\t\t\n\t);\n\tactivity_string = \t'New query has logged '||\n\t\t\t\t\t\t' database_id = '|| log_database_id ||\n\t\t\t\t\t\t' query_md5hash='||log_md5hash||\n\t\t\t\t\t\t' , timepoint = '||to_char(log_timepoint,'YYYYMMDD HH24:MI:SS');\n\t\t\t\t\t\n\tRAISE NOTICE '%',activity_string;\t\t\t\t\t\n\t\t\t\t\t \n\tPERFORM pg_log( log_database_id , 'log_query' , activity_string);  \n\n\tEXCEPTION\n\t  WHEN unique_violation THEN\n\t\tRAISE NOTICE '*** unique_violation *** query already has logged';\n\tEND;\n\n\tSELECT \tqueryid\n\tINTO   \tlog_queryid\n\tFROM \tlog_query \n\tWHERE \tquery_md5hash = log_md5hash AND\n\t\t\ttimepoint = log_timepoint;\n\n\tIF log_queryid IS NOT NULL \n\tTHEN \n\t  RAISE NOTICE 'log_query with query_md5hash = % and timepoint = % has already has a QUERYID = %',log_md5hash,log_timepoint , log_queryid ;\n\t  RETURN result;\n\tEND IF;\n\t\n\t------------------------------------------------\n\tRAISE NOTICE 'Update queryid';\t\n\t\n\tSELECT * \n\tINTO log_query_rec\n\tFROM log_query\n\tWHERE query_md5hash = log_md5hash AND timepoint = log_timepoint ; \n\t\n\tlog_query_rec.query=regexp_replace(log_query_rec.query,';+','','g');\n\t\n\tFOR pg_stat_history_rec IN\n\t SELECT \n         queryid ,\n\t  query \n\t FROM \n         pg_stat_db_queries \n     WHERE  \n      database_id = log_database_id AND\n       queryid is not null \n\tLOOP\n\t  pg_stat_query = pg_stat_history_rec.query ; \n\t  pg_stat_query=regexp_replace(pg_stat_query,'n+',' ','g');\n\t  pg_stat_query=regexp_replace(pg_stat_query,'t+',' ','g');\n\t  pg_stat_query=regexp_replace(pg_stat_query,' +',' ','g');\n\t  pg_stat_query=regexp_replace(pg_stat_query,'$.','%','g');\n\t\n\t  log_query_text = trim(trailing ' ' from log_query_rec.query);\n\t  pg_stat_query_text = pg_stat_query; \n\t\n\t  \n\t  --SELECT log_query_rec.query like pg_stat_query INTO found_flag ; \n\t  IF (log_query_text LIKE pg_stat_query_text) THEN\n\t\tfound_flag = TRUE ;\n\t  ELSE\n\t\tfound_flag = FALSE ;\n\t  END IF;\t  \n\t  \n\t  \n\t  IF found_flag THEN\n\t    \n\t\tUPDATE log_query SET queryid = pg_stat_history_rec.queryid WHERE query_md5hash = log_md5hash AND timepoint = log_timepoint ;\n\t\tactivity_string = \t' updated queryid = '||pg_stat_history_rec.queryid||\n\t\t                    ' for log_query with id = '||log_query_rec.id               \n\t\t   \t\t\t\t    ;\t\t\t\t\t\t\n\t    RAISE NOTICE '%',activity_string;\t\n\t\tEXIT ;\n\t  END IF ;\n\t  \n\tEND LOOP ;\n\t\n  RETURN result ;\nEND\n$$ LANGUAGE plpgsql;\n<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 <b>pg_stat_db_queries<\/b>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0430\u044f \u0441\u043d\u0438\u043c\u043e\u043a \u0442\u0435\u043a\u0443\u0449\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<b> pg_stat_history<\/b> (<i>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0437\u0434\u0435\u0441\u044c \u2014 <noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/company\/icl_services\/blog\/446734\/\">\u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 PostgreSQL. \u0427\u0430\u0441\u0442\u044c 1 \u2014 \u0440\u0435\u043f\u043e\u0440\u0442\u0438\u043d\u0433<\/a><\/noindex><\/i>)<\/p>\n<pre><code class=\"plaintext\">TABLE pg_stat_db_queries\n(\n   database_id integer,  \n   queryid bigint ,  \n   query text , \n   max_time double precision \n);\n<\/code><\/pre>\n<p><\/p>\n<pre><code class=\"plaintext\">TABLE pg_stat_history \n(\n\u2026\ndatabase_id integer ,\n\u2026\nqueryid bigint ,\n\u2026\nmax_time double precision\t , \t\n\u2026\n);\n<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u0440\u044f\u0434 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u0437 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430. \u0410 \u0438\u043c\u0435\u043d\u043d\u043e:<\/p>\n<h3>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u21161 \u2014 \u0418\u0441\u0442\u043e\u0440\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/h3>\n<p>\n\u041e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438\u043d\u0446\u0438\u0434\u0435\u043d\u0442\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u0438\u0441\u0442\u043e\u0440\u0438\u0435\u0439 \u2014 \u0430 \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0447\u0430\u043b\u043e\u0441\u044c \u0437\u0430\u043c\u0435\u0434\u043b\u0435\u043d\u0438\u0435? <br \/>\n\u0417\u0430\u0442\u0435\u043c, \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u043a\u0435 \u2013 \u043f\u043e\u0438\u0441\u043a\u0430\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043f\u0440\u0438\u0447\u0438\u043d\u044b. \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0435\u0437\u043a\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u043b\u0430\u0441\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0438 \u043f\u0440\u0438 \u0447\u0435\u043c.<br \/>\n<b class=\"spoiler_title\">\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 log_query<\/b><\/p>\n<pre><code class=\"plaintext\">  port_start = position('(' in ip_port);\n  port_end = position(')' in ip_port);\n  client_ip = substring( ip_port from 1 for port_start-1 );\n  client_port = substring( ip_port from port_start+1 for port_end-port_start-1 );\n\n  SELECT e.host , d.name , d.owner_pwd \n  INTO database_rec\n  FROM database d JOIN endpoint e ON e.id = d.endpoint_id\n  WHERE d.id = log_database_id ;\n  \n  log_timepoint = to_timestamp(log_date||' '||log_time,'YYYY-MM-DD HH24-MI-SS');\n  log_duration = to_number(duration,'99999999999999999999D9999999999'); \n\n  \n  pos = position ('SELECT' in UPPER(sql_line) );\n  log_query = substring( sql_line from pos for LENGTH(sql_line));\n  log_query = regexp_replace(log_query,' +',' ','g');\n  log_query = regexp_replace(log_query,';+','','g');\n  log_query = trim(trailing ' ' from log_query);\n \n  RAISE NOTICE 'log_query=%',log_query ;   \n\n  log_md5hash = md5( log_query::text );\n  \n  --Explain execution plan--\n  EXECUTE 'SELECT dblink_connect(''LINK1'',''host='||database_rec.host||' dbname='||database_rec.name||' user=DATABASE password='||database_rec.owner_pwd||' '')'; \n  \n  log_explain_plan = ARRAY ( SELECT * FROM dblink('LINK1', 'EXPLAIN '||log_query ) AS t (plan text) );\n  log_plan_wo_costs = ARRAY ( SELECT * FROM dblink('LINK1', 'EXPLAIN ( COSTS FALSE ) '||log_query ) AS t (plan text) );\n    \n  PERFORM dblink_disconnect('LINK1');\n  --------------------------\n  BEGIN\n\tINSERT INTO log_query\n\t(\n\t\tquery_md5hash ,\n\t\tdatabase_id , \n\t\ttimepoint ,\n\t\tduration ,\n\t\tquery ,\n\t\texplained_plan ,\n\t\tplan_md5hash , \n\t\texplained_plan_wo_costs , \n\t\tplan_hash_value , \n\t\tip , \n\t\tport\n\t) \n\tVALUES \n\t(\n\t\tlog_md5hash ,\n\t\tlog_database_id , \n\t\tlog_timepoint , \n\t\tlog_duration , \n\t\tlog_query ,\n\t\tlog_explain_plan , \n\t\tmd5(log_explain_plan::text) ,\n\t\tlog_plan_wo_costs , \n\t\tmd5(log_plan_wo_costs::text),\n\t\tclient_ip , \n\t\tclient_port\t\t\n\t);\n<\/code><\/pre>\n<h3>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u21162 \u2014 \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043f\u043b\u0430\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/h3>\n<p>\n\u041d\u0430 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0432\u043e\u0437\u0440\u0430\u0436\u0435\u043d\u0438\u0435-\u0443\u0442\u043e\u0447\u043d\u0435\u043d\u0438\u0435-\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439: \u00ab<i>\u041d\u043e \u0432\u0435\u0434\u044c \u0443\u0436\u0435 \u0435\u0441\u0442\u044c autoexplain<\/i>\u00bb. \u0415\u0441\u0442\u044c \u0442\u043e \u043e\u043d \u0435\u0441\u0442\u044c, \u0430 \u0447\u0442\u043e \u0442\u043e\u043b\u043a\u0443, \u0435\u0441\u043b\u0438 \u043f\u043b\u0430\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u0442\u043e\u043c \u0436\u0435 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0435 \u0438 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430, \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u0430\u0440\u0441\u0438\u0442\u044c \u043b\u043e\u0433-\u0444\u0430\u0439\u043b? <\/p>\n<p>\u041c\u043d\u0435, \u0436\u0435, \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e:<br \/>\n\u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445: \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043f\u043b\u0430\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430;<br \/>\n\u0432\u043e-\u0432\u0442\u043e\u0440\u044b\u0445: \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u043f\u043b\u0430\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439, \u0447\u0442\u043e \u0431\u044b \u0441\u0440\u0430\u0437\u0443 \u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u043f\u043b\u0430\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f.<\/p>\n<p>\u0417\u0430\u043f\u0440\u043e\u0441 \u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438\u043c\u0435\u0435\u0442\u0441\u044f. \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0435\u0433\u043e \u043f\u043b\u0430\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f EXPLAIN \u2014 \u0437\u0430\u0434\u0430\u0447\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u0430\u044f. <br \/>\n\u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 EXPLAIN (COSTS FALSE), \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u0430\u0440\u043a\u0430\u0441 \u043f\u043b\u0430\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f hash-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043b\u0430\u043d\u0430, \u0447\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u043b\u0430\u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<br \/>\n<b class=\"spoiler_title\">\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u043b\u0430\u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/b><\/p>\n<pre><code class=\"plaintext\">  --Explain execution plan--\n  EXECUTE 'SELECT dblink_connect(''LINK1'',''host='||database_rec.host||' dbname='||database_rec.name||' user=DATABASE password='||database_rec.owner_pwd||' '')'; \n  \n  log_explain_plan = ARRAY ( SELECT * FROM dblink('LINK1', 'EXPLAIN '||log_query ) AS t (plan text) );\n  log_plan_wo_costs = ARRAY ( SELECT * FROM dblink('LINK1', 'EXPLAIN ( COSTS FALSE ) '||log_query ) AS t (plan text) );\n    \n  PERFORM dblink_disconnect('LINK1');\n<\/code><\/pre>\n<h3>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u21163 \u2014 \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043b\u043e\u0433\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430<\/h3>\n<p>\n\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u043d\u0435 \u043d\u0430 \u0442\u0435\u043a\u0441\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0430 \u043d\u0430 \u0435\u0433\u043e ID, \u043d\u0443\u0436\u043d\u043e \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u0437 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430 \u0441 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. <br \/>\n\u041d\u0443 \u0445\u043e\u0442\u044f \u0431\u044b \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u0442\u043e\u0447\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u0438\u043d\u0446\u0438\u0434\u0435\u043d\u0442\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u0440\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u0438\u043d\u0446\u0438\u0434\u0435\u043d\u0442\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f ID \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0431\u0443\u0434\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0438 \u0442\u043e\u0447\u043d\u044b\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 <b>pg_stat_statements<\/b> \u2014 \u043d\u0435\u043b\u044c\u0437\u044f.<br \/>\n<b class=\"spoiler_title\">\u041d\u0430\u0439\u0442\u0438 queryid \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 log_query<\/b><\/p>\n<pre><code class=\"plaintext\">SELECT * \n\tINTO log_query_rec\n\tFROM log_query\n\tWHERE query_md5hash = log_md5hash AND timepoint = log_timepoint ; \n\t\n\tlog_query_rec.query=regexp_replace(log_query_rec.query,';+','','g');\n\t\n\tFOR pg_stat_history_rec IN\n\t SELECT \n      queryid ,\n\t  query \n\t FROM \n       pg_stat_db_queries \n     WHERE  \n\t   database_id = log_database_id AND\n       queryid is not null \n\tLOOP\n\t  pg_stat_query = pg_stat_history_rec.query ; \n\t  pg_stat_query=regexp_replace(pg_stat_query,'n+',' ','g');\n\t  pg_stat_query=regexp_replace(pg_stat_query,'t+',' ','g');\n\t  pg_stat_query=regexp_replace(pg_stat_query,' +',' ','g');\n\t  pg_stat_query=regexp_replace(pg_stat_query,'$.','%','g');\n\t\n\t  log_query_text = trim(trailing ' ' from log_query_rec.query);\n\t  pg_stat_query_text = pg_stat_query; \n\t  \n\t  --SELECT log_query_rec.query like pg_stat_query INTO found_flag ; \n\t  IF (log_query_text LIKE pg_stat_query_text) THEN\n\t\tfound_flag = TRUE ;\n\t  ELSE\n\t\tfound_flag = FALSE ;\n\t  END IF;\t  \n\t  \n\t  \n\t  IF found_flag THEN\n\t    \n\t\tUPDATE log_query SET queryid = pg_stat_history_rec.queryid WHERE query_md5hash = log_md5hash AND timepoint = log_timepoint ;\n\t\tactivity_string = \t' updated queryid = '||pg_stat_history_rec.queryid||\n\t\t                    ' for log_query with id = '||log_query_rec.id\t\t                    \n\t\t   \t\t\t\t    ;\t\t\t\t\t\t\n\t\t\t\t\t\n\t    RAISE NOTICE '%',activity_string;\t\n\t\tEXIT ;\n\t  END IF ;\n\t  \n\tEND LOOP ;\n<\/code><\/pre>\n<h2>\u041f\u043e\u0441\u043b\u0435\u0441\u043b\u043e\u0432\u0438\u0435<\/h2>\n<p>\n\u041e\u043f\u0438\u0441\u0430\u043d\u043d\u0430\u044f \u043c\u0435\u0442\u043e\u0434\u0438\u043a\u0430 \u0432 \u0438\u0442\u043e\u0433\u0435, \u043d\u0430\u0448\u043b\u0430 \u0441\u0435\u0431\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432 <noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/post\/444988\/\">\u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 PostgreSQL<\/a><\/noindex>, \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0432 \u0438\u043c\u0435\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043f\u0440\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0438\u0445 \u0438\u043d\u0446\u0438\u0434\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<p>\u0425\u043e\u0442\u044f, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0430 \u043c\u043e\u0439 \u043b\u0438\u0447\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u0440\u0441\u043a\u0438\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0435\u0449\u0435 \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u0434 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c \u0432\u044b\u0431\u043e\u0440\u0430 \u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c\u043e\u0439 \u043f\u043e\u0440\u0446\u0438\u0438. \u0417\u0430\u0434\u0430\u0447\u0430 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0440\u0435\u0448\u0435\u043d\u0430 \u0432 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435. \u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e.<\/p>\n<p><b><i>\u041d\u043e \u044d\u0442\u043e \u0443\u0436\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u0430\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u2026<\/i><\/b><br \/>\n<br \/>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a: <a content=\"nofollow\" rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/company\/icl_services\/blog\/447926\/\">habr.com<\/a><\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"excerpt":{"rendered":"<p>\u0418\u043b\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0439 \u0442\u0435\u0442\u0440\u0438\u0441\u043e\u043b\u043e\u0433\u0438\u0438. \u0412\u0441\u0451 \u043d\u043e\u0432\u043e\u0435- \u0445\u043e\u0440\u043e\u0448\u043e \u0437\u0430\u0431\u044b\u0442\u043e\u0435 \u0441\u0442\u0430\u0440\u043e\u0435. \u042d\u043f\u0438\u0433\u0440\u0430\u0444\u044b. \u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b PostgreSQL \u0438\u0437 \u043e\u0431\u043b\u0430\u043a\u0430 AWS \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 Linux \u0445\u043e\u0441\u0442. \u041d\u0435 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043d\u043e, \u0441\u043a\u0430\u0436\u0435\u043c \u0442\u0430\u043a, \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439. \u041f\u0435\u0440\u0438\u043e\u0434 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430 \u2014 5 \u043c\u0438\u043d\u0443\u0442. \u041b\u043e\u0433-\u0444\u0430\u0439\u043b, \u0432 AWS, \u0440\u043e\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0447\u0430\u0441. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0414\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430 \u043d\u0430 \u0445\u043e\u0441\u0442 [&hellip;]<\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"author":1,"featured_media":24515,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[688],"tags":[],"class_list":["post-32731","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-administrirovanie"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"\u0418\u043b\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0439 \u0442\u0435\u0442\u0440\u0438\u0441\u043e\u043b\u043e\u0433\u0438\u0438. \u0412\u0441\u0451 \u043d\u043e\u0432\u043e\u0435- \u0445\u043e\u0440\u043e\u0448\u043e \u0437\u0430\u0431\u044b\u0442\u043e\u0435 \u0441\u0442\u0430\u0440\u043e\u0435. \u042d\u043f\u0438\u0433\u0440\u0430\u0444\u044b. \u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b PostgreSQL \u0438\u0437 \u043e\u0431\u043b\u0430\u043a\u0430 AWS \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 Linux \u0445\u043e\u0441\u0442. \u041d\u0435 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043d\u043e, \u0441\u043a\u0430\u0436\u0435\u043c \u0442\u0430\u043a, \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439. \u041f\u0435\u0440\u0438\u043e\u0434 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430 \u2014 5 \u043c\u0438\u043d\u0443\u0442. \u041b\u043e\u0433-\u0444\u0430\u0439\u043b, \u0432 AWS, \u0440\u043e\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0447\u0430\u0441. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0414\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430 \u043d\u0430 \u0445\u043e\u0441\u0442\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Yuri Gagarin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/prohoster.info\/de\/blog\/administrirovanie\/vygruzka-loga-postgresql-s-oblaka-aws\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"de_DE\" \/>\n\t\t<meta property=\"og:site_name\" content=\"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"\ud83e\udd47\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u043b\u043e\u0433\u0430 PostgreSQL \u0441 \u043e\u0431\u043b\u0430\u043a\u0430 AWS | ProHoster\" \/>\n\t\t<meta property=\"og:description\" content=\"\u0418\u043b\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0439 \u0442\u0435\u0442\u0440\u0438\u0441\u043e\u043b\u043e\u0433\u0438\u0438. \u0412\u0441\u0451 \u043d\u043e\u0432\u043e\u0435- \u0445\u043e\u0440\u043e\u0448\u043e \u0437\u0430\u0431\u044b\u0442\u043e\u0435 \u0441\u0442\u0430\u0440\u043e\u0435. \u042d\u043f\u0438\u0433\u0440\u0430\u0444\u044b. \u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b PostgreSQL \u0438\u0437 \u043e\u0431\u043b\u0430\u043a\u0430 AWS \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 Linux \u0445\u043e\u0441\u0442. \u041d\u0435 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043d\u043e, \u0441\u043a\u0430\u0436\u0435\u043c \u0442\u0430\u043a, \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439. \u041f\u0435\u0440\u0438\u043e\u0434 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430 \u2014 5 \u043c\u0438\u043d\u0443\u0442. \u041b\u043e\u0433-\u0444\u0430\u0439\u043b, \u0432 AWS, \u0440\u043e\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0447\u0430\u0441. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0414\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430 \u043d\u0430 \u0445\u043e\u0441\u0442\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/prohoster.info\/de\/blog\/administrirovanie\/vygruzka-loga-postgresql-s-oblaka-aws\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"350\" \/>\n\t\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2019-10-31T18:48:38+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2019-10-31T18:48:38+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"\ud83e\udd47Exportieren von PostgreSQL-Protokollen aus der AWS-Cloud | ProHoster","description":"Oder ein bisschen praktische Tetris-Theorie. Alles Neue ist gut vergessenes Altes. Epigraphen. Problemstellung: Es ist erforderlich, regelm\u00e4\u00dfig die aktuelle Protokolldatei von PostgreSQL aus der AWS-Cloud auf einen lokalen Linux-Host zu laden. Nicht in Echtzeit, aber sagen wir, mit einer kurzen Verz\u00f6gerung. Der Zeitraum f\u00fcr das Laden des aktualisierten Protokolls betr\u00e4gt 5 Minuten. Die Protokolldatei in AWS wird jede Stunde rotiert. Verwendete Werkzeuge zur \u00dcbertragung der Protokolldatei auf den Host.","canonical_url":"https:\/\/prohoster.info\/de\/blog\/administrirovanie\/vygruzka-loga-postgresql-s-oblaka-aws","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"de_DE","og:site_name":"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b","og:type":"article","og:title":"\ud83e\udd47\u0412\u044b\u0433\u0440\u0443\u0437\u043a\u0430 \u043b\u043e\u0433\u0430 PostgreSQL \u0441 \u043e\u0431\u043b\u0430\u043a\u0430 AWS | ProHoster","og:description":"\u0418\u043b\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0439 \u0442\u0435\u0442\u0440\u0438\u0441\u043e\u043b\u043e\u0433\u0438\u0438. \u0412\u0441\u0451 \u043d\u043e\u0432\u043e\u0435- \u0445\u043e\u0440\u043e\u0448\u043e \u0437\u0430\u0431\u044b\u0442\u043e\u0435 \u0441\u0442\u0430\u0440\u043e\u0435. \u042d\u043f\u0438\u0433\u0440\u0430\u0444\u044b. \u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b PostgreSQL \u0438\u0437 \u043e\u0431\u043b\u0430\u043a\u0430 AWS \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 Linux \u0445\u043e\u0441\u0442. \u041d\u0435 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043d\u043e, \u0441\u043a\u0430\u0436\u0435\u043c \u0442\u0430\u043a, \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439. \u041f\u0435\u0440\u0438\u043e\u0434 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430 \u2014 5 \u043c\u0438\u043d\u0443\u0442. \u041b\u043e\u0433-\u0444\u0430\u0439\u043b, \u0432 AWS, \u0440\u043e\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0447\u0430\u0441. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0414\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043b\u043e\u0433-\u0444\u0430\u0439\u043b\u0430 \u043d\u0430 \u0445\u043e\u0441\u0442","og:url":"https:\/\/prohoster.info\/de\/blog\/administrirovanie\/vygruzka-loga-postgresql-s-oblaka-aws","og:image":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:secure_url":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:width":350,"og:image:height":350,"article:published_time":"2019-10-31T18:48:38+00:00","article:modified_time":"2019-10-31T18:48:38+00:00","article:publisher":"https:\/\/www.facebook.com\/prohoster","article:author":"https:\/\/www.facebook.com\/prohoster"},"aioseo_meta_data":{"post_id":"32731","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"seo_analyzer_scan_date":"2026-01-21 12:18:19","breadcrumb_settings":null,"limit_modified_date":false,"reviewed_by":null,"ai":null,"created":"2021-03-01 02:53:25","updated":"2026-01-21 12:18:19"},"gt_translate_keys":[{"key":"link","format":"url"}],"_links":{"self":[{"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/posts\/32731","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/comments?post=32731"}],"version-history":[{"count":0,"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/posts\/32731\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/media\/24515"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/media?parent=32731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/categories?post=32731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/tags?post=32731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}