postgresql 11 + yum + centos 7.4

版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/ctypyb2002/article/details/84869547

os: centos 7.4.1708
db: postgresql 11.2

参考《centos 7.x 安装 postgresql 的优化设置》设置好centos 7.4

os 安装 postgresql 11 的 yum source

参考:
https://www.postgresql.org/download/linux/redhat/

# yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm

安装 postgresql 11

[root@tpg-1 ~]# yum install postgresql11*

Downloading packages:
(1/16): llvm5.0-5.0.1-7.el7.x86_64.rpm                                                     | 2.6 MB  00:00:06     
(2/16): postgresql11-contrib-11.1-1PGDG.rhel7.x86_64.rpm                                   | 614 kB  00:00:16     
(3/16): postgresql11-11.1-1PGDG.rhel7.x86_64.rpm                                           | 1.6 MB  00:00:23     
(4/16): postgresql11-devel-11.1-1PGDG.rhel7.x86_64.rpm                                     | 2.0 MB  00:00:07     
(5/16): llvm5.0-libs-5.0.1-7.el7.x86_64.rpm                                                |  13 MB  00:00:32     
(6/16): postgresql11-docs-11.1-1PGDG.rhel7.x86_64.rpm                                      |  15 MB  00:00:21     
(7/16): postgresql11-libs-11.1-1PGDG.rhel7.x86_64.rpm                                      | 359 kB  00:00:00     
(8/16): postgresql11-debuginfo-11.1-1PGDG.rhel7.x86_64.rpm                                 |  10 MB  00:00:56     
(9/16): postgresql11-llvmjit-11.1-1PGDG.rhel7.x86_64.rpm                                   | 9.0 MB  00:00:19     
(10/16): postgresql11-odbc-10.03.0000-1PGDG.rhel7.1.x86_64.rpm                             | 282 kB  00:00:01     
(11/16): postgresql11-plperl-11.1-1PGDG.rhel7.x86_64.rpm                                   |  61 kB  00:00:00     
(12/16): postgresql11-plpython-11.1-1PGDG.rhel7.x86_64.rpm                                 |  82 kB  00:00:00     
(13/16): postgresql11-pltcl-11.1-1PGDG.rhel7.x86_64.rpm                                    |  39 kB  00:00:00     
(14/16): postgresql11-tcl-2.4.0-2.rhel7.1.x86_64.rpm                                       | 309 kB  00:00:01     
(15/16): postgresql11-test-11.1-1PGDG.rhel7.x86_64.rpm                                     | 1.7 MB  00:00:08     
(16/16): postgresql11-server-11.1-1PGDG.rhel7.x86_64.rpm                                   | 4.7 MB  00:00:15     
------------------------------------------------------------------------------------------------------------------
Total                                                                             695 kB/s |  62 MB  00:01:30     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : postgresql11-libs-11.1-1PGDG.rhel7.x86_64                                                     1/16 
  Installing : postgresql11-11.1-1PGDG.rhel7.x86_64                                                          2/16 
  Installing : postgresql11-server-11.1-1PGDG.rhel7.x86_64                                                   3/16 
  Installing : llvm5.0-libs-5.0.1-7.el7.x86_64                                                               4/16 
  Installing : llvm5.0-5.0.1-7.el7.x86_64                                                                    5/16 
  Installing : postgresql11-devel-11.1-1PGDG.rhel7.x86_64                                                    6/16 
  Installing : postgresql11-test-11.1-1PGDG.rhel7.x86_64                                                     7/16 
  Installing : postgresql11-llvmjit-11.1-1PGDG.rhel7.x86_64                                                  8/16 
  Installing : postgresql11-pltcl-11.1-1PGDG.rhel7.x86_64                                                    9/16 
  Installing : postgresql11-plpython-11.1-1PGDG.rhel7.x86_64                                                10/16 
  Installing : postgresql11-plperl-11.1-1PGDG.rhel7.x86_64                                                  11/16 
  Installing : postgresql11-contrib-11.1-1PGDG.rhel7.x86_64                                                 12/16 
  Installing : postgresql11-tcl-2.4.0-2.rhel7.1.x86_64                                                      13/16 
  Installing : postgresql11-odbc-10.03.0000-1PGDG.rhel7.1.x86_64                                            14/16 
  Installing : postgresql11-docs-11.1-1PGDG.rhel7.x86_64                                                    15/16 
  Installing : postgresql11-debuginfo-11.1-1PGDG.rhel7.x86_64                                               16/16 
  Verifying  : postgresql11-debuginfo-11.1-1PGDG.rhel7.x86_64                                                1/16 
  Verifying  : llvm5.0-libs-5.0.1-7.el7.x86_64                                                               2/16 
  Verifying  : postgresql11-llvmjit-11.1-1PGDG.rhel7.x86_64                                                  3/16 
  Verifying  : postgresql11-contrib-11.1-1PGDG.rhel7.x86_64                                                  4/16 
  Verifying  : postgresql11-docs-11.1-1PGDG.rhel7.x86_64                                                     5/16 
  Verifying  : postgresql11-server-11.1-1PGDG.rhel7.x86_64                                                   6/16 
  Verifying  : postgresql11-pltcl-11.1-1PGDG.rhel7.x86_64                                                    7/16 
  Verifying  : postgresql11-11.1-1PGDG.rhel7.x86_64                                                          8/16 
  Verifying  : postgresql11-plpython-11.1-1PGDG.rhel7.x86_64                                                 9/16 
  Verifying  : postgresql11-test-11.1-1PGDG.rhel7.x86_64                                                    10/16 
  Verifying  : postgresql11-tcl-2.4.0-2.rhel7.1.x86_64                                                      11/16 
  Verifying  : postgresql11-libs-11.1-1PGDG.rhel7.x86_64                                                    12/16 
  Verifying  : postgresql11-plperl-11.1-1PGDG.rhel7.x86_64                                                  13/16 
  Verifying  : llvm5.0-5.0.1-7.el7.x86_64                                                                   14/16 
  Verifying  : postgresql11-odbc-10.03.0000-1PGDG.rhel7.1.x86_64                                            15/16 
  Verifying  : postgresql11-devel-11.1-1PGDG.rhel7.x86_64                                                   16/16 

