{"id":464498,"date":"2025-06-25T15:05:42","date_gmt":"2025-06-25T15:05:42","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=464498"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=464498","title":{"rendered":"<span>\u0418\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442 Postgres? \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 pg_stat_statements<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>pg_stat_statements \u2014 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 PostgreSQL \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432: \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u0432, \u043e\u0431\u0449\u0435\u0435 \u0438 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0447\u0438\u0441\u043b\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0451\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438. \u042d\u0442\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0432\u044b\u044f\u0432\u043b\u044f\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u044b\u0435 \u0443\u0447\u0430\u0441\u0442\u043a\u0438 \u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0441 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0446\u0438\u0435\u0439 pg_stat_statements \u0441\u0430\u043c\u043e \u043f\u043e \u0441\u0435\u0431\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0443\u0437\u043a\u0438\u043c \u043c\u0435\u0441\u0442\u043e\u043c \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0430\u0434\u043a\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c, \u0432 \u043a\u0430\u043a\u0438\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0432 \u043a\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b.<\/p>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430<\/h2>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 pg_stat_statements \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043a\u043e\u0440\u043e\u0442\u043a\u043e \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u043a\u0430\u043a \u043e\u043d\u043e \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u0432\u043d\u0443\u0442\u0440\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0441\u0442\u0430\u0442\u044c \u0443\u0437\u043a\u0438\u043c \u043c\u0435\u0441\u0442\u043e\u043c \u043f\u0440\u0438 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0435.<\/p>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 pg_stat_statements \u2014 \u044d\u0442\u043e \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430. \u041a\u0430\u0436\u0434\u044b\u0439 \u0431\u0430\u043a\u0435\u0442 \u0432 \u043d\u0435\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0443. \u041a\u043b\u044e\u0447 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0447\u0435\u0442\u044b\u0440\u0451\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>queryid \u2014 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430;<\/p>\n<\/li>\n<li>\n<p>OID \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f;<\/p>\n<\/li>\n<li>\n<p>OID \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445;<\/p>\n<\/li>\n<li>\n<p>\u0444\u043b\u0430\u0433 toplevel, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u0435\u0440\u0445\u043d\u0435\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u043c, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0435 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c \u0432 \u043a\u0430\u043a\u0443\u044e-\u043b\u0438\u0431\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044e\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438\u043b\u0438 \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e \u044d\u0442\u043e\u043c\u0443 \u043a\u043b\u044e\u0447\u0443 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/df6\/ca9\/9fe\/df6ca99fe312c3c69eb220d85aa17736.png\" alt=\"Tantor Labs &gt; \u041a\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 pg_stat_statements? &gt; pg_stat_statements (1).drawio (1).png\" title=\" \" width=\"621\" height=\"552\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/df6\/ca9\/9fe\/df6ca99fe312c3c69eb220d85aa17736.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/df6\/ca9\/9fe\/df6ca99fe312c3c69eb220d85aa17736.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption> <\/figcaption><\/div>\n<\/figure>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441, pg_stat_statements \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u0438\u0441\u043a \u0431\u0430\u043a\u0435\u0442\u0430: \u043d\u0430 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f shared-\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 LWLock \u0438 \u043f\u043e \u043a\u043b\u044e\u0447\u0443 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0438\u0441\u043a \u0432 \u043d\u0435\u0439;<\/p>\n<\/li>\n<li>\n<p>\u041d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f (\u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438): \u0435\u0441\u043b\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0431\u0430\u043a\u0435\u0442\u0430 \u043d\u0435\u0442, \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f: \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044b \u0437\u0430\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u044b \u0432\u0438\u0434\u0430\u00a0$1, $2\u00a0\u0438 \u0442. \u0434.;<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u0431\u0430\u043a\u0435\u0442\u0430: \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 LWLock \u0434\u043e exclusive\u00a0\u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u0431\u0430\u043a\u0435\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0438\u0441\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0432 \u0431\u0430\u043a\u0435\u0442: \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0431\u0430\u043a\u0435\u0442\u0435, \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f SpinLock \u044d\u0442\u043e\u0433\u043e \u0431\u0430\u043a\u0435\u0442\u0430. \u0417\u0430\u0442\u0435\u043c \u0441\u043e SpinLock \u0438 LWLock \u0441\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430.\u00a0<\/p>\n<\/li>\n<\/ol>\n<p>\u042d\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430\u043c\u0438 \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u043b\u0438<strong> <\/strong>\u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 pg_stat_statements \u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0443\u0437\u043a\u0438\u043c \u043c\u0435\u0441\u0442\u043e\u043c. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u043e \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u0441\u0435 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f pg_stat_statements. \u0414\u043b\u044f \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u0430\u0448\u0438\u043d\u044b \u0441 48 CPU. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0431\u044b\u043b\u0438 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c 1000 \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0438\u043c\u0435\u043d\u0430\u043c\u0438:<\/p>\n<pre><code class=\"sql\">DO $$ DECLARE     i INT; BEGIN     FOR i IN 1..1000 LOOP         EXECUTE format('CREATE TABLE table_%s (id INT PRIMARY KEY, value TEXT);', i);         EXECUTE format('INSERT INTO table_%s (id, value) VALUES (1, ''test'');', i);     END LOOP; END; $$;<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0432 pgbench (pgbench_script.sql) \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u044d\u0442\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u043e\u0442\u043b\u0438\u0447\u0430\u043b\u0441\u044f \u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u043b \u0432 \u043d\u043e\u0432\u044b\u0439 \u0431\u0430\u043a\u0435\u0442 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b pg_stat_statements.<\/p>\n<pre><code class=\"sql\">\\set table1_id random(1, 1000) \\set table2_id random(1, 1000) \\set table3_id random(1, 1000)  SELECT t1.value AS value1, t2.value AS value2, t3.value AS value3 FROM table_:table1_id t1 JOIN table_:table2_id t2 ON t1.id = t2.id JOIN table_:table3_id t3 ON t2.id = t3.id WHERE t1.id = 1 AND t2.id = 1 AND t3.id = 1;<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u043f\u0430\u0434\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0431\u0443\u0434\u0435\u043c \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u0440\u0430\u0437 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c pg_stat_activity. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432 \u0444\u0430\u0439\u043b \/tmp\/waits:<\/p>\n<pre><code class=\"sql\">\\o \/tmp\/waits select 'OUT', COALESCE(wait_event, 'None') wait_event, COALESCE(wait_event_type, 'No wait') wait_event_type from  pg_stat_activity where state = 'active'; \\watch 1<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u0432\u0438\u0434\u044b \u0437\u0430\u0434\u0435\u0440\u0436\u0435\u043a \u0438 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043d\u0438\u0445 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043b\u0430\u0441\u044c:<\/p>\n<pre><code class=\"bash\">cat \/tmp\/waits | grep OUT | awk '{print $2 \"|\" $3}' FS=\"|\" | sort | uniq -c | sort -n -r -k1<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a, \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0441 \u0432\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u044b\u043c \u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c pg_stat_statements, \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u0435\u0435 \u043f\u0430\u0434\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0443\u0442\u0438\u043b\u0438\u0442\u0443 pgbench:<\/p>\n<ul>\n<li>\n<p>\u0427\u0438\u0441\u043b\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 (-c): 48 -\u043f\u043e \u0447\u0438\u0441\u043b\u0443 CPU;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0442\u043e\u043a\u0438 (-j): 20 &#8212; \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0446\u0438\u044e \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u041e\u0421, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0442\u044c CPU \u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c (-T): 120 \u0441\u0435\u043a\u0443\u043d\u0434;<\/p>\n<\/li>\n<li>\n<p>\u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439: \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442 pgbench_script.sql (-f pgbench_script.sql);<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u0440\u0438\u043a\u0438: \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u0434\u0435\u0440\u0436\u0435\u043a \u0438 \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 TPS.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"bash\">pgbench -c48 -j20 -T120 -f pgbench_script.sql --progress 10 | grep \"tps = \" 2&gt;&gt;$RESULTS &gt;&gt;$RESULTS &amp;<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0431\u0435\u0440\u0435\u043c \u0432\u0441\u0435 \u044d\u0442\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432 \u043e\u0434\u0438\u043d \u0441\u043a\u0440\u0438\u043f\u0442:<\/p>\n<pre><code class=\"bash\">RESULTS=\"\/tmp\/results\"  rm -rfv $RESULTS nohup pgbench -c48 -j20 -T120 -f pgbench_script.sql --progress 10 | grep \"tps = \" 2&gt;&gt;$RESULTS &gt;&gt;$RESULTS &amp; timeout 125 psql -f waits.sql echo \" count | wait_event | wait_event_type\" &gt;&gt;$RESULTS echo \"--------------------------------------\" &gt;&gt;$RESULTS cat \/tmp\/waits | grep OUT | awk '{print $2 \"|\" $3}' FS=\"|\" | sort | uniq -c | sort -n -r -k1 &gt;&gt;$RESULTS cat $RESULTS rm -rfv \/tmp\/waits<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b:<\/p>\n<pre><code class=\"bash\"># \u0412\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0439 pg_stat_statements tps = 237 437.104223 (without initial connection time)  count | wait_event | wait_event_type --------------------------------------    2922  None        No wait     918  ClientRead    Client  # \u0412\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0439 pg_stat_statements tps =  32 112.129029 (without initial connection time)  count |     wait_event     | wait_event_type --------------------------------------    4703  pg_stat_statements  LWLock     884  None                No wait     143  ClientRead          Client<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u044b\u0439 pg_stat_statements \u043c\u043e\u0436\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u2014 \u0432\u043f\u043b\u043e\u0442\u044c \u0434\u043e \u043a\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043f\u0430\u0434\u0435\u043d\u0438\u044f TPS. \u0412\u0441\u0451 \u0438\u0437-\u0437\u0430 <strong>\u0447\u0430\u0441\u0442\u043e\u0433\u043e \u0437\u0430\u0445\u0432\u0430\u0442\u0430 LWLock \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 exclusive<\/strong>.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u2014 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0445\u0441\u044f<strong> <\/strong>\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0417\u0434\u0435\u0441\u044c \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043c\u043e\u0449\u043d\u0430\u044f \u043c\u0430\u0448\u0438\u043d\u0430 \u0441 192 CPU. \u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0430 \u043c\u044b \u0441\u043d\u043e\u0432\u0430 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442, \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0449\u0438\u0439 pg_stat_activity, \u043d\u043e \u043d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u0442\u043e\u0433\u043e \u0436\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0447\u0435\u0440\u0435\u0437 pgbench -M prepared -S \u0441 \u0447\u0438\u0441\u043b\u043e\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432, \u0440\u0430\u0432\u043d\u044b\u043c 192:<\/p>\n<pre><code class=\"bash\">pgbench -c192 -j20 -T120 -M prepared -S --progress 10 | grep \"tps = \" 2&gt;&gt;$RESULTS &gt;&gt;$RESULTS &amp;<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u044f \u044d\u0442\u043e\u0442 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a&#8230;<\/p>\n<pre><code class=\"bash\">RESULTS=\"\/tmp\/results\"  rm -rfv $RESULTS pgbench -i -s500 nohup pgbench -c192 -j20 -T120 -M prepared -S --progress 10 | grep \"tps = \" 2&gt;&gt;$RESULTS &gt;&gt;$RESULTS &amp; timeout 125 psql -f waits.sql echo \" count | wait_event | wait_event_type\" &gt;&gt;$RESULTS echo \"--------------------------------------\" &gt;&gt;$RESULTS cat \/tmp\/waits | grep OUT | awk '{print $2}' FS=\"|\" | sort | uniq -c | sort -n -r -k1 &gt;&gt;$RESULTS cat $RESULTS rm -rfv \/tmp\/waits<\/code><\/pre>\n<p>&#8230;\u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b:<\/p>\n<pre><code class=\"bash\"># \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u043c pg_stat_statements tps = 1 015 425.438193 (without initial connection time)  count | wait_event | wait_event_type --------------------------------------   13201  None             No wait    3482  ClientRead       Client  # \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u043c pg_stat_statements tps =   484 338.163894 (without initial connection time)  count | wait_event | wait_event_type --------------------------------------  11 214  SpinDelay        Timeout    9481  None             No wait     930  ClientRead       Client<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0436\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u044d\u0442\u043e \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0435 \u0441 48 CPU (\u0442.\u0435. \u0441 48 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438)&#8230;<\/p>\n<pre><code class=\"bash\">pgbench -c48 -j20 -T120 -M prepared -S --progress 10 | grep \"tps = \" 2&gt;&gt;$RESULTS &gt;&gt;$RESULTS &amp;<\/code><\/pre>\n<p>&#8230;\u0442\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043e\u0441\u0442\u0430\u043d\u0443\u0442\u0441\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u0438.<\/p>\n<pre><code class=\"bash\"># \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u043c pg_stat_statements tps = 625 335.965464 (without initial connection time)  count | wait_event | wait_event_type --------------------------------------     979  ClientRead  Client     927  None        No wait  # \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u043c pg_stat_statements tps = 611 708.477697 (without initial connection time)  count | wait_event | wait_event_type --------------------------------------    1000  ClientRead Client     978  None       No wait<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u043b\u0438\u044f\u043d\u0438\u0435\u00a0pg_stat_statements \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0437\u0430\u043c\u0435\u0442\u043d\u044b\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u043e\u0447\u0435\u043d\u044c \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0430. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u2014 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0446\u0438\u044f \u0437\u0430 \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0435\u0442\u0441\u044f <strong>\u0447\u0430\u0441\u0442\u044b\u043c\u0438 \u0437\u0430\u0445\u0432\u0430\u0442\u0430\u043c\u0438 SpinLock \u043f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u043c\u0435\u0442\u0440\u0438\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0431\u0430\u043a\u0435\u0442\u0435 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/strong>. \u041a\u043e\u0433\u0434\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0437\u0430\u043f\u0440\u043e\u0441, \u043e\u043d\u0438 \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u2014 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0438 \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438. \u042d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0438\u043d\u0442\u0435\u043d\u0441\u0438\u0432\u043d\u043e\u0439 \u0431\u043e\u0440\u044c\u0431\u0435 \u0437\u0430 SpinLock, \u0447\u0442\u043e \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 \u0438 \u0441\u043d\u0438\u0436\u0430\u0435\u0442 TPS.<\/p>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435?<\/h2>\n<p>\u0421\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u2014 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432 \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u043b\u0438\u0448\u044c \u0447\u0430\u0441\u0442\u044c \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0412 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 pg_stat_statements \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043c\u0435\u0442\u0440\u0438\u043a\u0430\u0445 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u043e\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0443, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0438\u0437 \u043d\u0438\u0445, \u0441 \u0440\u0430\u0432\u043d\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e. \u041f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0432 PostgreSQL \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0438 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445: \u0434\u043b\u044f \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0451\u043c\u0430 \u043b\u043e\u0433\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f log_transaction_sample_rate, log_statement_sample_rate, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f\u0445\u00a0auto_explain.sample_rate \u0438 pg_store_plans.sample_rate. \u0412 Tantor Postgres 17.5 \u0432 pg_stat_statements \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u2014 GUC-\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <strong>pg_stat_statements.sample_rate<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u0434\u0430\u0442\u044c \u0434\u043e\u043b\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0445 \u0432 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 (\u043e\u0442 0 \u0434\u043e 1)\u00a0\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0434\u043e\u043b\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043f\u0430\u0434\u0443\u0442 \u0432 pg_stat_statements. \u0417\u0430\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d, \u0435\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435:<\/p>\n<pre><code class=\"sql\">is_query_sampled = pgss_sample_rate != 0.0 &amp;&amp; (pgss_sample_rate == 1.0 || pg_prng_double(&amp;pg_global_prng_state) &lt;= pgss_sample_rate);<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0435\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u0438\u0448\u044c \u0437\u0430\u0434\u0430\u043d\u043d\u0443\u044e \u0434\u043e\u043b\u044e \u0438\u0437 \u043d\u0438\u0445.<\/p>\n<p>\u0423 \u043c\u0435\u0442\u043e\u0434\u0430 \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u0432\u0430\u0436\u043d\u044b\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a: \u0432 pg_stat_statements \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u043d\u0435 \u0432\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u042d\u0442\u043e \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0442\u0443 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u0440\u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0435 \u0438\u043b\u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u0440\u0435\u0434\u043a\u0438\u0445, \u043d\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u0447\u0430\u0441\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0441\u043d\u0438\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043d\u0430 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0438, \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435, \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u0449\u0430\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<\/p>\n<h2>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h2>\n<p>\u0415\u0441\u043b\u0438 \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0431\u0430\u043a\u0435\u0442\u0430 \u0432 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0440\u0430\u0437\u0433\u0440\u0443\u0436\u0430\u044f LWLock, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0440\u0438\u0441\u043a \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c \u0446\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 pg_stat_statements. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0431\u044b \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u0448\u0430\u043b\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0431\u0430\u043a\u0435\u0442\u0430 \u0432 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043a\u0430\u043a \u0434\u043e, \u0442\u0430\u043a \u0438 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430\u044f \u0434\u043b\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e <strong>\u0434\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/strong>,<strong> <\/strong>\u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u0433\u0434\u0435 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044b \u0434\u043b\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<strong>.<\/strong> \u0415\u0441\u043b\u0438 \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 pg_stat_statements \u0440\u0435\u0448\u0438\u0442 \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0437-\u0437\u0430 \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u043e \u0437\u0430\u0442\u0435\u043c (\u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f) \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u043c (\u043d\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u043c) \u0432\u0438\u0434\u0435. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0443\u0442\u0435\u0447\u043a\u0435 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 pg_stat_statements (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0430\u0440\u043e\u043b\u0435\u0439 \u0438\u043b\u0438 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u0430\u0445 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0435\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e: \u043e\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0440\u0443\u0448\u0438\u0442\u044c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u043a\u0430\u043a \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e PostgreSQL, \u0442\u0430\u043a \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u00ab\u0422\u0430\u043d\u0442\u043e\u0440 \u041b\u0430\u0431\u0441\u00bb \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u0440\u0435\u0448\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u2014 \u043f\u0443\u0442\u0451\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0445\u043e\u0436\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e\u0434 \u043e\u0434\u043d\u0438\u043c queryid. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u0435\u0451 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438. \u0421\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e \u0443\u0436\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043b\u043e \u0432 \u043e\u0434\u0438\u043d QueryId \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b:<\/p>\n<ul>\n<li>\n<p>\u0412 <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/dc68515968e80d75f8106d0df05da346be537628\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u043c\u0430\u043d\u0434\u0430\u0445 SET<\/a>;<\/p>\n<\/li>\n<li>\n<p>\u041e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/9fbd53dea5d513a78ca04834101ca1aa73b63e59\" rel=\"noopener noreferrer nofollow\">\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0441 \u0440\u0430\u0437\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u043e\u0439 IN<\/a>(&#8230;);<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/docs.tantorlabs.ru\/tdb\/ru\/17_5\/se\/differences.html#:~:text=%D0%98%D0%BD%D1%82%D0%B5%D0%BB%D0%BB%D0%B5%D0%BA%D1%82%D1%83%D0%B0%D0%BB%D1%8C%D0%BD%D0%B0%D1%8F%20%D0%B0%D0%B3%D1%80%D0%B5%D0%B3%D0%B0%D1%86%D0%B8%D1%8F%20%D0%B4%D0%B0%D0%BD%D0%BD%D1%8B%D1%85%3A%20%D1%81%D0%B8%D1%81%D1%82%D0%B5%D0%BC%D0%B0%20%D1%82%D0%B5%D0%BF%D0%B5%D1%80%D1%8C%20%D0%BC%D0%B0%D1%81%D0%BA%D0%B8%D1%80%D1%83%D0%B5%D1%82%20%D0%B8%D0%BC%D0%B5%D0%BD%D0%B0%20%D0%B2%D1%80%D0%B5%D0%BC%D0%B5%D0%BD%D0%BD%D1%8B%D1%85%20%D1%82%D0%B0%D0%B1%D0%BB%D0%B8%D1%86%20%D0%B8%20%D0%BC%D0%B0%D1%81%D1%81%D0%B8%D0%B2%D0%BE%D0%B2%2C%20%D1%87%D1%82%D0%BE%20%D0%BF%D0%BE%D0%B7%D0%B2%D0%BE%D0%BB%D1%8F%D0%B5%D1%82%20%D0%B1%D0%BE%D0%BB%D0%B5%D0%B5%20%D1%82%D0%BE%D1%87%D0%BD%D0%BE%20%D0%B0%D0%B3%D1%80%D0%B5%D0%B3%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D1%82%D1%8C%20%D1%81%D1%82%D0%B0%D1%82%D0%B8%D1%81%D1%82%D0%B8%D0%BA%D1%83%20%D0%BF%D0%BE%20%D0%BE%D0%B4%D0%BD%D0%BE%D1%82%D0%B8%D0%BF%D0%BD%D1%8B%D0%BC%20%D0%B7%D0%B0%D0%BF%D1%80%D0%BE%D1%81%D0%B0%D0%BC%20%D1%81%20%D1%80%D0%B0%D0%B7%D0%BD%D1%8B%D0%BC%D0%B8%20%D0%BF%D0%B0%D1%80%D0%B0%D0%BC%D0%B5%D1%82%D1%80%D0%B0%D0%BC%D0%B8\" rel=\"noopener noreferrer nofollow\">\u0412\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/a>.<\/p>\n<\/li>\n<\/ul>\n<p>\u0410 \u0432\u043e\u0442 \u0432 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445, \u0433\u0434\u0435 \u0443\u0437\u043a\u0438\u043c \u043c\u0435\u0441\u0442\u043e\u043c \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043d\u0430 SpinLock \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0447\u0430\u0441\u0442\u043e\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u2014 \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0432\u0435\u0441\u044c\u043c\u0430 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 SpinLock \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0431\u0430\u043a\u0435\u0442, \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439 \u043a \u043d\u0435\u043c\u0443 (\u0437\u0430 \u0441\u0447\u0451\u0442 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430 \u0447\u0430\u0441\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432) \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0446\u0438\u044e \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u0438 \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442 \u043e\u0431\u0449\u0443\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/p>\n<h2>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h2>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b\u0438 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0430 \u043c\u043e\u0449\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u0441 192 CPU. \u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0442\u0435 \u0436\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b waits.sql \u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0439 pg_stat_statements.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0432\u0435\u0434\u0451\u043c \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 pg_stat_statements.sample_rate \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0439. \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0446\u0438\u043a\u043b \u043f\u043e \u043f\u044f\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c sample_rate: 1, 0.75, 0.5, 0.25 \u0438 0. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e pgbench:<\/p>\n<pre><code class=\"bash\">CONNECTIONS=192 RESULTS=\"\/tmp\/results\" pgbench -i -s500  rm -rfv $RESULTS for i in 1 .75 .5 .25 0 do   psql -c \"alter system set pg_stat_statements.sample_rate = ${i};\" 2&gt;\/dev\/null &gt;\/dev\/null   psql -c \"select pg_reload_conf();\" 2&gt;\/dev\/null &gt;\/dev\/null   psql -c \"show pg_stat_statements.sample_rate;\" 2&gt;\/dev\/null &gt;\/dev\/null   echo -e \"\\nsample_rate = $i\" &gt;&gt;$RESULTS   nohup pgbench -c $CONNECTIONS -j20 -T120 -S -Mprepared --progress 10 | grep \"tps = \" 2&gt;&gt;\/tmp\/results &gt;&gt;$RESULTS &amp;   timeout 125 psql -f \/tmp\/waits.sql   echo \" count | wait_event | wait_event_type\" &gt;&gt;$RESULTS   echo \"--------------------------------------\" &gt;&gt;$RESULTS   cat \/tmp\/waits | grep OUT | awk '{print $2 \"|\" $3}' FS=\"|\" | sort | uniq -c | sort -n -r -k1 &gt;&gt;$RESULTS   rm -rfv \/tmp\/waits done cat $RESULTS<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 pg_stat_statements.sample_rate \u0431\u044b\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u044b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043d\u0438\u0436\u0435. \u041e\u043d\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0439 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0434\u043e\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0445 \u0432 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0443:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">sample_rate<\/p>\n<\/th>\n<th>\n<p align=\"left\">tps<\/p>\n<\/th>\n<th>\n<p align=\"left\">SpinDelay<\/p>\n<\/th>\n<th>\n<p align=\"left\">NoWait<\/p>\n<\/th>\n<th>\n<p align=\"left\">ClientRead<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1.00<\/p>\n<\/td>\n<td>\n<p align=\"left\"> 484 338<\/p>\n<\/td>\n<td>\n<p align=\"left\">11 107<\/p>\n<\/td>\n<td>\n<p align=\"left\">9 568<\/p>\n<\/td>\n<td>\n<p align=\"left\">929<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">0.75<\/p>\n<\/td>\n<td>\n<p align=\"left\"> 909 547<\/p>\n<\/td>\n<td>\n<p align=\"left\">4 781<\/p>\n<\/td>\n<td>\n<p align=\"left\">12 079<\/p>\n<\/td>\n<td>\n<p align=\"left\">2100<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">0.50<\/p>\n<\/td>\n<td>\n<p align=\"left\">1 019 507<\/p>\n<\/td>\n<td>\n<p align=\"left\">174<\/p>\n<\/td>\n<td>\n<p align=\"left\">13 253<\/p>\n<\/td>\n<td>\n<p align=\"left\">3378<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">0.25<\/p>\n<\/td>\n<td>\n<p align=\"left\">1 019 507<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">13 397<\/p>\n<\/td>\n<td>\n<p align=\"left\">3423<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">0.00<\/p>\n<\/td>\n<td>\n<p align=\"left\">1 015 425<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">13 106<\/p>\n<\/td>\n<td>\n<p align=\"left\">3502<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041f\u0440\u0438 sample_rate = 1.0, \u043a\u043e\u0433\u0434\u0430 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0432\u0441\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c, TPS \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u044b\u043c \u043d\u0438\u0437\u043a\u0438\u043c \u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043b\u043e\u0441\u0441\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0439 \u043d\u0430 SpinLock. \u041f\u0440\u0438 \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u0438 sample_rate \u0434\u043e 0.75 \u0438 \u043d\u0438\u0436\u0435 TPS \u0440\u0435\u0437\u043a\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u0435\u0442, \u0430 SpinDelay \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442\u0441\u044f \u0432 2,3 \u0440\u0430\u0437\u0430. \u041f\u0440\u0438 sample_rate = 0.25 \u0438 \u043d\u0438\u0436\u0435 SpinDelay \u0438\u0441\u0447\u0435\u0437\u0430\u0435\u0442.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b pg_stat_statements \u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445 \u0441 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0446\u0438\u0435\u0439 \u0437\u0430 SpinLock.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412 pg_stat_statements LWLock \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0438 \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u0443\u0437\u043a\u0438\u043c \u043c\u0435\u0441\u0442\u043e\u043c. \u0421\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e PostgreSQL \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0441\u043e\u043a\u0440\u0430\u0449\u0430\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u043e\u0432\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0437\u0430 \u0441\u0447\u0451\u0442 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0445\u043e\u0436\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e\u0434 \u043e\u0434\u043d\u0438\u043c\u00a0queryid, \u0430 \u0432 Tantor Postgres 17.5 \u0431\u044b\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0435 \u043c\u0430\u0441\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b: pg_stat_statements.mask_const_arrays \u0438 pg_stat_statements.mask_temp_tables. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0442\u043e\u0447\u043d\u0435\u0435 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0447\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0442\u0430\u043a\u0438\u0445 \u0441\u0438\u0441\u0442\u0435\u043c \u043a\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 1\u0421:ERP.<\/p>\n<p>\u0412 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c,\u00a0SpinLock \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u044b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0431\u0430\u043a\u0435\u0442\u043e\u0432 \u0438 \u043f\u0440\u0438 \u0447\u0430\u0441\u0442\u043e\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u043e\u0432 \u0434\u043b\u044f \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0446\u0438\u0438, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0430\u0445 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0447\u0438\u0441\u043b\u043e\u043c CPU. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432 Tantor Postgres SE 17.5 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 pg_stat_statements.sample_rate: \u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043d\u0438\u0436\u0430\u0442\u044c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443, \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u0443\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0438 \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0443\u0441\u0442\u0440\u0430\u043d\u044f\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443.<\/p>\n<p>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u00ab\u0422\u0430\u043d\u0442\u043e\u0440 \u041b\u0430\u0431\u0441\u00bb \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 pg_stat_statements \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0432\u0435\u0442\u043a\u0443 PostgreSQL. \u041e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0435 <a href=\"https:\/\/www.postgresql.org\/message-id\/flat\/fe99e0ca-e564-480e-b865-5f0cee30bc60%40tantorlabs.com\" rel=\"noopener noreferrer nofollow\">\u0443\u0436\u0435 \u0438\u0434\u0451\u0442<\/a> \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0435 \u043d\u0430 pgsql-hackers \u2014 \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f, \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0443\u0447\u0430\u0441\u0442\u0438\u0435 \u0432 \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0438.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/919592\/\"> https:\/\/habr.com\/ru\/articles\/919592\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>pg_stat_statements \u2014 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 PostgreSQL \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432: \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u0432, \u043e\u0431\u0449\u0435\u0435 \u0438 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0447\u0438\u0441\u043b\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0451\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438. \u042d\u0442\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0432\u044b\u044f\u0432\u043b\u044f\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u044b\u0435 \u0443\u0447\u0430\u0441\u0442\u043a\u0438 \u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0441 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0446\u0438\u0435\u0439 pg_stat_statements \u0441\u0430\u043c\u043e \u043f\u043e \u0441\u0435\u0431\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0443\u0437\u043a\u0438\u043c \u043c\u0435\u0441\u0442\u043e\u043c \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0430\u0434\u043a\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c, \u0432 \u043a\u0430\u043a\u0438\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0432 \u043a\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b.<\/p>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430<\/h2>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 pg_stat_statements \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043a\u043e\u0440\u043e\u0442\u043a\u043e \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u043a\u0430\u043a \u043e\u043d\u043e \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u0432\u043d\u0443\u0442\u0440\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0441\u0442\u0430\u0442\u044c \u0443\u0437\u043a\u0438\u043c \u043c\u0435\u0441\u0442\u043e\u043c \u043f\u0440\u0438 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0435.<\/p>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 pg_stat_statements \u2014 \u044d\u0442\u043e \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430. \u041a\u0430\u0436\u0434\u044b\u0439 \u0431\u0430\u043a\u0435\u0442 \u0432 \u043d\u0435\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0443. \u041a\u043b\u044e\u0447 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0447\u0435\u0442\u044b\u0440\u0451\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>queryid \u2014 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430;<\/p>\n<\/li>\n<li>\n<p>OID \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f;<\/p>\n<\/li>\n<li>\n<p>OID \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445;<\/p>\n<\/li>\n<li>\n<p>\u0444\u043b\u0430\u0433 toplevel, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u0435\u0440\u0445\u043d\u0435\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u043c, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0435 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c \u0432 \u043a\u0430\u043a\u0443\u044e-\u043b\u0438\u0431\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044e\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438\u043b\u0438 \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e \u044d\u0442\u043e\u043c\u0443 \u043a\u043b\u044e\u0447\u0443 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<figure class=\"full-width\">\n<div><figcaption> <\/figcaption><\/div>\n<\/figure>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441, pg_stat_statements \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u0438\u0441\u043a \u0431\u0430\u043a\u0435\u0442\u0430: \u043d\u0430 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f shared-\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 LWLock \u0438 \u043f\u043e \u043a\u043b\u044e\u0447\u0443 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0438\u0441\u043a \u0432 \u043d\u0435\u0439;<\/p>\n<\/li>\n<li>\n<p>\u041d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f (\u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438): \u0435\u0441\u043b\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0431\u0430\u043a\u0435\u0442\u0430 \u043d\u0435\u0442, \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f: \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044b \u0437\u0430\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u044b \u0432\u0438\u0434\u0430\u00a0$1, $2\u00a0\u0438 \u0442. \u0434.;<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u0431\u0430\u043a\u0435\u0442\u0430: \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 LWLock \u0434\u043e exclusive\u00a0\u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u0431\u0430\u043a\u0435\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0438\u0441\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0432 \u0431\u0430\u043a\u0435\u0442: \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0431\u0430\u043a\u0435\u0442\u0435, \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f SpinLock \u044d\u0442\u043e\u0433\u043e \u0431\u0430\u043a\u0435\u0442\u0430. \u0417\u0430\u0442\u0435\u043c \u0441\u043e SpinLock \u0438 LWLock \u0441\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430.\u00a0<\/p>\n<\/li>\n<\/ol>\n<p>\u042d\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430\u043c\u0438 \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u043b\u0438<strong> <\/strong>\u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 pg_stat_statements \u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0443\u0437\u043a\u0438\u043c \u043c\u0435\u0441\u0442\u043e\u043c. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u043e \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u0441\u0435 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f pg_stat_statements. \u0414\u043b\u044f \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u0430\u0448\u0438\u043d\u044b \u0441 48 CPU. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0431\u044b\u043b\u0438 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c 1000 \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0438\u043c\u0435\u043d\u0430\u043c\u0438:<\/p>\n<pre><code class=\"sql\">DO $$ DECLARE     i INT; BEGIN     FOR i IN 1..1000 LOOP         EXECUTE format('CREATE TABLE table_%s (id INT PRIMARY KEY, value TEXT);', i);         EXECUTE format('INSERT INTO table_%s (id, value) VALUES (1, ''test'');', i);     END LOOP; END; $$;<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0432 pgbench (pgbench_script.sql) \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u044d\u0442\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u043e\u0442\u043b\u0438\u0447\u0430\u043b\u0441\u044f \u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u043b \u0432 \u043d\u043e\u0432\u044b\u0439 \u0431\u0430\u043a\u0435\u0442 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b pg_stat_statements.<\/p>\n<pre><code class=\"sql\">\\set table1_id random(1, 1000) \\set table2_id random(1, 1000) \\set table3_id random(1, 1000)  SELECT t1.value AS value1, t2.value AS value2, t3.value AS value3 FROM table_:table1_id t1 JOIN table_:table2_id t2 ON t1.id = t2.id JOIN table_:table3_id t3 ON t2.id = t3.id WHERE t1.id = 1 AND t2.id = 1 AND t3.id = 1;<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u043f\u0430\u0434\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0431\u0443\u0434\u0435\u043c \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u0440\u0430\u0437 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c pg_stat_activity. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432 \u0444\u0430\u0439\u043b \/tmp\/waits:<\/p>\n<pre><code class=\"sql\">\\o \/tmp\/waits select 'OUT', COALESCE(wait_event, 'None') wait_event, COALESCE(wait_event_type, 'No wait') wait_event_type from  pg_stat_activity where state = 'active'; \\watch 1<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u0432\u0438\u0434\u044b \u0437\u0430\u0434\u0435\u0440\u0436\u0435\u043a \u0438 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043d\u0438\u0445 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043b\u0430\u0441\u044c:<\/p>\n<pre><code class=\"bash\">cat \/tmp\/waits | grep OUT | awk '{print $2 \"|\" $3}' FS=\"|\" | sort | uniq -c | sort -n -r -k1<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a, \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0441 \u0432\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u044b\u043c \u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c pg_stat_statements, \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u0435\u0435 \u043f\u0430\u0434\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0443\u0442\u0438\u043b\u0438\u0442\u0443 pgbench:<\/p>\n<ul>\n<li>\n<p>\u0427\u0438\u0441\u043b\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 (-c): 48 -\u043f\u043e \u0447\u0438\u0441\u043b\u0443 CPU;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0442\u043e\u043a\u0438 (-j): 20 &#8212; \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0446\u0438\u044e \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u041e\u0421, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0442\u044c CPU \u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c (-T): 120 \u0441\u0435\u043a\u0443\u043d\u0434;<\/p>\n<\/li>\n<li>\n<p>\u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439: \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442 pgbench_script.sql (-f pgbench_script.sql);<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u0440\u0438\u043a\u0438: \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u0434\u0435\u0440\u0436\u0435\u043a \u0438 \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 TPS.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"bash\">pgbench -c48 -j20 -T120 -f pgbench_script.sql --progress 10 | grep \"tps = \" 2&gt;&gt;$RESULTS &gt;&gt;$RESULTS &amp;<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0431\u0435\u0440\u0435\u043c \u0432\u0441\u0435 \u044d\u0442\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432 \u043e\u0434\u0438\u043d \u0441\u043a\u0440\u0438\u043f\u0442:<\/p>\n<pre><code class=\"bash\">RESULTS=\"\/tmp\/results\"  rm -rfv $RESULTS nohup pgbench -c48 -j20 -T120 -f pgbench_script.sql --progress 10 | grep \"tps = \" 2&gt;&gt;$RESULTS &gt;&gt;$RESULTS &amp; timeout 125 psql -f waits.sql echo \" count | wait_event | wait_event_type\" &gt;&gt;$RESULTS echo \"--------------------------------------\" &gt;&gt;$RESULTS cat \/tmp\/waits | grep OUT | awk '{print $2 \"|\" $3}' FS=\"|\" | sort | uniq -c | sort -n -r -k1 &gt;&gt;$RESULTS cat $RESULTS rm -rfv \/tmp\/waits<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b:<\/p>\n<pre><code class=\"bash\"># \u0412\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0439 pg_stat_statements tps = 237 437.104223 (without initial connection time)  count | wait_event | wait_event_type --------------------------------------    2922  None        No wait     918  ClientRead    Client  # \u0412\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0439 pg_stat_statements tps =  32 112.129029 (without initial connection time)  count |     wait_event     | wait_event_type --------------------------------------    4703  pg_stat_statements  LWLock     884  None                No wait     143  ClientRead          Client<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u044b\u0439 pg_stat_statements \u043c\u043e\u0436\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u2014 \u0432\u043f\u043b\u043e\u0442\u044c \u0434\u043e \u043a\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043f\u0430\u0434\u0435\u043d\u0438\u044f TPS. \u0412\u0441\u0451 \u0438\u0437-\u0437\u0430 <strong>\u0447\u0430\u0441\u0442\u043e\u0433\u043e \u0437\u0430\u0445\u0432\u0430\u0442\u0430 LWLock \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 exclusive<\/strong>.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u2014 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0445\u0441\u044f<strong> <\/strong>\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0417\u0434\u0435\u0441\u044c \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043c\u043e\u0449\u043d\u0430\u044f \u043c\u0430\u0448\u0438\u043d\u0430 \u0441 192 CPU. \u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0430 \u043c\u044b \u0441\u043d\u043e\u0432\u0430 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442, \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0449\u0438\u0439 pg_stat_activity, \u043d\u043e \u043d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u0442\u043e\u0433\u043e \u0436\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0447\u0435\u0440\u0435\u0437 pgbench -M prepared -S \u0441 \u0447\u0438\u0441\u043b\u043e\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432, \u0440\u0430\u0432\u043d\u044b\u043c 192:<\/p>\n<pre><code class=\"bash\">pgbench -c192 -j20 -T120 -M prepared -S --progress 10 | grep \"tps = \" 2&gt;&gt;$RESULTS &gt;&gt;$RESULTS &amp;<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u044f \u044d\u0442\u043e\u0442 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a&#8230;<\/p>\n<pre><code class=\"bash\">RESULTS=\"\/tmp\/results\"  rm -rfv $RESULTS pgbench -i -s500 nohup pgbench -c192 -j20 -T120 -M prepared -S --progress 10 | grep \"tps = \" 2&gt;&gt;$RESULTS &gt;&gt;$RESULTS &amp; timeout 125 psql -f waits.sql echo \" count | wait_event | wait_event_type\" &gt;&gt;$RESULTS echo \"--------------------------------------\" &gt;&gt;$RESULTS cat \/tmp\/waits | grep OUT | awk '{print $2}' FS=\"|\" | sort | uniq -c | sort -n -r -k1 &gt;&gt;$RESULTS cat $RESULTS rm -rfv \/tmp\/waits<\/code><\/pre>\n<p>&#8230;\u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b:<\/p>\n<pre><code class=\"bash\"># \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u043c pg_stat_statements tps = 1 015 425.438193 (without initial connection time)  count | wait_event | wait_event_type --------------------------------------   13201  None             No wait    3482  ClientRead       Client  # \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u043c pg_stat_statements tps =   484 338.163894 (without initial connection time)  count | wait_event | wait_event_type --------------------------------------  11 214  SpinDelay        Timeout    9481  None             No wait     930  ClientRead       Client<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0436\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u044d\u0442\u043e \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0435 \u0441 48 CPU (\u0442.\u0435. \u0441 48 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438)&#8230;<\/p>\n<pre><code class=\"bash\">pgbench -c48 -j20 -T120 -M prepared -S --progress 10 | grep \"tps = \" 2&gt;&gt;$RESULTS &gt;&gt;$RESULTS &amp;<\/code><\/pre>\n<p>&#8230;\u0442\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043e\u0441\u0442\u0430\u043d\u0443\u0442\u0441\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u0438.<\/p>\n<pre><code class=\"bash\"># \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u043c pg_stat_statements tps = 625 335.965464 (without initial connection time)  count | wait_event | wait_event_type --------------------------------------     979  ClientRead  Client     927  None        No wait  # \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u043c pg_stat_statements tps = 611 708.477697 (without initial connection time)  count | wait_event | wait_event_type --------------------------------------    1000  ClientRead Client     978  None       No wait<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u043b\u0438\u044f\u043d\u0438\u0435\u00a0pg_stat_statements \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0437\u0430\u043c\u0435\u0442\u043d\u044b\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u043e\u0447\u0435\u043d\u044c \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0430. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u2014 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0446\u0438\u044f \u0437\u0430 \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0435\u0442\u0441\u044f <strong>\u0447\u0430\u0441\u0442\u044b\u043c\u0438 \u0437\u0430\u0445\u0432\u0430\u0442\u0430\u043c\u0438 SpinLock \u043f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u043c\u0435\u0442\u0440\u0438\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0431\u0430\u043a\u0435\u0442\u0435 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/strong>. \u041a\u043e\u0433\u0434\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0437\u0430\u043f\u0440\u043e\u0441, \u043e\u043d\u0438 \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u2014 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0438 \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438. \u042d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0438\u043d\u0442\u0435\u043d\u0441\u0438\u0432\u043d\u043e\u0439 \u0431\u043e\u0440\u044c\u0431\u0435 \u0437\u0430 SpinLock, \u0447\u0442\u043e \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 \u0438 \u0441\u043d\u0438\u0436\u0430\u0435\u0442 TPS.<\/p>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435?<\/h2>\n<p>\u0421\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u2014 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432 \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u043b\u0438\u0448\u044c \u0447\u0430\u0441\u0442\u044c \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0412 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 pg_stat_statements \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043c\u0435\u0442\u0440\u0438\u043a\u0430\u0445 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u043e\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0443, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0438\u0437 \u043d\u0438\u0445, \u0441 \u0440\u0430\u0432\u043d\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e. \u041f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0432 PostgreSQL \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0438 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445: \u0434\u043b\u044f \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0451\u043c\u0430 \u043b\u043e\u0433\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f log_transaction_sample_rate, log_statement_sample_rate, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f\u0445\u00a0auto_explain.sample_rate \u0438 pg_store_plans.sample_rate. \u0412 Tantor Postgres 17.5 \u0432 pg_stat_statements \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u2014 GUC-\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <strong>pg_stat_statements.sample_rate<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u0434\u0430\u0442\u044c \u0434\u043e\u043b\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0445 \u0432 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 (\u043e\u0442 0 \u0434\u043e 1)\u00a0\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0434\u043e\u043b\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043f\u0430\u0434\u0443\u0442 \u0432 pg_stat_statements. \u0417\u0430\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d, \u0435\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435:<\/p>\n<pre><code class=\"sql\">is_query_sampled = pgss_sample_rate != 0.0 &amp;&amp; (pgss_sample_rate == 1.0 || pg_prng_double(&amp;pg_global_prng_state) &lt;= pgss_sample_rate);<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0435\u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u0438\u0448\u044c \u0437\u0430\u0434\u0430\u043d\u043d\u0443\u044e \u0434\u043e\u043b\u044e \u0438\u0437 \u043d\u0438\u0445.<\/p>\n<p>\u0423 \u043c\u0435\u0442\u043e\u0434\u0430 \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u0432\u0430\u0436\u043d\u044b\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a: \u0432 pg_stat_statements \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u043d\u0435 \u0432\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u042d\u0442\u043e \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0442\u0443 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u0440\u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0435 \u0438\u043b\u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u0440\u0435\u0434\u043a\u0438\u0445, <\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-464498","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/464498","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=464498"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/464498\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=464498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=464498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=464498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}