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

# 安装 PostgreSQL centos7 上安装更高版本缺依赖,比较麻烦
sudo yum install -y postgresql14-server

# 初始化数据库
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
sudo systemctl enable postgresql-14
sudo systemctl start postgresql-14
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  1. 修改用户名密码
//切换用户
su postgres

//切换SQL模式
psql

//修改密码
alter user postgres with password 'postgres';

// 退出
\q
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  1. 允许外部连接
cd /var/lib/pgsql/14/data/

# vi postgresql.conf ,找到listen_addresses改成*
listen_addresses = '*'


#vi pg_hba.conf,最后一行添加,允许任意主机连接
host    all             all             0.0.0.0/0               scram-sha-256
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  1. 退出当前账号
exit
  • 1.
  1. 重启 服务
systemctl restart postgresql-14

#开机自启动
systemctl enable postgresql-14
  • 1.
  • 2.
  • 3.
  • 4.
  1. 远程连接
  2. centos7安装posgresql_sql