{"id":341634,"date":"2022-11-24T09:00:08","date_gmt":"2022-11-24T09:00:08","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=341634"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=341634","title":{"rendered":"<span>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 PostgreSQL. \u0427\u0430\u0441\u0442\u044c 0. \u0421\u0442\u0430\u0440\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/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, Habr!<\/p>\n<p>Postgres &#8212; \u043e\u0434\u0438\u043d \u0438\u0437 \u043a\u0440\u0443\u043f\u043d\u0435\u0439\u0448\u0438\u0445 open source \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432. \u041e\u043d \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0441\u044f \u043c\u043d\u043e\u0433\u0438\u0435 \u0433\u043e\u0434\u0430. \u041a\u043e\u0434\u043e\u0432\u0430\u044f \u0431\u0430\u0437\u0430 \u043d\u0430\u043a\u043e\u043f\u0438\u043b\u0430\u0441\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u0430\u044f. \u041c\u043d\u0435, \u043a\u0430\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443, \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u044b\u043b\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043a\u0430\u043a \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c. \u041d\u043e \u043d\u0435 \u043f\u0440\u043e SQL \u043f\u043e\u0439\u0434\u0435\u0442 \u0440\u0435\u0447\u044c, \u0430 \u043f\u0440\u043e \u044f\u0437\u044b\u043a \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043d \u043d\u0430\u043f\u0438\u0441\u0430\u043d. \u041f\u0440\u043e C.\u00a0<\/p>\n<p>\u0421 \u043e\u0431\u0449\u0435\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f <a href=\"https:\/\/github.com\/yum-install-brains\/postgresql-spot\/blob\/master\/architecture\/architecture.md\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a><\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0439\u043c\u0435\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0434\u043e \u0432\u0445\u043e\u0434\u0430 \u0432 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0441\u0435\u0440\u0432\u0435\u0440\u0430. <\/p>\n<h2>int main(int argc, char** argv)<\/h2>\n<p>\u041b\u044e\u0431\u043e\u0435 C \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 main(). \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/backend\/main\/main.c\" rel=\"noopener noreferrer nofollow\">src\/backend\/main\/main.c\u00a0<\/a><\/p>\n<p>\u0421\u0430\u043c main \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u0435\u0439:<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0445\u0430\u043a\u043e\u0432 \u0441\u0442\u0430\u0440\u0442\u0430<\/strong><\/p>\n<p>Postgres \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430\u0445: Linux, Windows, FreeBSD \u0438 \u0442.\u0434. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u044b. \u0427\u0442\u043e\u0431\u044b \u0438\u0445 \u0443\u0447\u0435\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u044d\u0442\u0430 \u0447\u0430\u0441\u0442\u044c.\u00a0<\/p>\n<p>\u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0437\u0434\u0435\u0441\u044c \u0445\u0430\u043a\u0438 \u0434\u043b\u044f Windows:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 Winsock<\/p>\n<\/li>\n<li>\n<p>\u0423\u0431\u0440\u0430\u0442\u044c GUI \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0435<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0441\u0431\u043e\u0435\u0432 \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f <em>dummy spinlock<\/em>: \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430\u0445 \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u044b\u0439 \u0431\u0430\u0440\u044c\u0435\u0440 \u043f\u0430\u043c\u044f\u0442\u0438 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c (<code>pg_memory_barrier()<\/code>).\u00a0<\/p>\n<p>\u0421\u0430\u043c \u043c\u0435\u0442\u043e\u0434 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043b\u043e\u043a\u0430 \u0432 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435: \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u043e\u0432 \u0432 -1, \u0442.\u0435. \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u044b. \u0421\u0430\u043c \u0442\u0438\u043f \u043b\u043e\u043a\u0430 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>slock_t<\/code><\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u043d\u0443\u0442\u0440\u0438 \u0441\u043f\u0438\u043d\u043b\u043e\u043a\u043e\u0432<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0415\u0441\u043b\u0438 \u043a\u043e\u043f\u043d\u0443\u0442\u044c \u0433\u043b\u0443\u0431\u0436\u0435 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043b\u043e\u043a\u043e\u0432, \u0442\u043e \u0432\u044b \u0435\u0435 \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0438 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e. \u041e\u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u0430 &#8212; \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u043d\u043e \u0438 \u043e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f.\u00a0<\/p>\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/include\/storage\/s_lock.h\" rel=\"noopener noreferrer nofollow\">s_lock.h<\/a> \u0434\u0435\u043a\u043b\u0430\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0442\u0438\u043f\u044b \u0434\u043b\u044f \u0441\u043f\u0438\u043d \u043b\u043e\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c. \u0412\u043e\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u043d\u043b\u043e\u043a\u0430 \u0434\u043b\u044f linux, \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e gcc \u0434\u043b\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 Intel \u0434\u043b\u044f x32 \u0441\u0438\u0441\u0442\u0435\u043c\u044b<\/p>\n<pre><code class=\"cpp\">typedef unsigned char slock_t;<\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f HP \u0438\u043b\u0438 gcc \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u0432<\/p>\n<pre><code class=\"cpp\">typedef struct { intsema[4]; } slock_t;<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u043e\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043e\u0432\/\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c? \u0412\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e &#8212; \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440. \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u0433\u043b\u044f\u043d\u0435\u0442\u0435 \u0432 \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u0442\u0435, \u0447\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u0442\u0438\u043f\u043e\u0432 \u0441\u043f\u0438\u043d\u043b\u043e\u043a\u043e\u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f TAS (Test And Set) \u043c\u0430\u043a\u0440\u043e\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0442\u044c\u0441\u044f API Postgres. \u0418 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435 \u043c\u0430\u043a\u0440\u043e\u0441\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440. \u0412\u043e\u0442 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043b\u043d\u043e\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 \u0438 \u043c\u0430\u043a\u0440\u043e\u0441\u0430 \u0434\u043b\u044f 32 \u0431\u0438\u0442\u043d\u043e\u0433\u043e Intel \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e gcc<\/p>\n<pre><code class=\"cpp\">#if defined(__GNUC__) || defined(__INTEL_COMPILER) #ifdef __i386__\/* 32-bit i386 *\/ #define HAS_TEST_AND_SET  typedef unsigned char slock_t;  #define TAS(lock) tas(lock)  static __inline__ int tas(volatile slock_t *lock) { register slock_t _res = 1; __asm__ __volatile__( \"cmpb$0,%1\\n\" \"jne1f\\n\" \"lock\\n\" \"xchgb%0,%1\\n\" \"1: \\n\" :\"+q\"(_res), \"+m\"(*lock) :\/* no inputs *\/ :\"memory\", \"cc\"); return (int) _res; }  #define SPIN_DELAY() spin_delay()  static __inline__ void spin_delay(void) { __asm__ __volatile__( \" rep; nop\\n\"); }  #endif \/* __i386__ *\/ #endif<\/code><\/pre>\n<p>\u042d\u0442\u0438 \u043c\u0430\u043a\u0440\u043e\u0441\u044b &#8212; \u043d\u0435 \u0447\u0430\u0441\u0442\u044c API, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u0442\u0430\u043b\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u0445 \u043d\u0435 \u043d\u0430\u0434\u043e.<\/p>\n<\/div>\n<\/details>\n<p><strong>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f MemoryContext<\/strong><\/p>\n<p>\u0412 Postgres \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f (\u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u043d\u0435 \u043d\u0430 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0439 \u043e\u0441\u043d\u043e\u0432\u0435) \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 C (malloc, palloc). \u0412\u043c\u0435\u0441\u0442\u043e, \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u044b\u0439 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u043f\u0430\u043c\u044f\u0442\u0438, \u0442.\u0435. \u043f\u0430\u043c\u044f\u0442\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u0430\u044f.\u00a0<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u0440\u0430\u0442\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u0435\u043d\u0435\u0434\u0436\u043c\u0435\u043d\u0442\u0430 \u043f\u0430\u043c\u044f\u0442\u0438<\/summary>\n<div class=\"spoiler__content\">\n<p>MemoryContext &#8212; \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e (<a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/include\/utils\/palloc.h\" rel=\"noopener noreferrer nofollow\">palloc.h<\/a>). \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438 \u043f\u0430\u043c\u044f\u0442\u0438. \u0413\u0440\u0443\u0431\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u044d\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\/\u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0440\u044f\u0434 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 (<a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/include\/nodes\/memnodes.h\" rel=\"noopener noreferrer nofollow\">memnodes.h<\/a>):<\/p>\n<pre><code class=\"cpp\">typedef struct MemoryContextMethods { void   *(*alloc) (MemoryContext context, Size size); void(*free_p) (MemoryContext context, void *pointer); void   *(*realloc) (MemoryContext context, void *pointer, Size size); void(*reset) (MemoryContext context); void(*delete_context) (MemoryContext context); Size(*get_chunk_space) (MemoryContext context, void *pointer); bool(*is_empty) (MemoryContext context); void(*stats) (MemoryContext context,   MemoryStatsPrintFunc printfunc, void *passthru,   MemoryContextCounters *totals,   bool print_to_stderr); #ifdef MEMORY_CONTEXT_CHECKING void(*check) (MemoryContext context); #endif } MemoryContextMethods;<\/code><\/pre>\n<p>\u0412\u0441\u0435\u0433\u043e \u0435\u0441\u0442\u044c 3 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p><em>AllocSet<\/em> &#8212; \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/p>\n<\/li>\n<li>\n<p><em>SlabContext<\/em> &#8212; \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0447\u0430\u043d\u043a\u0430\u043c\u0438 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430<\/p>\n<\/li>\n<li>\n<p><em>GenerationContext<\/em> &#8212; \u0434\u043b\u044f \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0433\u0440\u0443\u043f\u043f\u0430\u043c\u0438 \u0447\u0430\u043d\u043a\u043e\u0432 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043e\u0434\u043d\u0438\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0435 \u0437\u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u044b:<\/p>\n<ul>\n<li>\n<p><em>TopMemoryContext<\/em> &#8212; \u0432\u0435\u0440\u0445\u043d\u0435\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/p>\n<\/li>\n<li>\n<p><em>PostmasterContext<\/em> &#8212; \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f Postmaster. \u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u044d\u043a\u044d\u043d\u0434\u0430, \u0431\u044d\u043a\u044d\u043d\u0434\u043e\u043c \u0436\u0435 \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437-\u0437\u0430 \u043d\u0435\u043d\u0430\u0434\u043e\u0431\u043d\u043e\u0441\u0442\u0438<\/p>\n<\/li>\n<li>\n<p><em>CacheMemoryContext<\/em> &#8212; \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u044d\u0448\u0430<\/p>\n<\/li>\n<li>\n<p><em>MessageContext<\/em> &#8212; \u0445\u0440\u0430\u043d\u0438\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u0441 \u0444\u0440\u043e\u043d\u0442\u044d\u043d\u0434\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0435\u0440\u0435\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430\/\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p><em>TopTransactionContext<\/em> &#8212; \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438. \u0425\u0440\u0430\u043d\u0438\u0442 \u0432\u0441\u0435, \u0447\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0435\u0439<\/p>\n<\/li>\n<li>\n<p><em>CurTransactionContext<\/em> &#8212; \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f \u043f\u043e\u0434-\u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439. \u0415\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0442\u043e\u043b\u044c\u043a\u043e 1 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f, \u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 <em>TopTransactionContext<\/em><\/p>\n<\/li>\n<li>\n<p><em>PortalContext<\/em> &#8212; \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 Portal.\u00a0 (Portal &#8212; \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f \u043d\u0430\u0434 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u043c\u0441\u044f\/\u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0432\u0448\u0438\u043c\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0430)<\/p>\n<\/li>\n<li>\n<p><em>ErrorContext<\/em> &#8212; \u043f\u0435\u0440\u0441\u0438\u0442\u0435\u043d\u0442\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439\u0441\u044f \u043f\u0440\u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u043f\u043e\u0441\u043b\u0435 \u043e\u0448\u0438\u0431\u043e\u043a.\u00a0<\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/backend\/utils\/mmgr\/README\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a><\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0430\u043a \u0432\u043e\u0442, \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043f\u0430\u043c\u044f\u0442\u0438 (TopMemoryContext) &#8212; \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>MemoryContextInit();<\/code><\/p>\n<p><strong>\u041b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/strong><\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f. \u0412\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f:<\/p>\n<ul>\n<li>\n<p><em>LC_COLLATE<\/em> &#8212; \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0441\u0442\u0440\u043e\u043a<\/p>\n<\/li>\n<li>\n<p><em>LC_CTYPE<\/em> &#8212; \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b \u0432 \u043d\u0438\u0436\u043d\u0435\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435 \u0438\u043b\u0438 \u043d\u0435\u0442)\u00a0<\/p>\n<\/li>\n<li>\n<p><em>LC_MESSAGES<\/em> &#8212; \u044f\u0437\u044b\u043a \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/p>\n<\/li>\n<li>\n<p><em>LC_MONETARY<\/em> &#8212; \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0430\u043b\u044e\u0442<\/p>\n<\/li>\n<li>\n<p><em>LC_NUMERIC<\/em> &#8212; \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0447\u0438\u0441\u0435\u043b<\/p>\n<\/li>\n<li>\n<p><em>LC_TIME<\/em> &#8212; \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u0442 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <em>LC_ALL<\/em> \u0441\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f.\u00a0<\/p>\n<p>* \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u0435\u043a\u044d\u043d\u0434\u043e\u0432, \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0432\u043e\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0437 pg_database, \u043d\u043e postmaster \u044d\u0442\u043e\u0433\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442.<\/p>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0431\u0430\u0433 \u0441 <em>strxfrm<\/em><\/p>\n<details class=\"spoiler\">\n<summary>\u0411\u0430\u043a strxfrm<\/summary>\n<div class=\"spoiler__content\">\n<p><code>strxfrm<\/code> &#8212; C \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0449\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0443 src \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u0443\u044e \u043e\u0442 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043b\u043e\u043a\u0430\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0443 \u0438 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 num \u0431\u0430\u0439\u0442\u043e\u0432 \u0432 dest.\u00a0<\/p>\n<pre><code class=\"cpp\">size_t strxfrm(char *destptr, const char *src, size_t num);<\/code><\/pre>\n<p>\u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437 \u0438 \u043e\u0442 \u043d\u0435\u0435 \u043c\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442, \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043a\u0430\u043a \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0430\u0433\u0430, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0441 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0441\u0432\u0435\u0449\u0435\u043d\u043e.<\/p>\n<p>\u0411\u0430\u0433\u043e\u0432 2 \u0438 \u043e\u0431\u0430 \u043d\u0430 \u041e\u0421 Solaris. \u041e\u0448\u0438\u0431\u043a\u0430 \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u0440\u0430\u0431\u043e\u0442\u043e\u0439 \u0441 \u043c\u0430\u043b\u044b\u043c\u0438 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0430\u0445:\u00a0<\/p>\n<ul>\n<li>\n<p>\u0414\u043b\u044f 2 \u0431\u0430\u0439\u0442\u043d\u043e\u0439 ASCII \u0441\u0442\u0440\u043e\u043a\u0438 Solaris 10 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 10 \u0431\u0430\u0439\u0442\u043e\u0432 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 18<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 num \u0440\u0430\u0432\u043d\u044b\u0439 1, \u0442\u043e \u044d\u0442\u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0430\u0439\u0442\u043e\u0432 \u043d\u0430 1 \u043c\u0435\u043d\u044c\u0448\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0438\u0437 \u0431\u0430\u0433\u043e\u0432 \u0431\u044b\u043b \u043d\u0430\u0439\u0434\u0435\u043d, \u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u043a\u0430\u043d\u0430\u0440\u0435\u0439\u043a\u0430<\/p>\n<pre><code class=\"cpp\">void check_strxfrm_bug(void) { charbuf[32]; const intcanary = 0x7F; boolok = true;  \/*  * Given a two-byte ASCII string and length limit 7, 8 or 9, Solaris 10  * 05\/08 returns 18 and modifies 10 bytes.  It respects limits above or  * below that range.  *  * The bug is present in Solaris 8 as well; it is absent in Solaris 10  * 01\/13 and Solaris 11.2.  Affected locales include is_IS.ISO8859-1,  * en_US.UTF-8, en_US.ISO8859-1, and ru_RU.KOI8-R.  Unaffected locales  * include de_DE.UTF-8, de_DE.ISO8859-1, zh_TW.UTF-8, and C.  *\/ buf[7] = canary; (void) strxfrm(buf, \"ab\", 7); if (buf[7] != canary) ok = false;  \/*  * illumos bug #1594 was present in the source tree from 2010-10-11 to  * 2012-02-01.  Given an ASCII string of any length and length limit 1,  * affected systems ignore the length limit and modify a number of bytes  * one less than the return value.  The problem inputs for this bug do not  * overlap those for the Solaris bug, hence a distinct test.  *  * Affected systems include smartos-20110926T021612Z.  Affected locales  * include en_US.ISO8859-1 and en_US.UTF-8.  Unaffected locales include C.  *\/ buf[1] = canary; (void) strxfrm(buf, \"a\", 1); if (buf[1] != canary) ok = false;  if (!ok) ereport(ERROR, (errcode(ERRCODE_SYSTEM_ERROR),  errmsg_internal(\"strxfrm(), in locale \\\"%s\\\", writes past the specified array length\",  setlocale(LC_COLLATE, NULL)),  errhint(\"Apply system library package updates.\"))); }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p><strong>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u201c\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0435\u201d \u0444\u043b\u0430\u0433\u0438<\/strong><\/p>\n<p>\u041f\u043e\u0434 \u201c\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c\u0438\u201d \u0438\u043c\u0435\u044e \u0432\u0432\u0438\u0434\u0443 \u043d\u0435 \u043c\u0435\u043d\u044f\u044e\u0449\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442\u0441\u044f:<\/p>\n<ul>\n<li>\n<p>\u2013help &#8212; \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043f\u043e\u043c\u043e\u0449\u0438<\/p>\n<\/li>\n<li>\n<p>\u2013version &#8212; \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u044e<\/p>\n<\/li>\n<li>\n<p>\u2013describe-config, -C &#8212; \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044f help \u0438 version \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 (\u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f exit(0)).\u00a0<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0444\u043b\u0430\u0433 (&#8212;describe-config \u0438\u043b\u0438 -C), \u0442\u043e \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0444\u043b\u0430\u0433 <em>do_check_root<\/em> \u0432 <em>false<\/em>. \u0417\u0430\u0447\u0435\u043c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<p><strong>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0440\u0443\u0442\u0430<\/strong><\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u0441\u044f \u043d\u0435 \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043f\u043e\u043c\u043e\u0449\u0438 (<em>&#8212;help<\/em>) \u0438\u043b\u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u044e (<em>&#8212;version<\/em>), \u0442\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u0441\u044f \u0432 \u0440\u0430\u0431\u043e\u0447\u0435\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0432\u043b\u0435\u0447\u044c \u0437\u0430 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f. \u0417\u0430\u043f\u0443\u0441\u043a \u043f\u043e\u0434 \u0430\u0434\u043c\u0438\u043d\u043e\u043c &#8212; \u043d\u0435 \u0441\u0430\u043c\u0430\u044f \u043b\u0443\u0447\u0448\u0430\u044f \u0438\u0434\u0435\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u0431\u044b\u043b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d \u0444\u043b\u0430\u0433 do_check_root \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c true.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0441 do_check_root \u0440\u0430\u0432\u043d\u044b\u043c <em>true<\/em>, \u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>check_root()<\/code> \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 (\u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b), \u0447\u0442\u043e \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u0441\u044f \u043e\u0442 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430:<\/p>\n<ul>\n<li>\n<p>UID = 0 \u0434\u043b\u044f unix,\u00a0<\/p>\n<\/li>\n<li>\n<p>pg32win_isadmin() \u0434\u043b\u044f Windows.\u00a0<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0440\u0443\u0442, \u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c\u0441\u044f.<\/p>\n<details class=\"spoiler\">\n<summary>void check_root(const char *progname)<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">static void check_root(const char *progname) { #ifndef WIN32 if (geteuid() == 0) { write_stderr(\"\\\"root\\\" execution of the PostgreSQL server is not permitted.\\n\"  \"The server must be started under an unprivileged user ID to prevent\\n\"  \"possible system security compromise.  See the documentation for\\n\"  \"more information on how to properly start the server.\\n\"); exit(1); }  \/*  * Also make sure that real and effective uids are the same. Executing as  * a setuid program from a root shell is a security hole, since on many  * platforms a nefarious subroutine could setuid back to root if real uid  * is root.  (Since nobody actually uses postgres as a setuid program,  * trying to actively fix this situation seems more trouble than it's  * worth; we'll just expend the effort to check for it.)  *\/ if (getuid() != geteuid()) { write_stderr(\"%s: real and effective user IDs must match\\n\",  progname); exit(1); } #else\/* WIN32 *\/ if (pgwin32_is_admin()) { write_stderr(\"Execution of PostgreSQL by a user with administrative permissions is not\\n\"  \"permitted.\\n\"  \"The server must be started under an unprivileged user ID to prevent\\n\"  \"possible system security compromises.  See the documentation for\\n\"  \"more information on how to properly start the server.\\n\"); exit(1); } #endif\/* WIN32 *\/ }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h3>\u0412\u044b\u0431\u043e\u0440 \u0442\u043e\u0447\u043a\u0438 \u0432\u0445\u043e\u0434\u0430<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0438\u0434\u0435\u0442 \u0432\u044b\u0431\u043e\u0440 \u0438\u0437 4 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p><em>AuxiliaryMain<\/em> (<em>&#8212;boot<\/em>) &#8212; \u0421\u0442\u0430\u0440\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0445 \u201c\u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0445\u201d \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432<\/p>\n<ul>\n<li>\n<p>Autovaccum<\/p>\n<\/li>\n<li>\n<p>PGARCH &#8212; \u0430\u0440\u0445\u0438\u0432\u0430\u0446\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>PGSTAT &#8212; \u0441\u0431\u043e\u0440 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438<\/p>\n<\/li>\n<li>\n<p>logger &#8212; \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/p>\n<\/li>\n<li>\n<p>Walwriter &#8212; \u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c WAL \u043b\u043e\u0433\u0430<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><em>GetGucInfo<\/em> (<em>&#8212;describe-config<\/em>) &#8212; \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e GUC (Global Unified Configuration)<\/p>\n<\/li>\n<li>\n<p><em>PostgresMain<\/em> (<em>&#8212;single<\/em>) &#8212; \u0437\u0430\u043f\u0443\u0441\u043a \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/p>\n<\/li>\n<li>\n<p><em>SubPostmasterMain<\/em> (<em>&#8212;fork<\/em>) &#8212; \u0434\u043b\u044f Windows \u0441\u044b\u043c\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c fork\/exec Unix \u043f\u0440\u043e\u0446\u0435\u0441\u0441<\/p>\n<\/li>\n<li>\n<p><em>PostmasterMain<\/em> (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0431\u0435\u0437 \u043a\u043b\u044e\u0447\u0430) &#8212; \u0432\u0445\u043e\u0434\u043d\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (\u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f)<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0438\u0434\u0435\u0442 \u043f\u043e \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0443.<\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 Postgres \u0446\u0435\u043b\u0438\u043a\u043e\u043c &#8212; \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c PostmasterMain.<\/p>\n<h2>PostmasterMain<\/h2>\n<p>\u0412\u0445\u043e\u0434\u043d\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u0434\u043b\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 argc \u0438 argv, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0430\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 main.<\/p>\n<p><strong>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f<\/strong><\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c, \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435:<\/p>\n<ul>\n<li>\n<p>\u0412\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c pid \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0440\u0430\u0432\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 (\u0432\u044b\u0437\u043e\u0432 <code>umask<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043f\u0430\u043c\u044f\u0442\u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f Postmaster (<em>PostmasterContext<\/em>)<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0421\u0438\u0433\u043d\u0430\u043b\u044b<\/strong><\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432. Postgres \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u044b \u0434\u043b\u044f \u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u043f\u043e\u0434 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 \u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432, \u043f\u0440\u0438\u0447\u0435\u043c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 (WAL Writer, Stats Collector, Backend, Postmaster \u0438 \u0442.\u0434.) \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0438\u0433\u043d\u0430\u043b \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. <\/p>\n<p>\u0414\u043b\u044f Postmaster:<\/p>\n<ul>\n<li>\n<p>SIGINT &#8212; (fast shutdown) &#8212; \u043f\u043e\u0441\u043b\u0430\u0442\u044c SIGTERM \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c \u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f<\/p>\n<\/li>\n<li>\n<p>SIGTERM &#8212; (smart shutdown) &#8212; \u0436\u0434\u0435\u043c \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f<\/p>\n<\/li>\n<li>\n<p>SIGQUIT &#8212; (immediate shutdown) &#8212; \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u0432\u0441\u0435 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b SIGQUIT (\u0438\u043b\u0438 \u0448\u043b\u0435\u043c SIGKILL, \u0435\u0441\u043b\u0438 \u043a\u0442\u043e-\u0442\u043e \u043d\u0435 \u0445\u043e\u0447\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u044c\u0441\u044f) \u0438 \u0432\u044b\u0445\u043e\u0434\u0438\u043c \u0431\u0435\u0437 \u0442\u0449\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>SIGABRT &#8212; \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0431\u0435\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0447\u0442\u043e-\u043b\u0438\u0431\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c (\u0434\u0430\u0436\u0435 \u043d\u0435 \u043b\u043e\u0433\u0438\u0440\u0443\u0435\u0442\u0441\u044f)<\/p>\n<\/li>\n<li>\n<p>SIGHUP &#8212; \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430<\/p>\n<\/li>\n<li>\n<p>SIGCHLD &#8212; \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430<\/p>\n<\/li>\n<li>\n<p>SIGUSR1 &#8212; \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0442 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430<\/p>\n<\/li>\n<li>\n<p>SIGUSR2 &#8212; \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f (\u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d)<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0441\u0438\u0433\u043d\u0430\u043b\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043c\u0430\u0448\u0438\u043d\u044b \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 Postmaster (\u043e\u0431 \u044d\u0442\u043e\u043c \u0434\u0430\u043b\u044c\u0448\u0435). <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 SIGTERM (\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432 \u0443\u0431\u0440\u0430\u043d\u0430)<\/p>\n<pre><code class=\"cpp\">\/*  * pmdie -- signal handler for processing various postmaster signals.  *\/ static void pmdie(SIGNAL_ARGS) { intsave_errno = errno;  \/*  * We rely on the signal mechanism to have blocked all signals ... except  * on Windows, which lacks sigaction(), so we have to do it manually.  *\/ #ifdef WIN32 PG_SETMASK(&amp;BlockSig); #endif  ereport(DEBUG2, (errmsg_internal(\"postmaster received signal %d\",  postgres_signal_arg)));  switch (postgres_signal_arg) { case SIGTERM:  \/*  * Smart Shutdown:  *  * Wait for children to end their work, then shut down.  *\/ if (Shutdown >= SmartShutdown) break; Shutdown = SmartShutdown; ereport(LOG, (errmsg(\"received smart shutdown request\")));  \/* Report status *\/ AddToDataDirLockFile(LOCK_FILE_LINE_PM_STATUS, PM_STATUS_STOPPING); #ifdef USE_SYSTEMD sd_notify(0, \"STOPPING=1\"); #endif  \/*  * If we reached normal running, we have to wait for any online  * backup mode to end; otherwise go straight to waiting for client  * backends to exit.  (The difference is that in the former state,  * we'll still let in new superuser clients, so that somebody can  * end the online backup mode.)  If already in PM_STOP_BACKENDS or  * a later state, do not change it.  *\/ if (pmState == PM_RUN) connsAllowed = ALLOW_SUPERUSER_CONNS; else if (pmState == PM_HOT_STANDBY) connsAllowed = ALLOW_NO_CONNS; else if (pmState == PM_STARTUP || pmState == PM_RECOVERY) { \/* There should be no clients, so proceed to stop children *\/ pmState = PM_STOP_BACKENDS; }  \/*  * Now wait for online backup mode to end and backends to exit. If  * that is already the case, PostmasterStateMachine will take the  * next step.  *\/ PostmasterStateMachine(); break;      \/*                *  \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432              *\/ }  #ifdef WIN32 PG_SETMASK(&amp;UnBlockSig); #endif  errno = save_errno; }<\/code><\/pre>\n<p><strong>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f<\/strong><\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0439 &#8212; \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f InitializeGUCOptions():<\/p>\n<ul>\n<li>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0440\u0435\u0436\u0438\u043c\u044b \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439 (\u0435\u0441\u043b\u0438 \u0432\u0434\u0440\u0443\u0433 \u043a\u0442\u043e-\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043d\u0435 \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0434\u043f\u0440\u0430\u0432\u0438\u043b \u043a\u043e\u0434)<\/p>\n<\/li>\n<li>\n<p>\u0427\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<ul>\n<li>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f getopt \u0438\u0437 &lt;unistd.h><\/p>\n<\/li>\n<li>\n<p>\u0412 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u0441\u0432\u0438\u0447\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043b\u043e\u0433\u0438\u043a\u0430\/\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f<\/p>\n<\/li>\n<\/ul>\n<details class=\"spoiler\">\n<summary>\u042d\u0442\u043e\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 switch<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">while ((opt = getopt(argc, argv, \"B:bc:C:D:d:EeFf:h:ijk:lN:nOPp:r:S:sTt:W:-:\")) != -1) { switch (opt) { case 'B': SetConfigOption(\"shared_buffers\", optarg, PGC_POSTMASTER, PGC_S_ARGV); break;  case 'b': \/* Undocumented flag used for binary upgrades *\/ IsBinaryUpgrade = true; break;  case 'C': output_config_variable = strdup(optarg); break;  case 'D': userDoption = strdup(optarg); break;  case 'd': set_debug_options(atoi(optarg), PGC_POSTMASTER, PGC_S_ARGV); break;  case 'E': SetConfigOption(\"log_statement\", \"all\", PGC_POSTMASTER, PGC_S_ARGV); break;  case 'e': SetConfigOption(\"datestyle\", \"euro\", PGC_POSTMASTER, PGC_S_ARGV); break;  case 'F': SetConfigOption(\"fsync\", \"false\", PGC_POSTMASTER, PGC_S_ARGV); break;  case 'f': if (!set_plan_disabling_options(optarg, PGC_POSTMASTER, PGC_S_ARGV)) { write_stderr(\"%s: invalid argument for option -f: \\\"%s\\\"\\n\",  progname, optarg); ExitPostmaster(1); } break;  case 'h': SetConfigOption(\"listen_addresses\", optarg, PGC_POSTMASTER, PGC_S_ARGV); break;  case 'i': SetConfigOption(\"listen_addresses\", \"*\", PGC_POSTMASTER, PGC_S_ARGV); break;  case 'j': \/* only used by interactive backend *\/ break;  case 'k': SetConfigOption(\"unix_socket_directories\", optarg, PGC_POSTMASTER, PGC_S_ARGV); break;  case 'l': SetConfigOption(\"ssl\", \"true\", PGC_POSTMASTER, PGC_S_ARGV); break;  case 'N': SetConfigOption(\"max_connections\", optarg, PGC_POSTMASTER, PGC_S_ARGV); break;  case 'n': \/* Don't reinit shared mem after abnormal exit *\/ Reinit = false; break;  case 'O': SetConfigOption(\"allow_system_table_mods\", \"true\", PGC_POSTMASTER, PGC_S_ARGV); break;  case 'P': SetConfigOption(\"ignore_system_indexes\", \"true\", PGC_POSTMASTER, PGC_S_ARGV); break;  case 'p': SetConfigOption(\"port\", optarg, PGC_POSTMASTER, PGC_S_ARGV); break;  case 'r': \/* only used by single-user backend *\/ break;  case 'S': SetConfigOption(\"work_mem\", optarg, PGC_POSTMASTER, PGC_S_ARGV); break;  case 's': SetConfigOption(\"log_statement_stats\", \"true\", PGC_POSTMASTER, PGC_S_ARGV); break;  case 'T':  \/*  * In the event that some backend dumps core, send SIGSTOP,  * rather than SIGQUIT, to all its peers.  This lets the wily  * post_hacker collect core dumps from everyone.  *\/ SendStop = true; break;  case 't': { const char *tmp = get_stats_option_name(optarg);  if (tmp) { SetConfigOption(tmp, \"true\", PGC_POSTMASTER, PGC_S_ARGV); } else { write_stderr(\"%s: invalid argument for option -t: \\\"%s\\\"\\n\",  progname, optarg); ExitPostmaster(1); } break; }  case 'W': SetConfigOption(\"post_auth_delay\", optarg, PGC_POSTMASTER, PGC_S_ARGV); break;  case 'c': case '-': { char   *name,    *value;  ParseLongOption(optarg, &amp;name, &amp;value); if (!value) { if (opt == '-') ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),  errmsg(\"--%s requires a value\", optarg))); else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),  errmsg(\"-c %s requires a value\", optarg))); }  SetConfigOption(name, value, PGC_POSTMASTER, PGC_S_ARGV); free(name); if (value) free(value); break; }  default: write_stderr(\"Try \\\"%s --help\\\" for more information.\\n\",  progname); ExitPostmaster(1); } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p><strong>\u0420\u0430\u0431\u043e\u0447\u0435\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435<\/strong><\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0447\u0435\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435: \u0444\u0430\u0439\u043b\u044b, \u043f\u0430\u043f\u043a\u0438, \u0440\u0430\u0431\u043e\u0447\u0443\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 (\u043d\u0435 \u0434\u043b\u044f Windows):<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e, \u043e\u0442 \u0438\u043c\u0435\u043d\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u0441\u044f<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u0440\u0430\u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 (\u0431\u0438\u0442\u043e\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0430) &#8212; \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043b\u0438\u0431\u043e <code>0700<\/code>, \u043b\u0438\u0431\u043e <code>0750<\/code>\u00a0<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430\u043b\u0438\u0447\u0438\u044f <code>pg_control<\/code> \u0444\u0430\u0439\u043b\u0430\u00a0<\/p>\n<\/li>\n<li>\n<p>\u0421\u043c\u0435\u043d\u0430 \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 LockFile (<em>postmaster.pid<\/em>) \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0435\u0434\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 SSL<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439 \u0441\u043c\u0435\u0440\u0442\u0438 Postmaster \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u043e\u0432 \u0438 \u043e\u0431\u0449\u0435\u0439 \u043f\u0430\u043c\u044f\u0442\u044c<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f.<\/p>\n<p><strong>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439<\/strong><\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0441\u043e\u043a\u0435\u0442\u044b. \u0425\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043e\u043d\u0438 \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0432\u0441\u0435 \u043f\u043e\u043c\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0435\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u0441\u043e\u043a\u0435\u0442\u043e\u0432 \u043f\u0440\u0438 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u0440\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e (\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <em>listen_addresses<\/em>), \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 TCP \u0441\u043e\u043a\u0435\u0442\u044b.\u00a0<\/p>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u0434\u0440\u0435\u0441\u0430 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0441\u043e\u043a\u0435\u0442 \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043d\u0430 \u043d\u0435\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u0430\u043a \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u0440\u0442\u044b \u0438 \u043f\u0440\u043e \u0442\u0438\u043f List<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">foreach(l, elemlist) {     char   *curhost = (char *) lfirst(l);      if (strcmp(curhost, \"*\") == 0)         status = StreamServerPort(AF_UNSPEC, NULL,                                   (unsigned short) PostPortNumber,                                   NULL,                                   ListenSocket, MAXLISTEN);     else         status = StreamServerPort(AF_UNSPEC, curhost,                                   (unsigned short) PostPortNumber,                                   NULL,                                   ListenSocket, MAXLISTEN);      if (status == STATUS_OK)     {         success++;         \/* record the first successful host addr in lockfile *\/         if (!listen_addr_saved)         {             AddToDataDirLockFile(LOCK_FILE_LINE_LISTEN_ADDR, curhost);             listen_addr_saved = true;         }     }     else         ereport(WARNING,                 (errmsg(\"could not create listen socket for \\\"%s\\\"\",                         curhost)));     }      if (!success &amp;&amp; elemlist != NIL)         ereport(FATAL,                 (errmsg(\"could not create any TCP\/IP sockets\")));      list_free(elemlist);     pfree(rawstring); }<\/code><\/pre>\n<p><code>elemList<\/code> &#8212;  \u0441\u043f\u0438\u0441\u043e\u043a \u0430\u0434\u0440\u0435\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043f\u0430\u0440\u0441\u0438\u043b\u0438 \u0438\u0437 <em>listen_adresses <\/em>\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430. \u0418\u043c\u0435\u0435\u0442 \u0442\u0438\u043f <em>List<\/em><\/p>\n<pre><code class=\"cpp\">typedef union ListCell { void   *ptr_value; intint_value; Oidoid_value; } ListCell;  typedef struct List { NodeTagtype;\/* T_List, T_IntList, or T_OidList *\/ intlength;\/* number of elements currently present *\/ intmax_length;\/* allocated length of elements[] *\/ ListCell   *elements;\/* re-allocatable array of cells *\/ \/* We may allocate some cells along with the List header: *\/ ListCellinitial_elements[FLEXIBLE_ARRAY_MEMBER]; \/* If elements == initial_elements, it's not a separate allocation *\/ } List;<\/code><\/pre>\n<p><code>foreach<\/code> &#8212; \u043c\u0430\u043a\u0440\u043e\u0441 Postgres \u0434\u043b\u044f \u0438\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0443<\/p>\n<pre><code class=\"cpp\">#define foreach(cell, lst)\\ for (ForEachState cell##__state = {(lst), 0}; \\  (cell##__state.l != NIL &amp;&amp; \\   cell##__state.i &lt; cell##__state.l->length) ? \\  (cell = &amp;cell##__state.l->elements[cell##__state.i], true) : \\  (cell = NULL, false); \\  cell##__state.i++)<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e \u0441\u043f\u0438\u0441\u043a\u0430\u043c\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/include\/nodes\/pg_list.h\" rel=\"noopener noreferrer nofollow\">pg_list.h<\/a><\/p>\n<\/div>\n<\/details>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0441\u0442\u0430\u0440\u0442\u0443\u0435\u043c <em>Bonjour<\/em> \u0441\u0435\u0440\u0432\u0438\u0441 \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c Unix \u0441\u043e\u043a\u0435\u0442 \u0444\u0430\u0439\u043b (\u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u044b Unix \u043f\u043e\u0440\u0442\u044b).<\/p>\n<p>\u0422\u043e\u043b\u044c\u043a\u043e \u0432 \u043a\u043e\u043d\u0446\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b 1 \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u0435\u043c\u044b\u0439 \u0441\u043e\u043a\u0435\u0442 (\u0442\u0430\u043a \u043a\u0430\u043a Unix \u0441\u043e\u043a\u0435\u0442\u044b \u0438 TCP \u0441\u043e\u043a\u0435\u0442\u044b \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b)<\/p>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0432 LockFile \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0445\u043e\u0441\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0441\u043e\u043a\u0435\u0442\u0430 (TCP \u0438\u043b\u0438 UNIX)<\/p>\n<p><strong>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043a \u0441\u0442\u0430\u0440\u0442\u0443<\/strong><\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0441\u043c\u043e\u0433\u0443\u0442 \u043a \u043d\u0430\u043c \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f, \u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u044b (\u043d\u043e \u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c):<\/p>\n<p>\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u043c <em>pg_hba.conf<\/em> \u0434\u043b\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 Startup<\/p>\n<pre><code class=\"cpp\">StartupPID = StartupDataBase();<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0415\u0441\u0442\u044c \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f AuxProcType<\/p>\n<pre><code class=\"cpp\">typedef enum { NotAnAuxProcess = -1, CheckerProcess = 0, BootstrapProcess, StartupProcess, BgWriterProcess, ArchiverProcess, CheckpointerProcess, WalWriterProcess, WalReceiverProcess,  NUM_AUXPROCTYPES\/* Must be last! *\/ } AuxProcType;<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>StartChildProcess(AuxProcType)<\/code> \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0444\u043e\u0440\u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0441\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u0442\u0438\u043f \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"cpp\">static pid_t StartChildProcess(AuxProcType type) { pid_tpid; char   *av[10]; intac = 0; chartypebuf[32];  \/*  * Set up command-line arguments for subprocess  *\/ av[ac++] = \"postgres\";  #ifdef EXEC_BACKEND av[ac++] = \"--forkboot\"; av[ac++] = NULL;\/* filled in by postmaster_forkexec *\/ #endif  snprintf(typebuf, sizeof(typebuf), \"-x%d\", type); av[ac++] = typebuf;  av[ac] = NULL; Assert(ac &lt; lengthof(av));  #ifdef EXEC_BACKEND pid = postmaster_forkexec(ac, av); #else\/* !EXEC_BACKEND *\/ pid = fork_process();  if (pid == 0)\/* child *\/ { InitPostmasterChild();  \/* Close the postmaster's sockets *\/ ClosePostmasterPorts(false);  \/* Release postmaster's working memory context *\/ MemoryContextSwitchTo(TopMemoryContext); MemoryContextDelete(PostmasterContext); PostmasterContext = NULL;  AuxiliaryProcessMain(ac, av);\/* does not return *\/ } #endif\/* EXEC_BACKEND *\/  if (pid &lt; 0) { \/* in parent, fork failed *\/                  \/\/ \u041a\u043e\u0434 \u043e\u043f\u0443\u0449\u0435\u043d          if (type == StartupProcess) ExitPostmaster(1); return 0; }  \/*  * in parent, successful fork  *\/ return pid; }<\/code><\/pre>\n<p>\u0421\u0430\u043c\u0430 \u0444\u0443\u043a\u043d\u0446\u0438\u044f <code>StartupDataBase()<\/code> &#8212; \u043c\u0430\u043a\u0440\u043e\u0441:<\/p>\n<pre><code class=\"cpp\">#define StartupDataBase() StartChildProcess(StartupProcess)<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> <code>EXEC_BACKEND<\/code> &#8212; \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430, \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u0432 Unix \u0441\u0440\u0435\u0434\u0435 \u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e <em>fork<\/em>, \u043d\u043e \u0438 <em>exec<\/em>. \u0413\u0440\u0443\u0431\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u043b\u044e\u0431\u043e\u0439 \u043a\u043e\u0434 \u0432 <code>#ifdef EXEC_BACKEND<\/code> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432 Windows<\/p>\n<\/div>\n<\/details>\n<p>\u0412\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0432 STARTUP_RUNNING, \u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0430\u0448\u0438\u043d\u044b \u0432 PM_STARTUP.<\/p>\n<details class=\"spoiler\">\n<summary>\u041e \u043c\u0430\u0448\u0438\u043d\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 Postmaster<\/summary>\n<div class=\"spoiler__content\">\n<p>Postmaster \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u0430\u0448\u0438\u043d\u0443 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430: \u0441\u0442\u0430\u0440\u0442\u0430, \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f, \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432 \u043e\u0442 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438.<\/p>\n<pre><code class=\"cpp\">typedef enum { PM_INIT,\/* postmaster starting *\/ PM_STARTUP,\/* waiting for startup subprocess *\/ PM_RECOVERY,\/* in archive recovery mode *\/ PM_HOT_STANDBY,\/* in hot standby mode *\/ PM_RUN,\/* normal \"database is alive\" state *\/ PM_STOP_BACKENDS,\/* need to stop remaining backends *\/ PM_WAIT_BACKENDS,\/* waiting for live backends to exit *\/ PM_SHUTDOWN,\/* waiting for checkpointer to do shutdown  * ckpt *\/ PM_SHUTDOWN_2,\/* waiting for archiver and walsenders to  * finish *\/ PM_WAIT_DEAD_END,\/* waiting for dead_end children to exit *\/ PM_NO_CHILDREN\/* all important children have exited *\/ } PMState;  static PMState pmState = PM_INIT;<\/code><\/pre>\n<p>\u0421\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <em>pmState <\/em>\u0445\u0440\u0430\u043d\u044f\u0449\u0430\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0430\u0448\u0438\u043d\u044b. <\/p>\n<p>\u0412 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b<\/p>\n<pre><code>\/*  * We use a simple state machine to control startup, shutdown, and  * crash recovery (which is rather like shutdown followed by startup).  *  * After doing all the postmaster initialization work, we enter PM_STARTUP  * state and the startup process is launched. The startup process begins by  * reading the control file and other preliminary initialization steps.  * In a normal startup, or after crash recovery, the startup process exits  * with exit code 0 and we switch to PM_RUN state.  However, archive recovery  * is handled specially since it takes much longer and we would like to support  * hot standby during archive recovery.  *  * When the startup process is ready to start archive recovery, it signals the  * postmaster, and we switch to PM_RECOVERY state. The background writer and  * checkpointer are launched, while the startup process continues applying WAL.  * If Hot Standby is enabled, then, after reaching a consistent point in WAL  * redo, startup process signals us again, and we switch to PM_HOT_STANDBY  * state and begin accepting connections to perform read-only queries.  When  * archive recovery is finished, the startup process exits with exit code 0  * and we switch to PM_RUN state.  *  * Normal child backends can only be launched when we are in PM_RUN or  * PM_HOT_STANDBY state.  (connsAllowed can also restrict launching.)  * In other states we handle connection requests by launching \"dead_end\"  * child processes, which will simply send the client an error message and  * quit.  (We track these in the BackendList so that we can know when they  * are all gone; this is important because they're still connected to shared  * memory, and would interfere with an attempt to destroy the shmem segment,  * possibly leading to SHMALL failure when we try to make a new one.)  * In PM_WAIT_DEAD_END state we are waiting for all the dead_end children  * to drain out of the system, and therefore stop accepting connection  * requests at all until the last existing child has quit (which hopefully  * will not be very long).  *  * Notice that this state variable does not distinguish *why* we entered  * states later than PM_RUN --- Shutdown and FatalError must be consulted  * to find that out.  FatalError is never true in PM_RECOVERY, PM_HOT_STANDBY,  * or PM_RUN states, nor in PM_SHUTDOWN states (because we don't enter those  * states when trying to recover from a crash).  It can be true in PM_STARTUP  * state, because we don't clear it until we've successfully started WAL redo.  *\/<\/code><\/pre>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 <em>PM_STARTUP<\/em> \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0436\u0434\u0435\u043c \u043f\u043e\u043a\u0430 \u0441\u0442\u0430\u0440\u0442\u0443\u044e\u0442 \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0447\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b, \u0437\u0430\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0432 <em>PM_RUN <\/em>(\u043f\u0440\u0438 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438)<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u043c \u043c\u044b \u043f\u0435\u0440\u0435\u0448\u043b\u0438 \u0438\u0437 <em>PM_INIT<\/em> \u0432 <em>PM_STARTUP<\/em>. \u041a\u0443\u0434\u0430 \u043c\u044b \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435?<\/p>\n<ul>\n<li>\n<p>PM_STOP_BACKENDS &#8212; \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 SIGTERM \u0438\u043b\u0438 SIGINT \u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u0431\u044d\u043a\u044d\u043d\u0434\u044b<\/p>\n<\/li>\n<li>\n<p>PM_WAIT_BACKENDS &#8212; \u0436\u0434\u0435\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u0435\u043a\u044d\u043d\u0434\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>PM_RECOVERY &#8212; \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441\u0438\u0433\u043d\u0430\u043b, \u0447\u0442\u043e \u043f\u043e\u0440\u044b \u0431\u044b \u043d\u0430\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435<\/p>\n<\/li>\n<li>\n<p>PM_RUN &#8212; \u0441\u0442\u0430\u0440\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0441\u044f \u0443\u0441\u043f\u0435\u0448\u043d\u043e<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0441\u0442\u0430\u0440\u0442\u0430\u043f\u0430<\/p>\n<pre><code class=\"cpp\">\/* Startup process's status *\/ typedef enum { STARTUP_NOT_RUNNING, STARTUP_RUNNING, STARTUP_SIGNALED,\/* we sent it a SIGQUIT or SIGKILL *\/ STARTUP_CRASHED } StartupStatusEnum;  static StartupStatusEnum StartupStatus = STARTUP_NOT_RUNNING;<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>P.S. \u041f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u0441\u044f \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u043f\u0435\u0440\u0435\u0434 \u0441\u0442\u0430\u0440\u0442\u043e\u043c \u0411\u0414<\/p>\n<pre><code class=\"cpp\">\/* * We're ready to rock and roll... *\/ StartupPID = StartupDataBase();<\/code><\/pre>\n<p><strong>\u0421\u0442\u0430\u0440\u0442<\/strong><\/p>\n<p>\u041c\u043e\u043c\u0435\u043d\u0442 \u0438\u0441\u0442\u0438\u043d\u044b.<\/p>\n<p>\u041f\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u0442\u0430\u0440\u0442\u0443\u0435\u043c \u0440\u0430\u0431\u043e\u0447\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b. \u041f\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u0442.\u043a. \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0441\u0435\u0431\u0435 \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b (\u043f\u043e\u0440\u0442\u044b \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u0443\u0436\u0435 \u043e\u0442\u043a\u0440\u044b\u043b\u0438) \u043c\u043e\u0433\u0443\u0442 \u043e\u0441\u0442\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u043c\u0438.\u00a0<\/p>\n<p>\u0418 \u0432\u043e\u0442 &#8212; \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0441\u0435\u0440\u0432\u0435\u0440\u0430!<\/p>\n<pre><code class=\"cpp\">status = ServerLoop();<\/code><\/pre>\n<h2>\u041f\u043e\u0441\u043b\u0435\u0441\u043b\u043e\u0432\u0438\u0435<\/h2>\n<p>\u0412\u0441\u0435\u0433\u0434\u0430 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0443\u0437\u043d\u0430\u0442\u044c \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e Postgres, \u043d\u043e \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043d\u0435 \u043d\u0430\u0448\u0435\u043b \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043e\u0434\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0448\u0438\u043b \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e. <\/p>\n<p>\u042d\u0442\u043e \u0431\u044b\u043b\u0430 \u043f\u0438\u043b\u043e\u0442\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0438 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u044e \u0432\u044b\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e. \u0410 \u043f\u043e\u043a\u0430, \u0434\u043e \u0441\u043a\u043e\u0440\u044b\u0445 \u0432\u0441\u0442\u0440\u0435\u0447!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <\/p>\n<div class=\"tm-article-poll\">\n<div class=\"tm-notice tm-article-poll__notice tm-notice_positive\"><!----> <\/p>\n<div class=\"tm-notice__inner\"><!----> <\/p>\n<div data-test-id=\"notice-content\" class=\"tm-notice__content\"><span>\u0422\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u043f\u0440\u043e\u0441\u0435. <a rel=\"nofollow\" href=\"\/kek\/v1\/auth\/habrahabr\/?back=\/ru\/post\/701284\/&#038;hl=ru\">\u0412\u043e\u0439\u0434\u0438\u0442\u0435<\/a>, \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430.<\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"tm-article-poll__header\">\u0414\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435?<\/div>\n<div class=\"tm-article-poll__answers\">\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent tm-article-poll__answer-percent_winning\">             100%           <\/span> <span class=\"tm-article-poll__answer-label\">\u0414\u0430<\/span> <span class=\"tm-article-poll__answer-votes\">             1           <\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress tm-article-poll__answer-progress_winning\" style=\"width:100%;\"><\/div>\n<\/div>\n<\/div>\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent\">             0%           <\/span> <span class=\"tm-article-poll__answer-label\">\u041d\u0435\u0442<\/span> <span class=\"tm-article-poll__answer-votes\">             0           <\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress\" style=\"width:0%;\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"tm-article-poll__stats\">        \u041f\u0440\u043e\u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b 1 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c.          \u0412\u043e\u0437\u0434\u0435\u0440\u0436\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u043d\u0435\u0442.      <\/div>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/701284\/\"> https:\/\/habr.com\/ru\/post\/701284\/<\/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, Habr!<\/p>\n<p>Postgres &#8212; \u043e\u0434\u0438\u043d \u0438\u0437 \u043a\u0440\u0443\u043f\u043d\u0435\u0439\u0448\u0438\u0445 open source \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432. \u041e\u043d \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0441\u044f \u043c\u043d\u043e\u0433\u0438\u0435 \u0433\u043e\u0434\u0430. \u041a\u043e\u0434\u043e\u0432\u0430\u044f \u0431\u0430\u0437\u0430 \u043d\u0430\u043a\u043e\u043f\u0438\u043b\u0430\u0441\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u0430\u044f. \u041c\u043d\u0435, \u043a\u0430\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443, \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u044b\u043b\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043a\u0430\u043a \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c. \u041d\u043e \u043d\u0435 \u043f\u0440\u043e SQL \u043f\u043e\u0439\u0434\u0435\u0442 \u0440\u0435\u0447\u044c, \u0430 \u043f\u0440\u043e \u044f\u0437\u044b\u043a \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043d \u043d\u0430\u043f\u0438\u0441\u0430\u043d. \u041f\u0440\u043e C.\u00a0<\/p>\n<p>\u0421 \u043e\u0431\u0449\u0435\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f <a href=\"https:\/\/github.com\/yum-install-brains\/postgresql-spot\/blob\/master\/architecture\/architecture.md\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a><\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0439\u043c\u0435\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0434\u043e \u0432\u0445\u043e\u0434\u0430 \u0432 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0441\u0435\u0440\u0432\u0435\u0440\u0430. <\/p>\n<h2>int main(int argc, char** argv)<\/h2>\n<p>\u041b\u044e\u0431\u043e\u0435 C \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 main(). \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/backend\/main\/main.c\" rel=\"noopener noreferrer nofollow\">src\/backend\/main\/main.c\u00a0<\/a><\/p>\n<p>\u0421\u0430\u043c main \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u0435\u0439:<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0445\u0430\u043a\u043e\u0432 \u0441\u0442\u0430\u0440\u0442\u0430<\/strong><\/p>\n<p>Postgres \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430\u0445: Linux, Windows, FreeBSD \u0438 \u0442.\u0434. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u044b. \u0427\u0442\u043e\u0431\u044b \u0438\u0445 \u0443\u0447\u0435\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u044d\u0442\u0430 \u0447\u0430\u0441\u0442\u044c.\u00a0<\/p>\n<p>\u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0437\u0434\u0435\u0441\u044c \u0445\u0430\u043a\u0438 \u0434\u043b\u044f Windows:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 Winsock<\/p>\n<\/li>\n<li>\n<p>\u0423\u0431\u0440\u0430\u0442\u044c GUI \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0435<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0441\u0431\u043e\u0435\u0432 \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f <em>dummy spinlock<\/em>: \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430\u0445 \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u044b\u0439 \u0431\u0430\u0440\u044c\u0435\u0440 \u043f\u0430\u043c\u044f\u0442\u0438 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c (<code>pg_memory_barrier()<\/code>).\u00a0<\/p>\n<p>\u0421\u0430\u043c \u043c\u0435\u0442\u043e\u0434 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043b\u043e\u043a\u0430 \u0432 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435: \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u043e\u0432 \u0432 -1, \u0442.\u0435. \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u044b. \u0421\u0430\u043c \u0442\u0438\u043f \u043b\u043e\u043a\u0430 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>slock_t<\/code><\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u043d\u0443\u0442\u0440\u0438 \u0441\u043f\u0438\u043d\u043b\u043e\u043a\u043e\u0432<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0415\u0441\u043b\u0438 \u043a\u043e\u043f\u043d\u0443\u0442\u044c \u0433\u043b\u0443\u0431\u0436\u0435 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043b\u043e\u043a\u043e\u0432, \u0442\u043e \u0432\u044b \u0435\u0435 \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0438 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e. \u041e\u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u0430 &#8212; \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u043d\u043e \u0438 \u043e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f.\u00a0<\/p>\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/include\/storage\/s_lock.h\" rel=\"noopener noreferrer nofollow\">s_lock.h<\/a> \u0434\u0435\u043a\u043b\u0430\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0442\u0438\u043f\u044b \u0434\u043b\u044f \u0441\u043f\u0438\u043d \u043b\u043e\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c. \u0412\u043e\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u043d\u043b\u043e\u043a\u0430 \u0434\u043b\u044f linux, \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e gcc \u0434\u043b\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 Intel \u0434\u043b\u044f x32 \u0441\u0438\u0441\u0442\u0435\u043c\u044b<\/p>\n<pre><code class=\"cpp\">typedef unsigned char slock_t;<\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f HP \u0438\u043b\u0438 gcc \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u0432<\/p>\n<pre><code class=\"cpp\">typedef struct { intsema[4]; } slock_t;<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u043e\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043e\u0432\/\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c? \u0412\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e &#8212; \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440. \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u0433\u043b\u044f\u043d\u0435\u0442\u0435 \u0432 \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u0442\u0435, \u0447\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u0442\u0438\u043f\u043e\u0432 \u0441\u043f\u0438\u043d\u043b\u043e\u043a\u043e\u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f TAS (Test And Set) \u043c\u0430\u043a\u0440\u043e\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0442\u044c\u0441\u044f API Postgres. \u0418 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435 \u043c\u0430\u043a\u0440\u043e\u0441\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440. \u0412\u043e\u0442 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043b\u043d\u043e\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 \u0438 \u043c\u0430\u043a\u0440\u043e\u0441\u0430 \u0434\u043b\u044f 32 \u0431\u0438\u0442\u043d\u043e\u0433\u043e Intel \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e gcc<\/p>\n<pre><code class=\"cpp\">#if defined(__GNUC__) || defined(__INTEL_COMPILER) #ifdef __i386__\/* 32-bit i386 *\/ #define HAS_TEST_AND_SET  typedef unsigned char slock_t;  #define TAS(lock) tas(lock)  static __inline__ int tas(volatile slock_t *lock) { register slock_t _res = 1; __asm__ __volatile__( \"cmpb$0,%1\\n\" \"jne1f\\n\" \"lock\\n\" \"xchgb%0,%1\\n\" \"1: \\n\" :\"+q\"(_res), \"+m\"(*lock) :\/* no inputs *\/ :\"memory\", \"cc\"); return (int) _res; }  #define SPIN_DELAY() spin_delay()  static __inline__ void spin_delay(void) { __asm__ __volatile__( \" rep; nop\\n\"); }  #endif \/* __i386__ *\/ #endif<\/code><\/pre>\n<p>\u042d\u0442\u0438 \u043c\u0430\u043a\u0440\u043e\u0441\u044b &#8212; \u043d\u0435 \u0447\u0430\u0441\u0442\u044c API, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u0442\u0430\u043b\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u0445 \u043d\u0435 \u043d\u0430\u0434\u043e.<\/p>\n<\/div>\n<\/details>\n<p><strong>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f MemoryContext<\/strong><\/p>\n<p>\u0412 Postgres \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f (\u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u043d\u0435 \u043d\u0430 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0439 \u043e\u0441\u043d\u043e\u0432\u0435) \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 C (malloc, palloc). \u0412\u043c\u0435\u0441\u0442\u043e, \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u044b\u0439 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u043f\u0430\u043c\u044f\u0442\u0438, \u0442.\u0435. \u043f\u0430\u043c\u044f\u0442\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u0430\u044f.\u00a0<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u0440\u0430\u0442\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u0435\u043d\u0435\u0434\u0436\u043c\u0435\u043d\u0442\u0430 \u043f\u0430\u043c\u044f\u0442\u0438<\/summary>\n<div class=\"spoiler__content\">\n<p>MemoryContext &#8212; \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e (<a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/include\/utils\/palloc.h\" rel=\"noopener noreferrer nofollow\">palloc.h<\/a>). \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438 \u043f\u0430\u043c\u044f\u0442\u0438. \u0413\u0440\u0443\u0431\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u044d\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\/\u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0440\u044f\u0434 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 (<a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/include\/nodes\/memnodes.h\" rel=\"noopener noreferrer nofollow\">memnodes.h<\/a>):<\/p>\n<pre><code class=\"cpp\">typedef struct MemoryContextMethods { void   *(*alloc) (MemoryContext context, Size size); void(*free_p) (MemoryContext context, void *pointer); void   *(*realloc) (MemoryContext context, void *pointer, Size size); void(*reset) (MemoryContext context); void(*delete_context) (MemoryContext context); Size(*get_chunk_space) (MemoryContext context, void *pointer); bool(*is_empty) (MemoryContext context); void(*stats) (MemoryContext context,   MemoryStatsPrintFunc printfunc, void *passthru,   MemoryContextCounters *totals,   bool print_to_stderr); #ifdef MEMORY_CONTEXT_CHECKING void(*check) (MemoryContext context); #endif } MemoryContextMethods;<\/code><\/pre>\n<p>\u0412\u0441\u0435\u0433\u043e \u0435\u0441\u0442\u044c 3 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p><em>AllocSet<\/em> &#8212; \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/p>\n<\/li>\n<li>\n<p><em>SlabContext<\/em> &#8212; \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0447\u0430\u043d\u043a\u0430\u043c\u0438 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430<\/p>\n<\/li>\n<li>\n<p><em>GenerationContext<\/em> &#8212; \u0434\u043b\u044f \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0433\u0440\u0443\u043f\u043f\u0430\u043c\u0438 \u0447\u0430\u043d\u043a\u043e\u0432 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043e\u0434\u043d\u0438\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0435 \u0437\u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u044b:<\/p>\n<ul>\n<li>\n<p><em>TopMemoryContext<\/em> &#8212; \u0432\u0435\u0440\u0445\u043d\u0435\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/p>\n<\/li>\n<li>\n<p><em>PostmasterContext<\/em> &#8212; \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f Postmaster. \u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u044d\u043a\u044d\u043d\u0434\u0430, \u0431\u044d\u043a\u044d\u043d\u0434\u043e\u043c \u0436\u0435 \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437-\u0437\u0430 \u043d\u0435\u043d\u0430\u0434\u043e\u0431\u043d\u043e\u0441\u0442\u0438<\/p>\n<\/li>\n<li>\n<p><em>CacheMemoryContext<\/em> &#8212; \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u044d\u0448\u0430<\/p>\n<\/li>\n<li>\n<p><em>MessageContext<\/em> &#8212; \u0445\u0440\u0430\u043d\u0438\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u0441 \u0444\u0440\u043e\u043d\u0442\u044d\u043d\u0434\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0435\u0440\u0435\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430\/\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p><em>TopTransactionContext<\/em> &#8212; \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438. \u0425\u0440\u0430\u043d\u0438\u0442 \u0432\u0441\u0435, \u0447\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0435\u0439<\/p>\n<\/li>\n<li>\n<p><em>CurTransactionContext<\/em> &#8212; \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f \u043f\u043e\u0434-\u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0439. \u0415\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0442\u043e\u043b\u044c\u043a\u043e 1 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f, \u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 <em>TopTransactionContext<\/em><\/p>\n<\/li>\n<li>\n<p><em>PortalContext<\/em> &#8212; \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 Portal.\u00a0 (Portal &#8212; \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f \u043d\u0430\u0434 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u043c\u0441\u044f\/\u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0432\u0448\u0438\u043c\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0430)<\/p>\n<\/li>\n<li>\n<p><em>ErrorContext<\/em> &#8212; \u043f\u0435\u0440\u0441\u0438\u0442\u0435\u043d\u0442\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439\u0441\u044f \u043f\u0440\u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u043f\u043e\u0441\u043b\u0435 \u043e\u0448\u0438\u0431\u043e\u043a.\u00a0<\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/backend\/utils\/mmgr\/README\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a><\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0430\u043a \u0432\u043e\u0442, \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043f\u0430\u043c\u044f\u0442\u0438 (TopMemoryContext) &#8212; \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>MemoryContextInit();<\/code><\/p>\n<p><strong>\u041b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/strong><\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f. \u0412\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f:<\/p>\n<ul>\n<li>\n<p><em>LC_COLLATE<\/em> &#8212; \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0441\u0442\u0440\u043e\u043a<\/p>\n<\/li>\n<li>\n<p><em>LC_CTYPE<\/em> &#8212; \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b \u0432 \u043d\u0438\u0436\u043d\u0435\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435 \u0438\u043b\u0438 \u043d\u0435\u0442)\u00a0<\/p>\n<\/li>\n<li>\n<p><em>LC_MESSAGES<\/em> &#8212; \u044f\u0437\u044b\u043a \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/p>\n<\/li>\n<li>\n<p><em>LC_MONETARY<\/em> &#8212; \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0430\u043b\u044e\u0442<\/p>\n<\/li>\n<li>\n<p><em>LC_NUMERIC<\/em> &#8212; \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0447\u0438\u0441\u0435\u043b<\/p>\n<\/li>\n<li>\n<p><em>LC_TIME<\/em> &#8212; \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u0442 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <em>LC_ALL<\/em> \u0441\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f.\u00a0<\/p>\n<p>* \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u0435\u043a\u044d\u043d\u0434\u043e\u0432, \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0432\u043e\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0437 pg_database, \u043d\u043e postmaster \u044d\u0442\u043e\u0433\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442.<\/p>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0431\u0430\u0433 \u0441 <em>strxfrm<\/em><\/p>\n<details class=\"spoiler\">\n<summary>\u0411\u0430\u043a strxfrm<\/summary>\n<div class=\"spoiler__content\">\n<p><code>strxfrm<\/code> &#8212; C \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0449\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0443 src \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u0443\u044e \u043e\u0442 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043b\u043e\u043a\u0430\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0443 \u0438 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 num \u0431\u0430\u0439\u0442\u043e\u0432 \u0432 dest.\u00a0<\/p>\n<pre><code class=\"cpp\">size_t strxfrm(char *destptr, const char *src, size_t num);<\/code><\/pre>\n<p>\u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437 \u0438 \u043e\u0442 \u043d\u0435\u0435 \u043c\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442, \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043a\u0430\u043a \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0430\u0433\u0430, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0441 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0441\u0432\u0435\u0449\u0435\u043d\u043e.<\/p>\n<p>\u0411\u0430\u0433\u043e\u0432 2 \u0438 \u043e\u0431\u0430 \u043d\u0430 \u041e\u0421 Solaris. \u041e\u0448\u0438\u0431\u043a\u0430 \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u0440\u0430\u0431\u043e\u0442\u043e\u0439 \u0441 \u043c\u0430\u043b\u044b\u043c\u0438 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0430\u0445:\u00a0<\/p>\n<ul>\n<li>\n<p>\u0414\u043b\u044f 2 \u0431\u0430\u0439\u0442\u043d\u043e\u0439 ASCII \u0441\u0442\u0440\u043e\u043a\u0438 Solaris 10 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 10 \u0431\u0430\u0439\u0442\u043e\u0432 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 18<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 num \u0440\u0430\u0432\u043d\u044b\u0439 1, \u0442\u043e \u044d\u0442\u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0430\u0439\u0442\u043e\u0432 \u043d\u0430 1 \u043c\u0435\u043d\u044c\u0448\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0438\u0437 \u0431\u0430\u0433\u043e\u0432 \u0431\u044b\u043b \u043d\u0430\u0439\u0434\u0435\u043d, \u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u043a\u0430\u043d\u0430\u0440\u0435\u0439\u043a\u0430<\/p>\n<pre><code class=\"cpp\">void check_strxfrm_bug(void) { charbuf[32]; const intcanary = 0x7F; boolok = true;  \/*  * Given a two-byte ASCII string and length limit 7, 8 or 9, Solaris 10  * 05\/08 returns 18 and modifies 10 bytes.  It respects limits above or  * below that range.  *  * The bug is present in Solaris 8 as well; it is absent in Solaris 10  * 01\/13 and Solaris 11.2.  Affected locales include is_IS.ISO8859-1,  * en_US.UTF-8, en_US.ISO8859-1, and ru_RU.KOI8-R.  Unaffected locales  * include de_DE.UTF-8, de_DE.ISO8859-1, zh_TW.UTF-8, and C.  *\/ buf[7] = canary; (void) strxfrm(buf, \"ab\", 7); if (buf[7] != canary) ok = false;  \/*  * illumos bug #1594 was present in the source tree from 2010-10-11 to  * 2012-02-01.  Given an ASCII string of any length and length limit 1,  * affected systems ignore the length limit and modify a number of bytes  * one less than the return value.  The problem inputs for this bug do not  * overlap those for the Solaris bug, hence a distinct test.  *  * Affected systems include smartos-20110926T021612Z.  Affected locales  * include en_US.ISO8859-1 and en_US.UTF-8.  Unaffected locales include C.  *\/ buf[1] = canary; (void) strxfrm(buf, \"a\", 1); if (buf[1] != canary) ok = false;  if (!ok) ereport(ERROR, (errcode(ERRCODE_SYSTEM_ERROR),  errmsg_internal(\"strxfrm(), in locale \\\"%s\\\", writes past the specified array length\",  setlocale(LC_COLLATE, NULL)),  errhint(\"Apply system library package updates.\"))); }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p><strong>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u201c\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0435\u201d \u0444\u043b\u0430\u0433\u0438<\/strong><\/p>\n<p>\u041f\u043e\u0434 \u201c\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c\u0438\u201d \u0438\u043c\u0435\u044e \u0432\u0432\u0438\u0434\u0443 \u043d\u0435 \u043c\u0435\u043d\u044f\u044e\u0449\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442\u0441\u044f:<\/p>\n<ul>\n<li>\n<p>\u2013help &#8212; \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043f\u043e\u043c\u043e\u0449\u0438<\/p>\n<\/li>\n<li>\n<p>\u2013version &#8212; \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u044e<\/p>\n<\/li>\n<li>\n<p>\u2013describe-config, -C &#8212; \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044f help \u0438 version \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 (\u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f exit(0)).\u00a0<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0444\u043b\u0430\u0433 (&#8212;describe-config \u0438\u043b\u0438 -C), \u0442\u043e \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0444\u043b\u0430\u0433 <em>do_check_root<\/em> \u0432 <em>false<\/em>. \u0417\u0430\u0447\u0435\u043c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<p><strong>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0440\u0443\u0442\u0430<\/strong><\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u0441\u044f \u043d\u0435 \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043f\u043e\u043c\u043e\u0449\u0438 (<em>&#8212;help<\/em>) \u0438\u043b\u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u044e (<em>&#8212;version<\/em>), \u0442\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u0441\u044f \u0432 \u0440\u0430\u0431\u043e\u0447\u0435\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0432\u043b\u0435\u0447\u044c \u0437\u0430 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f. \u0417\u0430\u043f\u0443\u0441\u043a \u043f\u043e\u0434 \u0430\u0434\u043c\u0438\u043d\u043e\u043c &#8212; \u043d\u0435 \u0441\u0430\u043c\u0430\u044f \u043b\u0443\u0447\u0448\u0430\u044f \u0438\u0434\u0435\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u0431\u044b\u043b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d \u0444\u043b\u0430\u0433 do_check_root \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c true.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0441 do_check_root \u0440\u0430\u0432\u043d\u044b\u043c <em>true<\/em>, \u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>check_root()<\/code> \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 (\u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b), \u0447\u0442\u043e \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u0441\u044f \u043e\u0442 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430:<\/p>\n<ul>\n<li>\n<p>UID = 0 \u0434\u043b\u044f unix,\u00a0<\/p>\n<\/li>\n<li>\n<p>pg32win_isadmin() \u0434\u043b\u044f Windows.\u00a0<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0440\u0443\u0442, \u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c\u0441\u044f.<\/p>\n<details class=\"spoiler\">\n<summary>void check_root(const char *progname)<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">static void check_root(const char *progname) { #ifndef WIN32 if (geteuid() == 0) { write_stderr(\"\\\"root\\\" execution of the PostgreSQL server is not permitted.\\n\"  \"The server must be started under an unprivileged user ID to prevent\\n\"  \"possible system security compromise.  See the documentation for\\n\"  \"more information on how to properly start the server.\\n\"); exit(1); }  \/*  * Also make sure that real and effective uids are the same. Executing as  * a setuid program from a root shell is a security hole, since on many  * platforms a nefarious subroutine could setuid back to root if real uid  * is root.  (Since nobody actually uses postgres as a setuid program,  * trying to actively fix this situation seems more trouble than it's  * worth; we'll just expend the effort to check for it.)  *\/ if (getuid() != geteuid()) { write_stderr(\"%s: real and effective user IDs must match\\n\",  progname); exit(1); } #else\/* WIN32 *\/ if (pgwin32_is_admin()) { write_stderr(\"Execution of PostgreSQL by a user with<\/code><\/pre>\n<\/div>\n<\/details>\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-341634","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/341634","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=341634"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/341634\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=341634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=341634"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=341634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}