centos7搭建postgresql-14

环境:centos7  + pg 14

 

1:在postgresql官网下载页面,根据提示下载

https://www.postgresql.org/download/linux/redhat/

 

 

 

2 连接到centos7服务器进行安装

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

# Install PostgreSQL:
sudo yum install -y postgresql14-server

# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb

#设置开机启动 sudo systemctl enable postgresql
-14

#启动服务 sudo systemctl start postgresql-14

 

3:配置pg,让所有计算机能访问到该测试数据库

cd /var/lib/pgsql/14/data/

1:vim postgresql.conf

修改:
listen_addresses = 'localhost' 修改为:
listen_addresses = '*'

2:
vim pg_hba.conf
127.0.0.1/32 修改为 0.0.0.0/0

 

 

 

4:账号密码修改

安装pg后,centos会默认会创建一个名为postgres的linux登录用户,这里进行密码修改
(注意,这里修改的是linux登陆的账号密码,不是数据库的)

passwd postgres

 

 

重新启动pg服务器

systemctl restart postgresql-14

 

5:修改pg数据库密码

使用postgres 账号密码登录ssh。

 

 

#进入pg
 psql -U postgres

#修改密码
\password

 

 

 

 

6;链接一下

 

 

7:卸载

yum remove postgresql*

 

 

 

参考文档:

https://www.postgresql.org/download/linux/redhat/

https://www.cnblogs.com/xikui/p/12036360.html

https://www.jianshu.com/p/3f8d77d258d8

 

 

 

 
posted @ 2022-02-22 16:13  Foto_CShow  阅读(846)  评论(1编辑  收藏  举报