{"id":41594,"date":"2023-07-12T21:54:06","date_gmt":"2023-02-21T18:30:23","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/postgresql%e7%9a%84%e4%bf%a1%e5%8f%b7%e5%a4%84%e7%90%86%e9%83%a8%e5%88%86\/"},"modified":"2024-04-30T13:15:26","modified_gmt":"2024-04-30T05:15:26","slug":"postgresql%e7%9a%84%e4%bf%a1%e5%8f%b7%e5%a4%84%e7%90%86%e9%83%a8%e5%88%86","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/postgresql%e7%9a%84%e4%bf%a1%e5%8f%b7%e5%a4%84%e7%90%86%e9%83%a8%e5%88%86\/","title":{"rendered":"PostgreSQL\u7684\u4fe1\u53f7\u5904\u7406\u90e8\u5206"},"content":{"rendered":"<h1>\u73af\u5883<\/h1>\n<p>PostgreSQL 10.5\uff1aPostgreSQL 10.5 \u7248\u672c<\/p>\n<h1>\u4e2d\u6587\u7ffb\u8bd1\uff1a\u5f00\u573a\u767d<\/h1>\n<p>\u6709\u65f6\u4f1a\u51fa\u73b0\u6267\u884c\u975e\u5e38\u91cd\u7684SQL\u5bfc\u81f4\u6570\u636e\u5e93\u6027\u80fd\u663e\u8457\u4e0b\u964d\u7684\u60c5\u51b5\u3002\u6211\u5c1d\u8bd5\u53d6\u6d88\u76f8\u5e94\u7684\u540e\u7aef\u8fdb\u7a0b\u67e5\u8be2\uff0c\u4f7f\u7528\u4e86pg_cancel_backend(pid int)\uff0c\u4f46\u67e5\u8be2\u5e76\u672a\u88ab\u53d6\u6d88\u3002\u5373\u4f7f\u4f7f\u7528pg_terminate_backend(pid int)\u4e5f\u65e0\u6cd5\u7ec8\u6b62\u8fdb\u7a0b\uff0c\u5e76\u91cd\u65b0\u542f\u52a8\u8bf7\u6c42\u6267\u884c\u8be5\u67e5\u8be2\u7684\u8fdb\u7a0b\uff0c\u60c5\u51b5\u4f9d\u7136\u6ca1\u6709\u6539\u53d8\uff0c\u6700\u7ec8\u6211\u9009\u62e9\u91cd\u65b0\u542f\u52a8\u4e86\u6570\u636e\u5e93\u3002\u6211\u77e5\u9053pg_cancel_backend()\u53d1\u9001\u4e86sigint\u4fe1\u53f7\uff0cpg_terminate_backend()\u53d1\u9001\u4e86sigterm\u4fe1\u53f7\uff0c\u4f46\u4e3a\u4ec0\u4e48\u67e5\u8be2\u65e0\u6cd5\u88ab\u6b63\u786e\u53d6\u6d88\uff0c\u8fdb\u7a0b\u65e0\u6cd5\u88ab\u7ec8\u6b62\u5462\uff1f\u4e8e\u662f\u6211\u67e5\u770b\u4e86\u5b9e\u73b0\u3002<\/p>\n<h1>\u4fe1\u53f7\u76f8\u5173\u7684\u4ee3\u7801<\/h1>\n<p>\u9996\u5148\uff0cPostgreSQL\u6709\u4e00\u4e2a\u540d\u4e3apostmaster\u7684\u5b88\u62a4\u8fdb\u7a0b\uff0c\u7528\u4e8e\u63a5\u6536\u6765\u81ea\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\uff0c\u5e76\u5728\u9700\u8981\u65f6fork\u51fa\u540e\u7aef\u8fdb\u7a0b\uff08\u53ef\u4ee5\u8bf4\u6240\u6709\u6784\u6210PostgreSQL\u7684\u8fdb\u7a0b\u90fd\u662f\u4ecepostmaster\u4e2dfork\u51fa\u6765\u7684\uff09\u3002postmaster\u5728\u521d\u59cb\u5316\u65f6\u8fd8\u4f1a\u8fdb\u884c\u4fe1\u53f7\u5c4f\u853d\u548c\u4fe1\u53f7\u5904\u7406\u7a0b\u5e8f\u7684\u6ce8\u518c\u3002\u540e\u7aef\u8fdb\u7a0b\u4ecepostmaster\u4e2dfork\u51fa\u6765\uff0c\u56e0\u6b64\u4f1a\u6ce8\u518c\u9488\u5bf9sigint\u548csigterm\u7684\u540e\u7aef\u8fdb\u7a0b\u4fe1\u53f7\u5904\u7406\u7a0b\u5e8f\u3002\u5728\u6e90\u4ee3\u7801\u4e2d\uff0c\u53ef\u4ee5\u5728main()\u7684\u6700\u540e\u8c03\u7528PostmasterMain(argc, argv)\u51fd\u6570\uff0c\u8fd9\u4e2a\u51fd\u6570\u4f1a\u6267\u884c\u975e\u5e38\u591a\u7684\u64cd\u4f5c\uff08\u5982\u5904\u7406\u9009\u9879\u3001\u521b\u5efa\u5957\u63a5\u5b57\u7b49\uff09\u3002\u5176\u4e2d\u4e00\u4e2a\u64cd\u4f5c\u662f\u5904\u7406\u4fe1\u53f7\u3002\u4ee5\u4e0b\u662f\u6ce8\u518c\u4fe1\u53f7\u7684\u90e8\u5206\uff08\u5b9e\u9645\u4e0a\u8fd8\u6d89\u53ca\u66f4\u591a\u7684\u4fe1\u53f7\uff0c\u4f46\u5728\u8fd9\u91cc\u6211\u4eec\u4e3b\u8981\u770bsigterm\u548csigint\uff09\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"n\">pqinitmask<\/span><span class=\"p\">();<\/span>\r\n<span class=\"n\">PG_SETMASK<\/span><span class=\"p\">(<\/span><span class=\"o\">&amp;<\/span><span class=\"n\">BlockSig<\/span><span class=\"p\">);<\/span>\r\n                                                 <span class=\"o\">*<\/span> <span class=\"n\">have<\/span> <span class=\"n\">children<\/span> <span class=\"k\">do<\/span> <span class=\"n\">same<\/span> <span class=\"err\">*\/<\/span>\r\n<span class=\"n\">pqsignal_no_restart<\/span><span class=\"p\">(<\/span><span class=\"n\">SIGINT<\/span><span class=\"p\">,<\/span> <span class=\"n\">pmdie<\/span><span class=\"p\">);<\/span> <span class=\"cm\">\/* send SIGTERM and shut down *\/<\/span>\r\n<span class=\"n\">pqsignal_no_restart<\/span><span class=\"p\">(<\/span><span class=\"n\">SIGQUIT<\/span><span class=\"p\">,<\/span> <span class=\"n\">pmdie<\/span><span class=\"p\">);<\/span>    <span class=\"cm\">\/* send SIGQUIT and die *\/<\/span>\r\n<span class=\"n\">pqsignal_no_restart<\/span><span class=\"p\">(<\/span><span class=\"n\">SIGTERM<\/span><span class=\"p\">,<\/span> <span class=\"n\">pmdie<\/span><span class=\"p\">);<\/span>    <span class=\"cm\">\/* wait for children and shut down *\/<\/span>\r\n<\/code><\/pre>\n<p>\u4ece\u4e0a\u5f80\u4e0b\u770b\u3002\u5728pqinitmask()\u51fd\u6570\u4e2d\uff0c\u521d\u59cb\u5316\u4e86\u5168\u5c40\u53d8\u91cfBlockSig\uff08\u4ee5\u53caStartupBlockSig\uff09\u3002\u7136\u540e\uff0cPG_SETMASK(mask)\u662fsigprocmask(SIG_SETMASK, mask, NULL)\u7684\u5b8f\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u8fdb\u884c\u4fe1\u53f7\u963b\u585e\u3002pqsignal_no_restart()\u5c06sigaction(2)\u7ed3\u6784\u4f53\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570sa_flags\u8bbe\u4e3a0\uff0c\u5e76\u8c03\u7528sigaction(2)\u51fd\u6570\u5c06\u4f20\u5165\u7684\u51fd\u6570\u4f5c\u4e3a\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u3002\u800cpqsignal()\u5c06sa_flags\u8bbe\u4e3aSA_RESTART\uff0c\u5e76\u8c03\u7528sigaction(2)\u51fd\u6570\u5c06\u4f20\u5165\u7684\u51fd\u6570\u4f5c\u4e3a\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u3002<\/p>\n<p>PostmasterMain(argc, argv)\u8fdb\u5165\u4e00\u4e2a\u5faa\u73af\uff0c\u6700\u7ec8\u7b49\u5f85\u6765\u81ea\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u3002\u8fd9\u4e2a\u5faa\u73af\u5c31\u662fServerLoop()\u51fd\u6570\u3002\u5728ServerLoop()\u51fd\u6570\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528select(2)\u51fd\u6570\u6765\u76d1\u89c6\u6765\u81ea\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u3002\u7136\u540e\uff0c\u5728\u4ee5\u4e0b\u90e8\u5206\uff0c\u6211\u4eec\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u8fdb\u7a0b\uff0c\u5e76\u5728\u8be5\u8fdb\u7a0b\u4e2d\u5904\u7406\u67e5\u8be2\u3002\u8fd9\u5c31\u662f\u540e\u7aef\u8fdb\u7a0b\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"n\">Port<\/span>       <span class=\"o\">*<\/span><span class=\"n\">port<\/span><span class=\"p\">;<\/span>\r\n\r\n<span class=\"n\">port<\/span> <span class=\"o\">=<\/span> <span class=\"n\">ConnCreate<\/span><span class=\"p\">(<\/span><span class=\"n\">ListenSocket<\/span><span class=\"p\">[<\/span><span class=\"n\">i<\/span><span class=\"p\">]);<\/span>\r\n<span class=\"k\">if<\/span> <span class=\"p\">(<\/span><span class=\"n\">port<\/span><span class=\"p\">)<\/span>\r\n<span class=\"p\">{<\/span>\r\n    <span class=\"n\">BackendStartup<\/span><span class=\"p\">(<\/span><span class=\"n\">port<\/span><span class=\"p\">);<\/span>\r\n\r\n    <span class=\"cm\">\/*\r\n     * We no longer need the open socket or port structure\r\n     * in this process\r\n     *\/<\/span>\r\n    <span class=\"n\">StreamClose<\/span><span class=\"p\">(<\/span><span class=\"n\">port<\/span><span class=\"o\">-&gt;<\/span><span class=\"n\">sock<\/span><span class=\"p\">);<\/span>\r\n    <span class=\"n\">ConnFree<\/span><span class=\"p\">(<\/span><span class=\"n\">port<\/span><span class=\"p\">);<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<p>\u786e\u8ba4\u4e86\u53ef\u8bfb\u5199\u7684\u5957\u63a5\u5b57\u4e4b\u540e\uff0c\u6211\u4eec\u8fdb\u884c\u8def\u5f84\u9009\u62e9\u3002\u5728\u8fd9\u91cc\uff0c\u8c03\u7528BackendStartup()\u51fd\u6570\u6765\u751f\u6210\u540e\u7aef\u8fdb\u7a0b\u3002\u5b9e\u9645\u4e0a\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u6b63\u5728\u8fdb\u884c\u7684fork(2)\u64cd\u4f5c\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"n\">pid<\/span> <span class=\"o\">=<\/span> <span class=\"n\">fork_process<\/span><span class=\"p\">();<\/span>\r\n<span class=\"k\">if<\/span> <span class=\"p\">(<\/span><span class=\"n\">pid<\/span> <span class=\"o\">==<\/span> <span class=\"mi\">0<\/span><span class=\"p\">)<\/span>               <span class=\"cm\">\/* child *\/<\/span>\r\n<span class=\"p\">{<\/span>\r\n    <span class=\"n\">free<\/span><span class=\"p\">(<\/span><span class=\"n\">bn<\/span><span class=\"p\">);<\/span>\r\n\r\n    <span class=\"cm\">\/* Detangle from postmaster *\/<\/span>\r\n    <span class=\"n\">InitPostmasterChild<\/span><span class=\"p\">();<\/span>\r\n\r\n    <span class=\"cm\">\/* Close the postmaster's sockets *\/<\/span>\r\n    <span class=\"n\">ClosePostmasterPorts<\/span><span class=\"p\">(<\/span><span class=\"nb\">false<\/span><span class=\"p\">);<\/span>\r\n\r\n    <span class=\"cm\">\/* Perform additional initialization and collect startup packet *\/<\/span>\r\n    <span class=\"n\">BackendInitialize<\/span><span class=\"p\">(<\/span><span class=\"n\">port<\/span><span class=\"p\">);<\/span>\r\n\r\n    <span class=\"cm\">\/* And run the backend *\/<\/span>\r\n    <span class=\"n\">BackendRun<\/span><span class=\"p\">(<\/span><span class=\"n\">port<\/span><span class=\"p\">);<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<p>pid\u4e3a0\u662f\u5b50\u8fdb\u7a0b\uff0c\u56e0\u6b64\u8fd9\u662f\u540e\u7aef\u8fdb\u7a0b\u7684\u6267\u884c\u8def\u5f84\u3002\u5728\u5176\u4e2d\uff0c\u6709\u5173\u4fe1\u53f7\u5904\u7406\u7684\u64cd\u4f5c\u5728BackendInitialize()\u51fd\u6570\u4e2d\u5904\u7406\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"n\">pqsignal<\/span><span class=\"p\">(<\/span><span class=\"n\">SIGTERM<\/span><span class=\"p\">,<\/span> <span class=\"n\">startup_die<\/span><span class=\"p\">);<\/span>\r\n<span class=\"n\">pqsignal<\/span><span class=\"p\">(<\/span><span class=\"n\">SIGQUIT<\/span><span class=\"p\">,<\/span> <span class=\"n\">startup_die<\/span><span class=\"p\">);<\/span>\r\n<span class=\"n\">InitializeTimeouts<\/span><span class=\"p\">();<\/span>       <span class=\"cm\">\/* establishes SIGALRM handler *\/<\/span>\r\n<span class=\"n\">PG_SETMASK<\/span><span class=\"p\">(<\/span><span class=\"o\">&amp;<\/span><span class=\"n\">StartupBlockSig<\/span><span class=\"p\">);<\/span>\r\n<\/code><\/pre>\n<p>\u4ecepgsignal.c\u4e2d\u53ef\u4ee5\u770b\u51fa\uff0cStartupBlockSig\u662f\u9664\u4e86sigterm\u3001sigquit\u548csigalarm\u4e4b\u5916\u7684\u4e00\u4e2a\u9879\u3002\u662f\u7684\uff0c\u8fd9\u6837\u4e00\u6765\uff0c\u540e\u7aef\u8fdb\u7a0b\u5728\u542f\u52a8\u65f6\u5c06startup_die\u6ce8\u518c\u4e3a\u4fe1\u53f7\u5904\u7406\u7a0b\u5e8f\u3002\u5b83\u4f1a\u6267\u884cexit(2)\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u6765\u770b\u4e00\u4e0bBackendRun()\u3002\u5728\u8fd9\u91cc\u8c03\u7528\u4e86PostgresMain()\uff0c\u800c\u5728\u8be5\u51fd\u6570\u4e2d\u6709\u4e00\u4e2a\u6ce8\u518c\u67e5\u8be2\u5904\u7406\u4fe1\u53f7\u5904\u7406\u5668\u7684\u90e8\u5206\u3002\u4ee5\u4e0b\u662f\u76f8\u5173\u7247\u6bb5\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"n\">pqsignal<\/span><span class=\"p\">(<\/span><span class=\"n\">SIGINT<\/span><span class=\"p\">,<\/span> <span class=\"n\">StatementCancelHandler<\/span><span class=\"p\">);<\/span>   <span class=\"cm\">\/* cancel current query *\/<\/span>\r\n<span class=\"n\">pqsignal<\/span><span class=\"p\">(<\/span><span class=\"n\">SIGTERM<\/span><span class=\"p\">,<\/span> <span class=\"n\">die<\/span><span class=\"p\">);<\/span> <span class=\"cm\">\/* cancel current query and exit *\/<\/span>\r\n<\/code><\/pre>\n<p>\u6bcf\u4e2a\u4fe1\u53f7\u5904\u7406\u7a0b\u5e8f\u90fd\u88ab\u5b9e\u73b0\u4e3a\u4ee5\u4e0b\u65b9\u5f0f\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"kt\">void<\/span>\r\n<span class=\"nf\">StatementCancelHandler<\/span><span class=\"p\">(<\/span><span class=\"n\">SIGNAL_ARGS<\/span><span class=\"p\">)<\/span>\r\n<span class=\"p\">{<\/span>\r\n    <span class=\"kt\">int<\/span>         <span class=\"n\">save_errno<\/span> <span class=\"o\">=<\/span> <span class=\"n\">errno<\/span><span class=\"p\">;<\/span>\r\n\r\n    <span class=\"cm\">\/*\r\n     * Don't joggle the elbow of proc_exit\r\n     *\/<\/span>\r\n    <span class=\"k\">if<\/span> <span class=\"p\">(<\/span><span class=\"o\">!<\/span><span class=\"n\">proc_exit_inprogress<\/span><span class=\"p\">)<\/span>\r\n    <span class=\"p\">{<\/span>\r\n        <span class=\"n\">InterruptPending<\/span> <span class=\"o\">=<\/span> <span class=\"nb\">true<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"n\">QueryCancelPending<\/span> <span class=\"o\">=<\/span> <span class=\"nb\">true<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"p\">}<\/span>\r\n\r\n    <span class=\"cm\">\/* If we're still here, waken anything waiting on the process latch *\/<\/span>\r\n    <span class=\"n\">SetLatch<\/span><span class=\"p\">(<\/span><span class=\"n\">MyLatch<\/span><span class=\"p\">);<\/span>\r\n\r\n    <span class=\"n\">errno<\/span> <span class=\"o\">=<\/span> <span class=\"n\">save_errno<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code><span class=\"kt\">void<\/span>\r\n<span class=\"nf\">die<\/span><span class=\"p\">(<\/span><span class=\"n\">SIGNAL_ARGS<\/span><span class=\"p\">)<\/span>\r\n<span class=\"p\">{<\/span>\r\n    <span class=\"kt\">int<\/span>         <span class=\"n\">save_errno<\/span> <span class=\"o\">=<\/span> <span class=\"n\">errno<\/span><span class=\"p\">;<\/span>\r\n\r\n    <span class=\"cm\">\/* Don't joggle the elbow of proc_exit *\/<\/span>\r\n    <span class=\"k\">if<\/span> <span class=\"p\">(<\/span><span class=\"o\">!<\/span><span class=\"n\">proc_exit_inprogress<\/span><span class=\"p\">)<\/span>\r\n    <span class=\"p\">{<\/span>\r\n        <span class=\"n\">InterruptPending<\/span> <span class=\"o\">=<\/span> <span class=\"nb\">true<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"n\">ProcDiePending<\/span> <span class=\"o\">=<\/span> <span class=\"nb\">true<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"p\">}<\/span>\r\n\r\n    <span class=\"cm\">\/* If we're still here, waken anything waiting on the process latch *\/<\/span>\r\n    <span class=\"n\">SetLatch<\/span><span class=\"p\">(<\/span><span class=\"n\">MyLatch<\/span><span class=\"p\">);<\/span>\r\n\r\n    <span class=\"cm\">\/*\r\n     * If we're in single user mode, we want to quit immediately - we can't\r\n     * rely on latches as they wouldn't work when stdin\/stdout is a file.\r\n     * Rather ugly, but it's unlikely to be worthwhile to invest much more\r\n     * effort just for the benefit of single user mode.\r\n     *\/<\/span>\r\n    <span class=\"k\">if<\/span> <span class=\"p\">(<\/span><span class=\"n\">DoingCommandRead<\/span> <span class=\"o\">&amp;&amp;<\/span> <span class=\"n\">whereToSendOutput<\/span> <span class=\"o\">!=<\/span> <span class=\"n\">DestRemote<\/span><span class=\"p\">)<\/span>\r\n        <span class=\"n\">ProcessInterrupts<\/span><span class=\"p\">();<\/span>\r\n\r\n    <span class=\"n\">errno<\/span> <span class=\"o\">=<\/span> <span class=\"n\">save_errno<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<p>\u6211\u6b63\u5728\u505a\u5404\u79cd\u4e8b\u60c5\uff0c\u4f46\u91cd\u8981\u7684\u662f\u8bbe\u7f6e\u6807\u5fd7\uff08InterruptPending\uff0cQueryCancelPending\uff0cProcDiePending\uff09\u3002\u76f8\u53cd\uff0c\u6ca1\u6709\u53d6\u6d88\u67e5\u8be2\u6216\u6740\u6b7b\u8fdb\u7a0b\u7684\u5904\u7406\u3002\u6211\u7684\u610f\u601d\u662f\uff0c\u8fd9\u662f\u9488\u5bf9PostgreSQL\u4fe1\u53f7\u7684\u5904\u7406\u3002\u5f53\u63a5\u6536\u5230\u4fe1\u53f7\u65f6\uff0c\u5728\u4fe1\u53f7\u5904\u7406\u7a0b\u5e8f\u4e2d\u53ea\u8bbe\u7f6e\u6807\u5fd7\u3002\u7136\u540e\uff0c\u5b9a\u671f\u68c0\u67e5\u8be5\u6807\u5fd7\uff08\u5f53\u7136\uff0c\u5728\u4e0d\u4f1a\u4ea7\u751f\u95ee\u9898\u7684\u60c5\u51b5\u4e0b\u53d6\u6d88\u67e5\u8be2\u6216\u6740\u6b7b\u8fdb\u7a0b\uff09\uff0c\u5e76\u6267\u884c\u4e0e\u4fe1\u53f7\u76f8\u5bf9\u5e94\u7684\u5904\u7406\u3002<\/p>\n<p>\u5728PostgresMain()\u51fd\u6570\u4e2d\uff0c\u8fd8\u6267\u884c\u67e5\u8be2\u64cd\u4f5c\uff0c\u4f46\u662f\u5230\u5904\u90fd\u4f1a\u8c03\u7528CHECK_FOR_INTERRUPTS()\u5b8f\u3002\u8be5\u5b8f\u7684\u5b9a\u4e49\u5982\u4e0b\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"cp\">#define CHECK_FOR_INTERRUPTS() \\\r\ndo { \\\r\n    if (InterruptPending) \\\r\n        ProcessInterrupts(); \\\r\n} while(0)\r\n#else\r\n<\/span><\/code><\/pre>\n<p>\u5982\u679cInterruptPending\u4e3a\u771f\uff0c\u5219\u6267\u884cProcessInterrupts()\u3002\u5982\u679c\u6267\u884csigint\u6216\u8005sigterm\u7684\u4fe1\u53f7\u5904\u7406\u7a0b\u5e8f\uff0cInterruptPending\u5c06\u8bbe\u7f6e\u4e3a\u771f\uff0c\u7136\u540e\u6267\u884cProcessInterrupts()\u3002\u5f53\u6267\u884csigterm\u7684\u4fe1\u53f7\u5904\u7406\u7a0b\u5e8f\u65f6\uff0cProcDiePending\u5c06\u8bbe\u7f6e\u4e3a\u771f\uff0c\u5728ProcessInterrupts()\u5185\uff0c\u5982\u679cProcDiePending\u4e3a\u771f\uff0c\u5219\u51e0\u4e4e\u603b\u662f\u4f1a\u8c03\u7528ereport()\u51fd\u6570\uff0c\u5e76\u5c06\u9519\u8bef\u7ea7\u522b\u8bbe\u7f6e\u4e3aFATAL\u3002\u5f53ereport()\u51fd\u6570\u4ee5FATAL\u9519\u8bef\u7ea7\u522b\u88ab\u8c03\u7528\u65f6\uff0c\u4f1a\u6267\u884cexit(2)\uff0c\u56e0\u6b64\u8fdb\u7a0b\u5c06\u88ab\u7ec8\u6b62\u3002<\/p>\n<h1>\u6982\u62ec<\/h1>\n<p>\u4ee5\u4e0b\u662f\u5bfc\u81f4pg_terminate_backend()\u65e0\u6cd5\u7acb\u5373\u7ec8\u6b62\u8fdb\u7a0b\u7684\u4e24\u4e2a\u539f\u56e0\u3002<\/p>\n<p>sigprocmask(2)\u3067\u30b7\u30b0\u30ca\u30eb\u304c\u30d6\u30ed\u30c3\u30af\u3055\u308c\u3066\u3044\u308b\u6642\u304c\u3042\u308b<br \/>\n\u30b7\u30b0\u30ca\u30eb\u30cf\u30f3\u30c9\u30e9\u30fc\u304c\u5b9f\u969b\u306b\u5b9f\u884c\u3055\u308c\u3066\u3082\u30d5\u30e9\u30b0\u3092\u7acb\u3066\u308b\u3060\u3051\u306a\u306e\u3067\u3001\u4f55\u3089\u304b\u306e\u7406\u7531\u3067\u51e6\u7406\u304c\u6b62\u307e\u3063\u3066\u3044\u308b\u5834\u5408\u3001\u5b9f\u969b\u306e\u671f\u5f85\u3059\u308b\u51e6\u7406\u304c\u884c\u308f\u308c\u306a\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u73af\u5883 PostgreSQL 10.5\uff1aPostgreSQL 10.5 \u7248\u672c \u4e2d\u6587\u7ffb\u8bd1\uff1a\u5f00\u573a\u767d \u6709\u65f6\u4f1a\u51fa\u73b0\u6267\u884c\u975e [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-41594","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PostgreSQL\u7684\u4fe1\u53f7\u5904\u7406\u90e8\u5206 - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/postgresql\u7684\u4fe1\u53f7\u5904\u7406\u90e8\u5206\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL\u7684\u4fe1\u53f7\u5904\u7406\u90e8\u5206\" \/>\n<meta property=\"og:description\" content=\"\u73af\u5883 PostgreSQL 10.5\uff1aPostgreSQL 10.5 \u7248\u672c \u4e2d\u6587\u7ffb\u8bd1\uff1a\u5f00\u573a\u767d \u6709\u65f6\u4f1a\u51fa\u73b0\u6267\u884c\u975e [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/postgresql\u7684\u4fe1\u53f7\u5904\u7406\u90e8\u5206\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-21T18:30:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-30T05:15:26+00:00\" \/>\n<meta name=\"author\" content=\"\u79d1, \u9896\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u79d1, \u9896\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/postgresql%e7%9a%84%e4%bf%a1%e5%8f%b7%e5%a4%84%e7%90%86%e9%83%a8%e5%88%86\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/postgresql%e7%9a%84%e4%bf%a1%e5%8f%b7%e5%a4%84%e7%90%86%e9%83%a8%e5%88%86\/\",\"name\":\"PostgreSQL\u7684\u4fe1\u53f7\u5904\u7406\u90e8\u5206 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-02-21T18:30:23+00:00\",\"dateModified\":\"2024-04-30T05:15:26+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/8ca01ba7f7362ad4edb7da206a12f29e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/postgresql%e7%9a%84%e4%bf%a1%e5%8f%b7%e5%a4%84%e7%90%86%e9%83%a8%e5%88%86\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/postgresql%e7%9a%84%e4%bf%a1%e5%8f%b7%e5%a4%84%e7%90%86%e9%83%a8%e5%88%86\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/postgresql%e7%9a%84%e4%bf%a1%e5%8f%b7%e5%a4%84%e7%90%86%e9%83%a8%e5%88%86\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL\u7684\u4fe1\u53f7\u5904\u7406\u90e8\u5206\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/8ca01ba7f7362ad4edb7da206a12f29e\",\"name\":\"\u79d1, \u9896\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8a6fb3cc7ba2f69d2189ba532aec4633ea7ed75ac0af162ec367cb3abc0fb2af?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8a6fb3cc7ba2f69d2189ba532aec4633ea7ed75ac0af162ec367cb3abc0fb2af?s=96&d=mm&r=g\",\"caption\":\"\u79d1, \u9896\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/keying\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/postgresql%e7%9a%84%e4%bf%a1%e5%8f%b7%e5%a4%84%e7%90%86%e9%83%a8%e5%88%86\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"PostgreSQL\u7684\u4fe1\u53f7\u5904\u7406\u90e8\u5206 - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/postgresql\u7684\u4fe1\u53f7\u5904\u7406\u90e8\u5206\/","og_locale":"zh_CN","og_type":"article","og_title":"PostgreSQL\u7684\u4fe1\u53f7\u5904\u7406\u90e8\u5206","og_description":"\u73af\u5883 PostgreSQL 10.5\uff1aPostgreSQL 10.5 \u7248\u672c \u4e2d\u6587\u7ffb\u8bd1\uff1a\u5f00\u573a\u767d \u6709\u65f6\u4f1a\u51fa\u73b0\u6267\u884c\u975e [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/postgresql\u7684\u4fe1\u53f7\u5904\u7406\u90e8\u5206\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-02-21T18:30:23+00:00","article_modified_time":"2024-04-30T05:15:26+00:00","author":"\u79d1, \u9896","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u79d1, \u9896","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/postgresql%e7%9a%84%e4%bf%a1%e5%8f%b7%e5%a4%84%e7%90%86%e9%83%a8%e5%88%86\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/postgresql%e7%9a%84%e4%bf%a1%e5%8f%b7%e5%a4%84%e7%90%86%e9%83%a8%e5%88%86\/","name":"PostgreSQL\u7684\u4fe1\u53f7\u5904\u7406\u90e8\u5206 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-02-21T18:30:23+00:00","dateModified":"2024-04-30T05:15:26+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/8ca01ba7f7362ad4edb7da206a12f29e"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/postgresql%e7%9a%84%e4%bf%a1%e5%8f%b7%e5%a4%84%e7%90%86%e9%83%a8%e5%88%86\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/postgresql%e7%9a%84%e4%bf%a1%e5%8f%b7%e5%a4%84%e7%90%86%e9%83%a8%e5%88%86\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/postgresql%e7%9a%84%e4%bf%a1%e5%8f%b7%e5%a4%84%e7%90%86%e9%83%a8%e5%88%86\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL\u7684\u4fe1\u53f7\u5904\u7406\u90e8\u5206"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/8ca01ba7f7362ad4edb7da206a12f29e","name":"\u79d1, \u9896","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8a6fb3cc7ba2f69d2189ba532aec4633ea7ed75ac0af162ec367cb3abc0fb2af?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8a6fb3cc7ba2f69d2189ba532aec4633ea7ed75ac0af162ec367cb3abc0fb2af?s=96&d=mm&r=g","caption":"\u79d1, \u9896"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/keying\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/postgresql%e7%9a%84%e4%bf%a1%e5%8f%b7%e5%a4%84%e7%90%86%e9%83%a8%e5%88%86\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/41594","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=41594"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/41594\/revisions"}],"predecessor-version":[{"id":92126,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/41594\/revisions\/92126"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=41594"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=41594"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=41594"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}