这篇文章主要介绍“postgresql的yum安装跟配置方法”,在日常操作中,相信很多人在postgresql的yum安装跟配置方法问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”postgresql的yum安装跟配置方法”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
总结
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/
到此,关于“postgresql的yum安装跟配置方法”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。