9.1centos安装postgres

目录

一、安装并启动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 5432

sudo -u postgres psql 已经不能用了

六、远程连接

使用pgAdmin

连接即可

  • 7
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值