目录
一、安装并启动postgres
二、设置允许远程连接
三、重置密码
四、开放防火墙端口
五、重启服务后进入命令行模式
六、远程连接
一、安装并启动postgres
# Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-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 /bin/postgresql-14-setup initdb
sudo systemctl enable postgresql-14
sudo systemctl start postgresql-14
重启服务
sudo systemctl restart postgresql-14
报错:
sudo yum install -y postgresql14-server
报 无可用的软件包
//安装epel源
sudo yum install epel-release
//更新
yum update之后再执行 sudo yum install -y postxxxx,就可以了
查看数据库启动后的状态
systemctl status postgresql-14.service有个绿色的active,即可
二、设置允许远程连接
1)修改postgresql.conf文件
sudo vim /var/lib/pgsql/14/data/postgresql.conf修改listen_addresses="*" , 原来是被注释的,取消注释

2)修改pg_hab.conf
sudo vim /var/lib/pgsql/14/data/pg_hba.conf找到IPv4,增加一行
host    all             all             0.0.0.0/0            md5三、重置密码
进入数据库
sudo -u postgres psql\password postgres
或者
ALTER USER postgres WITH PASSWORD 'postgres';四、开放防火墙端口
[root@localhost conf]# firewall-cmd --zone=public --permanent --add-port=5432/tcp
success
[root@localhost conf]# firewall-cmd --reload五、重启服务后进入命令行模式
psql -U postgres -h 127.0.0.1 --port 5432sudo -u postgres psql 已经不能用了
六、远程连接
使用pgAdmin
连接即可






![while (r > b[i].r) del(a[r--]); while (r < b[i].r)](https://img-home.csdnimg.cn/images/20230724024159.png?origin_url=https%3A%2F%2Fflowus.cn%2Fpreview%2F8bfd4119-efea-4086-a4b7-a79c71729416&pos_id=img-XBONbYxR-1725195479633)











