{"id":452902,"date":"2025-03-23T15:16:17","date_gmt":"2025-03-23T15:16:17","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=452902"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=452902","title":{"rendered":"<span>\u041f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0439 FDW \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>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0412\u00a0\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u00a0\u0431\u044b\u0441\u0442\u0440\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u043a\u0430\u043a\u00a0\u0443\u0441\u0442\u0440\u043e\u0435\u043d PostgreSQL\u00a0\u2014 \u043e\u0442\u00a0\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u00a0Heap \u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u00a0FSM\/VM \u0434\u043e\u00a0\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0432\u043e\u0435\u0433\u043e FDW \u0441\u00a0\u043a\u043e\u043c\u043f\u0440\u0435\u0441\u0441\u0438\u0435\u0439 \u043d\u0430\u00a0\u0431\u0430\u0437\u0435 zlib. <\/p>\n<h3>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 PostgreSQL<\/h3>\n<h4>Heap: \u043e\u0441\u043d\u043e\u0432\u0430 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 PostgreSQL<\/h4>\n<p>PostgreSQL \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <strong>Heap<\/strong> \u043a\u0430\u043a\u00a0\u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u0430\u0436\u0434\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0432\u00a0\u0432\u0438\u0434\u0435 \u043d\u0430\u0431\u043e\u0440\u0430 \u0431\u043b\u043e\u043a\u043e\u0432 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <strong>8\u00a0\u041a\u0411<\/strong>). \u042d\u0442\u0438 \u0431\u043b\u043e\u043a\u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0432\u00a0\u0444\u0430\u0439\u043b\u0430\u0445 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 PostgreSQL, \u0430\u00a0\u0441\u0430\u043c\u0438 \u0444\u0430\u0439\u043b\u044b \u0438\u043c\u0435\u043d\u0443\u044e\u0442\u0441\u044f \u0432\u00a0\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441\u00a0relfilenode.<\/p>\n<p>\u0417\u0430\u043f\u0438\u0441\u0438 \u0432\u00a0\u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 (\u0438\u043b\u0438 \u00abtuple\u00bb) \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0431\u043b\u043e\u043a\u043e\u0432, \u0430\u00a0\u0434\u043e\u0441\u0442\u0443\u043f \u043a\u00a0\u043d\u0438\u043c \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438. \u041a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f <strong>INSERT, UPDATE \u0438\u043b\u0438\u00a0DELETE<\/strong>, PostgreSQL \u0440\u0435\u0448\u0430\u0435\u0442, \u043a\u0430\u043a\u00a0\u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044f \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e.<\/p>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 8-\u041a\u0411 \u0431\u043b\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445 (\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430, <strong>Page<\/strong>) \u0432\u00a0PostgreSQL \u0438\u043c\u0435\u0435\u0442 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"162\" width=\"162\">\n<p align=\"left\">\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0431\u043b\u043e\u043a\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"162\" width=\"162\">\n<p align=\"left\"><strong>PageHeaderData<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0431\u043b\u043e\u043a\u0430, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"162\" width=\"162\">\n<p align=\"left\"><strong>ItemIdData<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0439, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u043d\u0430\u00a0\u043d\u0430\u0447\u0430\u043b\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432\u00a0\u0431\u043b\u043e\u043a\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"162\" width=\"162\">\n<p align=\"left\"><strong>Tuple Data<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u0430\u043d\u043d\u044b\u0435 (tuple)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"162\" width=\"162\">\n<p align=\"left\"><strong>Free Space<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u0434\u043b\u044f\u00a0\u043d\u043e\u0432\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0432\u00a0PostgreSQL \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437\u00a0\u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0438 \u0441\u0430\u043c\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"110\" width=\"110\">\n<p align=\"left\">\u041f\u043e\u043b\u0435<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"110\" width=\"110\">\n<p align=\"left\">xmin<\/p>\n<\/td>\n<td>\n<p align=\"left\">ID \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0437\u0434\u0430\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u044c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"110\" width=\"110\">\n<p align=\"left\">xmax<\/p>\n<\/td>\n<td>\n<p align=\"left\">ID \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0434\u0430\u043b\u0438\u043b\u0430\/\u043e\u0431\u043d\u043e\u0432\u0438\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u044c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"110\" width=\"110\">\n<p align=\"left\">ctid<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430\u00a0\u0441\u0430\u043c\u0443 \u0437\u0430\u043f\u0438\u0441\u044c (\u0438\u043b\u0438 \u043d\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e, \u0435\u0441\u043b\u0438\u00a0\u0431\u044b\u043b UPDATE)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"110\" width=\"110\">\n<p align=\"left\">data<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>PostgreSQL \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <strong>MVCC<\/strong>, \u0447\u0442\u043e\u00a0\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e\u00a0UPDATE \u0438 DELETE \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435\u00a0\u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u0430\u00a0\u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u043d\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e. \u042d\u0442\u043e \u0432\u0435\u0434\u0435\u0442 \u043a\u00a0\u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u044e \u043c\u0443\u0441\u043e\u0440\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0447\u0442\u043e\u00a0\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f <strong>VACUUM<\/strong>, \u0447\u0442\u043e\u0431\u044b \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u044c \u043c\u0435\u0441\u0442\u043e.<\/p>\n<p>\u041a\u0430\u043a\u00a0\u0443\u0437\u043d\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0431\u043b\u043e\u043a\u043e\u0432 \u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0432\u00a0PostgreSQL:<\/p>\n<pre><code class=\"sql\">SELECT pg_relation_size('your_table'); -- \u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 \u0431\u0430\u0439\u0442\u0430\u0445 SELECT relpages FROM pg_class WHERE relname = 'your_table'; -- \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446<\/code><\/pre>\n<h4>Free Space Map (FSM)<\/h4>\n<p>Free Space Map (FSM)\u00a0\u2014 \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c PostgreSQL, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 <strong>\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u043c \u043c\u0435\u0441\u0442\u043e\u043c \u0432\u00a0\u0431\u043b\u043e\u043a\u0430\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/strong>. \u041a\u043e\u0433\u0434\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f <strong>INSERT<\/strong>, PostgreSQL \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a\u00a0FSM, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438, \u0433\u0434\u0435 \u0435\u0441\u0442\u044c \u043c\u0435\u0441\u0442\u043e \u0434\u043b\u044f\u00a0\u0437\u0430\u043f\u0438\u0441\u0438, \u0430\u00a0\u043d\u0435\u00a0\u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u0442 \u0432\u0441\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443.<\/p>\n<p>FSM\u00a0\u2014 \u044d\u0442\u043e \u0431\u0438\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0440\u0442\u0430, \u0433\u0434\u0435 \u0434\u043b\u044f\u00a0\u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e\u00a0\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435:<\/p>\n<ul>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432\u00a0\u0431\u043b\u043e\u043a\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u0435\u0441\u0442\u0430\u00a0\u2014 FSM \u043e\u0442\u043c\u0435\u0447\u0430\u0435\u0442 \u0435\u0433\u043e \u043a\u0430\u043a \u00ab\u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0439\u00bb.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0431\u043b\u043e\u043a \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u00a0\u2014 \u043e\u043d \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0438\u0437\u00a0FSM.<\/p>\n<\/li>\n<li>\n<p><strong>VACUUM<\/strong> \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 FSM, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044f, \u043a\u0430\u043a\u0438\u0435 \u0431\u043b\u043e\u043a\u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u043c\u0435\u044e\u0442 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e.<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0430\u043a\u00a0\u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 FSM:<\/p>\n<pre><code class=\"sql\">SELECT pg_freespace('your_table');<\/code><\/pre>\n<p>\u042d\u0442\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043f\u043e\u043a\u0430\u0436\u0435\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0432\u00a0\u043a\u0430\u0436\u0434\u043e\u043c \u0431\u043b\u043e\u043a\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<h4>Visibility Map (VM)<\/h4>\n<p>Visibility Map\u00a0\u2014 \u044d\u0442\u043e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0445\u0440\u0430\u043d\u0438\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u00a0\u0442\u043e\u043c, \u043a\u0430\u043a\u0438\u0435 \u0431\u043b\u043e\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 <strong>\u043d\u0435\u00a0\u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u0440\u0438\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 VACUUM \u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u043e\u0433\u043e \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/strong>.<\/p>\n<p><strong>\u0417\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u0435\u043d VM:<\/strong><\/p>\n<ol>\n<li>\n<p><strong>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f VACUUM:<\/strong> \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432\u00a0\u0431\u043b\u043e\u043a\u0435 \u0443\u0436\u0435 \u0432\u0438\u0434\u0438\u043c\u044b \u0434\u043b\u044f\u00a0\u0432\u0441\u0435\u0445 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439, VACUUM \u043c\u043e\u0436\u0435\u0442 <strong>\u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a<\/strong>, \u0441\u043d\u0438\u0436\u0430\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043d\u0430\u00a0\u0434\u0438\u0441\u043a.<\/p>\n<\/li>\n<li>\n<p><strong>\u0423\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u043e\u0433\u043e \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/strong> \u0435\u0441\u043b\u0438 \u0431\u043b\u043e\u043a \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u00ab\u0432\u0438\u0434\u0438\u043c\u044b\u0439\u00bb, PostgreSQL \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 xmin\/xmax, \u0443\u0441\u043a\u043e\u0440\u044f\u044f SELECT\u2011\u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u0430\u043a\u00a0\u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441 Visibility Map:<\/p>\n<pre><code class=\"sql\">SELECT relallvisible FROM pg_class WHERE relname = 'your_table';<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 <code>relallvisible &gt; 0<\/code>, \u0437\u043d\u0430\u0447\u0438\u0442 \u0432\u00a0\u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0435\u0441\u0442\u044c \u0431\u043b\u043e\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 <strong>\u043d\u0435\u00a0\u0442\u0440\u0435\u0431\u0443\u044e\u0442 VACUUM<\/strong>.<\/p>\n<h4>pg_filenode<\/h4>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u0438\u043d\u0434\u0435\u043a\u0441 \u0438\u043b\u0438\u00a0\u0434\u0440\u0443\u0433\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043a\u0430\u043a <strong>\u0444\u0430\u0439\u043b \u0432\u00a0\u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435<\/strong>. PostgreSQL \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u0442\u0438\u043c \u0441\u00a0\u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>pg_filenode<\/code>.<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"143\" width=\"143\">\n<p align=\"left\">\u041a\u043e\u043c\u0430\u043d\u0434\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"143\" width=\"143\">\n<p align=\"left\">oid<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"143\" width=\"143\">\n<p align=\"left\">relfilenode<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0418\u043c\u044f \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u0432\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"143\" width=\"143\">\n<p align=\"left\">relpages<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0432\u00a0\u0444\u0430\u0439\u043b\u0435<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041a\u0430\u043a\u00a0\u0443\u0437\u043d\u0430\u0442\u044c, \u0432\u00a0\u043a\u0430\u043a\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430:<\/p>\n<pre><code class=\"sql\">SELECT oid, relfilenode, relname FROM pg_class WHERE relname = 'your_table';<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 <strong>pg_filenode<\/strong> \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043f\u043e\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0444\u0430\u0439\u043b \u0432\u00a0\u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0424\u0430\u0439\u043b\u044b \u0441\u00a0\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u00a0\u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 <code>PGDATA\/base\/&lt;database_oid&gt;\/<\/code>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code>ls $PGDATA\/base\/16384\/<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 <code>relfilenode <\/code>\u0442\u0430\u0431\u043b\u0438\u0446\u044b <strong>12\u00a0345<\/strong>, \u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432\u00a0\u0444\u0430\u0439\u043b\u0435 <code>$PGDATA\/base\/16384\/12345<\/code>.<\/p>\n<h4>Foreign Data Wrapper (FDW)<\/h4>\n<p><strong>FDW <\/strong>\u2014 \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 PostgreSQL \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 <strong>\u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0437\u0430\u00a0\u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f<\/strong>.<\/p>\n<p>FDW\u00a0\u2014 \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0445\u0443\u043a\u2011\u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c PostgreSQL \u043f\u0440\u0438\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439:<\/p>\n<ul>\n<li>\n<p><strong>\u0427\u0442\u0435\u043d\u0438\u0435 (SELECT)<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u0417\u0430\u043f\u0438\u0441\u044c (INSERT, UPDATE, DELETE)<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 (Foreign Scan)<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (Planner Hook)<\/strong><\/p>\n<\/li>\n<\/ul>\n<p>FDW \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c <strong>\u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 backend<\/strong>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<ul>\n<li>\n<p>\u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 <strong>\u0434\u0440\u0443\u0433\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435<\/strong> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u00a0\u043a\u043e\u043c\u043f\u0440\u0435\u0441\u0441\u0438\u0435\u0439).<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a <strong>\u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\u043c<\/strong> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u00a0NoSQL \u0438\u043b\u0438\u00a0\u043e\u0431\u043b\u0430\u0447\u043d\u043e\u043c\u0443 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0443).<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 <strong>\u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f<\/strong> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0444\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430, \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043f\u043e\u0434\u00a0\u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438).<\/p>\n<\/li>\n<\/ul>\n<h3>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e FDW<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043d\u0430\u00a0\u044f\u0437\u044b\u043a\u0435 C, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 FDW. \u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0438\u0437\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u0414\u043b\u044f\u00a0\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f. \u041f\u0440\u043e\u0435\u043a\u0442 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u0444\u0430\u0439\u043b\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><code>custom_fdw.c<\/code>\u00a0\u2014 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u0434 FDW.<\/p>\n<\/li>\n<li>\n<p><code>Makefile<\/code>\u00a0\u2014 \u0434\u043b\u044f\u00a0\u0441\u0431\u043e\u0440\u043a\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><code>custom_fdw.control<\/code>\u00a0\u2014 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f\u00a0PostgreSQL.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441\u00a0\u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 <code>custom_fdw.c<\/code>:<\/p>\n<pre><code class=\"cs\">#include \"postgres.h\" #include \"fmgr.h\" #include \"access\/reloptions.h\" #include \"foreign\/fdwapi.h\" #include \"foreign\/foreign.h\" #include \"utils\/elog.h\" #include \"catalog\/pg_type.h\" #include \"commands\/explain.h\" #include \"executor\/executor.h\" #include \"utils\/builtins.h\" #include \"nodes\/pg_list.h\" #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt;  \/* \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f FDW *\/ typedef struct CustomFdwState {     char *storage_path;     FILE *data_file; } CustomFdwState;  \/* \u041f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u044b \u043d\u0430\u0448\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 FDW *\/ extern Datum custom_fdw_handler(PG_FUNCTION_ARGS); extern Datum custom_fdw_validator(PG_FUNCTION_ARGS);  static void customBeginForeignScan(ForeignScanState *node, int eflags); static TupleTableSlot *customIterateForeignScan(ForeignScanState *node); static void customEndForeignScan(ForeignScanState *node); static void customReScanForeignScan(ForeignScanState *node);  \/* \u0417\u0434\u0435\u0441\u044c \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u044b \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0432\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f *\/ static void customGetForeignRelSize(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid); static void customGetForeignPaths(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid); static ForeignScan *customGetForeignPlan(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid,                                          ForeignPath *best_path, List *tlist, List *scan_clauses);<\/code><\/pre>\n<p>\u0421\u0430\u043c\u0430\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0434\u043e\u043b\u0436\u0435\u043d \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c FDW\u00a0\u2014 \u044d\u0442\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 FdwRoutine \u0441\u00a0\u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0432\u0441\u0435\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432:<\/p>\n<pre><code class=\"cs\">PG_MODULE_MAGIC;  PG_FUNCTION_INFO_V1(custom_fdw_handler); PG_FUNCTION_INFO_V1(custom_fdw_validator);  Datum custom_fdw_handler(PG_FUNCTION_ARGS) {     FdwRoutine *fdw_routine = makeNode(FdwRoutine);      \/* \u041f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0448\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a FDW *\/     fdw_routine-&gt;GetForeignRelSize = customGetForeignRelSize;     fdw_routine-&gt;GetForeignPaths = customGetForeignPaths;     fdw_routine-&gt;GetForeignPlan = customGetForeignPlan;     fdw_routine-&gt;BeginForeignScan = customBeginForeignScan;     fdw_routine-&gt;IterateForeignScan = customIterateForeignScan;     fdw_routine-&gt;ReScanForeignScan = customReScanForeignScan;     fdw_routine-&gt;EndForeignScan = customEndForeignScan;      PG_RETURN_POINTER(fdw_routine); }  \/* \u041f\u0440\u043e\u0441\u0442\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u043f\u0446\u0438\u0439 *\/ Datum custom_fdw_validator(PG_FUNCTION_ARGS) {     \/* \u0417\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043e\u043f\u0446\u0438\u0439, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u0432 CREATE SERVER \u0438\u043b\u0438 FOREIGN TABLE *\/     PG_RETURN_VOID(); }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a\u00a0\u043e\u0441\u043d\u043e\u0432\u0435 \u043d\u0430\u0448\u0435\u0433\u043e FDW\u00a0\u2014 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c \u0447\u0442\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u0417\u0434\u0435\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>customBeginForeignScan <\/code>\u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0444\u0430\u0439\u043b, \u0432\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445. <\/p>\n<pre><code class=\"cs\">static void customBeginForeignScan(ForeignScanState *node, int eflags) {     CustomFdwState *state = palloc(sizeof(CustomFdwState));      \/* \u041f\u0443\u0441\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u043f\u0446\u0438\u044f, \u043d\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u0435\u0433\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 *\/     state-&gt;storage_path = \"data\/custom_storage.dat\";      state-&gt;data_file = fopen(state-&gt;storage_path, \"rb\");     if (state-&gt;data_file == NULL)         elog(ERROR, \"\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0444\u0430\u0439\u043b \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430: %s\", state-&gt;storage_path);      \/* \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 FDW *\/     node-&gt;fdw_state = (void *) state; }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>customIterateForeignScan <\/code>\u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430\u00a0\u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u00a0\u0432\u0438\u0434\u0435 <code>tuple<\/code>. \u0422\u0443\u0442 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u044b\u0440\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u00a0\u0444\u043e\u0440\u043c\u0430\u0442, \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 PostgreSQL.<\/p>\n<pre><code class=\"cs\">static TupleTableSlot * customIterateForeignScan(ForeignScanState *node) {     CustomFdwState *state = (CustomFdwState *) node-&gt;fdw_state;     TupleTableSlot *slot = node-&gt;ss.ss_ScanTupleSlot;     bool eof = false;     char buffer[1024];      \/* \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 *\/     if (fgets(buffer, sizeof(buffer), state-&gt;data_file) == NULL)         eof = true;      if (eof)     {         ExecClearTuple(slot);         return slot;     }          \/* \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u0437\u0430\u043f\u044f\u0442\u044b\u043c\u0438, \u0438 \u0443 \u043d\u0430\u0441 \u0434\u0432\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u0430:        \u043f\u0435\u0440\u0432\u044b\u0439 \u2013 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0432\u0442\u043e\u0440\u043e\u0439 \u2013 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435 *\/     char *token = strtok(buffer, \",\");     if (token == NULL)     {         elog(WARNING, \"\u041d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u0441\u0442\u0440\u043e\u043a\u0438: %s\", buffer);         ExecClearTuple(slot);         return slot;     }     int col1 = atoi(token);      token = strtok(NULL, \",\");     char *col2 = token ? pstrdup(token) : NULL;     if (col2 &amp;&amp; col2[strlen(col2)-1] == '\\n')         col2[strlen(col2)-1] = '\\0';      \/* \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 Datum \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u0444\u043b\u0430\u0433\u043e\u0432 isnull *\/     Datum values[2];     bool nulls[2] = {false, false};      values[0] = Int32GetDatum(col1);     values[1] = CStringGetTextDatum(col2);      \/* \u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c tuple *\/     slot = ExecClearTuple(slot);     slot = ExecStoreTuple(heap_form_tuple(slot-&gt;tts_tupleDescriptor, values, nulls), slot, false);      return slot; }<\/code><\/pre>\n<p>\u041d\u0435\u00a0\u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043e\u00a0\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u00a0\u2014 \u043e\u043d\u0430 \u043d\u0443\u0436\u043d\u0430 \u0434\u043b\u044f\u00a0\u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0430 \u043f\u043e\u00a0\u0434\u0430\u043d\u043d\u044b\u043c, \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f\u00a0\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0433\u043e \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"cs\">static void customReScanForeignScan(ForeignScanState *node) {     CustomFdwState *state = (CustomFdwState *) node-&gt;fdw_state;     rewind(state-&gt;data_file);  \/\/ \u041f\u0435\u0440\u0435\u043c\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0432 \u043d\u0430\u0447\u0430\u043b\u043e }  static void customEndForeignScan(ForeignScanState *node) {     CustomFdwState *state = (CustomFdwState *) node-&gt;fdw_state;     if (state)     {         if (state-&gt;data_file)             fclose(state-&gt;data_file);         pfree(state);     } }<\/code><\/pre>\n<p>\u0414\u043b\u044f\u00a0\u043f\u043e\u043b\u043d\u043e\u0442\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u044b \u0441\u0442\u043e\u0438\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442\u00a0\u0431\u044b\u0442\u044c \u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0430\u043c\u0438, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435\u00a0\u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430\u00a0\u0443\u0440\u043e\u0432\u043d\u0435 FDW:<\/p>\n<pre><code class=\"dart\">static void customGetForeignRelSize(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid) {     \/* \u0417\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u043d\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a, \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0442.\u0434.        \u041f\u043e\u043a\u0430 \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043f\u0443\u0441\u0442\u044b\u0448\u043a\u0443 *\/ }  static void customGetForeignPaths(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid) {     \/* \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u043b\u0430\u043d \u043e\u0431\u0445\u043e\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 *\/     add_path(baserel, (Path *) create_foreignscan_path(root, baserel,                    NULL,  \/* default pathtarget *\/                    baserel-&gt;rows,                    10.0,  \/* \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c *\/                    0,     \/* startup cost *\/                    baserel-&gt;rows,  \/* total cost *\/                    NIL,   \/* no extra plan *\/                    NULL,  \/* no fdw_private data *\/                    NIL)); }  static ForeignScan * customGetForeignPlan(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid,                      ForeignPath *best_path, List *tlist, List *scan_clauses) {     \/* \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u043b\u0438\u0448\u043d\u0438\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u044b *\/     List *fdw_private = NIL;     scan_clauses = extract_actual_clauses(scan_clauses, false);      return make_foreignscan(tlist, scan_clauses, baserel-&gt;relid, NIL, fdw_private,                             NIL, NIL, NIL); }<\/code><\/pre>\n<h3>\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c \u043a\u043e\u043c\u043f\u0440\u0435\u0441\u0441\u0438\u0438 \u043d\u0430 \u0431\u0430\u0437\u0435 zlib<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u043c \u0437\u0430\u0434\u0430\u0447\u0443\u00a0\u2014 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0436\u0430\u0442\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. <\/p>\n<p>\u0411\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <strong>zlib<\/strong>. \u0424\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0436\u0438\u043c\u0430\u0435\u0442 \u0432\u0445\u043e\u0434\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443:<\/p>\n<pre><code class=\"cs\">#include &lt;zlib.h&gt;  #define CHUNK 16384  \/* \u0424\u0443\u043d\u043a\u0446\u0438\u044f compress_data \u0441\u0436\u0438\u043c\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 input \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0441\u0436\u0430\u0442\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 output *\/ int compress_data(const char *input, size_t input_len, char **output, size_t *output_len) {     int ret;     int flush;     unsigned have;     z_stream strm;     unsigned char out[CHUNK];     size_t total_written = 0;     size_t allocated = CHUNK;          *output = palloc(allocated);      \/* \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f zlib *\/     strm.zalloc = Z_NULL;     strm.zfree = Z_NULL;     strm.opaque = Z_NULL;     ret = deflateInit(&amp;strm, Z_DEFAULT_COMPRESSION);     if (ret != Z_OK)         return ret;      strm.avail_in = input_len;     strm.next_in = (unsigned char *) input;      do {         strm.avail_out = CHUNK;         strm.next_out = out;         flush = (strm.avail_in == 0) ? Z_FINISH : Z_NO_FLUSH;         ret = deflate(&amp;strm, flush);         if (ret == Z_STREAM_ERROR) {             deflateEnd(&amp;strm);             return ret;         }         have = CHUNK - strm.avail_out;         if (total_written + have &gt; allocated)         {             allocated *= 2;             *output = repalloc(*output, allocated);         }         memcpy(*output + total_written, out, have);         total_written += have;     } while (flush != Z_FINISH);          deflateEnd(&amp;strm);     *output_len = total_written;     return Z_OK; }<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0441\u0436\u0430\u0442\u0438\u044f \u0438\u0437\u00a0zlib. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0436\u0438\u043c\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u00a0\u0431\u043b\u043e\u043a\u0430\u043c, \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u044f \u0431\u0443\u0444\u0435\u0440, \u0435\u0441\u043b\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f. <\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043d\u0435\u00a0\u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u043e\u00a0\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0438\u0445 \u0432\u00a0\u0444\u0430\u0439\u043b\u043e\u0432\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u00a0\u043a\u043e\u043c\u043f\u0440\u0435\u0441\u0441\u0438\u0435\u0439. \u0414\u043b\u044f\u00a0\u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 INSERT \u0447\u0435\u0440\u0435\u0437 FDW:<\/p>\n<pre><code class=\"cs\">static void customInsertData(const char *data) {     char *compressed;     size_t compressed_len;          if (compress_data(data, strlen(data), &amp;compressed, &amp;compressed_len) != Z_OK)         elog(ERROR, \"\u041e\u0448\u0438\u0431\u043a\u0430 \u0441\u0436\u0430\u0442\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445\");      \/* \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 (append binary) *\/     FILE *fp = fopen(\"data\/custom_storage.dat\", \"ab\");     if (!fp)         elog(ERROR, \"\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438: data\/custom_storage.dat\"); static void customInsertData(const char *data) {     char *compressed;     size_t compressed_len;          if (compress_data(data, strlen(data), &amp;compressed, &amp;compressed_len) != Z_OK)         elog(ERROR, \"\u041e\u0448\u0438\u0431\u043a\u0430 \u0441\u0436\u0430\u0442\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445\");      \/* \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 (append binary) *\/     FILE *fp = fopen(\"data\/custom_storage.dat\", \"ab\");     if (!fp)         elog(ERROR, \"\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438: data\/custom_storage.dat\");          if (fwrite(compressed, 1, compressed_len, fp) != compressed_len)         elog(ERROR, \"\u041e\u0448\u0438\u0431\u043a\u0430 \u0437\u0430\u043f\u0438\u0441\u0438 \u0441\u0436\u0430\u0442\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0444\u0430\u0439\u043b\");      fclose(fp);     pfree(compressed); }          if (fwrite(compressed, 1, compressed_len, fp) != compressed_len)         elog(ERROR, \"\u041e\u0448\u0438\u0431\u043a\u0430 \u0437\u0430\u043f\u0438\u0441\u0438 \u0441\u0436\u0430\u0442\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0444\u0430\u0439\u043b\");      fclose(fp);     pfree(compressed); }<\/code><\/pre>\n<p>\u041a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u00a0\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 INSERT\u2011\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u0447\u0442\u043e\u0431\u044b \u043b\u044e\u0431\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u0432\u00a0\u043d\u0430\u0448\u0443 \u0444\u0430\u0439\u043b\u043e\u0432\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0436\u0438\u043c\u0430\u043b\u0438\u0441\u044c. <\/p>\n<hr\/>\n<p>\u0410\u00a0\u043a\u0430\u043a \u043d\u0430\u0441\u0447\u0435\u0442 \u0432\u0430\u0441? \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u00a0\u043b\u0438 \u0432\u044b \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b, \u0438 \u043a\u0430\u043a\u043e\u0439 \u0443\u00a0\u0432\u0430\u0441 \u043e\u043f\u044b\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u00a0\u044d\u0442\u0438\u043c? \u0414\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0432\u00a0\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.<\/p>\n<p><em>24 \u043c\u0430\u0440\u0442\u0430 \u0432 Otus \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0443\u0440\u043e\u043a \u00ab\u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u0432 PostgreSQL\u00bb. \u041d\u0430 \u043d\u0435\u043c \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 PostgreSQL: \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u0435 (SSL\/TLS), \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u0430 (pg_hba.conf, \u0440\u043e\u043b\u0438, RLS) \u0438 \u0430\u0443\u0434\u0438\u0442 (pg_audit). \u0423\u0437\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u0437\u0430\u0449\u0438\u0442\u0438\u0442\u044c\u0441\u044f \u043e\u0442 SQL-\u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0439 \u0438 DDoS-\u0430\u0442\u0430\u043a. \u041d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435. <\/em><a href=\"https:\/\/otus.pw\/SYlT\/\"><em>\u0417\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435.<\/em><\/a><\/p>\n<\/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\/889876\/\"> https:\/\/habr.com\/ru\/articles\/889876\/<\/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>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0412\u00a0\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u00a0\u0431\u044b\u0441\u0442\u0440\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u043a\u0430\u043a\u00a0\u0443\u0441\u0442\u0440\u043e\u0435\u043d PostgreSQL\u00a0\u2014 \u043e\u0442\u00a0\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u00a0Heap \u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u00a0FSM\/VM \u0434\u043e\u00a0\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0432\u043e\u0435\u0433\u043e FDW \u0441\u00a0\u043a\u043e\u043c\u043f\u0440\u0435\u0441\u0441\u0438\u0435\u0439 \u043d\u0430\u00a0\u0431\u0430\u0437\u0435 zlib. <\/p>\n<h3>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 PostgreSQL<\/h3>\n<h4>Heap: \u043e\u0441\u043d\u043e\u0432\u0430 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 PostgreSQL<\/h4>\n<p>PostgreSQL \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <strong>Heap<\/strong> \u043a\u0430\u043a\u00a0\u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u0430\u0436\u0434\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0432\u00a0\u0432\u0438\u0434\u0435 \u043d\u0430\u0431\u043e\u0440\u0430 \u0431\u043b\u043e\u043a\u043e\u0432 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <strong>8\u00a0\u041a\u0411<\/strong>). \u042d\u0442\u0438 \u0431\u043b\u043e\u043a\u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0432\u00a0\u0444\u0430\u0439\u043b\u0430\u0445 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 PostgreSQL, \u0430\u00a0\u0441\u0430\u043c\u0438 \u0444\u0430\u0439\u043b\u044b \u0438\u043c\u0435\u043d\u0443\u044e\u0442\u0441\u044f \u0432\u00a0\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441\u00a0relfilenode.<\/p>\n<p>\u0417\u0430\u043f\u0438\u0441\u0438 \u0432\u00a0\u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 (\u0438\u043b\u0438 \u00abtuple\u00bb) \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0431\u043b\u043e\u043a\u043e\u0432, \u0430\u00a0\u0434\u043e\u0441\u0442\u0443\u043f \u043a\u00a0\u043d\u0438\u043c \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438. \u041a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f <strong>INSERT, UPDATE \u0438\u043b\u0438\u00a0DELETE<\/strong>, PostgreSQL \u0440\u0435\u0448\u0430\u0435\u0442, \u043a\u0430\u043a\u00a0\u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044f \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e.<\/p>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 8-\u041a\u0411 \u0431\u043b\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445 (\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430, <strong>Page<\/strong>) \u0432\u00a0PostgreSQL \u0438\u043c\u0435\u0435\u0442 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"162\" width=\"162\">\n<p align=\"left\">\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0431\u043b\u043e\u043a\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"162\" width=\"162\">\n<p align=\"left\"><strong>PageHeaderData<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0431\u043b\u043e\u043a\u0430, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"162\" width=\"162\">\n<p align=\"left\"><strong>ItemIdData<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0439, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u043d\u0430\u00a0\u043d\u0430\u0447\u0430\u043b\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432\u00a0\u0431\u043b\u043e\u043a\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"162\" width=\"162\">\n<p align=\"left\"><strong>Tuple Data<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u0430\u043d\u043d\u044b\u0435 (tuple)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"162\" width=\"162\">\n<p align=\"left\"><strong>Free Space<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u0434\u043b\u044f\u00a0\u043d\u043e\u0432\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0432\u00a0PostgreSQL \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437\u00a0\u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0438 \u0441\u0430\u043c\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"110\" width=\"110\">\n<p align=\"left\">\u041f\u043e\u043b\u0435<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"110\" width=\"110\">\n<p align=\"left\">xmin<\/p>\n<\/td>\n<td>\n<p align=\"left\">ID \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0437\u0434\u0430\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u044c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"110\" width=\"110\">\n<p align=\"left\">xmax<\/p>\n<\/td>\n<td>\n<p align=\"left\">ID \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0434\u0430\u043b\u0438\u043b\u0430\/\u043e\u0431\u043d\u043e\u0432\u0438\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u044c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"110\" width=\"110\">\n<p align=\"left\">ctid<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430\u00a0\u0441\u0430\u043c\u0443 \u0437\u0430\u043f\u0438\u0441\u044c (\u0438\u043b\u0438 \u043d\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e, \u0435\u0441\u043b\u0438\u00a0\u0431\u044b\u043b UPDATE)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"110\" width=\"110\">\n<p align=\"left\">data<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>PostgreSQL \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <strong>MVCC<\/strong>, \u0447\u0442\u043e\u00a0\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e\u00a0UPDATE \u0438 DELETE \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435\u00a0\u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u0430\u00a0\u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u043d\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e. \u042d\u0442\u043e \u0432\u0435\u0434\u0435\u0442 \u043a\u00a0\u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u044e \u043c\u0443\u0441\u043e\u0440\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0447\u0442\u043e\u00a0\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f <strong>VACUUM<\/strong>, \u0447\u0442\u043e\u0431\u044b \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u044c \u043c\u0435\u0441\u0442\u043e.<\/p>\n<p>\u041a\u0430\u043a\u00a0\u0443\u0437\u043d\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0431\u043b\u043e\u043a\u043e\u0432 \u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0432\u00a0PostgreSQL:<\/p>\n<pre><code class=\"sql\">SELECT pg_relation_size('your_table'); -- \u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 \u0431\u0430\u0439\u0442\u0430\u0445 SELECT relpages FROM pg_class WHERE relname = 'your_table'; -- \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446<\/code><\/pre>\n<h4>Free Space Map (FSM)<\/h4>\n<p>Free Space Map (FSM)\u00a0\u2014 \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c PostgreSQL, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 <strong>\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u043c \u043c\u0435\u0441\u0442\u043e\u043c \u0432\u00a0\u0431\u043b\u043e\u043a\u0430\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/strong>. \u041a\u043e\u0433\u0434\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f <strong>INSERT<\/strong>, PostgreSQL \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a\u00a0FSM, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438, \u0433\u0434\u0435 \u0435\u0441\u0442\u044c \u043c\u0435\u0441\u0442\u043e \u0434\u043b\u044f\u00a0\u0437\u0430\u043f\u0438\u0441\u0438, \u0430\u00a0\u043d\u0435\u00a0\u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u0442 \u0432\u0441\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443.<\/p>\n<p>FSM\u00a0\u2014 \u044d\u0442\u043e \u0431\u0438\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0440\u0442\u0430, \u0433\u0434\u0435 \u0434\u043b\u044f\u00a0\u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e\u00a0\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435:<\/p>\n<ul>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432\u00a0\u0431\u043b\u043e\u043a\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u0435\u0441\u0442\u0430\u00a0\u2014 FSM \u043e\u0442\u043c\u0435\u0447\u0430\u0435\u0442 \u0435\u0433\u043e \u043a\u0430\u043a \u00ab\u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0439\u00bb.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0431\u043b\u043e\u043a \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u00a0\u2014 \u043e\u043d \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0438\u0437\u00a0FSM.<\/p>\n<\/li>\n<li>\n<p><strong>VACUUM<\/strong> \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 FSM, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044f, \u043a\u0430\u043a\u0438\u0435 \u0431\u043b\u043e\u043a\u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u043c\u0435\u044e\u0442 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e.<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0430\u043a\u00a0\u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 FSM:<\/p>\n<pre><code class=\"sql\">SELECT pg_freespace('your_table');<\/code><\/pre>\n<p>\u042d\u0442\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043f\u043e\u043a\u0430\u0436\u0435\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0432\u00a0\u043a\u0430\u0436\u0434\u043e\u043c \u0431\u043b\u043e\u043a\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<h4>Visibility Map (VM)<\/h4>\n<p>Visibility Map\u00a0\u2014 \u044d\u0442\u043e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0445\u0440\u0430\u043d\u0438\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u00a0\u0442\u043e\u043c, \u043a\u0430\u043a\u0438\u0435 \u0431\u043b\u043e\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 <strong>\u043d\u0435\u00a0\u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u0440\u0438\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 VACUUM \u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u043e\u0433\u043e \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/strong>.<\/p>\n<p><strong>\u0417\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u0435\u043d VM:<\/strong><\/p>\n<ol>\n<li>\n<p><strong>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f VACUUM:<\/strong> \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432\u00a0\u0431\u043b\u043e\u043a\u0435 \u0443\u0436\u0435 \u0432\u0438\u0434\u0438\u043c\u044b \u0434\u043b\u044f\u00a0\u0432\u0441\u0435\u0445 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439, VACUUM \u043c\u043e\u0436\u0435\u0442 <strong>\u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a<\/strong>, \u0441\u043d\u0438\u0436\u0430\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043d\u0430\u00a0\u0434\u0438\u0441\u043a.<\/p>\n<\/li>\n<li>\n<p><strong>\u0423\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u043e\u0433\u043e \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/strong> \u0435\u0441\u043b\u0438 \u0431\u043b\u043e\u043a \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u00ab\u0432\u0438\u0434\u0438\u043c\u044b\u0439\u00bb, PostgreSQL \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 xmin\/xmax, \u0443\u0441\u043a\u043e\u0440\u044f\u044f SELECT\u2011\u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u0430\u043a\u00a0\u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441 Visibility Map:<\/p>\n<pre><code class=\"sql\">SELECT relallvisible FROM pg_class WHERE relname = 'your_table';<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 <code>relallvisible &gt; 0<\/code>, \u0437\u043d\u0430\u0447\u0438\u0442 \u0432\u00a0\u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0435\u0441\u0442\u044c \u0431\u043b\u043e\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 <strong>\u043d\u0435\u00a0\u0442\u0440\u0435\u0431\u0443\u044e\u0442 VACUUM<\/strong>.<\/p>\n<h4>pg_filenode<\/h4>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u0438\u043d\u0434\u0435\u043a\u0441 \u0438\u043b\u0438\u00a0\u0434\u0440\u0443\u0433\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043a\u0430\u043a <strong>\u0444\u0430\u0439\u043b \u0432\u00a0\u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435<\/strong>. PostgreSQL \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u0442\u0438\u043c \u0441\u00a0\u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>pg_filenode<\/code>.<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"143\" width=\"143\">\n<p align=\"left\">\u041a\u043e\u043c\u0430\u043d\u0434\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"143\" width=\"143\">\n<p align=\"left\">oid<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"143\" width=\"143\">\n<p align=\"left\">relfilenode<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0418\u043c\u044f \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u0432\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"143\" width=\"143\">\n<p align=\"left\">relpages<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0432\u00a0\u0444\u0430\u0439\u043b\u0435<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041a\u0430\u043a\u00a0\u0443\u0437\u043d\u0430\u0442\u044c, \u0432\u00a0\u043a\u0430\u043a\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430:<\/p>\n<pre><code class=\"sql\">SELECT oid, relfilenode, relname FROM pg_class WHERE relname = 'your_table';<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 <strong>pg_filenode<\/strong> \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043f\u043e\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0444\u0430\u0439\u043b \u0432\u00a0\u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0424\u0430\u0439\u043b\u044b \u0441\u00a0\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u00a0\u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 <code>PGDATA\/base\/&lt;database_oid&gt;\/<\/code>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code>ls $PGDATA\/base\/16384\/<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 <code>relfilenode <\/code>\u0442\u0430\u0431\u043b\u0438\u0446\u044b <strong>12\u00a0345<\/strong>, \u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432\u00a0\u0444\u0430\u0439\u043b\u0435 <code>$PGDATA\/base\/16384\/12345<\/code>.<\/p>\n<h4>Foreign Data Wrapper (FDW)<\/h4>\n<p><strong>FDW <\/strong>\u2014 \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 PostgreSQL \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 <strong>\u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0437\u0430\u00a0\u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f<\/strong>.<\/p>\n<p>FDW\u00a0\u2014 \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0445\u0443\u043a\u2011\u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c PostgreSQL \u043f\u0440\u0438\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439:<\/p>\n<ul>\n<li>\n<p><strong>\u0427\u0442\u0435\u043d\u0438\u0435 (SELECT)<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u0417\u0430\u043f\u0438\u0441\u044c (INSERT, UPDATE, DELETE)<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 (Foreign Scan)<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (Planner Hook)<\/strong><\/p>\n<\/li>\n<\/ul>\n<p>FDW \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c <strong>\u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 backend<\/strong>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<ul>\n<li>\n<p>\u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 <strong>\u0434\u0440\u0443\u0433\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435<\/strong> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u00a0\u043a\u043e\u043c\u043f\u0440\u0435\u0441\u0441\u0438\u0435\u0439).<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a <strong>\u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\u043c<\/strong> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u00a0NoSQL \u0438\u043b\u0438\u00a0\u043e\u0431\u043b\u0430\u0447\u043d\u043e\u043c\u0443 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0443).<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 <strong>\u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f<\/strong> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0444\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430, \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043f\u043e\u0434\u00a0\u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438).<\/p>\n<\/li>\n<\/ul>\n<h3>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e FDW<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043d\u0430\u00a0\u044f\u0437\u044b\u043a\u0435 C, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 FDW. \u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0438\u0437\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u0414\u043b\u044f\u00a0\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f. \u041f\u0440\u043e\u0435\u043a\u0442 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u0444\u0430\u0439\u043b\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><code>custom_fdw.c<\/code>\u00a0\u2014 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u0434 FDW.<\/p>\n<\/li>\n<li>\n<p><code>Makefile<\/code>\u00a0\u2014 \u0434\u043b\u044f\u00a0\u0441\u0431\u043e\u0440\u043a\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><code>custom_fdw.control<\/code>\u00a0\u2014 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f\u00a0PostgreSQL.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441\u00a0\u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 <code>custom_fdw.c<\/code>:<\/p>\n<pre><code class=\"cs\">#include \"postgres.h\" #include \"fmgr.h\" #include \"access\/reloptions.h\" #include \"foreign\/fdwapi.h\" #include \"foreign\/foreign.h\" #include \"utils\/elog.h\" #include \"catalog\/pg_type.h\" #include \"commands\/explain.h\" #include \"executor\/executor.h\" #include \"utils\/builtins.h\" #include \"nodes\/pg_list.h\" #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt;  \/* \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f FDW *\/ typedef struct CustomFdwState {     char *storage_path;     FILE *data_file; } CustomFdwState;  \/* \u041f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u044b \u043d\u0430\u0448\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 FDW *\/ extern Datum custom_fdw_handler(PG_FUNCTION_ARGS); extern Datum custom_fdw_validator(PG_FUNCTION_ARGS);  static void customBeginForeignScan(ForeignScanState *node, int eflags); static TupleTableSlot *customIterateForeignScan(ForeignScanState *node); static void customEndForeignScan(ForeignScanState *node); static void customReScanForeignScan(ForeignScanState *node);  \/* \u0417\u0434\u0435\u0441\u044c \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u044b \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0432\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f *\/ static void customGetForeignRelSize(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid); static void customGetForeignPaths(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid); static ForeignScan *customGetForeignPlan(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid,                                          ForeignPath *best_path, List *tlist, List *scan_clauses);<\/code><\/pre>\n<p>\u0421\u0430\u043c\u0430\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0434\u043e\u043b\u0436\u0435\u043d \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c FDW\u00a0\u2014 \u044d\u0442\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 FdwRoutine \u0441\u00a0\u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0432\u0441\u0435\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432:<\/p>\n<pre><code class=\"cs\">PG_MODULE_MAGIC;  PG_FUNCTION_INFO_V1(custom_fdw_handler); PG_FUNCTION_INFO_V1(custom_fdw_validator);  Datum custom_fdw_handler(PG_FUNCTION_ARGS) {     FdwRoutine *fdw_routine = makeNode(FdwRoutine);      \/* \u041f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0448\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a FDW *\/     fdw_routine-&gt;GetForeignRelSize = customGetForeignRelSize;     fdw_routine-&gt;GetForeignPaths = customGetForeignPaths;     fdw_routine-&gt;GetForeignPlan = customGetForeignPlan;     fdw_routine-&gt;BeginForeignScan = customBeginForeignScan;     fdw_routine-&gt;IterateForeignScan = customIterateForeignScan;     fdw_routine-&gt;ReScanForeignScan = customReScanForeignScan;     fdw_routine-&gt;EndForeignScan = customEndForeignScan;      PG_RETURN_POINTER(fdw_routine); }  \/* \u041f\u0440\u043e\u0441\u0442\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u043f\u0446\u0438\u0439 *\/ Datum custom_fdw_validator(PG_FUNCTION_ARGS) {     \/* \u0417\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043e\u043f\u0446\u0438\u0439, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u0432 CREATE SERVER \u0438\u043b\u0438 FOREIGN TABLE *\/     PG_RETURN_VOID(); }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a\u00a0\u043e\u0441\u043d\u043e\u0432\u0435 \u043d\u0430\u0448\u0435\u0433\u043e FDW\u00a0\u2014 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c \u0447\u0442\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u0417\u0434\u0435\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>customBeginForeignScan <\/code>\u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0444\u0430\u0439\u043b, \u0432\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445. <\/p>\n<pre><code class=\"cs\">static void customBeginForeignScan(ForeignScanState *node, int eflags) {     CustomFdwState *state = palloc(sizeof(CustomFdwState));      \/* \u041f\u0443\u0441\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u043f\u0446\u0438\u044f, \u043d\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u0435\u0433\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 *\/     state-&gt;storage_path = \"data\/custom_storage.dat\";      state-&gt;data_file = fopen(state-&gt;storage_path, \"rb\");     if (state-&gt;data_file == NULL)         elog(ERROR, \"\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0444\u0430\u0439\u043b \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430: %s\", state-&gt;storage_path);      \/* \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 FDW *\/     node-&gt;fdw_state = (void *) state; }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>customIterateForeignScan <\/code>\u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430\u00a0\u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u00a0\u0432\u0438\u0434\u0435 <code>tuple<\/code>. \u0422\u0443\u0442 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u044b\u0440\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u00a0\u0444\u043e\u0440\u043c\u0430\u0442, \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 PostgreSQL.<\/p>\n<pre><code class=\"cs\">static TupleTableSlot * customIterateForeignScan(ForeignScanState *node) {     CustomFdwState *state = (CustomFdwState *) node-&gt;fdw_state;     TupleTableSlot *slot = node-&gt;ss.ss_ScanTupleSlot;     bool eof = false;     char buffer[1024];      \/* \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 *\/     if (fgets(buffer, sizeof(buffer), state-&gt;data_file) == NULL)         eof = true;      if (eof)     {         ExecClearTuple(slot);         return slot;     }          \/* \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u0437\u0430\u043f\u044f\u0442\u044b\u043c\u0438, \u0438 \u0443 \u043d\u0430\u0441 \u0434\u0432\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u0430:        \u043f\u0435\u0440\u0432\u044b\u0439 \u2013 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0432\u0442\u043e\u0440\u043e\u0439 \u2013 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435 *\/     char *token = strtok(buffer, \",\");     if (token == NULL)     {         elog(WARNING, \"\u041d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u0441\u0442\u0440\u043e\u043a\u0438: %s\", buffer);         ExecClearTuple(slot);         return slot;     }     int col1 = atoi(token);      token = strtok(NULL, \",\");     char *col2 = token ? pstrdup(token) : NULL;     if (col2 &amp;&amp; col2[strlen(col2)-1] == '\\n')         col2[strlen(col2)-1] = '\\0';      \/* \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 Datum \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u0444\u043b\u0430\u0433\u043e\u0432 isnull *\/     Datum values[2];     bool nulls[2] = {false, false};      values[0] = Int32GetDatum(col1);     values[1] = CStringGetTextDatum(col2);      \/* \u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c tuple *\/     slot = ExecClearTuple(slot);     slot = ExecStoreTuple(heap_form_tuple(slot-&gt;tts_tupleDescriptor, values, nulls), slot, false);      return slot; }<\/code><\/pre>\n<p>\u041d\u0435\u00a0\u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043e\u00a0\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u00a0\u2014 \u043e\u043d\u0430 \u043d\u0443\u0436\u043d\u0430 \u0434\u043b\u044f\u00a0\u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0430 \u043f\u043e\u00a0\u0434\u0430\u043d\u043d\u044b\u043c, \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f\u00a0\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0433\u043e \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"cs\">static void customReScanForeignScan(ForeignScanState *node) {     CustomFdwState *state = (CustomFdwState *) node-&gt;fdw_state;<\/code><\/pre>\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-452902","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/452902","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=452902"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/452902\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=452902"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=452902"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=452902"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}