centos7安装posgresql

  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
    
  2. 修改用户名密码

    //切换用户
    su postgres
    
    //切换SQL模式
    psql
    
    //修改密码
    alter user postgres with password 'postgres';
    
    // 退出
    \q
    
  3. 允许外部连接

    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
    
    
    
    
  4. 退出当前账号

    exit
    
  5. 重启 服务

    systemctl restart postgresql-14
    
    #开机自启动
    systemctl enable postgresql-14
    
  6. 远程连接
    image-20240206205009016

posted on 2024-02-06 23:18  zhangyukun  阅读(57)  评论(0编辑  收藏  举报

导航