postgresql的yum安装及配置方法

centos7+pgsql11的安装方法

总结
1、确定好PGDATA环境变量后再initdb初始化数据库
2、systemctl启动后进程ps-ef|grep pg显示为/usr/pgsql-11/bin/postmaster -D /pgdata/data/
   但是使用/usr/pgsql-11/bin/pg_ctl status看到的还是/usr/pgsql-11/bin/postgres “-D” “/pgdata/data”
   /usr/pgsql-11/bin/pg_ctl start启动后进程ps-ef|grep pg显示为/usr/pgsql-11/bin/postgres -D /pgdata/data   
3、pg_ctl stop可以杀掉由systemctl启动的服务
   systemctl stop无法杀掉pg_ctl start启动的服务

步骤
1、
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

2、
vi /etc/sysctl.conf
vi /etc/security/limits.conf

3、
yum list|grep postgresql11

4、
yum -y install postgresql11
yum -y install postgresql11-server
yum -y install postgresql11-contrib.x86_64 –这个步骤主要是安装pg_recvlogical

5、
mkdir -p /pgdata/data/
chown -R postgres.postgres /pgdata

6、systemctl enable postgresql-11
vi /usr/lib/systemd/system/postgresql-11.service  
–Environment=PGDATA=/var/lib/pgsql/11/data/修改为Environment=PGDATA=/pgdata/data/
systemctl reload postgresql-11
查看环境变量PGDATA是否正常了
systemctl show -p Environment “postgresql-11.service” |sed ‘s/^Environment=//’ | tr ‘ ‘ ‘\n’ |sed -n ‘s/^PGDATA=//p’ |tail -n 1

7、/usr/pgsql-11/bin/postgresql-11-setup initdb

8、systemctl start postgresql-11

9、ps -ef|grep pg
postgres  6175     1  0 00:07 ?        00:00:00 /usr/pgsql-11/bin/postmaster -D /pgdata/data/

10、su – postgres
/usr/pgsql-11/bin/pg_ctl status
pg_ctl: directory “/var/lib/pgsql/11/data” is not a database cluster directory

11、vi .bash_profile
–修改PGDATA=/pgdata/data

12、source .bash_profile
/usr/pgsql-11/bin/pg_ctl status
pg_ctl: server is running (PID: 6175)
/usr/pgsql-11/bin/postgres “-D” “/pgdata/data/”

systemctl stop无法杀掉pg_ctl start启动的服务

[root@FRSPGSQLDEV2 ~]# su – postgres
-bash-4.2$ /usr/pgsql-11/bin/pg_ctl start -D /pgdata/data/
-bash-4.2$ /usr/pgsql-11/bin/pg_ctl status
pg_ctl: server is running (PID: 6659)
/usr/pgsql-11/bin/postgres “-D” “/pgdata/data”
-bash-4.2$ exit
logout
[root@FRSPGSQLDEV2 ~]# ps -ef|grep pg
postgres  6659     1  0 00:29 pts/1    00:00:00 /usr/pgsql-11/bin/postgres -D /pgdata/data
root      6670  6483  0 00:30 pts/1    00:00:00 grep –color=auto pg
[root@FRSPGSQLDEV2 ~]# systemctl stop postgresql-11
[root@FRSPGSQLDEV2 ~]# ps -ef|grep pg
postgres  6659     1  0 00:29 pts/1    00:00:00 /usr/pgsql-11/bin/postgres -D /pgdata/data
root      6678  6483  0 00:30 pts/1    00:00:00 grep –color=auto pg

pg_ctl stop可以杀掉由systemctl启动的服务

[root@FRSPGSQLDEV2 ~]# systemctl start postgresql-11
[root@FRSPGSQLDEV2 ~]# ps -ef|grep pg
postgres  6587     1  1 00:28 ?        00:00:00 /usr/pgsql-11/bin/postmaster -D   /pgdata/data/
[root@FRSPGSQLDEV2 ~]# su – postgres
Last login: Fri Oct 18 00:26:32 PDT 2019 on pts/1
-bash-4.2$ /usr/pgsql-11/bin/pg_ctl status
pg_ctl: server is running (PID: 6587)
/usr/pgsql-11/bin/postgres “-D” “/pgdata/data/”
-bash-4.2$ /usr/pgsql-11/bin/pg_ctl stop
waiting for server to shut down…. done
-bash-4.2$ exit
logout
[root@FRSPGSQLDEV2 ~]# ps -ef|grep pg

[root@FRSPGSQLDEV2 init.d]# /usr/pgsql-11/bin/postgresql-11-setup initdb
Initializing database … OK

[root@FRSPGSQLDEV2 init.d]# systemctl enable postgresql-11
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-11.service to /usr/lib/systemd/system/postgresql-11.service.

修改PGDATA后需要systemctl daemon-reload

[root@FRSPGSQLDEV2 init.d]#mkdir -p /pgdata/data/
[root@FRSPGSQLDEV2 init.d]#chown -R postgres.postgres /pgdata

[root@FRSPGSQLDEV2 init.d]# vi /usr/lib/systemd/system/postgresql-11.service
Environment=PGDATA的值把/var/lib/pgsql/11/data/修改为/pgdata/data

[root@FRSPGSQLDEV2 init.d]# systemctl start postgresql-11
Warning: postgresql-11.service changed on disk. Run ‘systemctl daemon-reload’ to reload units

[root@FRSPGSQLDEV2 init.d]# systemctl daemon-reload
[root@FRSPGSQLDEV2 init.d]# systemctl start postgresql-11

[root@FRSPGSQLDEV2 init.d]# ps -ef|grep pg
postgres 16192     1  0 19:00 ?        00:00:00 /usr/pgsql-11/bin/postmaster -D /pgdata/data/

    原文作者:lusklusklusk
    原文地址: http://blog.itpub.net/30126024/viewspace-2661671/
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