{"id":42032,"date":"2023-07-30T20:09:01","date_gmt":"2023-03-06T17:19:51","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8centos-7%e4%b8%8a%e5%ae%89%e8%a3%85postgresql-11%e3%80%82\/"},"modified":"2024-04-30T16:08:24","modified_gmt":"2024-04-30T08:08:24","slug":"%e5%9c%a8centos-7%e4%b8%8a%e5%ae%89%e8%a3%85postgresql-11%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8centos-7%e4%b8%8a%e5%ae%89%e8%a3%85postgresql-11%e3%80%82\/","title":{"rendered":"\u5728CentOS 7\u4e0a\u5b89\u88c5PostgreSQL 11"},"content":{"rendered":"<h1>\u73af\u5883<\/h1>\n<p>\u4ee5\u4e0b\u662f\u5b89\u88c5PostgreSQL 11\u7684CentOS 7\u5907\u5fd8\u5f55\u3002<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">CentOS 7.5(firewalld\u3068SELinux\u306f\u7121\u52b9\u5316\u3057\u3066\u3044\u307e\u3059)<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">Postgres 11.2<\/ul>\n<p>\u624b\u9806\u51e0\u4e4e\u76f8\u540c\uff0c\u4f46\u9002\u7528\u4e8ePostgreSQL12\u7684\u6b65\u9aa4\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<ul class=\"post-ul\">CentOS 7.5\u306bPostgreSQL12\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/ul>\n<h1>\u5b89\u88c5PostgreSQL\u7684yum\u5b58\u50a8\u5e93\u3002<\/h1>\n<p>\u5b89\u88c5\u9002\u7528\u4e8eCentOS\u7684PostgreSQL\u5b58\u50a8\u5e93\u5305\u3002<br \/>\n\u6bcf\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u7684\u5b58\u50a8\u5e93\u5305URL\u5217\u8868\u5df2\u5728\u4ee5\u4e0b\u7f51\u7ad9\u4e2d\u5217\u51fa\u3002<\/p>\n<pre class=\"post-pre\"><code># yum -y install https:\/\/download.postgresql.org\/pub\/repos\/yum\/reporpms\/EL-7-x86_64\/pgdg-redhat-repo-latest.noarch.rpm\r\n\uff5e\u7701\u7565\uff5e\r\nRunning transaction\r\n  Installing : pgdg-redhat-repo-42.0-4.noarch                                                                                      1\/1 \r\n  Verifying  : pgdg-redhat-repo-42.0-4.noarch                                                                                      1\/1 \r\n\r\nInstalled:\r\n  pgdg-redhat-repo.noarch 0:42.0-4                                                                                                     \r\n\r\nComplete!\r\n<\/code><\/pre>\n<h1>\u5b89\u88c5PostgreSQL<\/h1>\n<p>\u5b89\u88c5PostgreSQL\u3002<\/p>\n<pre class=\"post-pre\"><code># yum -y install postgresql11-server postgresql11-contrib\r\n\r\n\uff5e\u7701\u7565\uff5e\r\nRunning transaction\r\n  Installing : postgresql11-libs-11.5-1PGDG.rhel7.x86_64                                                                                             1\/6 \r\n  Installing : libicu-50.2-3.el7.x86_64                                                                                                              2\/6 \r\n  Installing : postgresql11-11.5-1PGDG.rhel7.x86_64                                                                                                  3\/6 \r\n  Installing : libxslt-1.1.28-5.el7.x86_64                                                                                                           4\/6 \r\n  Installing : postgresql11-contrib-11.5-1PGDG.rhel7.x86_64                                                                                          5\/6 \r\n  Installing : postgresql11-server-11.5-1PGDG.rhel7.x86_64                                                                                           6\/6 \r\n  Verifying  : postgresql11-server-11.5-1PGDG.rhel7.x86_64                                                                                           1\/6 \r\n  Verifying  : libicu-50.2-3.el7.x86_64                                                                                                              2\/6 \r\n  Verifying  : postgresql11-contrib-11.5-1PGDG.rhel7.x86_64                                                                                          3\/6 \r\n  Verifying  : postgresql11-libs-11.5-1PGDG.rhel7.x86_64                                                                                             4\/6 \r\n  Verifying  : libxslt-1.1.28-5.el7.x86_64                                                                                                           5\/6 \r\n  Verifying  : postgresql11-11.5-1PGDG.rhel7.x86_64                                                                                                  6\/6 \r\n\r\nInstalled:\r\n  postgresql11-contrib.x86_64 0:11.5-1PGDG.rhel7                              postgresql11-server.x86_64 0:11.5-1PGDG.rhel7                             \r\n\r\nDependency Installed:\r\n  libicu.x86_64 0:50.2-3.el7    libxslt.x86_64 0:1.1.28-5.el7    postgresql11.x86_64 0:11.5-1PGDG.rhel7    postgresql11-libs.x86_64 0:11.5-1PGDG.rhel7   \r\n\r\nComplete!\r\n<\/code><\/pre>\n<p>PostgreSQL\u5c06\u5b89\u88c5\u5728&#8221;\/usr\/pgsql-11\/&#8221;\u76ee\u5f55\u4e0b\u3002<\/p>\n<pre class=\"post-pre\"><code># ls -l \/usr\/pgsql-11\/\r\ntotal 12\r\ndrwxr-xr-x. 2 root root 4096 May  1 03:42 bin\r\ndrwxr-xr-x. 3 root root 4096 May  1 03:42 lib\r\ndrwxr-xr-x. 7 root root 4096 May  1 03:42 share\r\n<\/code><\/pre>\n<h1>\u81ea\u52a8\u542f\u52a8PostgreSQL<\/h1>\n<p>\u4e3a\u4e86\u81ea\u52a8\u542f\u52a8PostgreSQL\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u3002<\/p>\n<pre class=\"post-pre\"><code># systemctl enable postgresql-11.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\u4ee5root\u7528\u6237\u8eab\u4efd\u6267\u884c\u3002<br \/>\n\u6570\u636e\u5e93\u6587\u4ef6\u9ed8\u8ba4\u4f1a\u521b\u5efa\u5728\u201c\/var\/lib\/pgsql\/11\/data\/\u201d\uff0c\u4f46\u73b0\u5728\u5c06\u5176\u6539\u4e3a\u5728\u201c\/data\/\u201d\u76ee\u5f55\u4e0b\u3002<br \/>\n\u53ef\u4ee5\u901a\u8fc7postgresql-11.service\u6587\u4ef6\u4e2d\u7684\u201cPGDATA\u201d\u73af\u5883\u53d8\u91cf\u6307\u5b9a\u3002<\/p>\n<pre class=\"post-pre\"><code>$ vi \/usr\/lib\/systemd\/system\/postgresql-11.service\r\n\r\n\u5909\u66f4\u524d\uff09\r\nEnvironment=PGDATA=\/var\/lib\/pgsql\/11\/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\u7684\u547d\u4ee4\u5c06\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93\u96c6\u7fa4\u3002\uff08\u5c3d\u7ba1\u53ef\u4ee5\u4f7f\u7528initdb\u547d\u4ee4\u521b\u5efa\uff0c\u4f46\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528\u4e86postgresql-11-setup\uff09<\/p>\n<pre class=\"post-pre\"><code># PGSETUP_INITDB_OPTIONS=\"-E UTF8 --no-locale\" \/usr\/pgsql-11\/bin\/postgresql-11-setup initdb\r\nInitializing database ... OK\r\n<\/code><\/pre>\n<p>\u786e\u8ba4\u751f\u6210\u5728\u300c\/data\/\u300d\u4e0b\u9762\u3002<\/p>\n<pre class=\"post-pre\"><code># cat \/data\/PG_VERSION \r\n11\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-11\/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\/11\/data\r\nPGDATA=\/data\r\n\r\n# source ~\/.bash_profile\r\n<\/code><\/pre>\n<p>\u5728\u4e2d\u6587\u4e2d\uff0cPostgreSQL\u7684\u542f\u52a8\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u547d\u4ee4\u300cpg_ctl start\u300d\u6765\u5b9e\u73b0\u3002<\/p>\n<pre class=\"post-pre\"><code>$ pg_ctl start\r\nwaiting for server to start....2019-05-01 03:58:27.020 CEST [12912] LOG:  listening on IPv6 address \"::1\", port 5432\r\n2019-05-01 03:58:27.020 CEST [12912] LOG:  listening on IPv4 address \"127.0.0.1\", port 5432\r\n2019-05-01 03:58:27.022 CEST [12912] LOG:  listening on Unix socket \"\/var\/run\/postgresql\/.s.PGSQL.5432\"\r\n2019-05-01 03:58:27.025 CEST [12912] LOG:  listening on Unix socket \"\/tmp\/.s.PGSQL.5432\"\r\n2019-05-01 03:58:27.033 CEST [12912] LOG:  redirecting log output to logging collector process\r\n2019-05-01 03:58:27.033 CEST [12912] HINT:  Future log output will appear in directory \"log\".\r\n done\r\nserver started\r\n<\/code><\/pre>\n<p>\u203b &#8220;systemctl start postgresql-11&#8221; \u4e5f\u53ef\u4ee5<\/p>\n<h1>\u67e5\u8be2\u6570\u636e\u5e93<\/h1>\n<p>\u6211\u5c06\u67e5\u770b\u521b\u5efa\u7684\u6570\u636e\u5e93\u96c6\u7fa4\u3002<br \/>\n\u6211\u5c06\u5c1d\u8bd5\u663e\u793a\u7248\u672c\u548c\u6570\u636e\u5e93\u5217\u8868\u3002<\/p>\n<pre class=\"post-pre\"><code>-bash-4.2$ psql -V\r\npsql (PostgreSQL) 11.2\r\n-bash-4.2$ 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<\/code><\/pre>\n<h1>\u521b\u5efa\u7528\u6237\u548c\u6570\u636e\u5e93<\/h1>\n<p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201ctestuser\u201d\u7684\u7528\u6237\u548c\u4e00\u4e2a\u540d\u4e3a\u201ctestdb\u201d\u7684\u6570\u636e\u5e93\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>\u7531\u4e8e\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cPostgreSQL\u65e0\u6cd5\u8fdb\u884c\u8fdc\u7a0b\u8fde\u63a5\uff0c\u6240\u4ee5\u9700\u8981\u8fdb\u884c\u8bbe\u7f6e\u66f4\u6539\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\/11\/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\u8981\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\/11\/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\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\u66f4\u6539\u3002<\/p>\n<pre class=\"post-pre\"><code>$ pg_ctl reload\r\n\u203b\u3000\u3082\u3057\u304f\u306fsystemctl reload postgresql-11\u3067\u3082\u3044\u3044\u306f\u305a\u3002\r\n<\/code><\/pre>\n<p>\u66f4\u6539postgres\u7528\u6237\u7684\u5bc6\u7801\uff08\u53ef\u4ee5\u9009\u62e9\u4e0d\u66f4\u6539\uff09\u3002<\/p>\n<pre class=\"post-pre\"><code>$ psql\r\npsql (11.5)\r\nType \"help\" for help.\r\n\r\npostgres=# alter role postgres with password 'postgres';\r\n<\/code><\/pre>\n<p>\u6211\u5c06\u786e\u8ba4\u4ece\u8fdc\u7a0b\u8fde\u63a5\uff08A5: \u5df2\u786e\u8ba4\u4eceSQL\u8fde\u63a5\uff0c\u4f46\u7701\u7565\u4e86\u8bf4\u660e\uff09\u3002<\/p>\n<p>\u53ef\u4ee5\u6309\u4ee5\u4e0b\u65b9\u5f0f\u6267\u884c\u4ece\u672c\u5730\u8fdb\u884c\u7684\u8fde\u63a5\u786e\u8ba4\u3002<\/p>\n<pre class=\"post-pre\"><code>$ psql testdb testuser\r\nPassword for user testuser: \r\npsql (11.2)\r\nType \"help\" for help.\r\n\r\ntestdb=&gt; \r\n<\/code><\/pre>\n<h1>\u521b\u5efa\u8868<\/h1>\n<p>\u6211\u5c06\u521b\u5efa\u4e00\u4e2a\u8868\u683c\u5e76\u8f93\u5165\u4e00\u4e9b\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\u67e5\u770b\u8868\u683c\u5217\u8868\uff0c\u4f7f\u7528\u300c\\du\u300d\u67e5\u770b\u89d2\u8272\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<\/code><\/pre>\n<h1>\u5176\u4ed6\u8bbe\u7f6e\u66f4\u6539<\/h1>\n<p>PostgreSQL\u4f3c\u4e4e\u6574\u4f53\u4e0a\u8bbe\u7f6e\u4e86\u8f83\u5c0f\u7684\u5404\u79cd\u53c2\u6570\u503c\u3002<br \/>\n\u6211\u53ea\u6539\u53d8\u4e86\u5171\u4eab\u7f13\u51b2\u533a\uff0c\u4ece128MB\u589e\u52a0\u5230512MB\uff08\u636e\u8bf4\u6700\u597d\u662f\u603b\u5185\u5b58\u768420%\u81f340%\uff09\u3002\u867d\u7136\u8fd8\u6709\u8bb8\u591a\u5176\u4ed6\u53c2\u6570\u4e5f\u5e94\u8be5\u6539\u53d8\uff0c\u4f46\u7531\u4e8e\u5171\u4eab\u7f13\u51b2\u533a\u548c\u5176\u4ed6\u53c2\u6570\u90fd\u4f9d\u8d56\u4e8e\u7cfb\u7edf\uff0c\u6240\u4ee5\u8fd9\u6b21\u4e0d\u505a\u66f4\u6539\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u66f4\u6539\u5171\u4eab\u7f13\u51b2\u533a\u7684\u65b9\u6cd5\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\/11\/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>\u53ea\u9700\u8981\u91cd\u65b0\u542f\u52a8PostgreSQL\u5373\u53ef\u3002<\/p>\n<h1>\u65e5\u5fd7\u7684\u8bbe\u7f6e<\/h1>\n<p>\u6211\u5df2\u5c06\u65e5\u5fd7\u8bbe\u7f6e\u66f4\u6539\u5982\u4e0b\u3002<\/p>\n<pre class=\"post-pre\"><code>$ vi \/data\/postgresql.conf\r\n<\/code><\/pre>\n<p>\u4ee5\u4e0b\u662f\u53d8\u66f4\u524d\u7684\u5185\u5bb9\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>\u66f4\u6539\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>\u4f7f\u7528pgbench\u8fdb\u884c\u57fa\u51c6\u6d4b\u8bd5\u3002<\/h1>\n<p>\u5728PostgreSQL\u4e2d\uff0c\u6807\u914d\u4e86\u7528\u4e8e\u57fa\u51c6\u6d4b\u8bd5\u7684pgbench\u5de5\u5177\u3002<br \/>\n\u9996\u5148\uff0c\u4f7f\u7528pgbench\u521b\u5efa\u7528\u4e8e\u57fa\u51c6\u6d4b\u8bd5\u7684\u8868\u548c\u6570\u636e\u3002<\/p>\n<pre class=\"post-pre\"><code>$ pgbench -i 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...\r\n100000 of 100000 tuples (100%) done (elapsed 0.12 s, remaining 0.00 s)\r\nvacuuming...\r\ncreating primary keys...\r\ndone.\r\n<\/code><\/pre>\n<p>\u5f53\u6570\u636e\u51c6\u5907\u597d\u540e\uff0c\u63a5\u4e0b\u6765\u4f1a\u6267\u884c\u57fa\u51c6\u6d4b\u8bd5\u3002<\/p>\n<pre class=\"post-pre\"><code>$ pgbench -c 10 -t 1000 testdb\r\nstarting vacuum...end.\r\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\r\nscaling factor: 1\r\nquery mode: simple\r\nnumber of clients: 10\r\nnumber of threads: 1\r\nnumber of transactions per client: 1000\r\nnumber of transactions actually processed: 10000\/10000\r\nlatency average = 7.902 ms\r\ntps = 1265.495967 (including connections establishing)\r\ntps = 1265.842732 (excluding connections establishing)\r\n<\/code><\/pre>\n<p>&#8220;-c 10&#8243;\u8868\u793a\u5ba2\u6237\u7aef\u6570\u4e3a&#8221;10&#8243;\uff0c&#8221;-t 1000&#8243;\u8868\u793a\u6bcf\u4e2a\u5ba2\u6237\u7aef\u7684\u4ea4\u6613\u6570\u3002<\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u5728\u8fd0\u884c\u57fa\u51c6\u6d4b\u8bd5\u540e\u7684\u7f13\u5b58\u547d\u4e2d\u7387\u5982\u4e0b\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             |           60.00\r\n pgbench_accounts |           98.00\r\n pgbench_history  |           99.00\r\n pgbench_tellers  |           99.00\r\n pgbench_branches |           99.00\r\n<\/code><\/pre>\n<p>\u7d22\u5f15\u7684\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  |           96.00\r\n pgbench_branches | pgbench_branches_pkey |           99.00\r\n pgbench_accounts | pgbench_accounts_pkey |           99.00\r\n\r\n<\/code><\/pre>\n<h1>\u8bf7\u63d0\u4f9b\u66f4\u5177\u4f53\u7684\u4fe1\u606f\u3002<\/h1>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">PostgreSQL 11 \u3092 CentOS 7 \u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u306b\u306f<\/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 11.2 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 \u4ee5\u4e0b\u662f\u5b89\u88c5PostgreSQL 11\u7684CentOS 7\u5907\u5fd8\u5f55\u3002 CentOS 7.5(firewalld [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-42032","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>\u5728CentOS 7\u4e0a\u5b89\u88c5PostgreSQL 11 - 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\/\u5728centos-7\u4e0a\u5b89\u88c5postgresql-11\u3002\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5728CentOS 7\u4e0a\u5b89\u88c5PostgreSQL 11\" \/>\n<meta property=\"og:description\" content=\"\u73af\u5883 \u4ee5\u4e0b\u662f\u5b89\u88c5PostgreSQL 11\u7684CentOS 7\u5907\u5fd8\u5f55\u3002 CentOS 7.5(firewalld [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u5728centos-7\u4e0a\u5b89\u88c5postgresql-11\u3002\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-06T17:19:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-30T08:08:24+00:00\" \/>\n<meta name=\"author\" content=\"\u96c5, \u609f\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u96c5, \u609f\" \/>\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%9c%a8centos-7%e4%b8%8a%e5%ae%89%e8%a3%85postgresql-11%e3%80%82\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8centos-7%e4%b8%8a%e5%ae%89%e8%a3%85postgresql-11%e3%80%82\/\",\"name\":\"\u5728CentOS 7\u4e0a\u5b89\u88c5PostgreSQL 11 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-03-06T17:19:51+00:00\",\"dateModified\":\"2024-04-30T08:08:24+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8centos-7%e4%b8%8a%e5%ae%89%e8%a3%85postgresql-11%e3%80%82\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8centos-7%e4%b8%8a%e5%ae%89%e8%a3%85postgresql-11%e3%80%82\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8centos-7%e4%b8%8a%e5%ae%89%e8%a3%85postgresql-11%e3%80%82\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5728CentOS 7\u4e0a\u5b89\u88c5PostgreSQL 11\"}]},{\"@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\/f044a4b7fa4ee2701702942002419ca6\",\"name\":\"\u96c5, \u609f\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g\",\"caption\":\"\u96c5, \u609f\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/yawu\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8centos-7%e4%b8%8a%e5%ae%89%e8%a3%85postgresql-11%e3%80%82\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u5728CentOS 7\u4e0a\u5b89\u88c5PostgreSQL 11 - 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\/\u5728centos-7\u4e0a\u5b89\u88c5postgresql-11\u3002\/","og_locale":"zh_CN","og_type":"article","og_title":"\u5728CentOS 7\u4e0a\u5b89\u88c5PostgreSQL 11","og_description":"\u73af\u5883 \u4ee5\u4e0b\u662f\u5b89\u88c5PostgreSQL 11\u7684CentOS 7\u5907\u5fd8\u5f55\u3002 CentOS 7.5(firewalld [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u5728centos-7\u4e0a\u5b89\u88c5postgresql-11\u3002\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-03-06T17:19:51+00:00","article_modified_time":"2024-04-30T08:08:24+00:00","author":"\u96c5, \u609f","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u96c5, \u609f","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8centos-7%e4%b8%8a%e5%ae%89%e8%a3%85postgresql-11%e3%80%82\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8centos-7%e4%b8%8a%e5%ae%89%e8%a3%85postgresql-11%e3%80%82\/","name":"\u5728CentOS 7\u4e0a\u5b89\u88c5PostgreSQL 11 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-03-06T17:19:51+00:00","dateModified":"2024-04-30T08:08:24+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8centos-7%e4%b8%8a%e5%ae%89%e8%a3%85postgresql-11%e3%80%82\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8centos-7%e4%b8%8a%e5%ae%89%e8%a3%85postgresql-11%e3%80%82\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8centos-7%e4%b8%8a%e5%ae%89%e8%a3%85postgresql-11%e3%80%82\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u5728CentOS 7\u4e0a\u5b89\u88c5PostgreSQL 11"}]},{"@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\/f044a4b7fa4ee2701702942002419ca6","name":"\u96c5, \u609f","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g","caption":"\u96c5, \u609f"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/yawu\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8centos-7%e4%b8%8a%e5%ae%89%e8%a3%85postgresql-11%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\/42032","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\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=42032"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/42032\/revisions"}],"predecessor-version":[{"id":92913,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/42032\/revisions\/92913"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=42032"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=42032"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=42032"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}