Centos7.9 通过官方源安装 PostgreSQL 数据库

如果服务器可以连互联网,可以通过官方源安装 PostgreSQL 数据库,这样更加简单快速。

PostgreSQL 数据库官方网站:

https://www.postgresql.org
图片[1]-Centos7.9 通过官方源安装 PostgreSQL 数据库-李佳程的个人主页

进入下载页面,可以根据服务器系统类型来选择官方包:

https://www.postgresql.org/download/
图片[2]-Centos7.9 通过官方源安装 PostgreSQL 数据库-李佳程的个人主页

因为我们的系统是Centos7.9,所以选择红帽系的安装:

https://www.postgresql.org/download/linux/redhat/
图片[3]-Centos7.9 通过官方源安装 PostgreSQL 数据库-李佳程的个人主页

可以选择版本和对应系统信息来生成安装脚本:

图片[4]-Centos7.9 通过官方源安装 PostgreSQL 数据库-李佳程的个人主页

使用脚本中的安装方法安装:

# 下载官方源配置
[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 数据库-李佳程的个人主页
# 安装Postgresql v15
[root@centos7 ~]# sudo yum install -y postgresql15-server
图片[6]-Centos7.9 通过官方源安装 PostgreSQL 数据库-李佳程的个人主页
图片[7]-Centos7.9 通过官方源安装 PostgreSQL 数据库-李佳程的个人主页
# 初始化数据库
[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 数据库-李佳程的个人主页

连接数据库:

# 必须切换到数据库用户
[root@centos7 ~]# su - postgres 

# 进入数据库
-bash-4.2$ psql 

# 查看登录的数据库用户
postgres=# \c

# 查看数据库版本
postgres=# select version();

# 查看数据库
postgres=# \l
图片[9]-Centos7.9 通过官方源安装 PostgreSQL 数据库-李佳程的个人主页

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享