{"id":20796,"date":"2024-01-02T06:05:40","date_gmt":"2024-01-02T06:05:40","guid":{"rendered":"https:\/\/server.hk\/blog\/20796\/"},"modified":"2024-11-14T10:38:30","modified_gmt":"2024-11-14T02:38:30","slug":"postgresql-command-create-publication","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/20796\/","title":{"rendered":"PostgreSQL \u547d\u4ee4\uff1aCREATE PUBLICATION"},"content":{"rendered":"<h1 id=\"postgresql-command-create-publication-vzYBUPmvNJ\">PostgreSQL \u547d\u4ee4\uff1aCREATE PUBLICATION<\/h1>\n<p>PostgreSQL \u662f\u4e00\u500b\u529f\u80fd\u5f37\u5927\u7684\u958b\u6e90\u95dc\u806f\u5f0f\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u63d0\u4f9b\u4e86\u5ee3\u6cdb\u7684\u529f\u80fd\u548c\u7279\u6027\u3002\u5176\u986f\u8457\u7279\u9ede\u4e4b\u4e00\u662f\u80fd\u5920\u4f7f\u7528\u767c\u4f48\/\u8a02\u95b1\u6a21\u578b\u5728\u591a\u53f0\u4f3a\u670d\u5668\u4e4b\u9593\u8907\u88fd\u6578\u64da\u3002\u672c\u6587\u5c07\u63a2\u8a0e PostgreSQL \u547d\u4ee4 <code>CREATE PUBLICATION<\/code> \u4e26\u4e86\u89e3\u5982\u4f55\u4f7f\u7528\u5b83\u4f86\u8a2d\u7f6e\u6578\u64da\u8907\u88fd\u3002<\/p>\n<h2 id=\"introduction-to-postgresql-replication-vzYBUPmvNJ\">PostgreSQL \u8907\u88fd\u4ecb\u7d39<\/h2>\n<p>\u8907\u88fd\u662f\u5275\u5efa\u548c\u7dad\u8b77\u591a\u500b\u6578\u64da\u5eab\u526f\u672c\u7684\u904e\u7a0b\uff0c\u4ee5\u78ba\u4fdd\u6578\u64da\u53ef\u7528\u6027\u3001\u5bb9\u932f\u80fd\u529b\u548c\u8ca0\u8f09\u5e73\u8861\u3002PostgreSQL \u652f\u63f4\u591a\u7a2e\u8907\u88fd\u65b9\u6cd5\uff0c\u5305\u62ec\u4e32\u6d41\u8907\u88fd\u3001\u908f\u8f2f\u8907\u88fd\u548c\u96d9\u5411\u8907\u88fd\u3002<\/p>\n<p>\u908f\u8f2f\u8907\u88fd\u65bc PostgreSQL 9.4 \u4e2d\u5f15\u5165\uff0c\u5141\u8a31\u60a8\u8907\u88fd\u8868\u7684\u4e00\u90e8\u5206\u6216\u751a\u81f3\u8868\u5167\u7684\u7279\u5b9a\u5217\u3002\u8207\u4e32\u6d41\u8907\u88fd\u76f8\u6bd4\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u9748\u6d3b\u6027\uff0c\u56e0\u70ba\u4e32\u6d41\u8907\u88fd\u6703\u8907\u88fd\u6574\u500b\u6578\u64da\u5eab\u96c6\u7fa4\u3002<\/p>\n<h2 id=\"understanding-create-publication-vzYBUPmvNJ\">\u7406\u89e3 CREATE PUBLICATION<\/h2>\n<p><code>CREATE PUBLICATION<\/code> \u547d\u4ee4\u7528\u4f86\u5728 PostgreSQL \u4e2d\u5b9a\u7fa9\u4e00\u500b\u767c\u4f48\u3002\u767c\u4f48\u4ee3\u8868\u4e00\u7d44\u8868\u6216\u8868\u4e2d\u67d0\u4e9b\u5217\u7684\u5b50\u96c6\uff0c\u9019\u4e9b\u5c07\u6703\u88ab\u8907\u88fd\u5230\u4e00\u500b\u6216\u591a\u500b\u8a02\u95b1\u8005\u3002\u5b83\u5141\u8a31\u60a8\u63a7\u5236\u54ea\u4e9b\u6578\u64da\u61c9\u8a72\u88ab\u8907\u88fd\uff0c\u4e26\u63d0\u4f9b\u5728\u8907\u88fd\u4e4b\u524d\u904e\u6ffe\u548c\u8f49\u63db\u6578\u64da\u7684\u6a5f\u5236\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u5275\u5efa\u767c\u4f48\u7684\u8a9e\u6cd5\uff1a<\/p>\n<pre><code>CREATE PUBLICATION publication_name FOR TABLE table_name [, ...] [WITH (option_name = option_value [, ...])]<\/code><\/pre>\n<p><code>publication_name<\/code> \u662f\u767c\u4f48\u7684\u540d\u7a31\uff0c\u800c <code>table_name<\/code> \u4ee3\u8868\u5c07\u5305\u542b\u5728\u767c\u4f48\u4e2d\u7684\u8868\u3002\u60a8\u53ef\u4ee5\u7528\u9017\u865f\u5206\u9694\u591a\u500b\u8868\u3002<\/p>\n<p><code>WITH<\/code> \u5b50\u53e5\u5141\u8a31\u60a8\u70ba\u767c\u4f48\u6307\u5b9a\u9644\u52a0\u9078\u9805\u3002\u4e00\u4e9b\u5e38\u7528\u7684\u9078\u9805\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><code>publish<\/code>\uff1a\u6307\u5b9a\u767c\u4f48\u662f\u5426\u6709\u6548\u3002\u9810\u8a2d\u503c\u70ba <code>true<\/code>\u3002<\/li>\n<li><code>publish_via_partition_root<\/code>\uff1a\u6307\u5b9a\u767c\u4f48\u662f\u5426\u61c9\u5305\u542b\u6307\u5b9a\u8868\u7684\u5206\u5340\u3002\u9810\u8a2d\u503c\u70ba <code>false<\/code>\u3002<\/li>\n<li><code>publish_all_columns<\/code>\uff1a\u6307\u5b9a\u662f\u5426\u61c9\u8907\u88fd\u8868\u7684\u6240\u6709\u5217\u3002\u9810\u8a2d\u503c\u70ba <code>false<\/code>\u3002<\/li>\n<\/ul>\n<h2 id=\"example-usage-vzYBUPmvNJ\">\u793a\u4f8b\u7528\u6cd5<\/h2>\n<p>\u8b93\u6211\u5011\u8003\u616e\u4e00\u500b\u4f8b\u5b50\uff0c\u6211\u5011\u6709\u4e00\u500b PostgreSQL \u6578\u64da\u5eab\uff0c\u5176\u4e2d\u6709\u5169\u500b\u8868\uff1a<code>customers<\/code> \u548c <code>orders<\/code>\u3002\u6211\u5011\u5e0c\u671b\u5c07 <code>customers<\/code> \u8868\u50c5\u8907\u88fd\u5230\u8a02\u95b1\u8005\u6578\u64da\u5eab\u3002<\/p>\n<p>\u8981\u70ba <code>customers<\/code> \u8868\u5275\u5efa\u767c\u4f48\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>CREATE PUBLICATION customer_publication FOR TABLE customers;<\/code><\/pre>\n<p>\u9019\u689d\u547d\u4ee4\u5275\u5efa\u4e00\u500b\u540d\u70ba <code>customer_publication<\/code> \u7684\u767c\u4f48\u4e26\u5305\u542b <code>customers<\/code> \u8868\u3002<\/p>\n<p>\u5275\u5efa\u767c\u4f48\u5f8c\uff0c\u6211\u5011\u53ef\u4ee5\u5728\u8a02\u95b1\u8005\u6578\u64da\u5eab\u4e2d\u5275\u5efa\u4e00\u500b\u8a02\u95b1\uff0c\u4ee5\u63a5\u6536\u8907\u88fd\u7684\u6578\u64da\u3002\u7136\u5f8c\uff0c\u8a02\u95b1\u8005\u53ef\u4ee5\u4f7f\u7528 <code>CREATE SUBSCRIPTION<\/code> \u547d\u4ee4\u8a02\u95b1\u8a72\u767c\u4f48\u4e26\u958b\u59cb\u63a5\u6536\u8907\u88fd\u7684\u6578\u64da\u3002<\/p>\n<h2 id=\"summary-vzYBUPmvNJ\">\u6458\u8981<\/h2>\n<p>PostgreSQL \u4e2d\u7684 <code>CREATE PUBLICATION<\/code> \u547d\u4ee4\u5141\u8a31\u60a8\u5b9a\u7fa9\u6578\u64da\u8907\u88fd\u7684\u767c\u4f48\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u7a2e\u9748\u6d3b\u7684\u65b9\u5f0f\u4f86\u9078\u64c7\u7279\u5b9a\u7684\u8868\u6216\u5217\u9032\u884c\u8907\u88fd\uff0c\u4e26\u63d0\u4f9b\u5404\u7a2e\u9078\u9805\u4f86\u63a7\u5236\u8907\u88fd\u904e\u7a0b\u3002\u901a\u904e\u4f7f\u7528\u9019\u500b\u547d\u4ee4\uff0c\u60a8\u53ef\u4ee5\u8f15\u9b06\u8a2d\u7f6e PostgreSQL \u4e2d\u7684\u6578\u64da\u8907\u88fd\uff0c\u78ba\u4fdd\u6578\u64da\u7684\u53ef\u7528\u6027\u548c\u5bb9\u932f\u80fd\u529b\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6709\u8208\u8da3\u6df1\u5165\u63a2\u7d22 PostgreSQL \u53ca\u5176\u8907\u88fd\u529f\u80fd\uff0c\u53ef\u4ee5\u8003\u616e\u67e5\u770b <a href=\"https:\/\/server.hk\">Server.HK<\/a>\uff0c\u9019\u662f\u4e00\u5bb6\u9818\u5148\u7684 VPS \u8a17\u7ba1\u516c\u53f8\uff0c\u63d0\u4f9b\u53ef\u9760\u4e14\u9ad8\u6027\u80fd\u7684 PostgreSQL \u8a17\u7ba1\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PostgreSQL \u547d\u4ee4\uff1aCR&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-20796","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/20796","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=20796"}],"version-history":[{"count":2,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/20796\/revisions"}],"predecessor-version":[{"id":24298,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/20796\/revisions\/24298"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=20796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=20796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=20796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}