亲测可用——PostgresSQL安装教程
首先官网先选择对应的操作系统 https://www.postgresql.org/download/然后选择对应的pg库版本,现在最新版为14,为了稳定起见我们选择了12sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noa
🎈个人公众号:🎈 :✨✨ 可为编程 ✨✨ 🍟🍟
🔑个人信条:🔑 知足知不足 有为有不为 为与不为皆为可为🌵
🍉本篇简介:🍉 本片详细说明了PostgresSQL安装教程操作规则和注意要点,并给出具体操作实例,如有出入还望指正。关注公众号【可为编程】回复【面试】领取2023年最新面试题!!!
PostgresSQL安装教程
一、下载安装
首先官网先选择对应的操作系统 https://www.postgresql.org/download/
然后选择对应的pg库版本,现在最新版为14,为了稳定起见我们选择了12
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql12-server
这个命令可能要等待一小会,会出现很多的Another app is currently holding the yum lock; waiting for it to exit… 一定不要退出!!!!切记
出现下面这样就是安装成功了。postgresSql默认端口是5432。
二、启动运行
现在是没有启动的状态,我们分别执行:
# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
sudo systemctl enable postgresql-12
sudo systemctl start postgresql-12
执行sudo /usr/pgsql-12/bin/postgresql-12-setup initdb可能会遇到这个问题:
initdb: 错误: 无法访问目录 “/var/lib/pgsql/12/data”: 权限不够
cd /var/lib/
chown -R postgres:postgres pgsql
一定要按照上面的操作命令去执行,少一步都会报错。
三、设置密码和远程链接
设置密码:
sudo passwd postgres
查看postgres相关用户:
su postgres
postgres=# psql
postgres-# \l
在CentOS上,默认的PostgreSQL数据目录是/var/lib/pgsql/版本号/data
navicate远程的时候宝这个错误,链接不上,所以我们还要修改一下postgresql的配置文件:
could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host"localhost" (:1) and acceptingTCP/IP connections on port 5433 ?
设置允许其他IP访问:
修改该配置文件中的参数,必须重启
postgreSql
服务,若要允许其它IP地址访问 该主机数据库,则必须修改
postgresql.conf
中的参数listen_addresses
为*
重启:systemctl restart postgresql-12.service 或者 pg_ctl reload 或者 执行SELECT pg_reload_conf()
但是我们为了安全性一般都不会上面的设置,上面的配置只是校验了用户名,并没有校验密码,不输入密码也能链接数据库。一般远程链接都需要密码才行。下面配置是每次远程连接时首先校验密码:
vim pg_hba.conf
然后重启,远程连接:
systemctl restart postgresql-12.service
如果遇到远程连接时报了如下错误:
postgresql 口令: psql: 致命错误: 用户 认证失败
psql :致命错误:用户postgres Password 认证失败
不要慌,首先登录pg库,改成你像设置的密码就可以了:
sudo -u postgres psql
ALTER USER postgres WITH PASSWORD 'postgres';
四、卸载postgresSql
一、首先执行以下命令:
[root@localhost ~]# rpm -qa | grep postgresql
postgresql12-libs-12.9-1PGDG.rhel7.x86_64
postgresql-server-9.2.24-4.el7_8.x86_64
postgresql12-server-12.9-1PGDG.rhel7.x86_64
postgresql-9.2.24-4.el7_8.x86_64
postgresql12-12.9-1PGDG.rhel7.x86_64
postgresql-libs-9.2.24-4.el7_8.x86_64
yum remove postgresql12-libs-12.9-1PGDG.rhel7.x86_64
二、删除服务管理脚本
rm -f /etc/init.d/postgresql-10
欢迎感兴趣的小伙伴一起探讨学习知识,以上是个人的一些总结分享,如有错误的地方望各位留言指出,十分感谢。
觉得有用的话别忘点赞、收藏、关注,手留余香! 😗 😗 😗
这里是一个真诚的***青年技术交流QQ群:761374713***,不管你是大学生、社畜、想学习变成的其他人员,欢迎大家加入我们,一起成长,一起进步,真诚的欢迎你,不管是技术,还是人生,还是学习方法。有道无术,术亦可求,有术无道,止于术。
欢迎大家关注【可为编程】,成长,进步,编程,技术、掌握更多知识!
更多推荐
所有评论(0)