{"id":204024,"date":"2025-05-29T10:19:30","date_gmt":"2025-05-29T02:19:30","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204024\/"},"modified":"2025-05-29T10:19:30","modified_gmt":"2025-05-29T02:19:30","slug":"%e4%b8%ba-macos-%e7%94%a8%e6%88%b7%e8%ae%be%e7%bd%ae-postgresql%ef%bc%9a%e5%88%86%e6%ad%a5%e8%af%b4%e6%98%8e","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204024\/","title":{"rendered":"\u4e3a macOS \u7528\u6237\u8bbe\u7f6e PostgreSQL\uff1a\u5206\u6b65\u8bf4\u660e"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u4e3a macOS \u7528\u6237\u8bbe\u7f6e PostgreSQL\uff1a\u5206\u6b65\u8bf4\u660e<\/h1>\n<p>\u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u4e3a macOS \u7528\u6237\u8bbe\u7f6e PostgreSQL\uff1a\u5206\u6b65\u8bf4\u660e\u300b<\/span>\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241019\/17293413916713a7cf98cd8.jpg\" class=\"aligncenter\"><\/p>\n<p>\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f macos\uff0c\u5b89\u88c5 postgresql \u548c\u8bbe\u7f6e\u73af\u5883\u7684\u6b65\u9aa4\u4f1a\u7565\u6709\u4e0d\u540c\u3002\u64cd\u4f5c\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<hr>\n<p>\u5728 macos \u4e0a\u5b89\u88c5 postgresql \u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u4f46\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u4e4b\u4e00\u662f\u4f7f\u7528 <strong>homebrew<\/strong>\uff0cmacos \u7684\u5305\u7ba1\u7406\u5668\u3002<\/p>\n<h4> <strong>\u7b2c 1 \u6b65\uff1a\u5b89\u88c5 homebrew\uff08\u5982\u679c\u672a\u5b89\u88c5\uff09<\/strong> <\/h4>\n<p>\u5982\u679c\u60a8\u6ca1\u6709\u5b89\u88c5 homebrew\uff0c\u8bf7\u6253\u5f00 <strong>\u7ec8\u7aef<\/strong> \u5e76\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>\/bin\/bash -c \"$(curl -fssl https:\/\/raw.githubusercontent.com\/homebrew\/install\/head\/install.sh)\"\n<\/pre>\n<p>\u8fd9\u5c06\u5728\u60a8\u7684\u7cfb\u7edf\u4e0a\u5b89\u88c5 homebrew\u3002<\/p>\n<h4> <strong>\u7b2c 2 \u6b65\uff1a\u901a\u8fc7 homebrew \u5b89\u88c5 postgresql<\/strong> <\/h4>\n<p>\u5b89\u88c5 homebrew \u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5 postgresql\uff1a<\/p>\n<pre>brew install postgresql\n<\/pre>\n<h4> <strong>\u7b2c\u4e09\u6b65\uff1a\u542f\u52a8 postgresql \u670d\u52a1<\/strong> <\/h4>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u542f\u52a8postgresql\u670d\u52a1\u5668\uff1a<\/p>\n<pre>brew services start postgresql\n<\/pre>\n<p>\u8fd9\u5c06\u786e\u4fdd postgresql \u670d\u52a1\u5668\u5728\u60a8\u7684 macos \u7cfb\u7edf\u542f\u52a8\u65f6\u81ea\u52a8\u542f\u52a8\u3002<\/p>\n<h4> <strong>\u7b2c 4 \u6b65\uff1a\u9a8c\u8bc1\u5b89\u88c5<\/strong> <\/h4>\n<p>\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5 postgresql \u662f\u5426\u5df2\u6b63\u786e\u5b89\u88c5\uff1a<\/p>\n<pre>psql --version\n<\/pre>\n<p>\u8fd9\u5e94\u8be5\u663e\u793a\u5df2\u5b89\u88c5\u7684 postgresql \u7248\u672c\u3002<\/p>\n<h4> <strong>\u7b2c 5 \u6b65\uff1a\u8bbf\u95ee postgresql<\/strong> <\/h4>\n<p>\u60a8\u73b0\u5728\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u5f0f\u8bbf\u95ee postgresql\uff1a<\/p>\n<pre>psql postgres\n<\/pre>\n<hr>\n<p>\u5b89\u88c5 postgresql \u540e\uff0c\u60a8\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93\u6765\u5b58\u50a8\u5177\u6709 jsonb \u5c5e\u6027\u7684\u4ea7\u54c1\u3002<\/p>\n<h4> <strong>\u7b2c 1 \u6b65\uff1a\u521b\u5efa\u65b0\u6570\u636e\u5e93<\/strong> <\/h4>\n<p>\u5728 postgresql \u547d\u4ee4\u884c\u754c\u9762 (psql) \u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u636e\u5e93\uff1a<\/p>\n<pre>create database products_db;\n<\/pre>\n<h4> <strong>\u7b2c2\u6b65\uff1a\u521b\u5efa\u5177\u6709\u6743\u9650\u7684\u7528\u6237<\/strong> <\/h4>\n<p>\u63a5\u4e0b\u6765\uff0c\u521b\u5efa\u4e00\u4e2a\u5177\u6709\u7ba1\u7406\u5458\u6743\u9650\u7684\u7528\u6237\uff1a<\/p>\n<pre>create user your_username with password 'your_password';\ngrant all privileges on database products_db to your_username;\n<\/pre>\n<h4> <strong>\u7b2c3\u6b65\uff1a\u521b\u5efa\u4e00\u4e2a\u8868\u6765\u5b58\u50a8\u4ea7\u54c1<\/strong> <\/h4>\n<p>\u6700\u540e\uff0c\u521b\u5efa\u4e00\u4e2a\u8868\uff0c\u4ee5 <strong>jsonb<\/strong> \u683c\u5f0f\u5b58\u50a8\u4ea7\u54c1\u53ca\u5176\u5c5e\u6027\uff1a<\/p>\n<pre>create table products (\n    id serial primary key,\n    name text not null,\n    attributes jsonb\n);\n<\/pre>\n<p>\u6b64\u8868\u7ed3\u6784\u5141\u8bb8\u60a8\u5b58\u50a8\u6bcf\u4e2a\u4ea7\u54c1\u7684\u52a8\u6001\u5c5e\u6027\uff0c\u5229\u7528 postgresql \u7684 jsonb \u529f\u80fd\u6765\u5b9e\u73b0\u7075\u6d3b\u6027\u548c\u6027\u80fd\u3002<\/p>\n<hr>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5728 macos \u4e0a\u624b\u52a8\u542f\u52a8\u6216\u505c\u6b62 postgresql\uff1a<\/p>\n<ul>\n<li> <strong>\u542f\u52a8 postgresql<\/strong>\uff1a <\/li>\n<\/ul>\n<pre>  brew services start postgresql\n<\/pre>\n<ul>\n<li> <strong>\u505c\u6b62 postgresql<\/strong>\uff1a <\/li>\n<\/ul>\n<pre>  brew services stop postgresql\n<\/pre>\n<ul>\n<li> <strong>\u91cd\u65b0\u542f\u52a8 postgresql<\/strong>\uff1a <\/li>\n<\/ul>\n<pre>  brew services restart postgresql\n<\/pre>\n<hr>\n<p>\u5982\u679c\u60a8\u9700\u8981\u4ece macos \u5378\u8f7d postgresql\uff0c\u53ef\u4ee5\u4f7f\u7528 homebrew \u6765\u5b8c\u6210\uff1a<\/p>\n<pre>brew uninstall postgresql\n<\/pre>\n<hr>\n<p>\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\uff0cmacos \u7528\u6237\u53ef\u4ee5\u8f7b\u677e\u5b89\u88c5\u548c\u914d\u7f6e postgresql\u3002\u4f7f\u7528 <strong>homebrew<\/strong>\uff0c\u5b89\u88c5\u8fc7\u7a0b\u5feb\u901f\u4e14\u65e0\u7f1d\u3002<\/p>\n<p>\u4e3a\u4e86\u83b7\u5f97\u6d41\u7545\u7684\u4f53\u9a8c\uff0c\u8bf7\u59cb\u7ec8\u786e\u4fdd postgresql \u670d\u52a1\u6b63\u5728\u8fd0\u884c\u5e76\u6b63\u786e\u914d\u7f6e\uff0c\u7136\u540e\u518d\u7ee7\u7eed\u3002<\/p>\n<p>\u611f\u8c22\u60a8\u7684\u9605\u8bfb&#8230;<br \/><strong>\u7f16\u7801\u5feb\u4e50\uff01<\/strong><\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300a\u4e3a macOS \u7528\u6237\u8bbe\u7f6e PostgreSQL\uff1a\u5206\u6b65\u8bf4\u660e\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a macOS \u7528\u6237\u8bbe\u7f6e Pos&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-204024","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204024","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=204024"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204024\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}