023.PGSQL-linux下的安装教程
参考博客 https://www.cnblogs.com/ningy1009/p/14467751.html
官网下载地址
https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
1.下载仓库源
[root@s101 /root]#sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
pgdg-redhat-repo-latest.noarch.rpm | 7.4 kB 00:00:00
Examining /var/tmp/yum-root-Xd3oez/pgdg-redhat-repo-latest.noarch.rpm: pgdg-redhat-repo-42.0-17.1.noarch
Marking /var/tmp/yum-root-Xd3oez/pgdg-redhat-repo-latest.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package pgdg-redhat-repo.noarch 0:42.0-17.1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================
Installing:
pgdg-redhat-repo noarch 42.0-17.1 /pgdg-redhat-repo-latest.noarch 11 k
Transaction Summary
=====================================================================================================================================
Install 1 Package
Total size: 11 k
Installed size: 11 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : pgdg-redhat-repo-42.0-17.1.noarch 1/1
Verifying : pgdg-redhat-repo-42.0-17.1.noarch 1/1
Installed:
pgdg-redhat-repo.noarch 0:42.0-17.1
Complete!
[root@s101 /root]#
2.安装数据库postgresql13 和 扩展包
[root@s101 /root]#sudo yum install -y postgresql13-server postgresql13-contrib postgresql13-devel
3.查看安装包和安装地址
[root@s101 /root]#rpm -qa grep postgres
[root@s101 /root]#rpm -qal | grep postgres
4.数据库初始化 ,初始化位置: /var/lib/pgsql/13/data
初始化前
初始化后
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb

数据库应用程序所在文件
5.设置开机自启动
sudo systemctl enable postgresql-13

6.启动服务
sudo systemctl start postgresql-13
#重新启动
sudo systemctl restart postgresql-13
#停止服务
sudo systemctl stop postgresql-13
#查看服务状态
sudo systemctl status postgresql-13
7.查看服务状态
8.如果防火墙有开启,开启防火墙的5432端口
查看防火墙的状态
firewall-cmd --state
firewall-cmd --permanent --add-port=5432/tcp
查看现有规则
iptables -nL
9.修改配置文件,添加允许远程连接IP
cd /var/lib/pgsql/13/data
1)postgresql.conf
添加
listen_addresses = '*'
2)pg_hba.conf
host all all 0.0.0.0/0 trust
10.重启服务
[root@s101 /var/lib/pgsql/13/data]#sudo systemctl restart postgresql-13
11. 修改数据库密码
su - postgres #注意这里postgers 前后都有空格
# 以postgres 用户进入系统
#登录数据库命令:
psql -U postgres #会进入postgres用户的控制台
#\l 查看有哪些数据库
#\c postgresql 选择postgresql 这个数据库,会提示进入连接
#然后就可以用select 等语句查询了
#修改数据库密码
ALTER USER postgres WITH PASSWORD '123456' ;
#退出数据库
\q
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下