{"id":274094,"date":"2023-06-03T20:08:50","date_gmt":"2023-06-03T12:08:50","guid":{"rendered":"https:\/\/lrxjmw.cn\/lxpazxjqsgd.html"},"modified":"2023-06-03T20:08:50","modified_gmt":"2023-06-03T12:08:50","slug":"lxpazxjqsgd","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/lxpazxjqsgd.html","title":{"rendered":"Linux\u4e0bpostgresql\u5b89\u88c5\u8be6\u89e3\uff0c\u8f7b\u677e\u641e\u5b9a\uff01"},"content":{"rendered":"

\u5728\u5f53\u4eca\u4e92\u8054\u7f51\u65f6\u4ee3\uff0c\u6570\u636e\u5df2\u7ecf\u6210\u4e3a\u4eba\u4eec\u751f\u6d3b\u548c\u5de5\u4f5c\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002\u800c\u6570\u636e\u5e93\u5219\u6210\u4e3a\u4e86\u5b58\u50a8\u3001\u7ba1\u7406\u548c\u5904\u7406\u6570\u636e\u7684\u91cd\u8981\u5de5\u5177\u3002postgresql<\/a>\u4f5c\u4e3a\u4e00\u6b3e\u5f00\u6e90\u7684\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf<\/a>\uff0c\u5907\u53d7\u5e7f\u5927\u7a0b\u5e8f\u5458\u7684\u9752\u7750\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u8bb2\u8ff0postgresql\u5728linux\u7cfb\u7edf\u4e0b\u7684\u5b89\u88c5\u8fc7\u7a0b\uff0c\u5e76\u5bf9\u6bcf\u4e2a\u6b65\u9aa4\u8fdb\u884c\u8be6\u5c3d\u89e3\u6790\uff0c\u5e0c\u671b\u5bf9\u8bfb\u8005\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n

1.\u786e\u8ba4\u7cfb\u7edf\u7248\u672c<\/b><\/p>\n

\u5728\u5b89\u88c5postgresql\u4e4b\u524dpostgresql \u5b89\u88c5 linux<\/strong>\uff0c\u9700\u8981\u786e\u8ba4\u81ea\u5df1\u7684linux\u7cfb\u7edf\u7248\u672c\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4<\/a>\u67e5\u770b\uff1a<\/p>\n

\n

\ncat \/etc\/issue\n<\/pre>\n<\/p>\n

\u901a\u5e38\u60c5\u51b5\u4e0b\uff0cpostgresql\u652f\u6301\u5927\u591a\u6570linux\u64cd\u4f5c\u7cfb\u7edf\u7248\u672clinux \u5185\u6838\uff0c\u4f46\u662f\u4e0d\u540c\u7248\u672c\u7684\u5b89\u88c5\u65b9\u5f0f\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\u3002\u56e0\u6b64\uff0c\u5728\u786e\u8ba4\u4e86\u81ea\u5df1\u7684\u64cd\u4f5c\u7cfb\u7edf\u7248\u672c\u540e\uff0c\u53ef\u4ee5\u8fdb\u5165postgresql\u5b98\u65b9\u7f51\u7ad9\u67e5\u627e\u5bf9\u5e94\u7248\u672c\u7684\u5b89\u88c5\u6559\u7a0b\u3002<\/p>\n

2.\u5b89\u88c5postgresql<\/b><\/p>\n

\u5728\u786e\u8ba4\u597d\u81ea\u5df1\u7684\u64cd\u4f5c\u7cfb\u7edf\u7248\u672c\u540e\uff0c\u5c31\u53ef\u4ee5\u5f00\u59cb\u5b89\u88c5postgresql\u4e86\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n

\uff081\uff09\u66f4\u65b0\u8f6f\u4ef6\u5305<\/p>\n

\u5728\u8fdb\u884c\u4efb\u4f55\u8f6f\u4ef6\u5b89\u88c5\u4e4b\u524d\uff0c\u90fd\u5e94\u8be5\u5148\u66f4\u65b0\u4e00\u4e0b\u8f6f\u4ef6\u5305\u5217\u8868\uff1a<\/p>\n

\n

\nsudo apt-get update\n<\/pre>\n<\/p>\n

\uff082\uff09\u5b89\u88c5postgresql<\/p>\n

\u5728\u66f4\u65b0\u8f6f\u4ef6\u5305\u5217\u8868\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5postgresql\uff1a<\/p>\n

\n

\nsudo apt-get install postgresql\n<\/pre>\n<\/p>\n

\uff083\uff09\u68c0\u67e5postgresql\u670d\u52a1\u662f\u5426\u542f\u52a8<\/p>\n

\u5728\u5b89\u88c5postgresql\u4e4b\u540e\uff0c\u8fd8\u9700\u8981\u68c0\u67e5postgresql\u670d\u52a1\u662f\u5426\u5df2\u7ecf\u542f\u52a8\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u68c0\u67e5\uff1a<\/p>\n

\n

\nsudo systemctl status postgresql\n<\/pre>\n<\/p>\n

\u5982\u679c\u8f93\u51fa\u7684\u7ed3\u679c\u4e2d\u5305\u542b\u201cactive (running)\u201d\u5b57\u6837\uff0c\u5c31\u8868\u793apostgresql\u670d\u52a1\u5df2\u7ecf\u542f\u52a8\u3002<\/p>\n

3.\u521b\u5efa\u7528\u6237\u548c\u6570\u636e\u5e93<\/b><\/p>\n

\u5728\u5b89\u88c5\u597dpostgresql\u4e4b\u540e\uff0c\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u7528\u6237\u548c\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u5e93\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n

\uff081\uff09\u5207\u6362\u5230postgres\u7528\u6237<\/p>\n

\u5728\u521b\u5efa\u7528\u6237\u548c\u6570\u636e\u5e93\u4e4b\u524d\uff0c\u9700\u8981\u5148\u5c06\u5f53\u524d\u7528\u6237\u5207\u6362\u4e3apostgres\u7528\u6237\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5207\u6362\uff1a<\/p>\n

\n

\nsudo su - postgres\n<\/pre>\n<\/p>\n

\uff082\uff09\u521b\u5efa\u65b0\u7528\u6237<\/p>\n

\u5728\u5207\u6362\u5230postgres\u7528\u6237\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u65b0\u7528\u6237\uff1a<\/p>\n

\n

\ncreateuser --interactive\n<\/pre>\n<\/p>\n

\u6267\u884c\u4ee5\u4e0a\u547d\u4ee4\u540e\u4f1a\u63d0\u793a\u8f93\u5165\u65b0\u7528\u6237\u540d\uff0c\u5e76\u8be2\u95ee\u662f\u5426\u4e3a\u8be5\u7528\u6237\u5206\u914d\u8d85\u7ea7\u7ba1\u7406\u5458\u6743\u9650\u3002<\/p>\n

\uff083\uff09\u521b\u5efa\u65b0\u6570\u636e\u5e93<\/p>\n

\u5728\u521b\u5efa\u65b0\u7528\u6237\u4e4b\u540epostgresql \u5b89\u88c5 linux<\/strong>\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u65b0\u7684\u6570\u636e\u5e93\uff1a<\/p>\n

\n

\ncreatedb mydatabase\n<\/pre>\n<\/p>\n

\u5176\u4e2d\uff0c\u201cmydatabase\u201d\u4e3a\u65b0\u6570\u636e\u5e93\u7684\u540d\u79f0\u3002<\/p>\n

4.\u914d\u7f6epg_hba.conf\u6587\u4ef6<\/b><\/p>\n

\u5728\u5b8c\u6210\u4e86\u4e0a\u8ff0\u6b65\u9aa4\u4e4b\u540e\uff0c\u8fd8\u9700\u8981\u914d\u7f6epg_hba.conf\u6587\u4ef6\u4ee5\u5141\u8bb8\u8fdc\u7a0b\u8bbf\u95eepostgresql\u6570\u636e\u5e93\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n

\uff081\uff09\u6253\u5f00pg_hba.conf\u6587\u4ef6<\/p>\n

pg_hba.conf\u6587\u4ef6\u4f4d\u4e8e\/etc\/postgresql\/\/main\u76ee\u5f55\u4e0b\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u6253\u5f00\u8be5\u6587\u4ef6\uff1a<\/p>\n

\n

\nsudo nano \/etc\/postgresql\/<version>\/main\/pg_hba.conf\n<\/pre>\n<\/p>\n

\u5176\u4e2d\uff0c\u201c\u201d\u4e3apostgresql\u7684\u7248\u672c\u53f7\u3002<\/p>\n

\uff082\uff09\u6dfb\u52a0\u5141\u8bb8\u8fdc\u7a0b\u8bbf\u95ee\u7684\u89c4\u5219<\/p>\n

\u5728pg_hba.conf\u6587\u4ef6\u4e2d\uff0c\u9700\u8981\u6dfb\u52a0\u4e00\u6761\u5141\u8bb8\u8fdc\u7a0b\u8bbf\u95ee\u7684\u89c4\u5219\u3002\u53ef\u4ee5\u5728\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n

\n

\nhost    all             all             0.0.0.0\/0               md5\n<\/pre>\n<\/p>\n

\u4e0a\u8ff0\u89c4\u5219\u8868\u793a\u5141\u8bb8\u6240\u6709IP\u5730\u5740\u7684\u4e3b\u673a\u901a\u8fc7md5\u52a0\u5bc6\u65b9\u5f0f\u8fdb\u884c\u8bbf\u95ee\u3002<\/p>\n

\uff083\uff09\u4fdd\u5b58\u5e76\u5173\u95edpg_hba.conf\u6587\u4ef6<\/p>\n

\u5728\u6dfb\u52a0\u5b8c\u89c4\u5219\u4e4b\u540e\uff0c\u9700\u8981\u4f7f\u7528Ctrl+X\u547d\u4ee4\u4fdd\u5b58\u5e76\u5173\u95edpg_hba.conf\u6587\u4ef6\u3002<\/p>\n

5.\u914d\u7f6epostgresql.conf\u6587\u4ef6<\/b><\/p>\n

\u9664\u4e86\u914d\u7f6epg_hba.conf\u6587\u4ef6\u4e4b\u5916\uff0c\u8fd8\u9700\u8981\u914d\u7f6epostgresql.conf\u6587\u4ef6\u4ee5\u5141\u8bb8\u8fdc\u7a0b\u8fde\u63a5\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n

\uff081\uff09\u6253\u5f00postgresql.conf\u6587\u4ef6<\/p>\n

postgresql.conf\u6587\u4ef6\u540c\u6837\u4f4d\u4e8e\/etc\/postgresql\/\/main\u76ee\u5f55\u4e0b\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u6253\u5f00\u8be5\u6587\u4ef6\uff1a<\/p>\n

\n

\nsudo nano \/etc\/postgresql\/<version>\/main\/postgresql.conf\n<\/pre>\n<\/p>\n

\uff082\uff09\u4fee\u6539listen_addresses\u53c2\u6570<\/p>\n

\u5728postgresql.conf\u6587\u4ef6\u4e2d\uff0c\u9700\u8981\u4fee\u6539listen_addresses\u53c2\u6570\u4ee5\u5141\u8bb8\u8fdc\u7a0b\u8fde\u63a5\u3002\u53ef\u4ee5\u627e\u5230\u8be5\u53c2\u6570\u5e76\u5c06\u5176\u8bbe\u7f6e\u4e3a\u201c*\u201d\uff0c\u8868\u793a\u5141\u8bb8\u6240\u6709IP\u5730\u5740\u7684\u4e3b\u673a\u8fdb\u884c\u8fde\u63a5\u3002\u5177\u4f53\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n

\n

\nlisten_addresses ='*'\n<\/pre>\n<\/p>\n

\uff083\uff09\u4fdd\u5b58\u5e76\u5173\u95edpostgresql.conf\u6587\u4ef6<\/p>\n

\u5728\u4fee\u6539\u5b8c\u53c2\u6570\u4e4b\u540e\uff0c\u540c\u6837\u9700\u8981\u4f7f\u7528Ctrl+X\u547d\u4ee4\u4fdd\u5b58\u5e76\u5173\u95edpostgresql.conf\u6587\u4ef6\u3002<\/p>\n

6.\u91cd\u542fpostgresql\u670d\u52a1<\/b><\/p>\n

\u5728\u5b8c\u6210\u4e86\u4e0a\u8ff0\u914d\u7f6e\u4e4b\u540e\uff0c\u9700\u8981\u91cd\u542fpostgresql\u670d\u52a1\u4ee5\u4f7f\u5176\u751f\u6548\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u91cd\u542fpostgresql\u670d\u52a1\uff1a<\/p>\n

\n

\nsudo systemctl restart postgresql\n<\/pre>\n<\/p>\n

7.\u6d4b\u8bd5\u8fde\u63a5<\/b><\/p>\n

\u5728\u5b8c\u6210\u4e86\u4e0a\u8ff0\u6b65\u9aa4\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u652f\u6301postgresql\u7684\u5ba2\u6237\u7aef\u5de5\u5177\u6765\u6d4b\u8bd5\u8fde\u63a5\u4e86\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528psql\u547d\u4ee4\u6765\u6d4b\u8bd5\u8fde\u63a5\uff1a<\/p>\n

\n

\npsql -h<host>-p<port>-U<username>-d<database>\n<\/pre>\n<\/p>\n

\u5176\u4e2d\uff0c\u201c\u201d\u4e3a\u670d\u52a1\u5668IP\u5730\u5740\uff0c\u201c\u201d\u4e3apostgresql\u7aef\u53e3\u53f7\uff0c\u201c\u201d\u4e3a\u65b0\u521b\u5efa\u7684\u7528\u6237\u540d\uff0c\u201c\u201d\u4e3a\u65b0\u521b\u5efa\u7684\u6570\u636e\u5e93\u540d\u79f0\u3002<\/p>\n

8.\u9632\u706b\u5899\u914d\u7f6e<\/b><\/p>\n

\u5728\u5141\u8bb8\u8fdc\u7a0b\u8bbf\u95eepostgresql\u4e4b\u540e\uff0c\u8fd8\u9700\u8981\u8fdb\u884c\u9632\u706b\u5899\u914d\u7f6e\u4ee5\u786e\u4fdd\u5b89\u5168\u6027\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n

\uff081\uff09\u6253\u5f00\u9632\u706b\u5899<\/p>\n

\u5982\u679c\u8fd8\u6ca1\u6709\u6253\u5f00\u9632\u706b\u5899\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u6253\u5f00\uff1a<\/p>\n

\n

\nsudo ufw enable\n<\/pre>\n<\/p>\n

\uff082\uff09\u6dfb\u52a0postgresql\u89c4\u5219<\/p>\n

\u5728\u6253\u5f00\u9632\u706b\u5899\u4e4b\u540e\uff0c\u8fd8\u9700\u8981\u6dfb\u52a0\u4e00\u6761\u5141\u8bb8postgresql\u8fde\u63a5\u7684\u89c4\u5219\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u6dfb\u52a0\uff1a<\/p>\n

\n

\nsudo ufw allow 5432\/tcp\n<\/pre>\n<\/p>\n

\u5176\u4e2d\uff0c\u201c5432\u201d\u4e3apostgresql\u9ed8\u8ba4\u7aef\u53e3\u53f7\u3002<\/p>\n

9.\u603b\u7ed3<\/b><\/p>\n

\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86postgresql\u5728linux\u7cfb\u7edf\u4e0b\u7684\u5b89\u88c5\u8fc7\u7a0b\uff0c\u5e76\u5bf9\u6bcf\u4e2a\u6b65\u9aa4\u8fdb\u884c\u4e86\u8be6\u5c3d\u89e3\u6790\u3002\u901a\u8fc7\u672c\u6587\u7684\u5b66\u4e60\uff0c\u76f8\u4fe1\u8bfb\u8005\u5df2\u7ecf\u638c\u63e1\u4e86postgresql\u7684\u5b89\u88c5\u548c\u914d\u7f6e\u65b9\u6cd5\u7ea2\u65d7linux\u5b98\u7f51\uff0c\u53ef\u4ee5\u987a\u5229\u5730\u5728linux\u7cfb\u7edf\u4e0b\u4f7f\u7528\u8be5\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u3002\u5728\u4f7f\u7528postgresql\u7684\u8fc7\u7a0b\u4e2d\uff0c\u8fd8\u9700\u8981\u6ce8\u610f\u6570\u636e\u5b89\u5168\u6027\uff0c\u5e76\u8fdb\u884c\u9002\u5f53\u7684\u9632\u706b\u5899\u914d\u7f6e\uff0c\u4ee5\u786e\u4fdd\u6570\u636e\u7684\u5b89\u5168\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728\u5b89\u88c5postgresql\u4e4b\u524d\uff0c\u9700\u8981\u786e\u8ba4\u81ea\u5df1\u7684linux\u7cfb\u7edf\u7248\u672c\u3002\u5728\u786e\u8ba4\u597d\u81ea\u5df1\u7684\u64cd\u4f5c\u7cfb\u7edf\u7248\u672c\u540e\uff0c\u5c31\u53ef\u4ee5\u5f00\u59cb\u5b89\u88c5postgresql\u4e86\u3002\u5728\u8fdb\u884c\u4efb\u4f55\u8f6f\u4ef6\u5b89\u88c5\u4e4b\u524d\uff0c\u90fd\u5e94\u8be5\u5148\u66f4\u65b0\u4e00\u4e0b\u8f6f\u4ef6\u5305\u5217\u8868\uff1a\u5728\u66f4\u65b0\u8f6f\u4ef6\u5305\u5217\u8868\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5postgresql\uff1a\u5728\u5b89\u88c5\u597dpostgresql\u4e4b\u540e\uff0c\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u7528\u6237\u548c\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u91cd\u542fpostgresql\u670d\u52a1\uff1a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[999],"class_list":["post-274094","post","type-post","status-publish","format-standard","hentry","category-tougao","tag-999"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/274094","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=274094"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/274094\/revisions"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=274094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=274094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=274094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}