{"id":64896,"date":"2026-01-24T09:48:23","date_gmt":"2026-01-24T01:48:23","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/64896.html"},"modified":"2026-01-24T09:48:23","modified_gmt":"2026-01-24T01:48:23","slug":"postgresql-18-%e4%bb%8e%e6%96%b0%e6%89%8b%e5%88%b0%e5%a4%a7%e5%b8%88%ef%bc%9a%e5%ae%9e%e6%88%98%e6%8c%87%e5%8d%97-5-4-%e9%ab%98%e7%ba%a7%e6%80%a7%e8%83%bd%e8%b0%83%e4%bc%98","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/64896.html","title":{"rendered":"PostgreSQL 18 \u4ece\u65b0\u624b\u5230\u5927\u5e08\uff1a\u5b9e\u6218\u6307\u5357 - 5.4 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18"},"content":{"rendered":"<h3>\u4e00\u3001\u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u6982\u8ff0<\/h3>\n<p>\u5728\u6570\u636e\u5e93\u7ba1\u7406\u4e2d&#xff0c;\u6027\u80fd\u8c03\u4f18\u662f\u4e00\u4e2a\u6301\u7eed\u7684\u8fc7\u7a0b&#xff0c;\u4ece\u57fa\u7840\u7684\u53c2\u6570\u8c03\u6574\u5230\u6df1\u5165\u7684\u5185\u6838\u8c03\u4f18&#xff0c;\u9700\u8981\u4e0d\u65ad\u5730\u76d1\u63a7\u3001\u5206\u6790\u548c\u4f18\u5316\u3002PostgreSQL 18\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6027\u80fd\u8c03\u4f18\u9009\u9879&#xff0c;\u80fd\u591f\u5904\u7406\u5927\u89c4\u6a21\u5e76\u53d1\u548c\u590d\u6742\u7684\u5de5\u4f5c\u8d1f\u8f7d\u3002<\/p>\n<h4>1.1 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u7684\u76ee\u6807<\/h4>\n<p>\u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u7684\u4e3b\u8981\u76ee\u6807\u662f&#xff1a;<\/p>\n<ul>\n<li>\u89e3\u51b3\u590d\u6742\u7684\u6027\u80fd\u74f6\u9888<\/li>\n<li>\u5904\u7406\u5927\u89c4\u6a21\u5e76\u53d1\u8bf7\u6c42<\/li>\n<li>\u4f18\u5316\u8d44\u6e90\u5229\u7528\u7387<\/li>\n<li>\u63d0\u9ad8\u7cfb\u7edf\u7684\u53ef\u6269\u5c55\u6027<\/li>\n<li>\u786e\u4fdd\u7cfb\u7edf\u5728\u9ad8\u8d1f\u8f7d\u4e0b\u7684\u7a33\u5b9a\u6027<\/li>\n<\/ul>\n<h4>1.2 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u7684\u8303\u56f4<\/h4>\n<p>\u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u6db5\u76d6\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762&#xff1a;<\/p>\n<li>\u9501\u4e89\u7528\u89e3\u51b3&#xff1a;\u8bc6\u522b\u548c\u89e3\u51b3\u9501\u4e89\u7528\u95ee\u9898<\/li>\n<li>\u5927\u89c4\u6a21\u5e76\u53d1\u5904\u7406&#xff1a;\u4f18\u5316\u7cfb\u7edf\u4ee5\u5904\u7406\u5927\u91cf\u5e76\u53d1\u8fde\u63a5<\/li>\n<li>\u5185\u6838\u8c03\u4f18&#xff1a;\u8c03\u6574PostgreSQL\u5185\u6838\u53c2\u6570\u4ee5\u63d0\u9ad8\u6027\u80fd<\/li>\n<li>\u5185\u5b58\u6df1\u5ea6\u4f18\u5316&#xff1a;\u4f18\u5316\u5185\u5b58\u4f7f\u7528&#xff0c;\u51cf\u5c11\u5185\u5b58\u538b\u529b<\/li>\n<li>I\/O\u6df1\u5ea6\u4f18\u5316&#xff1a;\u4f18\u5316I\/O\u64cd\u4f5c&#xff0c;\u63d0\u9ad8\u78c1\u76d8\u5229\u7528\u7387<\/li>\n<li>\u9ad8\u7ea7\u67e5\u8be2\u4f18\u5316&#xff1a;\u4f18\u5316\u590d\u6742\u67e5\u8be2&#xff0c;\u63d0\u9ad8\u67e5\u8be2\u6027\u80fd<\/li>\n<h3>\u4e8c\u3001\u9501\u4e89\u7528\u89e3\u51b3<\/h3>\n<p>\u9501\u4e89\u7528\u662f\u9ad8\u5e76\u53d1\u73af\u5883\u4e0b\u5e38\u89c1\u7684\u6027\u80fd\u74f6\u9888&#xff0c;\u5f53\u591a\u4e2a\u4e8b\u52a1\u540c\u65f6\u8bbf\u95ee\u76f8\u540c\u7684\u6570\u636e\u65f6&#xff0c;\u4f1a\u4ea7\u751f\u9501\u7ade\u4e89&#xff0c;\u5bfc\u81f4\u4e8b\u52a1\u7b49\u5f85&#xff0c;\u964d\u4f4e\u7cfb\u7edf\u541e\u5410\u91cf\u3002<\/p>\n<h4>2.1 \u9501\u7684\u7c7b\u578b<\/h4>\n<p>PostgreSQL\u652f\u6301\u591a\u79cd\u9501\u7c7b\u578b&#xff0c;\u4e3b\u8981\u5305\u62ec&#xff1a;<\/p>\n<table>\n<tr>\u9501\u7c7b\u578b\u63cf\u8ff0\u51b2\u7a81\u9501\u7c7b\u578b<\/tr>\n<tbody>\n<tr>\n<td>ACCESS SHARE<\/td>\n<td>\u53ea\u8bfb\u67e5\u8be2<\/td>\n<td>ACCESS EXCLUSIVE<\/td>\n<\/tr>\n<tr>\n<td>ROW SHARE<\/td>\n<td>SELECT FOR UPDATE\/SHARE<\/td>\n<td>EXCLUSIVE, ACCESS EXCLUSIVE<\/td>\n<\/tr>\n<tr>\n<td>ROW EXCLUSIVE<\/td>\n<td>INSERT, UPDATE, DELETE<\/td>\n<td>SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE, ACCESS EXCLUSIVE<\/td>\n<\/tr>\n<tr>\n<td>SHARE UPDATE EXCLUSIVE<\/td>\n<td>VACUUM, ANALYZE<\/td>\n<td>SHARE UPDATE EXCLUSIVE, SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE, ACCESS EXCLUSIVE<\/td>\n<\/tr>\n<tr>\n<td>SHARE<\/td>\n<td>CREATE INDEX<\/td>\n<td>ROW EXCLUSIVE, SHARE UPDATE EXCLUSIVE, EXCLUSIVE, ACCESS EXCLUSIVE<\/td>\n<\/tr>\n<tr>\n<td>SHARE ROW EXCLUSIVE<\/td>\n<td>CREATE CONSTRAINT TRIGGER<\/td>\n<td>ROW EXCLUSIVE, SHARE UPDATE EXCLUSIVE, EXCLUSIVE, ACCESS EXCLUSIVE<\/td>\n<\/tr>\n<tr>\n<td>EXCLUSIVE<\/td>\n<td>ALTER TABLE, DROP TABLE<\/td>\n<td>ROW SHARE, ROW EXCLUSIVE, SHARE UPDATE EXCLUSIVE, SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE, ACCESS EXCLUSIVE<\/td>\n<\/tr>\n<tr>\n<td>ACCESS EXCLUSIVE<\/td>\n<td>DROP DATABASE, VACUUM FULL<\/td>\n<td>\u6240\u6709\u9501\u7c7b\u578b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>2.2 \u9501\u4e89\u7528\u8bc6\u522b<\/h4>\n<h5>2.2.1 \u4f7f\u7528pg_locks\u89c6\u56fe<\/h5>\n<p><span class=\"token comment\">&#8212; \u67e5\u770b\u5f53\u524d\u9501\u4fe1\u606f<\/span><br \/>\n<span class=\"token keyword\">SELECT<\/span><br \/>\n    locktype<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">database<\/span><span class=\"token punctuation\">,<\/span> relation::regclass<span class=\"token punctuation\">,<\/span> page<span class=\"token punctuation\">,<\/span> tuple<span class=\"token punctuation\">,<\/span> virtualxid<span class=\"token punctuation\">,<\/span> transactionid<span class=\"token punctuation\">,<\/span><br \/>\n    classid<span class=\"token punctuation\">,<\/span> objid<span class=\"token punctuation\">,<\/span> objsubid<span class=\"token punctuation\">,<\/span><br \/>\n    pid<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">mode<\/span><span class=\"token punctuation\">,<\/span> granted<span class=\"token punctuation\">,<\/span><br \/>\n    query<br \/>\n<span class=\"token keyword\">FROM<\/span> pg_locks<br \/>\n<span class=\"token keyword\">JOIN<\/span> pg_stat_activity <span class=\"token keyword\">ON<\/span> pg_locks<span class=\"token punctuation\">.<\/span>pid <span class=\"token operator\">&#061;<\/span> pg_stat_activity<span class=\"token punctuation\">.<\/span>pid<br \/>\n<span class=\"token keyword\">WHERE<\/span> <span class=\"token operator\">NOT<\/span> granted<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">&#8212; \u53ea\u663e\u793a\u7b49\u5f85\u7684\u9501<\/span><\/p>\n<h5>2.2.2 \u4f7f\u7528pg_stat_activity\u89c6\u56fe<\/h5>\n<p><span class=\"token comment\">&#8212; \u67e5\u770b\u5f53\u524d\u6d3b\u52a8\u4f1a\u8bdd\u548c\u9501\u7b49\u5f85\u60c5\u51b5<\/span><br \/>\n<span class=\"token keyword\">SELECT<\/span><br \/>\n    pid<span class=\"token punctuation\">,<\/span> datname<span class=\"token punctuation\">,<\/span> usename<span class=\"token punctuation\">,<\/span> application_name<span class=\"token punctuation\">,<\/span> client_addr<span class=\"token punctuation\">,<\/span><br \/>\n    backend_start<span class=\"token punctuation\">,<\/span> query_start<span class=\"token punctuation\">,<\/span> state<span class=\"token punctuation\">,<\/span> wait_event_type<span class=\"token punctuation\">,<\/span> wait_event<span class=\"token punctuation\">,<\/span><br \/>\n    query<br \/>\n<span class=\"token keyword\">FROM<\/span> pg_stat_activity<br \/>\n<span class=\"token keyword\">WHERE<\/span> state <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;active&#039;<\/span> <span class=\"token operator\">OR<\/span> wait_event <span class=\"token operator\">IS<\/span> <span class=\"token operator\">NOT<\/span> <span class=\"token boolean\">NULL<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h5>2.2.3 \u4f7f\u7528pg_blocking_pids\u51fd\u6570<\/h5>\n<p><span class=\"token comment\">&#8212; \u67e5\u770b\u963b\u585e\u5176\u4ed6\u4f1a\u8bdd\u7684PID<\/span><br \/>\n<span class=\"token keyword\">SELECT<\/span> pid<span class=\"token punctuation\">,<\/span> pg_blocking_pids<span class=\"token punctuation\">(<\/span>pid<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">AS<\/span> blocking_pids<span class=\"token punctuation\">,<\/span> query<br \/>\n<span class=\"token keyword\">FROM<\/span> pg_stat_activity<br \/>\n<span class=\"token keyword\">WHERE<\/span> pg_blocking_pids<span class=\"token punctuation\">(<\/span>pid<span class=\"token punctuation\">)<\/span>::<span class=\"token keyword\">text<\/span> <span class=\"token operator\">!&#061;<\/span> <span class=\"token string\">&#039;{}&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>2.3 \u9501\u4e89\u7528\u89e3\u51b3\u7b56\u7565<\/h4>\n<h5>2.3.1 \u4f18\u5316\u4e8b\u52a1\u8bbe\u8ba1<\/h5>\n<ul>\n<li>\u4fdd\u6301\u4e8b\u52a1\u7b80\u77ed&#xff0c;\u51cf\u5c11\u4e8b\u52a1\u6301\u6709\u9501\u7684\u65f6\u95f4<\/li>\n<li>\u5c3d\u91cf\u5728\u4e8b\u52a1\u672b\u5c3e\u6267\u884c\u5199\u64cd\u4f5c<\/li>\n<li>\u907f\u514d\u5728\u4e8b\u52a1\u4e2d\u7b49\u5f85\u7528\u6237\u8f93\u5165<\/li>\n<li>\u4f7f\u7528\u5408\u9002\u7684\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b<\/li>\n<\/ul>\n<h5>2.3.2 \u4f18\u5316\u67e5\u8be2\u8bed\u53e5<\/h5>\n<ul>\n<li>\u907f\u514d\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u67e5\u8be2<\/li>\n<li>\u4f18\u5316\u67e5\u8be2\u8ba1\u5212&#xff0c;\u51cf\u5c11\u9501\u6301\u6709\u65f6\u95f4<\/li>\n<li>\u907f\u514d\u5168\u8868\u626b\u63cf&#xff0c;\u4f7f\u7528\u7d22\u5f15<\/li>\n<li>\u5408\u7406\u4f7f\u7528\u9501\u7ea7\u522b&#xff0c;\u907f\u514d\u8fc7\u5ea6\u9501\u5b9a<\/li>\n<\/ul>\n<h5>2.3.3 \u4f7f\u7528\u4e50\u89c2\u9501<\/h5>\n<p>\u5bf9\u4e8e\u5e76\u53d1\u66f4\u65b0\u9891\u7e41\u7684\u8868&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u4e50\u89c2\u9501\u673a\u5236&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u6dfb\u52a0\u7248\u672c\u5217<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> <span class=\"token keyword\">TABLE<\/span> products <span class=\"token keyword\">ADD<\/span> <span class=\"token keyword\">COLUMN<\/span> version <span class=\"token keyword\">INT<\/span> <span class=\"token keyword\">DEFAULT<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u66f4\u65b0\u65f6\u68c0\u67e5\u7248\u672c<\/span><br \/>\n<span class=\"token keyword\">UPDATE<\/span> products<br \/>\n<span class=\"token keyword\">SET<\/span> price <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">100<\/span><span class=\"token punctuation\">,<\/span> version <span class=\"token operator\">&#061;<\/span> version <span class=\"token operator\">&#043;<\/span> <span class=\"token number\">1<\/span><br \/>\n<span class=\"token keyword\">WHERE<\/span> id <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1<\/span> <span class=\"token operator\">AND<\/span> version <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u68c0\u67e5\u66f4\u65b0\u662f\u5426\u6210\u529f<\/span><br \/>\n<span class=\"token keyword\">IF<\/span> FOUND <span class=\"token keyword\">THEN<\/span><br \/>\n    <span class=\"token comment\">&#8212; \u66f4\u65b0\u6210\u529f<\/span><br \/>\n<span class=\"token keyword\">ELSE<\/span><br \/>\n    <span class=\"token comment\">&#8212; \u7248\u672c\u51b2\u7a81&#xff0c;\u9700\u8981\u91cd\u8bd5<\/span><br \/>\n<span class=\"token keyword\">END<\/span> <span class=\"token keyword\">IF<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h5>2.3.4 \u4f7f\u7528\u884c\u7ea7\u9501<\/h5>\n<ul>\n<li>\u4f7f\u7528SELECT FOR UPDATE\/SHARE\u53ea\u9501\u5b9a\u9700\u8981\u7684\u884c<\/li>\n<li>\u907f\u514d\u4f7f\u7528LOCK TABLE\u8bed\u53e5<\/li>\n<li>\u5408\u7406\u4f7f\u7528NOWAIT\u9009\u9879&#xff0c;\u907f\u514d\u957f\u65f6\u95f4\u7b49\u5f85<\/li>\n<\/ul>\n<h5>2.3.5 \u5206\u533a\u8868<\/h5>\n<p>\u5c06\u5927\u8868\u62c6\u5206\u4e3a\u591a\u4e2a\u5206\u533a\u8868&#xff0c;\u51cf\u5c11\u9501\u7684\u7c92\u5ea6&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u521b\u5efa\u5206\u533a\u8868<\/span><br \/>\n<span class=\"token keyword\">CREATE<\/span> <span class=\"token keyword\">TABLE<\/span> orders <span class=\"token punctuation\">(<\/span><br \/>\n    id <span class=\"token keyword\">SERIAL<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    order_date <span class=\"token keyword\">DATE<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><br \/>\n<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">PARTITION<\/span> <span class=\"token keyword\">BY<\/span> RANGE <span class=\"token punctuation\">(<\/span>order_date<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u521b\u5efa\u5206\u533a<\/span><br \/>\n<span class=\"token keyword\">CREATE<\/span> <span class=\"token keyword\">TABLE<\/span> orders_2023 <span class=\"token keyword\">PARTITION<\/span> <span class=\"token keyword\">OF<\/span> orders<br \/>\n    <span class=\"token keyword\">FOR<\/span> <span class=\"token keyword\">VALUES<\/span> <span class=\"token keyword\">FROM<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;2023-01-01&#039;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">TO<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;2024-01-01&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>2.4 \u9501\u4e89\u7528\u76d1\u63a7<\/h4>\n<p>\u4f7f\u7528pg_stat_statements\u6269\u5c55\u76d1\u63a7\u9501\u7b49\u5f85&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u67e5\u770b\u9501\u7b49\u5f85\u65f6\u95f4\u6700\u957f\u7684\u67e5\u8be2<\/span><br \/>\n<span class=\"token keyword\">SELECT<\/span><br \/>\n    query<span class=\"token punctuation\">,<\/span> calls<span class=\"token punctuation\">,<\/span> total_time<span class=\"token punctuation\">,<\/span><br \/>\n    mean_time<span class=\"token punctuation\">,<\/span> max_time<span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token keyword\">rows<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">100.0<\/span> <span class=\"token operator\">*<\/span> shared_blks_hit <span class=\"token operator\">\/<\/span> <span class=\"token keyword\">nullif<\/span><span class=\"token punctuation\">(<\/span>shared_blks_hit <span class=\"token operator\">&#043;<\/span> shared_blks_read<span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">AS<\/span> hit_percent<br \/>\n<span class=\"token keyword\">FROM<\/span> pg_stat_statements<br \/>\n<span class=\"token keyword\">ORDER<\/span> <span class=\"token keyword\">BY<\/span> max_time <span class=\"token keyword\">DESC<\/span><br \/>\n<span class=\"token keyword\">LIMIT<\/span> <span class=\"token number\">10<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h3>\u4e09\u3001\u5927\u89c4\u6a21\u5e76\u53d1\u5904\u7406<\/h3>\n<p>\u5904\u7406\u5927\u89c4\u6a21\u5e76\u53d1\u8bf7\u6c42\u662f\u9ad8\u8d1f\u8f7d\u7cfb\u7edf\u7684\u5173\u952e\u6311\u6218\u4e4b\u4e00&#xff0c;\u9700\u8981\u4ece\u591a\u4e2a\u65b9\u9762\u8fdb\u884c\u4f18\u5316\u3002<\/p>\n<h4>3.1 \u8fde\u63a5\u7ba1\u7406<\/h4>\n<h5>3.1.1 \u4f7f\u7528\u8fde\u63a5\u6c60<\/h5>\n<p>\u8fde\u63a5\u6c60\u53ef\u4ee5\u51cf\u5c11\u521b\u5efa\u548c\u9500\u6bc1\u8fde\u63a5\u7684\u5f00\u9500&#xff0c;\u63d0\u9ad8\u7cfb\u7edf\u5904\u7406\u5e76\u53d1\u8fde\u63a5\u7684\u80fd\u529b\u3002\u5e38\u7528\u7684\u8fde\u63a5\u6c60\u5305\u62ec&#xff1a;<\/p>\n<ul>\n<li>PgBouncer&#xff1a;\u8f7b\u91cf\u7ea7\u8fde\u63a5\u6c60&#xff0c;\u652f\u6301\u4e09\u79cd\u6a21\u5f0f&#xff08;\u4f1a\u8bdd\u3001\u4e8b\u52a1\u3001\u8bed\u53e5&#xff09;<\/li>\n<li>Pgpool-II&#xff1a;\u529f\u80fd\u4e30\u5bcc\u7684\u8fde\u63a5\u6c60&#xff0c;\u652f\u6301\u8d1f\u8f7d\u5747\u8861\u3001\u9ad8\u53ef\u7528\u7b49<\/li>\n<\/ul>\n<h5>3.1.2 PgBouncer\u914d\u7f6e<\/h5>\n<p>[databases]<br \/>\n* &#061; host&#061;localhost port&#061;5432<\/p>\n<p>[pgbouncer]<br \/>\nlisten_addr &#061; *<br \/>\nlisten_port &#061; 6432<br \/>\nauth_type &#061; md5<br \/>\nauth_file &#061; \/etc\/pgbouncer\/userlist.txt<br \/>\npool_mode &#061; transaction<br \/>\nmax_client_conn &#061; 1000<br \/>\ndefault_pool_size &#061; 20<br \/>\nmin_pool_size &#061; 5<br \/>\nreserve_pool_size &#061; 10<br \/>\nreserve_pool_timeout &#061; 5<\/p>\n<h5>3.1.3 \u8c03\u6574max_connections<\/h5>\n<p><span class=\"token comment\">&#8212; \u67e5\u770b\u5f53\u524d\u503c<\/span><br \/>\n<span class=\"token keyword\">SHOW<\/span> max_connections<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u6839\u636e\u7cfb\u7edf\u8d44\u6e90\u8c03\u6574<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> max_connections <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">500<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>3.2 \u5de5\u4f5c\u8fdb\u7a0b\u4f18\u5316<\/h4>\n<h5>3.2.1 \u8c03\u6574\u5de5\u4f5c\u8fdb\u7a0b\u53c2\u6570<\/h5>\n<p><span class=\"token comment\">&#8212; \u6700\u5927\u5de5\u4f5c\u8fdb\u7a0b\u6570<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> max_worker_processes <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">32<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u6700\u5927\u5e76\u884c\u5de5\u4f5c\u8fdb\u7a0b\u6570<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> max_parallel_workers <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">16<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u6bcf\u4e2aGather\u8282\u70b9\u7684\u6700\u5927\u5e76\u884c\u5de5\u4f5c\u8fdb\u7a0b\u6570<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> max_parallel_workers_per_gather <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">8<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>3.3 \u5185\u5b58\u4f18\u5316<\/h4>\n<h5>3.3.1 \u8c03\u6574shared_buffers<\/h5>\n<p><span class=\"token comment\">&#8212; \u8bbe\u7f6e\u4e3a\u7cfb\u7edf\u5185\u5b58\u768425%~40%<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> shared_buffers <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;16GB&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h5>3.3.2 \u8c03\u6574work_mem<\/h5>\n<p><span class=\"token comment\">&#8212; \u6839\u636e\u5e76\u53d1\u67e5\u8be2\u6570\u8c03\u6574<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> work_mem <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;64MB&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>3.4 \u4e8b\u52a1\u7ba1\u7406\u4f18\u5316<\/h4>\n<h5>3.4.1 \u4f7f\u7528\u5408\u9002\u7684\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b<\/h5>\n<p><span class=\"token comment\">&#8212; \u67e5\u770b\u5f53\u524d\u503c<\/span><br \/>\n<span class=\"token keyword\">SHOW<\/span> default_transaction_isolation<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u8bbe\u7f6e\u4e3aREAD COMMITTED&#xff08;\u9ed8\u8ba4\u503c&#xff0c;\u9002\u5408\u5927\u591a\u6570\u573a\u666f&#xff09;<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> default_transaction_isolation <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;read committed&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h5>3.4.2 \u542f\u7528\u5f02\u6b65\u63d0\u4ea4<\/h5>\n<p>\u5bf9\u4e8e\u975e\u5173\u952e\u4e1a\u52a1&#xff0c;\u53ef\u4ee5\u542f\u7528\u5f02\u6b65\u63d0\u4ea4\u4ee5\u63d0\u9ad8\u6027\u80fd&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u67e5\u770b\u5f53\u524d\u503c<\/span><br \/>\n<span class=\"token keyword\">SHOW<\/span> synchronous_commit<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u8bbe\u7f6e\u4e3aoff\u542f\u7528\u5f02\u6b65\u63d0\u4ea4<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> synchronous_commit <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">off<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h3>\u56db\u3001\u5185\u6838\u8c03\u4f18<\/h3>\n<p>\u5185\u6838\u8c03\u4f18\u662f\u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u7684\u91cd\u8981\u7ec4\u6210\u90e8\u5206&#xff0c;\u901a\u8fc7\u8c03\u6574PostgreSQL\u5185\u6838\u53c2\u6570&#xff0c;\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u7cfb\u7edf\u6027\u80fd\u3002<\/p>\n<h4>4.1 \u5185\u6838\u53c2\u6570\u5206\u7c7b<\/h4>\n<p>PostgreSQL\u5185\u6838\u53c2\u6570\u53ef\u4ee5\u5206\u4e3a\u4ee5\u4e0b\u51e0\u7c7b&#xff1a;<\/p>\n<li>\u5185\u5b58\u53c2\u6570&#xff1a;\u63a7\u5236\u5185\u5b58\u4f7f\u7528<\/li>\n<li>\u5e76\u53d1\u53c2\u6570&#xff1a;\u63a7\u5236\u5e76\u53d1\u5904\u7406<\/li>\n<li>I\/O\u53c2\u6570&#xff1a;\u63a7\u5236I\/O\u64cd\u4f5c<\/li>\n<li>\u67e5\u8be2\u4f18\u5316\u53c2\u6570&#xff1a;\u63a7\u5236\u67e5\u8be2\u4f18\u5316\u5668\u884c\u4e3a<\/li>\n<li>WAL\u53c2\u6570&#xff1a;\u63a7\u5236WAL\u5199\u5165<\/li>\n<li>\u68c0\u67e5\u70b9\u53c2\u6570&#xff1a;\u63a7\u5236\u68c0\u67e5\u70b9\u884c\u4e3a<\/li>\n<h4>4.2 \u5173\u952e\u5185\u6838\u53c2\u6570\u8c03\u4f18<\/h4>\n<h5>4.2.1 \u5185\u5b58\u53c2\u6570<\/h5>\n<p><span class=\"token comment\">&#8212; \u5171\u4eab\u7f13\u51b2\u533a<\/span><br \/>\nshared_buffers <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;16GB&#039;<\/span>          <span class=\"token comment\">&#8212; \u7cfb\u7edf\u5185\u5b58\u768425%~40%<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u5de5\u4f5c\u5185\u5b58<\/span><br \/>\nwork_mem <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;64MB&#039;<\/span>                <span class=\"token comment\">&#8212; \u6839\u636e\u5e76\u53d1\u67e5\u8be2\u6570\u8c03\u6574<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u7ef4\u62a4\u5de5\u4f5c\u5185\u5b58<\/span><br \/>\nmaintenance_work_mem <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;2GB&#039;<\/span>     <span class=\"token comment\">&#8212; \u7cfb\u7edf\u5185\u5b58\u76845%~10%<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u6709\u6548\u7f13\u5b58\u5927\u5c0f<\/span><br \/>\neffective_cache_size <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;48GB&#039;<\/span>    <span class=\"token comment\">&#8212; \u7cfb\u7edf\u5185\u5b58\u768450%~75%<\/span><\/p>\n<h5>4.2.2 \u5e76\u53d1\u53c2\u6570<\/h5>\n<p><span class=\"token comment\">&#8212; \u6700\u5927\u8fde\u63a5\u6570<\/span><br \/>\nmax_connections <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">500<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u6700\u5927\u5de5\u4f5c\u8fdb\u7a0b\u6570<\/span><br \/>\nmax_worker_processes <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">32<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u6700\u5927\u5e76\u884c\u5de5\u4f5c\u8fdb\u7a0b\u6570<\/span><br \/>\nmax_parallel_workers <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">16<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u6bcf\u4e2aGather\u8282\u70b9\u7684\u6700\u5927\u5e76\u884c\u5de5\u4f5c\u8fdb\u7a0b\u6570<\/span><br \/>\nmax_parallel_workers_per_gather <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">8<\/span><\/p>\n<h5>4.2.3 I\/O\u53c2\u6570<\/h5>\n<p><span class=\"token comment\">&#8212; \u968f\u673a\u9875\u9762\u6210\u672c&#xff08;SSD\u8bbe\u7f6e\u4e3a1.1&#xff09;<\/span><br \/>\nrandom_page_cost <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1.1<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u987a\u5e8f\u9875\u9762\u6210\u672c<\/span><br \/>\nseq_page_cost <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1.0<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u6709\u6548I\/O\u5e76\u53d1&#xff08;NVMe SSD\u8bbe\u7f6e\u4e3a300&#xff09;<\/span><br \/>\neffective_io_concurrency <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">300<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u7ef4\u62a4\u64cd\u4f5c\u7684\u6709\u6548I\/O\u5e76\u53d1<\/span><br \/>\nmaintenance_io_concurrency <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">150<\/span><\/p>\n<h5>4.2.4 WAL\u53c2\u6570<\/h5>\n<p><span class=\"token comment\">&#8212; WAL\u7f13\u51b2\u533a\u5927\u5c0f<\/span><br \/>\nwal_buffers <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;32MB&#039;<\/span>             <span class=\"token comment\">&#8212; shared_buffers\u76843%~5%<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u540c\u6b65\u63d0\u4ea4\u7ea7\u522b<\/span><br \/>\nsynchronous_commit <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">on<\/span>          <span class=\"token comment\">&#8212; \u6216local, remote_write, off<\/span><\/p>\n<p><span class=\"token comment\">&#8212; WAL\u538b\u7f29<\/span><br \/>\nwal_compression <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">on<\/span><\/p>\n<p><span class=\"token comment\">&#8212; WAL\u5199\u5165\u5ef6\u8fdf&#xff08;\u6beb\u79d2&#xff09;<\/span><br \/>\nwal_writer_delay <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">200<\/span>ms<\/p>\n<h5>4.2.5 \u68c0\u67e5\u70b9\u53c2\u6570<\/h5>\n<p><span class=\"token comment\">&#8212; \u68c0\u67e5\u70b9\u8d85\u65f6<\/span><br \/>\ncheckpoint_timeout <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;30min&#039;<\/span>     <span class=\"token comment\">&#8212; 15~30\u5206\u949f<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u6700\u5927WAL\u5927\u5c0f<\/span><br \/>\nmax_wal_size <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;64GB&#039;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u6700\u5c0fWAL\u5927\u5c0f<\/span><br \/>\nmin_wal_size <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;8GB&#039;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u68c0\u67e5\u70b9\u5b8c\u6210\u76ee\u6807<\/span><br \/>\ncheckpoint_completion_target <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0.9<\/span><\/p>\n<h4>4.3 \u5185\u6838\u8c03\u4f18\u6700\u4f73\u5b9e\u8df5<\/h4>\n<ul>\n<li>\u6839\u636e\u786c\u4ef6\u914d\u7f6e\u8c03\u6574\u53c2\u6570<\/li>\n<li>\u9010\u6b65\u8c03\u6574&#xff0c;\u907f\u514d\u4e00\u6b21\u8c03\u6574\u591a\u4e2a\u53c2\u6570<\/li>\n<li>\u5728\u6d4b\u8bd5\u73af\u5883\u4e2d\u9a8c\u8bc1\u8c03\u4f18\u6548\u679c<\/li>\n<li>\u76d1\u63a7\u8c03\u4f18\u540e\u7684\u7cfb\u7edf\u6027\u80fd<\/li>\n<li>\u6839\u636e\u5de5\u4f5c\u8d1f\u8f7d\u8c03\u6574\u53c2\u6570<\/li>\n<\/ul>\n<h3>\u4e94\u3001\u5185\u5b58\u6df1\u5ea6\u4f18\u5316<\/h3>\n<p>\u5185\u5b58\u662f\u6570\u636e\u5e93\u6027\u80fd\u7684\u5173\u952e\u8d44\u6e90&#xff0c;\u6df1\u5ea6\u4f18\u5316\u5185\u5b58\u4f7f\u7528\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u7cfb\u7edf\u6027\u80fd\u3002<\/p>\n<h4>5.1 \u5185\u5b58\u5206\u914d\u7b56\u7565<\/h4>\n<p>\u5bf9\u4e8e\u4e13\u7528\u6570\u636e\u5e93\u670d\u52a1\u5668&#xff0c;\u5efa\u8bae\u6309\u7167\u4ee5\u4e0b\u6bd4\u4f8b\u5206\u914d\u5185\u5b58&#xff1a;<\/p>\n<ul>\n<li>\u64cd\u4f5c\u7cfb\u7edf&#xff1a;20%<\/li>\n<li>shared_buffers&#xff1a;25%~40%<\/li>\n<li>work_mem&#xff1a;\u6839\u636e\u5e76\u53d1\u67e5\u8be2\u6570\u52a8\u6001\u8c03\u6574<\/li>\n<li>maintenance_work_mem&#xff1a;5%~10%<\/li>\n<li>\u5176\u4ed6\u8fdb\u7a0b\u548c\u7f13\u5b58&#xff1a;\u5269\u4f59\u5185\u5b58<\/li>\n<\/ul>\n<h4>5.2 \u5185\u5b58\u4e0a\u4e0b\u6587\u4f18\u5316<\/h4>\n<p>PostgreSQL\u4f7f\u7528\u5185\u5b58\u4e0a\u4e0b\u6587&#xff08;Memory Context&#xff09;\u7ba1\u7406\u5185\u5b58\u5206\u914d&#xff0c;\u4f18\u5316\u5185\u5b58\u4e0a\u4e0b\u6587\u53ef\u4ee5\u51cf\u5c11\u5185\u5b58\u788e\u7247\u548c\u5185\u5b58\u6cc4\u6f0f\u3002<\/p>\n<h5>5.2.1 \u76d1\u63a7\u5185\u5b58\u4f7f\u7528<\/h5>\n<p><span class=\"token comment\">&#8212; \u67e5\u770b\u5185\u5b58\u4f7f\u7528\u60c5\u51b5<\/span><br \/>\n<span class=\"token keyword\">SELECT<\/span> name<span class=\"token punctuation\">,<\/span> setting<span class=\"token punctuation\">,<\/span> unit <span class=\"token keyword\">FROM<\/span> pg_settings <span class=\"token keyword\">WHERE<\/span> category <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;Resource Usage&#039;<\/span> <span class=\"token operator\">AND<\/span> name <span class=\"token operator\">LIKE<\/span> <span class=\"token string\">&#039;%mem%&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>5.3 \u5927\u9875\u5185\u5b58\u652f\u6301<\/h4>\n<p>\u4f7f\u7528\u5927\u9875\u5185\u5b58\u53ef\u4ee5\u51cf\u5c11TLB&#xff08;Translation Lookaside Buffer&#xff09; misses&#xff0c;\u63d0\u9ad8\u5185\u5b58\u8bbf\u95ee\u6027\u80fd\u3002<\/p>\n<h5>5.3.1 \u5728Linux\u4e0a\u914d\u7f6e\u5927\u9875\u5185\u5b58<\/h5>\n<p><span class=\"token comment\"># \u67e5\u770b\u5f53\u524d\u5927\u9875\u8bbe\u7f6e<\/span><br \/>\n<span class=\"token function\">grep<\/span> Huge \/proc\/meminfo<\/p>\n<p><span class=\"token comment\"># \u914d\u7f6e\u5927\u9875<\/span><br \/>\n <span class=\"token builtin class-name\">echo<\/span> <span class=\"token number\">2048<\/span> <span class=\"token operator\">&gt;<\/span> \/sys\/kernel\/mm\/hugepages\/hugepages-2048kB\/nr_hugepages<\/p>\n<p><span class=\"token comment\"># \u6302\u8f7d\u5927\u9875\u5185\u5b58<\/span><br \/>\n<span class=\"token function\">mkdir<\/span> -p \/mnt\/hugepagesmmount -t hugetlbfs hugetlbfs \/mnt\/hugepages<\/p>\n<h5>5.3.2 \u914d\u7f6ePostgreSQL\u4f7f\u7528\u5927\u9875\u5185\u5b58<\/h5>\n<p># \u5728postgresql.conf\u4e2d\u6dfb\u52a0<br \/>\nshared_memory_type &#061; mmap<br \/>\nlarge_pages &#061; on<\/p>\n<h3>\u516d\u3001I\/O\u6df1\u5ea6\u4f18\u5316<\/h3>\n<p>I\/O\u662f\u6570\u636e\u5e93\u6027\u80fd\u7684\u91cd\u8981\u74f6\u9888&#xff0c;\u6df1\u5ea6\u4f18\u5316I\/O\u64cd\u4f5c\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u7cfb\u7edf\u6027\u80fd\u3002<\/p>\n<h4>6.1 \u5b58\u50a8\u8bbe\u5907\u4f18\u5316<\/h4>\n<ul>\n<li>\u4f7f\u7528NVMe SSD\u66ff\u4ee3HDD<\/li>\n<li>\u4f7f\u7528RAID 10\u63d0\u9ad8\u6027\u80fd\u548c\u53ef\u9760\u6027<\/li>\n<li>\u5206\u79bbWAL\u548c\u6570\u636e\u5b58\u50a8\u5230\u4e0d\u540c\u7684\u5b58\u50a8\u8bbe\u5907<\/li>\n<\/ul>\n<h4>6.2 \u6587\u4ef6\u7cfb\u7edf\u4f18\u5316<\/h4>\n<h5>6.2.1 Linux\u6587\u4ef6\u7cfb\u7edf\u9009\u62e9<\/h5>\n<ul>\n<li>XFS&#xff1a;\u9002\u5408\u5927\u578b\u6587\u4ef6\u7cfb\u7edf\u548c\u9ad8\u541e\u5410\u91cf<\/li>\n<li>ext4&#xff1a;\u7a33\u5b9a\u53ef\u9760&#xff0c;\u9002\u5408\u5927\u591a\u6570\u573a\u666f<\/li>\n<li>Btrfs&#xff1a;\u652f\u6301\u9ad8\u7ea7\u7279\u6027&#xff0c;\u5982\u5feb\u7167\u3001\u6821\u9a8c\u548c\u7b49<\/li>\n<\/ul>\n<h5>6.2.2 \u6587\u4ef6\u7cfb\u7edf\u6302\u8f7d\u9009\u9879<\/h5>\n<p># XFS\u6302\u8f7d\u9009\u9879<br \/>\n\/dev\/sdb1 \/pgdata xfs noatime,nodiratime,attr2,discard,inode64,logbufs&#061;8,logbsize&#061;256k 0 0<\/p>\n<p># ext4\u6302\u8f7d\u9009\u9879<br \/>\n\/dev\/sdb1 \/pgdata ext4 noatime,nodiratime,barrier&#061;0,data&#061;writeback 0 0<\/p>\n<h4>6.3 PostgreSQL I\/O\u4f18\u5316<\/h4>\n<h5>6.3.1 \u4f7f\u7528O_DIRECT<\/h5>\n<p># \u5728postgresql.conf\u4e2d\u6dfb\u52a0<br \/>\ndata_directory &#061; &#039;\/pgdata&#039;<br \/>\n# \u4f7f\u7528O_DIRECT\u7ed5\u8fc7\u64cd\u4f5c\u7cfb\u7edf\u7f13\u5b58<br \/>\n# wal_buffers\u9700\u8981\u8db3\u591f\u5927<br \/>\nwal_buffers &#061; &#039;64MB&#039;<\/p>\n<h5>6.3.2 \u8c03\u6574bgwriter\u53c2\u6570<\/h5>\n<p><span class=\"token comment\">&#8212; \u540e\u53f0\u5199\u8fdb\u7a0b\u5ef6\u8fdf&#xff08;\u6beb\u79d2&#xff09;<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> bgwriter_delay <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">200<\/span>ms<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u6bcf\u6b21\u5199\u5165\u7684\u6700\u5927\u7f13\u51b2\u533a\u6570<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> bgwriter_lru_maxpages <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">100<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u6bcf\u6b21\u5199\u5165\u7684\u76ee\u6807\u7f13\u51b2\u533a\u6570<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> bgwriter_lru_multiplier <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">2.0<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>6.4 \u8868\u7a7a\u95f4\u4f18\u5316<\/h4>\n<p>\u5c06\u4e0d\u540c\u7684\u6570\u636e\u5e93\u5bf9\u8c61\u5b58\u50a8\u5728\u4e0d\u540c\u7684\u5b58\u50a8\u8bbe\u5907\u4e0a&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u521b\u5efa\u8868\u7a7a\u95f4<\/span><br \/>\n<span class=\"token keyword\">CREATE<\/span> <span class=\"token keyword\">TABLESPACE<\/span> fast_ssd LOCATION <span class=\"token string\">&#039;\/mnt\/ssd\/pgdata&#039;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">CREATE<\/span> <span class=\"token keyword\">TABLESPACE<\/span> slow_hdd LOCATION <span class=\"token string\">&#039;\/mnt\/hdd\/pgdata&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u5c06WAL\u5b58\u50a8\u5728\u9ad8\u901f\u5b58\u50a8\u8bbe\u5907\u4e0a<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> wal_directory <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;\/mnt\/ssd\/pgwal&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h3>\u4e03\u3001\u9ad8\u7ea7\u67e5\u8be2\u4f18\u5316<\/h3>\n<p>\u9ad8\u7ea7\u67e5\u8be2\u4f18\u5316\u6d89\u53ca\u590d\u6742\u67e5\u8be2\u7684\u5206\u6790\u548c\u4f18\u5316&#xff0c;\u9700\u8981\u6df1\u5165\u7406\u89e3\u67e5\u8be2\u4f18\u5316\u5668\u7684\u5de5\u4f5c\u539f\u7406\u3002<\/p>\n<h4>7.1 \u4f7f\u7528\u9ad8\u7ea7\u7d22\u5f15\u6280\u672f<\/h4>\n<h5>7.1.1 \u90e8\u5206\u7d22\u5f15<\/h5>\n<p>\u4e3a\u8868\u7684\u5b50\u96c6\u521b\u5efa\u7d22\u5f15&#xff0c;\u51cf\u5c11\u7d22\u5f15\u5927\u5c0f\u548c\u7ef4\u62a4\u6210\u672c&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u4e3a\u6d3b\u8dc3\u7528\u6237\u521b\u5efa\u7d22\u5f15<\/span><br \/>\n<span class=\"token keyword\">CREATE<\/span> <span class=\"token keyword\">INDEX<\/span> idx_active_users <span class=\"token keyword\">ON<\/span> users<span class=\"token punctuation\">(<\/span>email<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">WHERE<\/span> active <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">true<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h5>7.1.2 \u8868\u8fbe\u5f0f\u7d22\u5f15<\/h5>\n<p>\u4e3a\u8868\u8fbe\u5f0f\u521b\u5efa\u7d22\u5f15&#xff0c;\u63d0\u9ad8\u8868\u8fbe\u5f0f\u67e5\u8be2\u7684\u6027\u80fd&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u4e3alower(email)\u521b\u5efa\u7d22\u5f15<\/span><br \/>\n<span class=\"token keyword\">CREATE<\/span> <span class=\"token keyword\">INDEX<\/span> idx_users_email_lower <span class=\"token keyword\">ON<\/span> users<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span>lower<span class=\"token punctuation\">(<\/span>email<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u4f7f\u7528\u7d22\u5f15\u7684\u67e5\u8be2<\/span><br \/>\n<span class=\"token keyword\">SELECT<\/span> <span class=\"token operator\">*<\/span> <span class=\"token keyword\">FROM<\/span> users <span class=\"token keyword\">WHERE<\/span> lower<span class=\"token punctuation\">(<\/span>email<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;example&#064;example.com&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h5>7.1.3 \u8986\u76d6\u7d22\u5f15<\/h5>\n<p>\u5305\u542b\u67e5\u8be2\u6240\u9700\u7684\u6240\u6709\u5217&#xff0c;\u907f\u514d\u56de\u8868\u67e5\u8be2&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u521b\u5efa\u8986\u76d6\u7d22\u5f15<\/span><br \/>\n<span class=\"token keyword\">CREATE<\/span> <span class=\"token keyword\">INDEX<\/span> idx_users_name_email <span class=\"token keyword\">ON<\/span> users<span class=\"token punctuation\">(<\/span>name<span class=\"token punctuation\">,<\/span> email<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u4f7f\u7528\u8986\u76d6\u7d22\u5f15\u7684\u67e5\u8be2<\/span><br \/>\n<span class=\"token keyword\">SELECT<\/span> name<span class=\"token punctuation\">,<\/span> email <span class=\"token keyword\">FROM<\/span> users <span class=\"token keyword\">WHERE<\/span> name <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;John&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>7.2 \u4f18\u5316\u590d\u6742\u67e5\u8be2<\/h4>\n<h5>7.2.1 \u91cd\u5199\u5b50\u67e5\u8be2<\/h5>\n<p>\u5c06\u76f8\u5173\u5b50\u67e5\u8be2\u91cd\u5199\u4e3a\u8fde\u63a5\u67e5\u8be2&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u5b50\u67e5\u8be2<\/span><br \/>\n<span class=\"token keyword\">SELECT<\/span> <span class=\"token operator\">*<\/span> <span class=\"token keyword\">FROM<\/span> users <span class=\"token keyword\">WHERE<\/span> id <span class=\"token operator\">IN<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">SELECT<\/span> user_id <span class=\"token keyword\">FROM<\/span> orders <span class=\"token keyword\">WHERE<\/span> amount <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">100<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u91cd\u5199\u4e3a\u8fde\u63a5\u67e5\u8be2<\/span><br \/>\n<span class=\"token keyword\">SELECT<\/span> u<span class=\"token punctuation\">.<\/span><span class=\"token operator\">*<\/span> <span class=\"token keyword\">FROM<\/span> users u <span class=\"token keyword\">JOIN<\/span> orders o <span class=\"token keyword\">ON<\/span> u<span class=\"token punctuation\">.<\/span>id <span class=\"token operator\">&#061;<\/span> o<span class=\"token punctuation\">.<\/span>user_id <span class=\"token keyword\">WHERE<\/span> o<span class=\"token punctuation\">.<\/span>amount <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">100<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h5>7.2.2 \u4f7f\u7528CTE\u4f18\u5316\u590d\u6742\u67e5\u8be2<\/h5>\n<p>\u4f7f\u7528\u516c\u5171\u8868\u8868\u8fbe\u5f0f&#xff08;CTE&#xff09;\u5206\u89e3\u590d\u6742\u67e5\u8be2&#xff1a;<\/p>\n<p><span class=\"token keyword\">WITH<\/span> recent_orders <span class=\"token keyword\">AS<\/span> <span class=\"token punctuation\">(<\/span><br \/>\n    <span class=\"token keyword\">SELECT<\/span> user_id<span class=\"token punctuation\">,<\/span> <span class=\"token function\">COUNT<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">AS<\/span> order_count<br \/>\n    <span class=\"token keyword\">FROM<\/span> orders<br \/>\n    <span class=\"token keyword\">WHERE<\/span> created_at <span class=\"token operator\">&gt;<\/span> <span class=\"token function\">NOW<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span> <span class=\"token keyword\">INTERVAL<\/span> <span class=\"token string\">&#039;30 days&#039;<\/span><br \/>\n    <span class=\"token keyword\">GROUP<\/span> <span class=\"token keyword\">BY<\/span> user_id<br \/>\n<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">SELECT<\/span> u<span class=\"token punctuation\">.<\/span>name<span class=\"token punctuation\">,<\/span> u<span class=\"token punctuation\">.<\/span>email<span class=\"token punctuation\">,<\/span> ro<span class=\"token punctuation\">.<\/span>order_count<br \/>\n<span class=\"token keyword\">FROM<\/span> users u<br \/>\n<span class=\"token keyword\">JOIN<\/span> recent_orders ro <span class=\"token keyword\">ON<\/span> u<span class=\"token punctuation\">.<\/span>id <span class=\"token operator\">&#061;<\/span> ro<span class=\"token punctuation\">.<\/span>user_id<br \/>\n<span class=\"token keyword\">ORDER<\/span> <span class=\"token keyword\">BY<\/span> ro<span class=\"token punctuation\">.<\/span>order_count <span class=\"token keyword\">DESC<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h5>7.2.3 \u4f7f\u7528\u7269\u5316\u89c6\u56fe<\/h5>\n<p>\u5bf9\u4e8e\u9891\u7e41\u6267\u884c\u7684\u590d\u6742\u67e5\u8be2&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u7269\u5316\u89c6\u56fe&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u521b\u5efa\u7269\u5316\u89c6\u56fe<\/span><br \/>\n<span class=\"token keyword\">CREATE<\/span> MATERIALIZED <span class=\"token keyword\">VIEW<\/span> daily_sales <span class=\"token keyword\">AS<\/span><br \/>\n<span class=\"token keyword\">SELECT<\/span><br \/>\n    <span class=\"token keyword\">DATE<\/span><span class=\"token punctuation\">(<\/span>created_at<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">AS<\/span> sale_date<span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token function\">SUM<\/span><span class=\"token punctuation\">(<\/span>amount<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">AS<\/span> total_sales<span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token function\">COUNT<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">AS<\/span> order_count<br \/>\n<span class=\"token keyword\">FROM<\/span> orders<br \/>\n<span class=\"token keyword\">GROUP<\/span> <span class=\"token keyword\">BY<\/span> <span class=\"token keyword\">DATE<\/span><span class=\"token punctuation\">(<\/span>created_at<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u5237\u65b0\u7269\u5316\u89c6\u56fe<\/span><br \/>\nREFRESH MATERIALIZED <span class=\"token keyword\">VIEW<\/span> daily_sales<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u67e5\u8be2\u7269\u5316\u89c6\u56fe<\/span><br \/>\n<span class=\"token keyword\">SELECT<\/span> <span class=\"token operator\">*<\/span> <span class=\"token keyword\">FROM<\/span> daily_sales <span class=\"token keyword\">WHERE<\/span> sale_date <span class=\"token operator\">BETWEEN<\/span> <span class=\"token string\">&#039;2023-01-01&#039;<\/span> <span class=\"token operator\">AND<\/span> <span class=\"token string\">&#039;2023-01-31&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>7.3 \u67e5\u8be2\u4f18\u5316\u5de5\u5177<\/h4>\n<h5>7.3.1 \u4f7f\u7528EXPLAIN ANALYZE<\/h5>\n<p><span class=\"token keyword\">EXPLAIN<\/span> <span class=\"token keyword\">ANALYZE<\/span> <span class=\"token keyword\">SELECT<\/span> <span class=\"token operator\">*<\/span> <span class=\"token keyword\">FROM<\/span> users <span class=\"token keyword\">WHERE<\/span> email <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;example&#064;example.com&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h5>7.3.2 \u4f7f\u7528pg_stat_statements<\/h5>\n<p><span class=\"token comment\">&#8212; \u67e5\u770b\u6162\u67e5\u8be2<\/span><br \/>\n<span class=\"token keyword\">SELECT<\/span> query<span class=\"token punctuation\">,<\/span> calls<span class=\"token punctuation\">,<\/span> total_time<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">rows<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">100.0<\/span> <span class=\"token operator\">*<\/span> shared_blks_hit <span class=\"token operator\">\/<\/span> <span class=\"token keyword\">nullif<\/span><span class=\"token punctuation\">(<\/span>shared_blks_hit <span class=\"token operator\">&#043;<\/span> shared_blks_read<span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">AS<\/span> hit_percent<br \/>\n<span class=\"token keyword\">FROM<\/span> pg_stat_statements<br \/>\n<span class=\"token keyword\">ORDER<\/span> <span class=\"token keyword\">BY<\/span> total_time <span class=\"token keyword\">DESC<\/span><br \/>\n<span class=\"token keyword\">LIMIT<\/span> <span class=\"token number\">10<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h5>7.3.3 \u4f7f\u7528pg_hint_plan\u6269\u5c55<\/h5>\n<p><span class=\"token comment\">&#8212; \u63d0\u793a\u4f7f\u7528\u7279\u5b9a\u7d22\u5f15<\/span><br \/>\n<span class=\"token comment\">\/*&#043; IndexScan(users idx_users_email) *\/<\/span><br \/>\n<span class=\"token keyword\">SELECT<\/span> <span class=\"token operator\">*<\/span> <span class=\"token keyword\">FROM<\/span> users <span class=\"token keyword\">WHERE<\/span> email <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;example&#064;example.com&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h3>\u516b\u3001\u76d1\u63a7\u4e0e\u8bca\u65ad<\/h3>\n<p>\u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u9700\u8981\u5f3a\u5927\u7684\u76d1\u63a7\u548c\u8bca\u65ad\u5de5\u5177&#xff0c;\u4ee5\u4fbf\u53ca\u65f6\u53d1\u73b0\u548c\u89e3\u51b3\u6027\u80fd\u95ee\u9898\u3002<\/p>\n<h4>8.1 \u5185\u7f6e\u76d1\u63a7\u89c6\u56fe<\/h4>\n<p>PostgreSQL\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5185\u7f6e\u76d1\u63a7\u89c6\u56fe&#xff1a;<\/p>\n<ul>\n<li>pg_stat_activity&#xff1a;\u5f53\u524d\u6d3b\u52a8\u4f1a\u8bdd<\/li>\n<li>pg_stat_database&#xff1a;\u6570\u636e\u5e93\u7edf\u8ba1\u4fe1\u606f<\/li>\n<li>pg_stat_user_tables&#xff1a;\u7528\u6237\u8868\u7edf\u8ba1\u4fe1\u606f<\/li>\n<li>pg_stat_user_indexes&#xff1a;\u7528\u6237\u7d22\u5f15\u7edf\u8ba1\u4fe1\u606f<\/li>\n<li>pg_stat_bgwriter&#xff1a;\u540e\u53f0\u5199\u8fdb\u7a0b\u7edf\u8ba1\u4fe1\u606f<\/li>\n<li>pg_stat_wal&#xff1a;WAL\u7edf\u8ba1\u4fe1\u606f<\/li>\n<li>pg_stat_checkpointer&#xff1a;\u68c0\u67e5\u70b9\u7edf\u8ba1\u4fe1\u606f<\/li>\n<li>pg_locks&#xff1a;\u9501\u4fe1\u606f<\/li>\n<\/ul>\n<h4>8.2 \u76d1\u63a7\u5de5\u5177<\/h4>\n<h5>8.2.1 Prometheus &#043; Grafana<\/h5>\n<p>\u4f7f\u7528Prometheus\u6536\u96c6PostgreSQL\u6307\u6807&#xff0c;\u4f7f\u7528Grafana\u53ef\u89c6\u5316\u76d1\u63a7\u6570\u636e\u3002<\/p>\n<p>PostgreSQL Exporter\u914d\u7f6e&#xff1a;<\/p>\n<p><span class=\"token key atrule\">scrape_configs<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">job_name<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;postgresql&#039;<\/span><br \/>\n    <span class=\"token key atrule\">static_configs<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">targets<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;localhost:9187&#039;<\/span><span class=\"token punctuation\">]<\/span><br \/>\n    <span class=\"token key atrule\">metrics_path<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;\/metrics&#039;<\/span><br \/>\n    <span class=\"token key atrule\">params<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token key atrule\">format<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;prometheus&#039;<\/span><span class=\"token punctuation\">]<\/span><\/p>\n<h5>8.2.2 pgAdmin<\/h5>\n<p>pgAdmin\u63d0\u4f9b\u4e86\u76f4\u89c2\u7684\u56fe\u5f62\u754c\u9762&#xff0c;\u7528\u4e8e\u76d1\u63a7PostgreSQL\u670d\u52a1\u5668\u3002<\/p>\n<h5>8.2.3 pganalyze<\/h5>\n<p>pganalyze\u662f\u4e00\u4e2a\u5546\u4e1a\u76d1\u63a7\u5de5\u5177&#xff0c;\u63d0\u4f9b\u9ad8\u7ea7\u7684\u67e5\u8be2\u5206\u6790\u548c\u6027\u80fd\u4f18\u5316\u5efa\u8bae\u3002<\/p>\n<h4>8.3 \u8bca\u65ad\u5de5\u5177<\/h4>\n<h5>8.3.1 \u4f7f\u7528strace<\/h5>\n<p>\u8ddf\u8e2aPostgreSQL\u8fdb\u7a0b\u7684\u7cfb\u7edf\u8c03\u7528&#xff1a;<\/p>\n<p><span class=\"token function\">strace<\/span> -p <span class=\"token operator\">&lt;<\/span>pid<span class=\"token operator\">&gt;<\/span> -f -e <span class=\"token assign-left variable\">trace<\/span><span class=\"token operator\">&#061;<\/span>open,read,write,close<\/p>\n<h5>8.3.2 \u4f7f\u7528perf<\/h5>\n<p>\u5206\u6790PostgreSQL\u7684CPU\u4f7f\u7528\u60c5\u51b5&#xff1a;<\/p>\n<p>perf record -p <span class=\"token operator\">&lt;<\/span>pid<span class=\"token operator\">&gt;<\/span> -g<br \/>\nperf report<\/p>\n<h5>8.3.3 \u4f7f\u7528gdb<\/h5>\n<p>\u8c03\u8bd5PostgreSQL\u8fdb\u7a0b&#xff1a;<\/p>\n<p>gdb -p <span class=\"token operator\">&lt;<\/span>pid<span class=\"token operator\">&gt;<\/span><\/p>\n<h3>\u4e5d\u3001\u5b9e\u6218\u6848\u4f8b&#xff1a;\u6df1\u5ea6\u6027\u80fd\u8c03\u4f18<\/h3>\n<h4>9.1 \u6848\u4f8b\u63cf\u8ff0<\/h4>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u5927\u578b\u7535\u5546\u7f51\u7ad9\u7684PostgreSQL\u6570\u636e\u5e93&#xff0c;\u6570\u636e\u91cf\u8d85\u8fc71TB&#xff0c;\u5e76\u53d1\u7528\u6237\u6570\u8d85\u8fc75000&#xff0c;\u9047\u5230\u4e86\u6027\u80fd\u74f6\u9888\u3002<\/p>\n<h4>9.2 \u6027\u80fd\u5206\u6790<\/h4>\n<p>\u901a\u8fc7\u76d1\u63a7\u53d1\u73b0\u4ee5\u4e0b\u95ee\u9898&#xff1a;<\/p>\n<li>\u9501\u4e89\u7528\u4e25\u91cd&#xff0c;\u7279\u522b\u662f\u5728\u8ba2\u5355\u8868\u4e0a<\/li>\n<li>\u5185\u5b58\u4f7f\u7528\u7387\u9ad8&#xff0c;\u7ecf\u5e38\u51fa\u73b0\u5185\u5b58\u538b\u529b<\/li>\n<li>I\/O\u7b49\u5f85\u65f6\u95f4\u957f&#xff0c;\u7279\u522b\u662f\u5728\u9ad8\u5cf0\u65f6\u6bb5<\/li>\n<li>\u90e8\u5206\u67e5\u8be2\u6267\u884c\u65f6\u95f4\u957f&#xff0c;\u5f71\u54cd\u7528\u6237\u4f53\u9a8c<\/li>\n<h4>9.3 \u8c03\u4f18\u65b9\u6848<\/h4>\n<h5>9.3.1 \u9501\u4e89\u7528\u89e3\u51b3<\/h5>\n<li>\n<p>\u4f18\u5316\u4e8b\u52a1\u8bbe\u8ba1&#xff1a;<\/p>\n<ul>\n<li>\u4fdd\u6301\u4e8b\u52a1\u7b80\u77ed<\/li>\n<li>\u5c06\u5199\u64cd\u4f5c\u653e\u5728\u4e8b\u52a1\u672b\u5c3e<\/li>\n<li>\u4f7f\u7528\u5408\u9002\u7684\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u4f18\u5316\u8ba2\u5355\u8868&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u4e3a\u8ba2\u5355\u8868\u6dfb\u52a0\u5408\u7406\u7684\u7d22\u5f15<\/span><br \/>\n<span class=\"token keyword\">CREATE<\/span> <span class=\"token keyword\">INDEX<\/span> idx_orders_user_id <span class=\"token keyword\">ON<\/span> orders<span class=\"token punctuation\">(<\/span>user_id<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">CREATE<\/span> <span class=\"token keyword\">INDEX<\/span> idx_orders_created_at <span class=\"token keyword\">ON<\/span> orders<span class=\"token punctuation\">(<\/span>created_at<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u5206\u533a\u8868<\/span><br \/>\n<span class=\"token keyword\">CREATE<\/span> <span class=\"token keyword\">TABLE<\/span> orders <span class=\"token punctuation\">(<\/span><br \/>\n    id <span class=\"token keyword\">SERIAL<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    user_id <span class=\"token keyword\">INT<\/span> <span class=\"token operator\">NOT<\/span> <span class=\"token boolean\">NULL<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    product_id <span class=\"token keyword\">INT<\/span> <span class=\"token operator\">NOT<\/span> <span class=\"token boolean\">NULL<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    amount <span class=\"token keyword\">DECIMAL<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">NOT<\/span> <span class=\"token boolean\">NULL<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    created_at <span class=\"token keyword\">TIMESTAMP<\/span> <span class=\"token operator\">NOT<\/span> <span class=\"token boolean\">NULL<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token keyword\">status<\/span> <span class=\"token keyword\">VARCHAR<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">20<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">NOT<\/span> <span class=\"token boolean\">NULL<\/span><br \/>\n<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">PARTITION<\/span> <span class=\"token keyword\">BY<\/span> RANGE <span class=\"token punctuation\">(<\/span>created_at<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u4e50\u89c2\u9501&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u6dfb\u52a0\u7248\u672c\u5217<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> <span class=\"token keyword\">TABLE<\/span> products <span class=\"token keyword\">ADD<\/span> <span class=\"token keyword\">COLUMN<\/span> version <span class=\"token keyword\">INT<\/span> <span class=\"token keyword\">DEFAULT<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<\/li>\n<h5>9.3.2 \u5185\u5b58\u4f18\u5316<\/h5>\n<li>\n<p>\u8c03\u6574\u5185\u5b58\u53c2\u6570&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u5171\u4eab\u7f13\u51b2\u533a&#xff1a;32GB&#xff08;\u7cfb\u7edf\u5185\u5b58\u768440%&#xff09;<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> shared_buffers <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;32GB&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u5de5\u4f5c\u5185\u5b58&#xff1a;128MB<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> work_mem <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;128MB&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u7ef4\u62a4\u5de5\u4f5c\u5185\u5b58&#xff1a;8GB<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> maintenance_work_mem <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;8GB&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u6709\u6548\u7f13\u5b58\u5927\u5c0f&#xff1a;64GB&#xff08;\u7cfb\u7edf\u5185\u5b58\u768475%&#xff09;<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> effective_cache_size <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;64GB&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<\/li>\n<li>\n<p>\u542f\u7528\u5927\u9875\u5185\u5b58&#xff1a;<\/p>\n<p># \u5728postgresql.conf\u4e2d\u6dfb\u52a0<br \/>\nshared_memory_type &#061; mmap<br \/>\nlarge_pages &#061; on<\/p>\n<\/li>\n<h5>9.3.3 I\/O\u4f18\u5316<\/h5>\n<li>\n<p>\u5b58\u50a8\u8bbe\u5907\u5347\u7ea7&#xff1a;<\/p>\n<ul>\n<li>\u5c06\u5b58\u50a8\u8bbe\u5907\u4eceSSD\u5347\u7ea7\u4e3aNVMe SSD<\/li>\n<li>\u5206\u79bbWAL\u548c\u6570\u636e\u5b58\u50a8\u5230\u4e0d\u540c\u7684NVMe SSD<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u6587\u4ef6\u7cfb\u7edf\u4f18\u5316&#xff1a;<\/p>\n<p># XFS\u6302\u8f7d\u9009\u9879<br \/>\n\/dev\/nvme0n1p1 \/pgdata xfs noatime,nodiratime,attr2,discard,inode64,logbufs&#061;8,logbsize&#061;256k 0 0<br \/>\n\/dev\/nvme1n1p1 \/pgwal xfs noatime,nodiratime,attr2,discard,inode64,logbufs&#061;8,logbsize&#061;256k 0 0<\/p>\n<\/li>\n<li>\n<p>\u8c03\u6574I\/O\u53c2\u6570&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u968f\u673a\u9875\u9762\u6210\u672c&#xff1a;1.1&#xff08;NVMe SSD&#xff09;<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> random_page_cost <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1.1<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u6709\u6548I\/O\u5e76\u53d1&#xff1a;500&#xff08;NVMe SSD&#xff09;<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> effective_io_concurrency <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">500<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u7ef4\u62a4I\/O\u5e76\u53d1&#xff1a;250<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> SYSTEM <span class=\"token keyword\">SET<\/span> maintenance_io_concurrency <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">250<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<\/li>\n<h5>9.3.4 \u67e5\u8be2\u4f18\u5316<\/h5>\n<li>\n<p>\u4f18\u5316\u6162\u67e5\u8be2&#xff1a;<\/p>\n<ul>\n<li>\u4e3a\u6162\u67e5\u8be2\u6dfb\u52a0\u5408\u9002\u7684\u7d22\u5f15<\/li>\n<li>\u91cd\u5199\u590d\u6742\u67e5\u8be2&#xff0c;\u4f7f\u7528CTE\u6216\u7269\u5316\u89c6\u56fe<\/li>\n<li>\u4f18\u5316\u67e5\u8be2\u8ba1\u5212<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u4f7f\u7528pg_stat_statements\u8bc6\u522b\u6162\u67e5\u8be2&#xff1a;<\/p>\n<p><span class=\"token keyword\">SELECT<\/span> query<span class=\"token punctuation\">,<\/span> calls<span class=\"token punctuation\">,<\/span> total_time<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">rows<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">100.0<\/span> <span class=\"token operator\">*<\/span> shared_blks_hit <span class=\"token operator\">\/<\/span> <span class=\"token keyword\">nullif<\/span><span class=\"token punctuation\">(<\/span>shared_blks_hit <span class=\"token operator\">&#043;<\/span> shared_blks_read<span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">AS<\/span> hit_percent<br \/>\n<span class=\"token keyword\">FROM<\/span> pg_stat_statements<br \/>\n<span class=\"token keyword\">ORDER<\/span> <span class=\"token keyword\">BY<\/span> total_time <span class=\"token keyword\">DESC<\/span><br \/>\n<span class=\"token keyword\">LIMIT<\/span> <span class=\"token number\">10<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<\/li>\n<h4>9.4 \u8c03\u4f18\u6548\u679c<\/h4>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u8c03\u4f18\u63aa\u65bd&#xff0c;\u9884\u671f\u53ef\u4ee5\u5b9e\u73b0&#xff1a;<\/p>\n<ul>\n<li>\u9501\u7b49\u5f85\u65f6\u95f4\u51cf\u5c1180%\u4ee5\u4e0a<\/li>\n<li>\u5185\u5b58\u4f7f\u7528\u7387\u964d\u4f4e30%\u4ee5\u4e0a<\/li>\n<li>I\/O\u7b49\u5f85\u65f6\u95f4\u51cf\u5c1160%\u4ee5\u4e0a<\/li>\n<li>\u67e5\u8be2\u54cd\u5e94\u65f6\u95f4\u51cf\u5c1150%\u4ee5\u4e0a<\/li>\n<li>\u7cfb\u7edf\u541e\u5410\u91cf\u63d0\u9ad840%\u4ee5\u4e0a<\/li>\n<\/ul>\n<h3>\u5341\u3001\u603b\u7ed3<\/h3>\n<p>\u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u662f\u4e00\u4e2a\u590d\u6742\u7684\u7cfb\u7edf\u5de5\u7a0b&#xff0c;\u6d89\u53ca\u591a\u4e2a\u65b9\u9762&#xff0c;\u5305\u62ec\u9501\u4e89\u7528\u89e3\u51b3\u3001\u5927\u89c4\u6a21\u5e76\u53d1\u5904\u7406\u3001\u5185\u6838\u8c03\u4f18\u3001\u5185\u5b58\u6df1\u5ea6\u4f18\u5316\u3001I\/O\u6df1\u5ea6\u4f18\u5316\u548c\u9ad8\u7ea7\u67e5\u8be2\u4f18\u5316\u7b49\u3002<\/p>\n<p>\u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u7684\u4e3b\u8981\u539f\u5219\u662f&#xff1a;<\/p>\n<li>\u76d1\u63a7\u5148\u884c&#xff1a;\u5728\u8c03\u4f18\u4e4b\u524d&#xff0c;\u5148\u6536\u96c6\u8db3\u591f\u7684\u6027\u80fd\u6570\u636e<\/li>\n<li>\u9010\u6b65\u8c03\u6574&#xff1a;\u4e00\u6b21\u53ea\u8c03\u6574\u4e00\u4e2a\u6216\u5c11\u6570\u51e0\u4e2a\u53c2\u6570<\/li>\n<li>\u6d4b\u8bd5\u9a8c\u8bc1&#xff1a;\u5728\u6d4b\u8bd5\u73af\u5883\u4e2d\u9a8c\u8bc1\u8c03\u4f18\u6548\u679c<\/li>\n<li>\u6301\u7eed\u4f18\u5316&#xff1a;\u6027\u80fd\u8c03\u4f18\u662f\u4e00\u4e2a\u6301\u7eed\u7684\u8fc7\u7a0b&#xff0c;\u9700\u8981\u5b9a\u671f\u76d1\u63a7\u548c\u8c03\u6574<\/li>\n<li>\u7ed3\u5408\u4e1a\u52a1&#xff1a;\u6839\u636e\u4e1a\u52a1\u9700\u6c42\u548c\u5de5\u4f5c\u8d1f\u8f7d\u8c03\u6574\u8c03\u4f18\u7b56\u7565<\/li>\n<p>\u901a\u8fc7\u6df1\u5165\u7406\u89e3PostgreSQL\u7684\u5de5\u4f5c\u539f\u7406&#xff0c;\u7ed3\u5408\u5b9e\u9645\u7684\u786c\u4ef6\u73af\u5883\u548c\u5de5\u4f5c\u8d1f\u8f7d&#xff0c;\u8fdb\u884c\u6709\u9488\u5bf9\u6027\u7684\u8c03\u4f18&#xff0c;\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8PostgreSQL\u6570\u636e\u5e93\u7684\u6027\u80fd\u548c\u53ef\u9760\u6027\u3002<\/p>\n<p>\u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u9700\u8981\u4e30\u5bcc\u7684\u7ecf\u9a8c\u548c\u6df1\u5165\u7684\u77e5\u8bc6&#xff0c;\u9700\u8981\u4e0d\u65ad\u5b66\u4e60\u548c\u5b9e\u8df5\u3002\u968f\u7740PostgreSQL\u7248\u672c\u7684\u66f4\u65b0&#xff0c;\u65b0\u7684\u6027\u80fd\u7279\u6027\u548c\u8c03\u4f18\u9009\u9879\u4e0d\u65ad\u51fa\u73b0&#xff0c;\u9700\u8981\u5173\u6ce8\u65b0\u7248\u672c\u7684\u53d8\u5316&#xff0c;\u5145\u5206\u5229\u7528\u65b0\u7279\u6027\u6765\u63d0\u9ad8\u7cfb\u7edf\u6027\u80fd\u3002<\/p>\n<p>\u901a\u8fc7\u672c\u7ae0\u8282\u7684\u5b66\u4e60&#xff0c;\u8bfb\u8005\u5e94\u8be5\u638c\u63e1PostgreSQL\u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u7684\u6838\u5fc3\u539f\u7406\u548c\u65b9\u6cd5&#xff0c;\u80fd\u591f\u8bc6\u522b\u548c\u89e3\u51b3\u590d\u6742\u7684\u6027\u80fd\u95ee\u9898&#xff0c;\u4f18\u5316\u7cfb\u7edf\u4ee5\u5904\u7406\u5927\u89c4\u6a21\u5e76\u53d1\u8bf7\u6c42&#xff0c;\u63d0\u9ad8\u7cfb\u7edf\u7684\u6027\u80fd\u548c\u53ef\u9760\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u6982\u8ff0<br \/>\n\u5728\u6570\u636e\u5e93\u7ba1\u7406\u4e2d&#xff0c;\u6027\u80fd\u8c03\u4f18\u662f\u4e00\u4e2a\u6301\u7eed\u7684\u8fc7\u7a0b&#xff0c;\u4ece\u57fa\u7840\u7684\u53c2\u6570\u8c03\u6574\u5230\u6df1\u5165\u7684\u5185\u6838\u8c03\u4f18&#xff0c;\u9700\u8981\u4e0d\u65ad\u5730\u76d1\u63a7\u3001\u5206\u6790\u548c\u4f18\u5316\u3002PostgreSQL 18\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6027\u80fd\u8c03\u4f18\u9009\u9879&#xff0c;\u80fd\u591f\u5904\u7406\u5927\u89c4\u6a21\u5e76\u53d1\u548c\u590d\u6742\u7684\u5de5\u4f5c\u8d1f\u8f7d\u3002<br \/>\n1.1 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u7684\u76ee\u6807<br \/>\n\u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u7684\u4e3b\u8981\u76ee\u6807\u662f&#xff1a;<br \/>\n\u89e3\u51b3\u590d\u6742\u7684\u6027\u80fd\u74f6\u9888\u5904\u7406\u5927\u89c4\u6a21\u5e76\u53d1\u8bf7\u6c42\u4f18\u5316\u8d44\u6e90\u5229\u7528\u7387\u63d0\u9ad8\u7cfb\u7edf\u7684\u53ef\u6269\u5c55\u6027\u786e\u4fdd\u7cfb\u7edf\u5728\u9ad8\u8d1f\u8f7d\u4e0b\u7684\u7a33\u5b9a\u6027<br \/>\n1.2 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u7684\u8303\u56f4<br \/>\n\u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u6db5<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[954,100],"topic":[],"class_list":["post-64896","post","type-post","status-publish","format-standard","hentry","category-server","tag-postgresql","tag-100"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PostgreSQL 18 \u4ece\u65b0\u624b\u5230\u5927\u5e08\uff1a\u5b9e\u6218\u6307\u5357 - 5.4 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/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.wsisp.com\/helps\/64896.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL 18 \u4ece\u65b0\u624b\u5230\u5927\u5e08\uff1a\u5b9e\u6218\u6307\u5357 - 5.4 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u3001\u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u6982\u8ff0 \u5728\u6570\u636e\u5e93\u7ba1\u7406\u4e2d&#xff0c;\u6027\u80fd\u8c03\u4f18\u662f\u4e00\u4e2a\u6301\u7eed\u7684\u8fc7\u7a0b&#xff0c;\u4ece\u57fa\u7840\u7684\u53c2\u6570\u8c03\u6574\u5230\u6df1\u5165\u7684\u5185\u6838\u8c03\u4f18&#xff0c;\u9700\u8981\u4e0d\u65ad\u5730\u76d1\u63a7\u3001\u5206\u6790\u548c\u4f18\u5316\u3002PostgreSQL 18\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6027\u80fd\u8c03\u4f18\u9009\u9879&#xff0c;\u80fd\u591f\u5904\u7406\u5927\u89c4\u6a21\u5e76\u53d1\u548c\u590d\u6742\u7684\u5de5\u4f5c\u8d1f\u8f7d\u3002 1.1 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u7684\u76ee\u6807 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u7684\u4e3b\u8981\u76ee\u6807\u662f&#xff1a; \u89e3\u51b3\u590d\u6742\u7684\u6027\u80fd\u74f6\u9888\u5904\u7406\u5927\u89c4\u6a21\u5e76\u53d1\u8bf7\u6c42\u4f18\u5316\u8d44\u6e90\u5229\u7528\u7387\u63d0\u9ad8\u7cfb\u7edf\u7684\u53ef\u6269\u5c55\u6027\u786e\u4fdd\u7cfb\u7edf\u5728\u9ad8\u8d1f\u8f7d\u4e0b\u7684\u7a33\u5b9a\u6027 1.2 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u7684\u8303\u56f4 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u6db5\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/64896.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-24T01:48:23+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/64896.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/64896.html\",\"name\":\"PostgreSQL 18 \u4ece\u65b0\u624b\u5230\u5927\u5e08\uff1a\u5b9e\u6218\u6307\u5357 - 5.4 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-24T01:48:23+00:00\",\"dateModified\":\"2026-01-24T01:48:23+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/64896.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/64896.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/64896.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL 18 \u4ece\u65b0\u624b\u5230\u5927\u5e08\uff1a\u5b9e\u6218\u6307\u5357 - 5.4 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PostgreSQL 18 \u4ece\u65b0\u624b\u5230\u5927\u5e08\uff1a\u5b9e\u6218\u6307\u5357 - 5.4 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","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.wsisp.com\/helps\/64896.html","og_locale":"zh_CN","og_type":"article","og_title":"PostgreSQL 18 \u4ece\u65b0\u624b\u5230\u5927\u5e08\uff1a\u5b9e\u6218\u6307\u5357 - 5.4 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00\u3001\u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u6982\u8ff0 \u5728\u6570\u636e\u5e93\u7ba1\u7406\u4e2d&#xff0c;\u6027\u80fd\u8c03\u4f18\u662f\u4e00\u4e2a\u6301\u7eed\u7684\u8fc7\u7a0b&#xff0c;\u4ece\u57fa\u7840\u7684\u53c2\u6570\u8c03\u6574\u5230\u6df1\u5165\u7684\u5185\u6838\u8c03\u4f18&#xff0c;\u9700\u8981\u4e0d\u65ad\u5730\u76d1\u63a7\u3001\u5206\u6790\u548c\u4f18\u5316\u3002PostgreSQL 18\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6027\u80fd\u8c03\u4f18\u9009\u9879&#xff0c;\u80fd\u591f\u5904\u7406\u5927\u89c4\u6a21\u5e76\u53d1\u548c\u590d\u6742\u7684\u5de5\u4f5c\u8d1f\u8f7d\u3002 1.1 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u7684\u76ee\u6807 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u7684\u4e3b\u8981\u76ee\u6807\u662f&#xff1a; \u89e3\u51b3\u590d\u6742\u7684\u6027\u80fd\u74f6\u9888\u5904\u7406\u5927\u89c4\u6a21\u5e76\u53d1\u8bf7\u6c42\u4f18\u5316\u8d44\u6e90\u5229\u7528\u7387\u63d0\u9ad8\u7cfb\u7edf\u7684\u53ef\u6269\u5c55\u6027\u786e\u4fdd\u7cfb\u7edf\u5728\u9ad8\u8d1f\u8f7d\u4e0b\u7684\u7a33\u5b9a\u6027 1.2 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u7684\u8303\u56f4 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18\u6db5","og_url":"https:\/\/www.wsisp.com\/helps\/64896.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-24T01:48:23+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/64896.html","url":"https:\/\/www.wsisp.com\/helps\/64896.html","name":"PostgreSQL 18 \u4ece\u65b0\u624b\u5230\u5927\u5e08\uff1a\u5b9e\u6218\u6307\u5357 - 5.4 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-24T01:48:23+00:00","dateModified":"2026-01-24T01:48:23+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/64896.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/64896.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/64896.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"PostgreSQL 18 \u4ece\u65b0\u624b\u5230\u5927\u5e08\uff1a\u5b9e\u6218\u6307\u5357 - 5.4 \u9ad8\u7ea7\u6027\u80fd\u8c03\u4f18"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/64896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=64896"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/64896\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=64896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=64896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=64896"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=64896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}