{"id":41950,"date":"2023-02-24T22:18:44","date_gmt":"2023-10-29T01:09:10","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql14%e5%88%b0almalinux8%e3%80%82\/"},"modified":"2024-04-29T16:07:03","modified_gmt":"2024-04-29T08:07:03","slug":"%e5%ae%89%e8%a3%85postgresql14%e5%88%b0almalinux8%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql14%e5%88%b0almalinux8%e3%80%82\/","title":{"rendered":"\u5b89\u88c5PostgreSQL14\u5230AlmaLinux8"},"content":{"rendered":"<h1>\u73af\u5883<\/h1>\n<p>\u7531\u4e8e PostgreSQL 14.0 \u5728 2021\/9\/30 \u53d1\u5e03\uff0c\u56e0\u6b64\u6211\u6253\u7b97\u5c1d\u8bd5\u5b89\u88c5\u5b83\u3002<\/p>\n<ul class=\"post-ul\">PostgreSQL 14 Press Kit<\/ul>\n<p>\u73af\u5883\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">AlmaLinux 8(firewalld\u306f\u7121\u52b9\u5316\u3057\u3066\u3044\u307e\u3059)<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">Postgres 14<\/ul>\n<p>\u6211\u4ee5\u524d\u4e00\u76f4\u5728\u4f7f\u7528CentOS\uff0c\u4f46\u7531\u4e8e\u6700\u65b0\u7248\u672c\u7684CentOS Linux 8\u5c06\u4e8e2021\u5e74\u5e95\u505c\u6b62\u652f\u6301\uff0c\u6240\u4ee5\u6211\u8f6c\u800c\u4f7f\u7528\u4ee3\u66ff\u64cd\u4f5c\u7cfb\u7edfAlmaLinux\u3002<\/p>\n<p>\u5728\u4ee5\u4e0b\u7684 PostgreSQL 13 \u4e2d\uff0c\u5b89\u88c5\u6b65\u9aa4\u6709\u4e9b\u8bb8\u53d8\u5316\u3002<\/p>\n<ul class=\"post-ul\">CentOS 7.5\u306bPostgreSQL13\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/ul>\n<h1>\u5b89\u88c5PostgreSQL\u7684yum\u4ed3\u5e93\u3002<\/h1>\n<p>\u6211\u5c06\u68c0\u67e5PostgreSQL\u7684\u8f6f\u4ef6\u5305\u3002<br \/>\n\u770b\u8d77\u6765AlmaLinux\u53ea\u63d0\u4f9b\u4e86\u6700\u9ad8\u523013\u7248\u672c\u7684PostgreSQL\u3002<\/p>\n<pre class=\"post-pre\"><code># dnf module list postgresql\r\ndetermining the fastest mirror (10 hosts).. done.  100% [==================================================] 1.1 kB\/s | 639  B     00:00 ETA\r\nAlmaLinux 8 - BaseOS                                                                                         3.1 MB\/s | 8.6 MB     00:02    \r\nAlmaLinux 8 - AppStream                                                                                      5.4 MB\/s | 9.4 MB     00:01    \r\nAlmaLinux 8 - Extras                                                                                          10 kB\/s |  10 kB     00:01    \r\nAlmaLinux 8 - AppStream\r\nName                         Stream                  Profiles                            Summary                                             \r\npostgresql                   9.6                     client, server [d]                  PostgreSQL server and client module                 \r\npostgresql                   10 [d]                  client, server [d]                  PostgreSQL server and client module                 \r\npostgresql                   12                      client, server [d]                  PostgreSQL server and client module                 \r\npostgresql                   13                      client, server [d]                  PostgreSQL server and client module                 \r\n\r\nHint: [d]efault, [e]nabled, [x]disabled, [i]nstalled\r\n<\/code><\/pre>\n<p>\u8bf7\u5b89\u88c5PostgreSQL\u7684\u5b58\u50a8\u5e93\u8f6f\u4ef6\u5305\u3002<br \/>\n\u8bf7\u53c2\u8003\u4ee5\u4e0b\u7f51\u7ad9\uff0c\u83b7\u53d6\u5404\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u7684\u5b58\u50a8\u5e93\u8f6f\u4ef6\u5305\u7684URL\u5217\u8868\u3002<\/p>\n<pre class=\"post-pre\"><code># dnf -y install https:\/\/download.postgresql.org\/pub\/repos\/yum\/reporpms\/EL-8-x86_64\/pgdg-redhat-repo-latest.noarch.rpm\r\n\uff5e\u7701\u7565\uff5e\r\nRunning transaction\r\n  Preparing        :                                                                                                                     1\/1 \r\n  Installing       : pgdg-redhat-repo-42.0-20.noarch                                                                                     1\/1 \r\n  Verifying        : pgdg-redhat-repo-42.0-20.noarch                                                                                     1\/1 \r\n\r\nInstalled:\r\n  pgdg-redhat-repo-42.0-20.noarch                                                                                                            \r\n\r\nComplete!\r\n<\/code><\/pre>\n<h1>\u5b89\u88c5PostgreSQL<\/h1>\n<p>\u5b89\u88c5PostgreSQL\u3002<br \/>\n\u8bf7\u6ce8\u610f\uff0c&#8221;postgresql14-devel&#8221;\u4e5f\u4e00\u5e76\u5b89\u88c5\uff0c\u8fd9\u662f\u4e3a\u4e86\u5728\u7f16\u8bd1\u6269\u5c55\u529f\u80fd\u65f6\u4f7f\u7528\uff0c\u4f46\u4e0d\u662f\u5fc5\u9700\u7684\u3002<\/p>\n<pre class=\"post-pre\"><code># dnf -qy module disable postgresql\r\n# dnf -y install postgresql14 postgresql14-server postgresql14-contrib postgresql14-devel\r\n\r\n\uff5e\u7701\u7565\uff5e\r\nInstalled:\r\n  annobin-9.50-1.el8.x86_64                                                clang-11.0.0-1.module_el8.4.0+2107+39fed697.x86_64                \r\n  clang-devel-11.0.0-1.module_el8.4.0+2107+39fed697.x86_64                 clang-libs-11.0.0-1.module_el8.4.0+2107+39fed697.x86_64           \r\n  clang-tools-extra-11.0.0-1.module_el8.4.0+2107+39fed697.x86_64           cmake-filesystem-3.18.2-11.el8_4.x86_64                           \r\n  compiler-rt-11.0.0-1.module_el8.4.0+2107+39fed697.x86_64                 emacs-filesystem-1:26.1-5.el8.noarch                              \r\n  gcc-8.4.1-1.el8.alma.x86_64                                              gcc-c++-8.4.1-1.el8.alma.x86_64                                   \r\n  glibc-devel-2.28-151.el8.x86_64                                          glibc-headers-2.28-151.el8.x86_64                                 \r\n  kernel-headers-4.18.0-305.19.1.el8_4.x86_64                              libicu-60.3-2.el8_1.x86_64                                        \r\n  libicu-devel-60.3-2.el8_1.x86_64                                         libomp-11.0.0-1.module_el8.4.0+2107+39fed697.x86_64               \r\n  libomp-devel-11.0.0-1.module_el8.4.0+2107+39fed697.x86_64                libstdc++-devel-8.4.1-1.el8.alma.x86_64                           \r\n  libxcrypt-devel-4.1.1-4.el8.x86_64                                       libxslt-1.1.32-6.el8.x86_64                                       \r\n  llvm-11.0.0-2.module_el8.4.0+2107+39fed697.x86_64                        llvm-devel-11.0.0-2.module_el8.4.0+2107+39fed697.x86_64           \r\n  llvm-libs-11.0.0-2.module_el8.4.0+2107+39fed697.x86_64                   llvm-static-11.0.0-2.module_el8.4.0+2107+39fed697.x86_64          \r\n  llvm-test-11.0.0-2.module_el8.4.0+2107+39fed697.x86_64                   lz4-1.8.3-3.el8_4.x86_64                                          \r\n  postgresql14-14.0-1PGDG.rhel8.x86_64                                     postgresql14-contrib-14.0-1PGDG.rhel8.x86_64                      \r\n  postgresql14-devel-14.0-1PGDG.rhel8.x86_64                               postgresql14-libs-14.0-1PGDG.rhel8.x86_64                         \r\n  postgresql14-server-14.0-1PGDG.rhel8.x86_64                              python3-lit-0.11.0-1.module_el8.4.0+2107+39fed697.noarch          \r\n  python3-setuptools-39.2.0-6.el8.noarch                                  \r\n\r\nComplete!\r\n<\/code><\/pre>\n<p>PostgreSQL\u4f1a\u88ab\u5b89\u88c5\u5728\u300c\/usr\/pgsql-14\/\u300d\u76ee\u5f55\u4e0b\u3002<\/p>\n<pre class=\"post-pre\"><code># ls -l \/usr\/pgsql-14\/\r\ntotal 20\r\ndrwxr-xr-x 2 root root 4096 Oct  4 23:00 bin\r\ndrwxr-xr-x 3 root root   23 Oct  4 23:00 doc\r\ndrwxr-xr-x 6 root root 4096 Oct  4 23:00 include\r\ndrwxr-xr-x 5 root root 4096 Oct  4 23:00 lib\r\ndrwxr-xr-x 8 root root 4096 Oct  4 23:00 share\r\n<\/code><\/pre>\n<h1>PostgreSQL\u7684\u81ea\u52a8\u542f\u52a8<\/h1>\n<p>\u4e3a\u4e86\u81ea\u52a8\u542f\u52a8PostgreSQL\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u3002<\/p>\n<pre class=\"post-pre\"><code># systemctl enable postgresql-14.service\r\n<\/code><\/pre>\n<h1>\u521b\u5efa\u6570\u636e\u5e93\u96c6\u7fa4<\/h1>\n<p>\u521b\u5efa\u6570\u636e\u5e93\u96c6\u7fa4\u3002<br \/>\n\u6b63\u5728\u4f7f\u7528root\u7528\u6237\u6267\u884c\u3002<br \/>\n\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6570\u636e\u5e93\u6587\u4ef6\u5c06\u4f1a\u88ab\u521b\u5efa\u5728&#8221;\/var\/lib\/pgsql\/14\/data\/&#8221;\u76ee\u5f55\u4e0b\uff0c\u4f46\u5728\u6b64\u6b21\u64cd\u4f5c\u4e2d\uff0c\u6211\u4eec\u5c06\u5176\u6539\u4e3a\u5728&#8221;\/data\/&#8221;\u76ee\u5f55\u4e0b\u3002<br \/>\n\u53ef\u4ee5\u901a\u8fc7postgresql-14.service\u6587\u4ef6\u4e2d\u7684&#8221;PGDATA&#8221;\u73af\u5883\u53d8\u91cf\u8fdb\u884c\u6307\u5b9a\u3002<\/p>\n<pre class=\"post-pre\"><code># vi \/usr\/lib\/systemd\/system\/postgresql-14.service\r\n\r\n\u5909\u66f4\u524d\uff09\r\nEnvironment=PGDATA=\/var\/lib\/pgsql\/14\/data\/\r\n\u5909\u66f4\u5f8c\uff09\r\nEnvironment=PGDATA=\/data\/\r\n\r\n# systemctl daemon-reload\r\n<\/code><\/pre>\n<p>\u4e0b\u9762\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u6570\u636e\u5e93\u96c6\u7fa4\u3002<\/p>\n<pre class=\"post-pre\"><code># PGSETUP_INITDB_OPTIONS=\"-E UTF8 --no-locale\" \/usr\/pgsql-14\/bin\/postgresql-14-setup initdb\r\nInitializing database ... OK\r\n<\/code><\/pre>\n<p>\u786e\u8ba4\u5728\u300c\/data\/\u300d\u4e0b\u751f\u6210\u7684\u5185\u5bb9\u3002<\/p>\n<pre class=\"post-pre\"><code># cat \/data\/PG_VERSION \r\n14\r\n<\/code><\/pre>\n<h1>\u542f\u52a8PostgreSQL<\/h1>\n<p>\u5728\u542f\u52a8\u4e4b\u524d\uff0c\u5c06PostgreSQL\u7684bin\u76ee\u5f55\u6dfb\u52a0\u5230\u8def\u5f84\u4e2d\u3002<\/p>\n<pre class=\"post-pre\"><code># su - postgres\r\n\r\n\/var\/lib\/pgsql\/.pgsql_profile\u306b\u30d1\u30b9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002\r\n\r\n# vi \/var\/lib\/pgsql\/.pgsql_profile\r\nPATH=\/usr\/pgsql-14\/bin:$PATH\r\nexport PATH\r\n\r\nPGDATA\u3092\u4fee\u6b63\u3057\u307e\u3059\u3002\r\n\r\n# vi \/var\/lib\/pgsql\/.bash_profile\r\n#PGDATA=\/var\/lib\/pgsql\/14\/data\r\nPGDATA=\/data\r\n\r\n# source ~\/.bash_profile\r\n<\/code><\/pre>\n<p>\u4f7f\u7528&#8221;pg_ctl start&#8221;\u6765\u542f\u52a8PostgreSQL\u3002<\/p>\n<pre class=\"post-pre\"><code>$ pg_ctl start\r\nwaiting for server to start....2021-10-04 23:02:57.238 UTC [8178] LOG:  redirecting log output to logging collector process\r\n2021-10-04 23:02:57.238 UTC [8178] HINT:  Future log output will appear in directory \"log\".\r\n done\r\nserver started\r\n<\/code><\/pre>\n<p>\u203b \u53ea\u9700\u8981\u4e00\u4e2a\u9009\u9879\uff0c\u5728\u4e2d\u6587\u4e2d\u8fdb\u884c\u91cd\u65b0\u8868\u8fbe:<br \/>\n\u203b \u5373\u4f7f\u662f &#8220;systemctl start postgresql-14&#8221; \u4e5f\u6ca1\u95ee\u9898\u3002<\/p>\n<h1>\u67e5\u8be2\u6570\u636e\u5e93<\/h1>\n<p>\u8ba9\u6211\u4eec\u6765\u67e5\u770b\u521b\u5efa\u7684\u6570\u636e\u5e93\u96c6\u7fa4\u3002<br \/>\n\u6211\u4eec\u5c06\u663e\u793a\u7248\u672c\u548c\u6570\u636e\u5e93\u5217\u8868\u3002<\/p>\n<pre class=\"post-pre\"><code>$ psql -V\r\npsql (PostgreSQL) 14.0\r\n$ psql -l\r\n                             List of databases\r\n   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges   \r\n-----------+----------+----------+---------+-------+-----------------------\r\n postgres  | postgres | UTF8     | C       | C     | \r\n template0 | postgres | UTF8     | C       | C     | =c\/postgres          +\r\n           |          |          |         |       | postgres=CTc\/postgres\r\n template1 | postgres | UTF8     | C       | C     | =c\/postgres          +\r\n           |          |          |         |       | postgres=CTc\/postgres\r\n(3 rows)\r\n<\/code><\/pre>\n<h1>\u521b\u5efa\u7528\u6237\u548c\u6570\u636e\u5e93<\/h1>\n<p>\u521b\u5efa\u4e00\u4e2a\u7528\u6237\uff08&#8221;testuser&#8221;\uff09\u548c\u4e00\u4e2a\u6570\u636e\u5e93\uff08&#8221;testdb&#8221;\uff09\u3002<\/p>\n<pre class=\"post-pre\"><code>$ createuser --login --pwprompt testuser\r\nEnter password for new role: \r\nEnter it again:\r\n\r\n$ createdb --owner=testuser testdb\r\n<\/code><\/pre>\n<h1>\u5141\u8bb8\u6765\u81ea\u5916\u90e8\u7684\u8fde\u63a5<\/h1>\n<p>PostgreSQL\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u65e0\u6cd5\u8fdb\u884c\u8fdc\u7a0b\u8fde\u63a5\uff0c\u56e0\u6b64\u9700\u8981\u66f4\u6539\u8bbe\u7f6e\u3002<\/p>\n<pre class=\"post-pre\"><code># vi \/data\/postgresql.conf\r\n\u203b\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u300c\/var\/lib\/pgsql\/14\/data\/postgresql.conf\u300d\r\n\r\n\u5909\u66f4\u524d\uff09\r\n#listen_addresses = 'localhost'\r\n\u5909\u66f4\u5f8c\uff09\r\nlisten_addresses = '*'\r\n<\/code><\/pre>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u4fee\u6539pg_hba.conf\u6587\u4ef6\u3002<\/p>\n<pre class=\"post-pre\"><code># vi \/data\/pg_hba.conf\r\n\u203b\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u300c\/var\/lib\/pgsql\/14\/data\/pg_hba.conf\u300d\r\n\r\n# \"local\" is for Unix domain socket connections only\r\nlocal   testdb          testuser                                md5\r\n\u2192\u30ed\u30fc\u30ab\u30eb\u304b\u3089testdb\u3078testuser\u3067md5\u63a5\u7d9a\u3067\u304d\u308b\u3088\u3046\u306b1\u884c\u8ffd\u52a0\u3002\r\nlocal   all             all                                     peer\r\n# IPv4 local connections:\r\nhost    all             all             192.168.10.0\/24         md5\r\n\u2192192.168.10.0\/24\uff08\u4eca\u56de\u306e\u30b5\u30fc\u30d0\u306e\u74b0\u5883\uff09\u304b\u3089\u63a5\u7d9a\u3067\u304d\u308b\u3088\u3046\u306b1\u884c\u8ffd\u52a0\u3002\r\nhost    all             all             127.0.0.1\/32            ident\r\n<\/code><\/pre>\n<p>\u91cd\u65b0\u52a0\u8f7d\u8bbe\u7f6e\u3002<\/p>\n<pre class=\"post-pre\"><code>$ pg_ctl reload\r\n\u203b\u3000\u3082\u3057\u304f\u306fsystemctl reload postgresql-14\u3067\u3082\u3044\u3044\u306f\u305a\u3002\r\n<\/code><\/pre>\n<p>\u66f4\u6539postgres\u7528\u6237\u7684\u5bc6\u7801\uff08\u4e0d\u9700\u8981\u66f4\u6539\u4e5f\u53ef\u4ee5\uff09\u3002<\/p>\n<pre class=\"post-pre\"><code>$ psql\r\nalter role postgres with password 'postgres';\r\n<\/code><\/pre>\n<p>\u786e\u8ba4\u4e0e\u8fdc\u7a0b\u8fde\u63a5\u7684\u8fde\u63a5\uff08A5\uff1a\u5df2\u8fdb\u884c\u4e86\u4e0eSQL\u7684\u8fde\u63a5\u786e\u8ba4\uff0c\u4f46\u7701\u7565\u4e86\u8bf4\u660e\uff09\u3002<\/p>\n<p>\u8bf7\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\u4ee5\u786e\u8ba4\u672c\u5730\u8fde\u63a5\u3002<\/p>\n<pre class=\"post-pre\"><code>$ psql testdb testuser\r\n\r\nPassword for user testuser: \r\npsql (13.0)\r\nType \"help\" for help.\r\n\r\ntestdb=&gt; \r\n<\/code><\/pre>\n<h1>\u521b\u5efa\u684c\u5b50<\/h1>\n<p>\u6211\u5c06\u521b\u5efa\u4e00\u4e2a\u8868\uff0c\u5e76\u5c1d\u8bd5\u63d2\u5165\u6570\u636e\u3002<\/p>\n<pre class=\"post-pre\"><code>testdb=&gt; create table test (id int, value text);\r\nCREATE TABLE\r\ntestdb=&gt; insert into test (id, value) values (1, 'test text');\r\nINSERT 0 1\r\ntestdb=&gt; select * from test;\r\n id |   value   \r\n----+-----------\r\n  1 | test text\r\n(1 row)\r\n<\/code><\/pre>\n<p>\u4f7f\u7528\u300c\\d\u300d\u547d\u4ee4\u6765\u67e5\u770b\u8868\u7684\u5217\u8868\uff0c\u4f7f\u7528\u300c\\du\u300d\u547d\u4ee4\u6765\u67e5\u770b\u89d2\u8272\u7684\u5217\u8868\u3002<\/p>\n<pre class=\"post-pre\"><code>testdb=&gt; \\d\r\n        List of relations\r\n Schema | Name | Type  |  Owner   \r\n--------+------+-------+----------\r\n public | test | table | testuser\r\n(1 row)\r\n\r\ntestdb=&gt; \\du\r\n                                   List of roles\r\n Role name |                         Attributes                         | Member of \r\n-----------+------------------------------------------------------------+-----------\r\n postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}\r\n testuser  |                                                            | {}\r\n\r\n<\/code><\/pre>\n<h1>\u5176\u4ed6\u7684\u8bbe\u7f6e\u66f4\u6539<\/h1>\n<p>\u4ece\u6574\u4f53\u4e0a\u6765\u770b\uff0cPostgreSQL\u4f3c\u4e4e\u8bbe\u7f6e\u4e86\u8f83\u5c0f\u7684\u5404\u79cd\u53c2\u6570\u503c\u3002\u6211\u8bd5\u7740\u5c06\u5171\u4eab\u7f13\u51b2\u533a\u4ece128MB\u589e\u52a0\u5230512MB\uff08\u5927\u7ea6\u4e3a\u603b\u5185\u5b58\u768420%~40%\uff09\u3002\u867d\u7136\u8fd8\u6709\u5f88\u591a\u5176\u4ed6\u5e94\u8be5\u6539\u53d8\u7684\u53c2\u6570\uff0c\u5305\u62ec\u5171\u4eab\u7f13\u51b2\u533a\uff0c\u4f46\u7531\u4e8e\u8fd9\u4e9b\u53c2\u6570\u4e0e\u7cfb\u7edf\u6709\u5173\uff0c\u6240\u4ee5\u672c\u6b21\u4e0d\u8fdb\u884c\u66f4\u6539\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u66f4\u6539\u5171\u4eab\u7f13\u51b2\u533a\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre class=\"post-pre\"><code># vi \/data\/postgresql.conf\r\n\u203b\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u300c\/var\/lib\/pgsql\/14\/data\/postgresql.conf\u300d\r\n\r\n\u5909\u66f4\u524d\uff09\r\nshared_buffers = 128MB\r\n\u5909\u66f4\u5f8c\uff09\r\nshared_buffers = 512MB\r\n<\/code><\/pre>\n<p>\u63a5\u4e0b\u6765\u53ea\u9700\u8981\u91cd\u65b0\u542f\u52a8PostgreSQL\u5373\u53ef\u3002<\/p>\n<h1>\u65e5\u5fd7\u914d\u7f6e<\/h1>\n<p>\u6211\u5df2\u7ecf\u5c06\u65e5\u5fd7\u7684\u8bbe\u7f6e\u66f4\u6539\u4e3a\u4ee5\u4e0b\u5185\u5bb9\u3002<\/p>\n<pre class=\"post-pre\"><code>$ vi \/data\/postgresql.conf\r\n<\/code><\/pre>\n<p>\u4fee\u6539\u524d\u5982\u4e0b\u3002<\/p>\n<pre class=\"post-pre\"><code>log_filename = 'postgresql-%a.log'\r\nlog_rotation_size = 0\r\n#log_min_duration_statement = -1\r\n#log_checkpoints = off\r\n#log_connections = off\r\n#log_disconnections = off\r\n#log_lock_waits = off\r\n<\/code><\/pre>\n<p>\u53d8\u66f4\u540e\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre class=\"post-pre\"><code>log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'\r\nlog_rotation_size = 1GB\r\nlog_min_duration_statement = 500ms\r\nlog_checkpoints = on\r\nlog_connections = on\r\nlog_disconnections = on\r\nlog_lock_waits = on\r\nlog_temp_files = 0\r\n<\/code><\/pre>\n<h1>\u5728pgbench\u4e0a\u6267\u884c\u57fa\u51c6\u6d4b\u8bd5\u3002<\/h1>\n<p>\u5728PostgreSQL\u4e2d\uff0c\u6807\u51c6\u914d\u5907\u4e86\u7528\u4e8e\u57fa\u51c6\u6d4b\u8bd5\u7684\u5de5\u5177pgbench\u3002<br \/>\n\u9996\u5148\uff0c\u4f7f\u7528pgbench\u521b\u5efa\u57fa\u51c6\u6d4b\u8bd5\u6240\u9700\u7684\u8868\u548c\u6570\u636e\u3002<\/p>\n<pre class=\"post-pre\"><code>$ pgbench -i -s 10 testdb\r\ndropping old tables...\r\nNOTICE:  table \"pgbench_accounts\" does not exist, skipping\r\nNOTICE:  table \"pgbench_branches\" does not exist, skipping\r\nNOTICE:  table \"pgbench_history\" does not exist, skipping\r\nNOTICE:  table \"pgbench_tellers\" does not exist, skipping\r\ncreating tables...\r\ngenerating data (client-side)...\r\n1000000 of 1000000 tuples (100%) done (elapsed 0.95 s, remaining 0.00 s)\r\nvacuuming...\r\ncreating primary keys...\r\ndone in 1.68 s (drop tables 0.00 s, create tables 0.00 s, client-side generate 0.98 s, vacuum 0.22 s, primary keys 0.47 s).\r\n<\/code><\/pre>\n<p>\u5f53\u6570\u636e\u51c6\u5907\u597d\u540e\uff0c\u63a5\u4e0b\u6765\u8981\u8fdb\u884c\u57fa\u51c6\u6d4b\u8bd5\u3002<\/p>\n<pre class=\"post-pre\"><code>$ pgbench -c 10 -j 10 -t 2000 -N testdb\r\npgbench (14.0)\r\nstarting vacuum...end.\r\ntransaction type: &lt;builtin: simple update&gt;\r\nscaling factor: 10\r\nquery mode: simple\r\nnumber of clients: 10\r\nnumber of threads: 10\r\nnumber of transactions per client: 2000\r\nnumber of transactions actually processed: 20000\/20000\r\nlatency average = 1.778 ms\r\ninitial connection time = 10.700 ms\r\ntps = 5625.815743 (without initial connection time)\r\n<\/code><\/pre>\n<p>&#8220;-c 10&#8221; \u8868\u793a\u5ba2\u6237\u7aef\u6570\u91cf\u4e3a &#8220;10&#8221;\uff0c&#8221;-t 1000&#8243; \u8868\u793a\u6bcf\u4e2a\u5ba2\u6237\u7aef\u7684\u4ea4\u6613\u6570\u3002<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u6765\u67e5\u770b\u57fa\u51c6\u6d4b\u8bd5\u540e\u7684\u7f13\u5b58\u547d\u4e2d\u7387\u3002<\/p>\n<pre class=\"post-pre\"><code>select relname,\r\n   round(heap_blks_hit * 100 \/ (heap_blks_hit+heap_blks_read), 2)\r\n   as cache_hit_ratio from pg_statio_user_tables\r\n     where heap_blks_read &gt; 0 order by cache_hit_ratio;\r\n\r\n     relname      | cache_hit_ratio \r\n------------------+-----------------\r\n test             |           50.00\r\n pgbench_accounts |           66.00\r\n pgbench_branches |           82.00\r\n pgbench_tellers  |           95.00\r\n pgbench_history  |           99.00\r\n(5 rows)\r\n<\/code><\/pre>\n<p>\u7d22\u5f15\u7f13\u5b58\u547d\u4e2d\u7387\u5982\u4e0b\u3002<\/p>\n<pre class=\"post-pre\"><code>select relname, indexrelname,\r\n   round(idx_blks_hit * 100 \/ (idx_blks_hit + idx_blks_read), 2)\r\n   as cache_hit_ratio from pg_statio_user_indexes\r\n     where idx_blks_read &gt; 0 order by cache_hit_ratio;\r\n\r\n     relname      |     indexrelname      | cache_hit_ratio \r\n------------------+-----------------------+-----------------\r\n pgbench_tellers  | pgbench_tellers_pkey  |            0.00\r\n pgbench_branches | pgbench_branches_pkey |           50.00\r\n pgbench_accounts | pgbench_accounts_pkey |           98.00\r\n(3 rows)\r\n<\/code><\/pre>\n<h1>\u8bf7\u53c2\u8003<\/h1>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">PostgreSQL 14 Press Kit<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">PostgreSQL 14.0 Documentation<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">pgbench\u306e\u4f7f\u3044\u3053\u306a\u3057 by Let&#8217;s Postgres<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u73af\u5883 \u7531\u4e8e PostgreSQL 14.0 \u5728 2021\/9\/30 \u53d1\u5e03\uff0c\u56e0\u6b64\u6211\u6253\u7b97\u5c1d\u8bd5\u5b89\u88c5\u5b83\u3002 Postgr [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-41950","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5b89\u88c5PostgreSQL14\u5230AlmaLinux8 - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u5b89\u88c5postgresql14\u5230almalinux8\u3002\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5b89\u88c5PostgreSQL14\u5230AlmaLinux8\" \/>\n<meta property=\"og:description\" content=\"\u73af\u5883 \u7531\u4e8e PostgreSQL 14.0 \u5728 2021\/9\/30 \u53d1\u5e03\uff0c\u56e0\u6b64\u6211\u6253\u7b97\u5c1d\u8bd5\u5b89\u88c5\u5b83\u3002 Postgr [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u5b89\u88c5postgresql14\u5230almalinux8\u3002\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-29T01:09:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-29T08:07:03+00:00\" \/>\n<meta name=\"author\" content=\"\u79d1, \u96c5\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u79d1, \u96c5\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql14%e5%88%b0almalinux8%e3%80%82\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql14%e5%88%b0almalinux8%e3%80%82\/\",\"name\":\"\u5b89\u88c5PostgreSQL14\u5230AlmaLinux8 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-10-29T01:09:10+00:00\",\"dateModified\":\"2024-04-29T08:07:03+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql14%e5%88%b0almalinux8%e3%80%82\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql14%e5%88%b0almalinux8%e3%80%82\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql14%e5%88%b0almalinux8%e3%80%82\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5b89\u88c5PostgreSQL14\u5230AlmaLinux8\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a\",\"name\":\"\u79d1, \u96c5\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g\",\"caption\":\"\u79d1, \u96c5\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/keya\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql14%e5%88%b0almalinux8%e3%80%82\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u5b89\u88c5PostgreSQL14\u5230AlmaLinux8 - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u5b89\u88c5postgresql14\u5230almalinux8\u3002\/","og_locale":"zh_CN","og_type":"article","og_title":"\u5b89\u88c5PostgreSQL14\u5230AlmaLinux8","og_description":"\u73af\u5883 \u7531\u4e8e PostgreSQL 14.0 \u5728 2021\/9\/30 \u53d1\u5e03\uff0c\u56e0\u6b64\u6211\u6253\u7b97\u5c1d\u8bd5\u5b89\u88c5\u5b83\u3002 Postgr [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u5b89\u88c5postgresql14\u5230almalinux8\u3002\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-10-29T01:09:10+00:00","article_modified_time":"2024-04-29T08:07:03+00:00","author":"\u79d1, \u96c5","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u79d1, \u96c5","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql14%e5%88%b0almalinux8%e3%80%82\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql14%e5%88%b0almalinux8%e3%80%82\/","name":"\u5b89\u88c5PostgreSQL14\u5230AlmaLinux8 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-10-29T01:09:10+00:00","dateModified":"2024-04-29T08:07:03+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql14%e5%88%b0almalinux8%e3%80%82\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql14%e5%88%b0almalinux8%e3%80%82\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql14%e5%88%b0almalinux8%e3%80%82\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u5b89\u88c5PostgreSQL14\u5230AlmaLinux8"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a","name":"\u79d1, \u96c5","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g","caption":"\u79d1, \u96c5"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/keya\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql14%e5%88%b0almalinux8%e3%80%82\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/41950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=41950"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/41950\/revisions"}],"predecessor-version":[{"id":86276,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/41950\/revisions\/86276"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=41950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=41950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=41950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}