如果服务器可以连互联网,可以通过官方源安装 PostgreSQL 数据库,这样更加简单快速。
PostgreSQL 数据库官方网站:
https://www.postgresql.org
![图片[1]-Centos7.9 通过官方源安装 PostgreSQL 数据库-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2024/06/image-1024x770.png)
进入下载页面,可以根据服务器系统类型来选择官方包:
https://www.postgresql.org/download/
![图片[2]-Centos7.9 通过官方源安装 PostgreSQL 数据库-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2024/06/image-1-1024x770.png)
因为我们的系统是Centos7.9,所以选择红帽系的安装:
https://www.postgresql.org/download/linux/redhat/
![图片[3]-Centos7.9 通过官方源安装 PostgreSQL 数据库-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2024/06/image-2-1024x770.png)
可以选择版本和对应系统信息来生成安装脚本:
![图片[4]-Centos7.9 通过官方源安装 PostgreSQL 数据库-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2024/06/image-3-1024x350.png)
使用脚本中的安装方法安装:
# 下载官方源配置
[root@centos7 ~]# sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
![图片[5]-Centos7.9 通过官方源安装 PostgreSQL 数据库-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2024/06/image-5-1024x612.png)
# 安装Postgresql v15
[root@centos7 ~]# sudo yum install -y postgresql15-server
![图片[6]-Centos7.9 通过官方源安装 PostgreSQL 数据库-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2024/06/image-4-1024x730.png)
![图片[7]-Centos7.9 通过官方源安装 PostgreSQL 数据库-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2024/06/image-6-1024x730.png)
# 初始化数据库
[root@centos7 ~]# sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
# 设置开机自启
[root@centos7 ~]# sudo systemctl enable postgresql-15
# 启动数据库
[root@centos7 ~]# sudo systemctl start postgresql-15
# 查看数据库运行状态
[root@centos7 ~]# systemctl status postgresql-15.service
# 查看数据库端口5432
[root@centos7 ~]# ss -ntl
![图片[8]-Centos7.9 通过官方源安装 PostgreSQL 数据库-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2024/06/image-7-1024x527.png)
连接数据库:
# 必须切换到数据库用户
[root@centos7 ~]# su - postgres
# 进入数据库
-bash-4.2$ psql
# 查看登录的数据库用户
postgres=# \c
# 查看数据库版本
postgres=# select version();
# 查看数据库
postgres=# \l
![图片[9]-Centos7.9 通过官方源安装 PostgreSQL 数据库-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2024/06/image-8-1024x408.png)
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END