CentOS 7.9 安装 PostgrepSQL 15(.rpm版本)

发布时间 2023-08-02 00:49:50作者: DeepInThought

环境准备

  • CentOS 7.9 服务器
  • postgresql-15.rpm

数据库安装

https://www.postgresql.org/download/linux/#generic
image
1、版本选择
image
2、下载安装包

sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

image

3、安装数据库

sudo yum install -y postgresql15-server

image

4、初始化数据库

sudo /usr/pgsql-15/bin/postgresql-15-setup initdb

image

5、启动数据库 && 设置开机自启

sudo systemctl enable postgresql-15
sudo systemctl start postgresql-15

image

注意: 安装完L数据库以后,系统默认会创建一个postgres的Linux登录用户名。

数据库配置

1、设置允许远程连接

vi  /var/lib/pgsql/15/data/postgresql.conf
## 默认:listen_addresses = 'localhost' ,仅允许本机连接
listen_addresses = '*'
vi  /var/lib/pgsql/15/data/pg_hba.conf
## 默认:host    all             all             127.0.0.1/32            scram-sha-256
host    all             all              0.0.0.0/0            scram-sha-256

image
2、重启数据库

systemctl restart postgresql-15

3、修改数据库默认用户postgre密码

## 使用linux用户postgre登录
su - postgres
psql -U postgres
\password
# postgres_Q

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

\q

image