安装

  1. sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
  2. sudo yum install -y postgresql14-server
  3. sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
  4. sudo systemctl enable postgresql-14
  5. sudo systemctl start postgresql-14

尝试

切换到数据库用户

  1. su - postgres

登录数据库

  1. psql

查看系统表

  1. select * from pg_roles;

修改监听地址

  1. vim /var/lib/pgsql/14/data/postgresql.conf
  2. # 修改内容,改成非注释
  3. listen_addresses = '*'
  4. port = 5432

修改连接认证方式

  1. vim /var/lib/pgsql/14/data/pg_hba.conf
  2. # 修改内容,改成非注释
  3. # TYPE DATABASE USER ADDRESS METHOD
  4. # "local" is for Unix domain socket connections only
  5. local all all trust
  6. # IPv4 local connections:
  7. host all all 0.0.0.0/0 trust
  8. # IPv6 local connections:
  9. host all all ::1/128 trust
  10. # Allow replication connections from localhost, by a user with the
  11. # replication privilege.
  12. local replication all trust
  13. host replication all 0.0.0.0/0 trust
  14. host replication all ::1/128 trust

METHOD 全部改成 trust,不安全的方式,非自己的机器请不要这样设置

开放防火墙

  1. firewall-cmd --zone=public --add-port=5432/tcp --permanent
  2. firewall-cmd --reload

更详细
https://www.jianshu.com/p/f246dc45e6dc