{"id":340478,"date":"2022-10-30T21:00:36","date_gmt":"2022-10-30T21:00:36","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=340478"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=340478","title":{"rendered":"<span>\u0422\u043e\u043f \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0434\u043b\u044f PostgreSQL<\/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<p>\u0421\u0442\u0430\u0442\u0435\u0439 \u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 PostgreSQL \u0438 \u0435\u0451 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430\u0445 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u043d\u043e\u0433\u043e, \u043d\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0437 \u043d\u0438\u0445 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0431\u0430\u0437\u044b \u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0430\u043c\u0438, \u0432\u043b\u0438\u044f\u044e\u0449\u0438\u043c\u0438 \u043d\u0430 \u0435\u0451 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0430\u043c \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8e9\/286\/c26\/8e9286c26aec7ed90129c105f7d82d45.png\" alt=\"\" title=\"\" width=\"1460\" height=\"730\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8e9\/286\/c26\/8e9286c26aec7ed90129c105f7d82d45.png\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u0417\u0430\u0447\u0435\u043c \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c PostgreSQL?<\/h2>\n<p>\u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u043a\u0436\u0435 \u0432\u0430\u0436\u0435\u043d, \u043a\u0430\u043a \u0438 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0432\u0430\u0448\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043e, \u0447\u0435\u043c \u043d\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438:<\/p>\n<ol>\n<li>\n<p>\u041d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u0435\u043d \u043a\u044d\u0448 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445?<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u0431\u043b\u0438\u0446 \u0432 \u0432\u0430\u0448\u0435\u0439 \u0411\u0414?<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043b\u0438 \u0432\u0430\u0448\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u044b?<\/p>\n<\/li>\n<li>\n<p>\u0418 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<\/li>\n<\/ol>\n<h2>\u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0411\u0414 \u0438 \u0435\u0451 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432<\/h2>\n<h3>1. \u0420\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432<\/h3>\n<pre><code class=\"sql\">SELECT spcname, pg_size_pretty(pg_tablespace_size(spcname))  FROM pg_tablespace WHERE spcname&lt;>'pg_global';<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0435 \u0432\u0441\u0435\u0445 tablespace \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0432\u0430\u0448\u0435\u0439 \u0411\u0414. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <strong>pg_tablespace_size<\/strong> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0435 tablespace \u0432 \u0431\u0430\u0439\u0442\u0430\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043a \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u043c\u0443 \u0432\u0438\u0434\u0443 \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <strong>pg_size_pretty<\/strong>. \u041f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e pg_global \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0431\u0449\u0438\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432.<\/p>\n<h3>2. \u0420\u0430\u0437\u043c\u0435\u0440 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<pre><code class=\"sql\">SELECT pg_database.datname,        pg_size_pretty(pg_database_size(pg_database.datname)) AS size FROM pg_database ORDER BY pg_database_size(pg_database.datname) DESC;<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0435 \u0432\u0441\u0435\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0432\u0430\u0448\u0435\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 PostgreSQL.<\/p>\n<h3>3. \u0420\u0430\u0437\u043c\u0435\u0440 \u0441\u0445\u0435\u043c \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<pre><code class=\"sql\">SELECT A.schemaname,        pg_size_pretty (SUM(pg_relation_size(C.oid))) as table,         pg_size_pretty (SUM(pg_total_relation_size(C.oid)-pg_relation_size(C.oid))) as index,         pg_size_pretty (SUM(pg_total_relation_size(C.oid))) as table_index,        SUM(n_live_tup) FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C .relnamespace) INNER JOIN pg_stat_user_tables A ON C.relname = A.relname WHERE nspname NOT IN ('pg_catalog', 'information_schema') AND C .relkind &lt;> 'i' AND nspname !~ '^pg_toast' GROUP BY A.schemaname;<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0445\u0435\u043c\u0435 \u0432 \u0432\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445: \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u0441\u0435\u0445 \u0442\u0430\u0431\u043b\u0438\u0446, \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u0441\u0435\u0445 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432, \u043e\u0431\u0449\u0438\u0439 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u0445\u0435\u043c\u044b \u0438 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u0432\u043e \u0432\u0441\u0435\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 \u0441\u0445\u0435\u043c\u044b.<\/p>\n<h3>4. \u0420\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u0431\u043b\u0438\u0446<\/h3>\n<pre><code class=\"sql\">SELECT schemaname,        C.relname AS \"relation\",        pg_size_pretty (pg_relation_size(C.oid)) as table,        pg_size_pretty (pg_total_relation_size (C.oid)-pg_relation_size(C.oid)) as index,        pg_size_pretty (pg_total_relation_size (C.oid)) as table_index,        n_live_tup FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C .relnamespace) LEFT JOIN pg_stat_user_tables A ON C.relname = A.relname WHERE nspname NOT IN ('pg_catalog', 'information_schema') AND C.relkind &lt;> 'i' AND nspname !~ '^pg_toast' ORDER BY pg_total_relation_size (C.oid) DESC<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0435\u0451 \u0441\u0445\u0435\u043c\u044b, \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0431\u0435\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432, \u0440\u0430\u0437\u043c\u0435\u0440\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432, \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435.<\/p>\n<h2>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a<\/h2>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0442\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u0440\u0438\u0441\u043a \u0432\u0437\u0430\u0438\u043c\u043d\u043e\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435. \u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0442\u0430\u043a\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0445 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u041e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u043c\u0435\u0448\u0430\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c\u0441\u044f \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0443 \u0438 \u043d\u0435 \u0434\u0430\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c\u0441\u044f \u0434\u0440\u0443\u0433\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c. \u0411\u043e\u043b\u044c\u0448\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 <a href=\"https:\/\/www.postgresql.org\/docs\/current\/explicit-locking.html\" rel=\"noopener noreferrer nofollow\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>. \u041c\u044b \u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a \u0438 \u0438\u0445 \u0441\u043d\u044f\u0442\u0438\u044f.<\/p>\n<h3>1. \u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a<\/h3>\n<pre><code class=\"sql\">SELECT COALESCE(blockingl.relation::regclass::text, blockingl.locktype) AS locked_item,        now() - blockeda.query_start                                     AS waiting_duration,        blockeda.pid                                                     AS blocked_pid,        blockeda.query                                                   AS blocked_query,        blockedl.mode                                                    AS blocked_mode,        blockinga.pid                                                    AS blocking_pid,        blockinga.query                                                  AS blocking_query,        blockingl.mode                                                   AS blocking_mode FROM pg_locks blockedl JOIN pg_stat_activity blockeda ON blockedl.pid = blockeda.pid JOIN pg_locks blockingl ON (blockingl.transactionid = blockedl.transactionid OR                             blockingl.relation = blockedl.relation AND                             blockingl.locktype = blockedl.locktype) AND blockedl.pid &lt;> blockingl.pid JOIN pg_stat_activity blockinga ON blockingl.pid = blockinga.pid AND blockinga.datid = blockeda.datid WHERE NOT blockedl.granted AND blockinga.datname = current_database();<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u043a\u0435\u043c \u043e\u043d\u0438 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u044b.<\/p>\n<h3>2. \u0421\u043d\u044f\u0442\u0438\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a<\/h3>\n<pre><code class=\"sql\">SELECT pg_cancel_backend(PID_ID); OR SELECT pg_terminate_backend(PID_ID);<\/code><\/pre>\n<p>PID_ID &#8212; \u044d\u0442\u043e ID \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0434\u0440\u0443\u0433\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043e\u0442\u043c\u0435\u043d\u044b \u043e\u0434\u043d\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0447\u0442\u043e\u0431\u044b \u0441\u043d\u044f\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u044e \u043d\u0430\u043a\u043e\u043f\u0438\u0432\u0448\u0443\u044e\u0441\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 <strong>pg_cancel_backend<\/strong> \u0438 <strong>pg_terminate_backend<\/strong> \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e <strong>pg_cancel_backend<\/strong> \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441, \u0430 <strong>pg_terminate_backend<\/strong> \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u0441\u0435\u0430\u043d\u0441 \u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u043e\u043c\u0430\u043d\u0434\u0430 <strong>pg_cancel_backend<\/strong> \u0431\u043e\u043b\u0435\u0435 \u0449\u0430\u0434\u044f\u0449\u0430\u044f \u0438 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0432\u0430\u043c \u0435\u0451 \u0445\u0432\u0430\u0442\u0438\u0442. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <strong>pg_terminate_backend<\/strong>. <\/p>\n<h2>\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u0430\u0448\u0435\u0439 \u0411\u0414<\/h2>\n<h3>1. \u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (Cache Hit Ratio)<\/h3>\n<pre><code class=\"sql\">SELECT sum(heap_blks_read) as heap_read,        sum(heap_blks_hit)  as heap_hit,        sum(heap_blks_hit) \/ (sum(heap_blks_hit) + sum(heap_blks_read)) as ratio FROM    pg_statio_user_tables;  <\/code><\/pre>\n<p>\u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f &#8212; \u044d\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0447\u0442\u0435\u043d\u0438\u044f, \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u043c\u044b\u0439 \u0434\u043e\u043b\u0435\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0447\u0442\u0435\u043d\u0438\u044f \u0438\u0437 \u043a\u044d\u0448\u0430 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043e\u0431\u0449\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0447\u0442\u0435\u043d\u0438\u044f \u043a\u0430\u043a \u0441 \u0434\u0438\u0441\u043a\u0430, \u0442\u0430\u043a \u0438 \u0438\u0437 \u043a\u044d\u0448\u0430. \u0417\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 99% \u0438\u043b\u0438 \u0432\u044b\u0448\u0435, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 99% \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0447\u0442\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0438\u0437 \u043a\u044d\u0448\u0430 \u0438 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 1% &#8212; \u0441 \u0434\u0438\u0441\u043a\u0430.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/31f\/44a\/c39\/31f44ac39521eeca84634f818b86fb49.png\" width=\"125\" height=\"35\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/31f\/44a\/c39\/31f44ac39521eeca84634f818b86fb49.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>2. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432<\/h3>\n<pre><code class=\"sql\">SELECT relname,           100 * idx_scan \/ (seq_scan + idx_scan) percent_of_times_index_used,           n_live_tup rows_in_table  FROM pg_stat_user_tables  WHERE seq_scan + idx_scan > 0  ORDER BY n_live_tup DESC;<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0432 \u0432\u0430\u0448\u0443 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043c\u0435\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0418\u043d\u0434\u0435\u043a\u0441\u044b \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432\u0430\u0436\u043d\u044b \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446. \u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 \u0438 \u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0447\u0442\u0435\u043d\u0438\u0435\u043c \u0431\u0435\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432. \u0418\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u044b \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0430 &#8212; \u044d\u0442\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0431\u043e\u043b\u0435\u0435 10000 \u0441\u0442\u0440\u043e\u043a \u0441 \u043d\u0443\u043b\u0435\u0432\u044b\u043c \u0438\u043b\u0438 \u043d\u0438\u0437\u043a\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u0430.<\/p>\n<h3>3. \u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 (Index Cache Hit Rate)<\/h3>\n<pre><code class=\"sql\">SELECT sum(idx_blks_read) as idx_read,        sum(idx_blks_hit)  as idx_hit,        (sum(idx_blks_hit) - sum(idx_blks_read)) \/ sum(idx_blks_hit) as ratio FROM pg_statio_user_indexes;<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u043e \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432.<\/p>\n<h3>4. \u041d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b<\/h3>\n<pre><code class=\"sql\">SELECT schemaname, relname, indexrelname FROM pg_stat_all_indexes WHERE idx_scan = 0 and schemaname &lt;> 'pg_toast' and  schemaname &lt;> 'pg_catalog'<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u044b, \u043d\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0432 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445.<\/p>\n<h3>5. \u0420\u0430\u0437\u0434\u0443\u0432\u0430\u043d\u0438\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (Database bloat)<\/h3>\n<pre><code class=\"sql\">SELECT   current_database(), schemaname, tablename, \/*reltuples::bigint, relpages::bigint, otta,*\/   ROUND((CASE WHEN otta=0 THEN 0.0 ELSE sml.relpages::float\/otta END)::numeric,1) AS tbloat,   CASE WHEN relpages &lt; otta THEN 0 ELSE bs*(sml.relpages-otta)::BIGINT END AS wastedbytes,   iname, \/*ituples::bigint, ipages::bigint, iotta,*\/   ROUND((CASE WHEN iotta=0 OR ipages=0 THEN 0.0 ELSE ipages::float\/iotta END)::numeric,1) AS ibloat,   CASE WHEN ipages &lt; iotta THEN 0 ELSE bs*(ipages-iotta) END AS wastedibytes FROM (   SELECT     schemaname, tablename, cc.reltuples, cc.relpages, bs,     CEIL((cc.reltuples*((datahdr+ma-       (CASE WHEN datahdr%ma=0 THEN ma ELSE datahdr%ma END))+nullhdr2+4))\/(bs-20::float)) AS otta,     COALESCE(c2.relname,'?') AS iname, COALESCE(c2.reltuples,0) AS ituples, COALESCE(c2.relpages,0) AS ipages,     COALESCE(CEIL((c2.reltuples*(datahdr-12))\/(bs-20::float)),0) AS iotta \/* very rough approximation, assumes all cols *\/   FROM (     SELECT       ma,bs,schemaname,tablename,       (datawidth+(hdr+ma-(case when hdr%ma=0 THEN ma ELSE hdr%ma END)))::numeric AS datahdr,       (maxfracsum*(nullhdr+ma-(case when nullhdr%ma=0 THEN ma ELSE nullhdr%ma END))) AS nullhdr2     FROM (       SELECT         schemaname, tablename, hdr, ma, bs,         SUM((1-null_frac)*avg_width) AS datawidth,         MAX(null_frac) AS maxfracsum,         hdr+(           SELECT 1+count(*)\/8           FROM pg_stats s2           WHERE null_frac&lt;>0 AND s2.schemaname = s.schemaname AND s2.tablename = s.tablename         ) AS nullhdr       FROM pg_stats s, (         SELECT           (SELECT current_setting('block_size')::numeric) AS bs,           CASE WHEN substring(v,12,3) IN ('8.0','8.1','8.2') THEN 27 ELSE 23 END AS hdr,           CASE WHEN v ~ 'mingw32' THEN 8 ELSE 4 END AS ma         FROM (SELECT version() AS v) AS foo       ) AS constants       GROUP BY 1,2,3,4,5     ) AS foo   ) AS rs   JOIN pg_class cc ON cc.relname = rs.tablename   JOIN pg_namespace nn ON cc.relnamespace = nn.oid AND nn.nspname = rs.schemaname AND nn.nspname &lt;> 'information_schema'   LEFT JOIN pg_index i ON indrelid = cc.oid   LEFT JOIN pg_class c2 ON c2.oid = i.indexrelid ) AS sml ORDER BY wastedbytes DESC;<\/code><\/pre>\n<p>\u0420\u0430\u0437\u0434\u0443\u0432\u0430\u043d\u0438\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 &#8212; \u044d\u0442\u043e \u0434\u0438\u0441\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 \u0438\u043b\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u0434\u043b\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u043d\u0435 \u0431\u044b\u043b\u043e \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u043e. \u0420\u0430\u0437\u0434\u0443\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0442\u0430\u0431\u043b\u0438\u0446 \u0438\u043b\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f, \u0440\u0430\u0437\u0434\u0443\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0432 \u0432\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u043e\u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u043d\u0435 \u0443\u0431\u0440\u0430\u0442\u044c. \u041f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 <strong>wastedbytes<\/strong> \u0434\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 <strong>wastedibytes<\/strong> \u0434\u043b\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0432\u0430\u043c, \u0435\u0441\u0442\u044c \u043b\u0438 \u0443 \u0432\u0430\u0441 \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0440\u0430\u0437\u0434\u0443\u0432\u0430\u043d\u0438\u0435\u043c. \u0414\u043b\u044f \u0431\u043e\u0440\u044c\u0431\u044b \u0441 \u0440\u0430\u0437\u0434\u0443\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 <strong>VACUUM<\/strong>.<\/p>\n<h3>6. \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u0432 VACUUM<\/h3>\n<pre><code class=\"sql\">SELECT relname,         last_vacuum,         last_autovacuum  FROM pg_stat_user_tables;<\/code><\/pre>\n<p>\u0420\u0430\u0437\u0434\u0443\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b <strong>VACUUM<\/strong>, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 PostgreSQL \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 <strong>AUTOVACUUM<\/strong>. \u041e \u0435\u0433\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/www.postgresql.org\/docs\/13\/runtime-config-autovacuum.html\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<h2>\u0415\u0449\u0451 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u0430\u043c \u043f\u043e\u043b\u0435\u0437\u043d\u044b<\/h2>\n<h3>1. \u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439<\/h3>\n<pre><code class=\"sql\">SELECT COUNT(*) as connections,        backend_type FROM pg_stat_activity where state = 'active' OR state = 'idle' GROUP BY backend_type ORDER BY connections DESC;<\/code><\/pre>\n<p>\u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a\u043e \u0432\u0441\u0435\u043c \u0431\u0430\u0437\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0432\u0430\u0448\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0435 PostgreSQL. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043e\u0434\u043d\u043e\u043c PostgreSQL, \u0442\u043e \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 WHERE \u0441\u0442\u043e\u0438\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c datname = &#8216;\u0412\u0430\u0448\u0430_\u0431\u0430\u0437\u0430_\u0434\u0430\u043d\u043d\u044b\u0445&#8217;.<\/p>\n<h3>2. \u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u044b<\/h3>\n<pre><code class=\"sql\">SELECT pid, age(clock_timestamp(), query_start), usename, query, state FROM pg_stat_activity WHERE state != 'idle' AND query NOT ILIKE '%pg_stat_activity%' ORDER BY query_start desc;<\/code><\/pre>\n<p>\u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u0438\u0445 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u044b\u0448\u0435 \u0441\u043e\u0431\u0440\u0430\u043d\u044b \u043c\u043d\u043e\u0439 \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430 \u043f\u0440\u0438 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u043b\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0432 \u043c\u043e\u0435\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0435\u0449\u0451 \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 PostgreSQL, \u0431\u0443\u0434\u0443 \u0440\u0430\u0434, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0438\u043c\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u043c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442 \u0432\u0430\u0448\u0435 \u0432\u0440\u0435\u043c\u044f.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/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\/post\/696274\/\"> https:\/\/habr.com\/ru\/post\/696274\/<\/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<p>\u0421\u0442\u0430\u0442\u0435\u0439 \u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 PostgreSQL \u0438 \u0435\u0451 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430\u0445 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u043d\u043e\u0433\u043e, \u043d\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0437 \u043d\u0438\u0445 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0431\u0430\u0437\u044b \u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0430\u043c\u0438, \u0432\u043b\u0438\u044f\u044e\u0449\u0438\u043c\u0438 \u043d\u0430 \u0435\u0451 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0430\u043c \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>\u0417\u0430\u0447\u0435\u043c \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c PostgreSQL?<\/h2>\n<p>\u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u043a\u0436\u0435 \u0432\u0430\u0436\u0435\u043d, \u043a\u0430\u043a \u0438 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0432\u0430\u0448\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043e, \u0447\u0435\u043c \u043d\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438:<\/p>\n<ol>\n<li>\n<p>\u041d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u0435\u043d \u043a\u044d\u0448 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445?<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u0431\u043b\u0438\u0446 \u0432 \u0432\u0430\u0448\u0435\u0439 \u0411\u0414?<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043b\u0438 \u0432\u0430\u0448\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u044b?<\/p>\n<\/li>\n<li>\n<p>\u0418 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<\/li>\n<\/ol>\n<h2>\u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0411\u0414 \u0438 \u0435\u0451 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432<\/h2>\n<h3>1. \u0420\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u0431\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432<\/h3>\n<pre><code class=\"sql\">SELECT spcname, pg_size_pretty(pg_tablespace_size(spcname))  FROM pg_tablespace WHERE spcname&lt;>'pg_global';<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0435 \u0432\u0441\u0435\u0445 tablespace \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0432\u0430\u0448\u0435\u0439 \u0411\u0414. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <strong>pg_tablespace_size<\/strong> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0435 tablespace \u0432 \u0431\u0430\u0439\u0442\u0430\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043a \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u043c\u0443 \u0432\u0438\u0434\u0443 \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <strong>pg_size_pretty<\/strong>. \u041f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e pg_global \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0431\u0449\u0438\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432.<\/p>\n<h3>2. \u0420\u0430\u0437\u043c\u0435\u0440 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<pre><code class=\"sql\">SELECT pg_database.datname,        pg_size_pretty(pg_database_size(pg_database.datname)) AS size FROM pg_database ORDER BY pg_database_size(pg_database.datname) DESC;<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0435 \u0432\u0441\u0435\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0432\u0430\u0448\u0435\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 PostgreSQL.<\/p>\n<h3>3. \u0420\u0430\u0437\u043c\u0435\u0440 \u0441\u0445\u0435\u043c \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<pre><code class=\"sql\">SELECT A.schemaname,        pg_size_pretty (SUM(pg_relation_size(C.oid))) as table,         pg_size_pretty (SUM(pg_total_relation_size(C.oid)-pg_relation_size(C.oid))) as index,         pg_size_pretty (SUM(pg_total_relation_size(C.oid))) as table_index,        SUM(n_live_tup) FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C .relnamespace) INNER JOIN pg_stat_user_tables A ON C.relname = A.relname WHERE nspname NOT IN ('pg_catalog', 'information_schema') AND C .relkind &lt;> 'i' AND nspname !~ '^pg_toast' GROUP BY A.schemaname;<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0445\u0435\u043c\u0435 \u0432 \u0432\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445: \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u0441\u0435\u0445 \u0442\u0430\u0431\u043b\u0438\u0446, \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u0441\u0435\u0445 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432, \u043e\u0431\u0449\u0438\u0439 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u0445\u0435\u043c\u044b \u0438 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u0432\u043e \u0432\u0441\u0435\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 \u0441\u0445\u0435\u043c\u044b.<\/p>\n<h3>4. \u0420\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u0431\u043b\u0438\u0446<\/h3>\n<pre><code class=\"sql\">SELECT schemaname,        C.relname AS \"relation\",        pg_size_pretty (pg_relation_size(C.oid)) as table,        pg_size_pretty (pg_total_relation_size (C.oid)-pg_relation_size(C.oid)) as index,        pg_size_pretty (pg_total_relation_size (C.oid)) as table_index,        n_live_tup FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C .relnamespace) LEFT JOIN pg_stat_user_tables A ON C.relname = A.relname WHERE nspname NOT IN ('pg_catalog', 'information_schema') AND C.relkind &lt;> 'i' AND nspname !~ '^pg_toast' ORDER BY pg_total_relation_size (C.oid) DESC<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0435\u0451 \u0441\u0445\u0435\u043c\u044b, \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0431\u0435\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432, \u0440\u0430\u0437\u043c\u0435\u0440\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432, \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435.<\/p>\n<h2>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a<\/h2>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0442\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u0440\u0438\u0441\u043a \u0432\u0437\u0430\u0438\u043c\u043d\u043e\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435. \u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0442\u0430\u043a\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0445 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u041e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u043c\u0435\u0448\u0430\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c\u0441\u044f \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0443 \u0438 \u043d\u0435 \u0434\u0430\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c\u0441\u044f \u0434\u0440\u0443\u0433\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c. \u0411\u043e\u043b\u044c\u0448\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 <a href=\"https:\/\/www.postgresql.org\/docs\/current\/explicit-locking.html\" rel=\"noopener noreferrer nofollow\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>. \u041c\u044b \u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a \u0438 \u0438\u0445 \u0441\u043d\u044f\u0442\u0438\u044f.<\/p>\n<h3>1. \u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a<\/h3>\n<pre><code class=\"sql\">SELECT COALESCE(blockingl.relation::regclass::text, blockingl.locktype) AS locked_item,        now() - blockeda.query_start                                     AS waiting_duration,        blockeda.pid                                                     AS blocked_pid,        blockeda.query                                                   AS blocked_query,        blockedl.mode                                                    AS blocked_mode,        blockinga.pid                                                    AS blocking_pid,        blockinga.query                                                  AS blocking_query,        blockingl.mode                                                   AS blocking_mode FROM pg_locks blockedl JOIN pg_stat_activity blockeda ON blockedl.pid = blockeda.pid JOIN pg_locks blockingl ON (blockingl.transactionid = blockedl.transactionid OR                             blockingl.relation = blockedl.relation AND                             blockingl.locktype = blockedl.locktype) AND blockedl.pid &lt;> blockingl.pid JOIN pg_stat_activity blockinga ON blockingl.pid = blockinga.pid AND blockinga.datid = blockeda.datid WHERE NOT blockedl.granted AND blockinga.datname = current_database();<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u043a\u0435\u043c \u043e\u043d\u0438 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u044b.<\/p>\n<h3>2. \u0421\u043d\u044f\u0442\u0438\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a<\/h3>\n<pre><code class=\"sql\">SELECT pg_cancel_backend(PID_ID); OR SELECT pg_terminate_backend(PID_ID);<\/code><\/pre>\n<p>PID_ID &#8212; \u044d\u0442\u043e ID \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0434\u0440\u0443\u0433\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043e\u0442\u043c\u0435\u043d\u044b \u043e\u0434\u043d\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0447\u0442\u043e\u0431\u044b \u0441\u043d\u044f\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u044e \u043d\u0430\u043a\u043e\u043f\u0438\u0432\u0448\u0443\u044e\u0441\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 <strong>pg_cancel_backend<\/strong> \u0438 <strong>pg_terminate_backend<\/strong> \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e <strong>pg_cancel_backend<\/strong> \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441, \u0430 <strong>pg_terminate_backend<\/strong> \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u0441\u0435\u0430\u043d\u0441 \u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u043e\u043c\u0430\u043d\u0434\u0430 <strong>pg_cancel_backend<\/strong> \u0431\u043e\u043b\u0435\u0435 \u0449\u0430\u0434\u044f\u0449\u0430\u044f \u0438 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0432\u0430\u043c \u0435\u0451 \u0445\u0432\u0430\u0442\u0438\u0442. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <strong>pg_terminate_backend<\/strong>. <\/p>\n<h2>\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u0430\u0448\u0435\u0439 \u0411\u0414<\/h2>\n<h3>1. \u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (Cache Hit Ratio)<\/h3>\n<pre><code class=\"sql\">SELECT sum(heap_blks_read) as heap_read,        sum(heap_blks_hit)  as heap_hit,        sum(heap_blks_hit) \/ (sum(heap_blks_hit) + sum(heap_blks_read)) as ratio FROM    pg_statio_user_tables;  <\/code><\/pre>\n<p>\u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f &#8212; \u044d\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0447\u0442\u0435\u043d\u0438\u044f, \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u043c\u044b\u0439 \u0434\u043e\u043b\u0435\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0447\u0442\u0435\u043d\u0438\u044f \u0438\u0437 \u043a\u044d\u0448\u0430 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043e\u0431\u0449\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0447\u0442\u0435\u043d\u0438\u044f \u043a\u0430\u043a \u0441 \u0434\u0438\u0441\u043a\u0430, \u0442\u0430\u043a \u0438 \u0438\u0437 \u043a\u044d\u0448\u0430. \u0417\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 99% \u0438\u043b\u0438 \u0432\u044b\u0448\u0435, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 99% \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0447\u0442\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0438\u0437 \u043a\u044d\u0448\u0430 \u0438 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 1% &#8212; \u0441 \u0434\u0438\u0441\u043a\u0430.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<h3>2. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432<\/h3>\n<pre><code class=\"sql\">SELECT relname,           100 * idx_scan \/ (seq_scan + idx_scan) percent_of_times_index_used,           n_live_tup rows_in_table  FROM pg_stat_user_tables  WHERE seq_scan + idx_scan > 0  ORDER BY n_live_tup DESC;<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0432 \u0432\u0430\u0448\u0443 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043c\u0435\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0418\u043d\u0434\u0435\u043a\u0441\u044b \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432\u0430\u0436\u043d\u044b \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446. \u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 \u0438 \u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0447\u0442\u0435\u043d\u0438\u0435\u043c \u0431\u0435\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432. \u0418\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u044b \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0430 &#8212; \u044d\u0442\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0431\u043e\u043b\u0435\u0435 10000 \u0441\u0442\u0440\u043e\u043a \u0441 \u043d\u0443\u043b\u0435\u0432\u044b\u043c \u0438\u043b\u0438 \u043d\u0438\u0437\u043a\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u0430.<\/p>\n<h3>3. \u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 (Index Cache Hit Rate)<\/h3>\n<pre><code class=\"sql\">SELECT sum(idx_blks_read) as idx_read,        sum(idx_blks_hit)  as idx_hit,        (sum(idx_blks_hit) - sum(idx_blks_read)) \/ sum(idx_blks_hit) as ratio FROM pg_statio_user_indexes;<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u043e \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432.<\/p>\n<h3>4. \u041d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b<\/h3>\n<pre><code class=\"sql\">SELECT schemaname, relname, indexrelname FROM pg_stat_all_indexes WHERE idx_scan = 0 and schemaname &lt;> 'pg_toast' and  schemaname &lt;> 'pg_catalog'<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u044b, \u043d\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0432 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445.<\/p>\n<h3>5. \u0420\u0430\u0437\u0434\u0443\u0432\u0430\u043d\u0438\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (Database bloat)<\/h3>\n<pre><code class=\"sql\">SELECT   current_database(), schemaname, tablename, \/*reltuples::bigint, relpages::bigint, otta,*\/   ROUND((CASE WHEN otta=0 THEN 0.0 ELSE sml.relpages::float\/otta END)::numeric,1) AS tbloat,   CASE WHEN relpages &lt; otta THEN 0 ELSE bs*(sml.relpages-otta)::BIGINT END AS wastedbytes,   iname, \/*ituples::bigint, ipages::bigint, iotta,*\/   ROUND((CASE WHEN iotta=0 OR ipages=0 THEN 0.0 ELSE ipages::float\/iotta END)::numeric,1) AS ibloat,   CASE WHEN ipages &lt; iotta THEN 0 ELSE bs*(ipages-iotta) END AS wastedibytes FROM (   SELECT     schemaname, tablename, cc.reltuples, cc.relpages, bs,     CEIL((cc.reltuples*((datahdr+ma-       (CASE WHEN datahdr%ma=0 THEN ma ELSE datahdr%ma END))+nullhdr2+4))\/(bs-20::float)) AS otta,     COALESCE(c2.relname,'?') AS iname, COALESCE(c2.reltuples,0) AS ituples, COALESCE(c2.relpages,0) AS ipages,     COALESCE(CEIL((c2.reltuples*(datahdr-12))\/(bs-20::float)),0) AS iotta \/* very rough approximation, assumes all cols *\/   FROM (     SELECT       ma,bs,schemaname,tablename,       (datawidth+(hdr+ma-(case when hdr%ma=0 THEN ma ELSE hdr%ma END)))::numeric AS datahdr,       (maxfracsum*(nullhdr+ma-(case when nullhdr%ma=0 THEN ma ELSE nullhdr%ma END))) AS nullhdr2     FROM (       SELECT         schemaname, tablename, hdr, ma, bs,         SUM((1-null_frac)*avg_width) AS datawidth,         MAX(null_frac) AS maxfracsum,         hdr+(           SELECT 1+count(*)\/8           FROM pg_stats s2           WHERE null_frac&lt;>0 AND s2.schemaname = s.schemaname AND s2.tablename = s.tablename         ) AS nullhdr       FROM pg_stats s, (         SELECT           (SELECT current_setting('block_size')::numeric) AS bs,           CASE WHEN substring(v,12,3) IN ('8.0','8.1','8.2') THEN 27 ELSE 23 END AS hdr,           CASE WHEN v ~ 'mingw32' THEN 8 ELSE 4 END AS ma         FROM (SELECT version() AS v) AS foo       ) AS constants       GROUP BY 1,2,3,4,5     ) AS foo   ) AS rs   JOIN pg_class cc ON cc.relname = rs.tablename   JOIN pg_namespace nn ON cc.relnamespace = nn.oid AND nn.nspname = rs.schemaname AND nn.nspname &lt;> 'information_schema'   LEFT JOIN pg_index i ON indrelid = cc.oid   LEFT JOIN pg_class c2 ON c2.oid = i.indexrelid ) AS sml ORDER BY wastedbytes DESC;<\/code><\/pre>\n<p>\u0420\u0430\u0437\u0434\u0443\u0432\u0430\u043d\u0438\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 &#8212; \u044d\u0442\u043e \u0434\u0438\u0441\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 \u0438\u043b\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u0434\u043b\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u043d\u0435<\/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-340478","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/340478","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=340478"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/340478\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=340478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=340478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=340478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}