postgresql的yum安装跟配置方法

52次阅读
没有评论

共计 3741 个字符,预计需要花费 10 分钟才能阅读完成。

这篇文章主要介绍“postgresql 的 yum 安装跟配置方法”,在日常操作中,相信很多人在 postgresql 的 yum 安装跟配置方法问题上存在疑惑,丸趣 TV 小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”postgresql 的 yum 安装跟配置方法”的疑惑有所帮助!接下来,请跟着丸趣 TV 小编一起来学习吧!

总结
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 安装跟配置方法”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注丸趣 TV 网站,丸趣 TV 小编会继续努力为大家带来更多实用的文章!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-01发表,共计3741字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)