Installed:
  postgresql11.x86_64 0:11.1-1PGDG.rhel7                 postgresql11-contrib.x86_64 0:11.1-1PGDG.rhel7           
  postgresql11-debuginfo.x86_64 0:11.1-1PGDG.rhel7       postgresql11-devel.x86_64 0:11.1-1PGDG.rhel7             
  postgresql11-docs.x86_64 0:11.1-1PGDG.rhel7            postgresql11-libs.x86_64 0:11.1-1PGDG.rhel7              
  postgresql11-llvmjit.x86_64 0:11.1-1PGDG.rhel7         postgresql11-odbc.x86_64 0:10.03.0000-1PGDG.rhel7.1      
  postgresql11-plperl.x86_64 0:11.1-1PGDG.rhel7          postgresql11-plpython.x86_64 0:11.1-1PGDG.rhel7          
  postgresql11-pltcl.x86_64 0:11.1-1PGDG.rhel7           postgresql11-server.x86_64 0:11.1-1PGDG.rhel7            
  postgresql11-tcl.x86_64 0:2.4.0-2.rhel7.1              postgresql11-test.x86_64 0:11.1-1PGDG.rhel7              

Dependency Installed:
  llvm5.0.x86_64 0:5.0.1-7.el7                          llvm5.0-libs.x86_64 0:5.0.1-7.el7                         

Complete!

postgresql-11.service

# find / -name "postgresql-11.service"
/usr/lib/systemd/system/postgresql-11.service

# systemctl disable postgresql-11

初始化数据库

# vi /usr/lib/systemd/system/postgresql-11.service
#Environment=PGDATA=/var/lib/pgsql/11/data/
Environment=PGDATA=/data/pgsql-11/data/

# su - postgres
$ pwd
/home/postgres
$ /usr/pgsql-11/bin/initdb -D /data/pgsql-11/data/ -U postgres -E UTF8 --locale=zh_CN.UTF-8    

注意这里只能使用 initdb 来初始化数据库集群,不能使用 postgresql-11-setup initdb 来初始化,原因是 postgresql-11-setup 依然有硬编码到 /var/lib/pgsql/11 下的文件。

同时 postgresql-11.service 已经设置了 Disable OOM kill on the postmaster

# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0

查看进程

# systemctl start postgresql-11.service 

# ps -ef|grep -i -E 'pgsql|postgres' |grep -v grep

postgres  6512     1  0 22:48 ?        00:00:00 /usr/pgsql-11/bin/postmaster -D /data/pgsql-11/data/
postgres  6519  6512  0 22:48 ?        00:00:00 postgres: logger   
postgres  6523  6512  0 22:48 ?        00:00:00 postgres: checkpointer   
postgres  6524  6512  0 22:48 ?        00:00:00 postgres: background writer   
postgres  6525  6512  0 22:48 ?        00:00:00 postgres: walwriter   
postgres  6526  6512  0 22:48 ?        00:00:00 postgres: autovacuum launcher   
postgres  6527  6512  0 22:48 ?        00:00:00 postgres: stats collector   
postgres  6528  6512  0 22:48 ?        00:00:00 postgres: logical replication launcher 

后台进程的名字较之前有了变化。

猜你喜欢

转载自blog.csdn.net/ctypyb2002/article/details/84869547