Avatar

Organizations

1 results for Postgresql
  • 安装

    $ yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
    
    # 安装服务端包
    $ yum install postgresql10-server postgresql10
    

    配置

    # 初始化数据库,设置自启动
    $ /usr/pgsql-10/bin/postgresql-10-setup initdb
    $ systemctl enable postgresql-10
    $ systemctl start postgresql-10
    
    # 设置防火墙规则
    $ iptables -A INPUT -p tcp -m tcp --dport 5432 -j ACCEPT              #开放Postgresql 5432端口
    
    $ service iptables save   # 保存防火墙规则
    

    配置远程访问

    # 切换至用户
    $ su - postgres
    
    ; ./10/data/postgres.conf
    - #listen_address
    + listen_address
    
    ; ./10/data/pg_hba.conf
    ; 允许所有IPv4地址
    + host all all 0.0.0.0/0 scram-sha-256
    

    登录数据库

    $ psql -U postgres
    
    -- 设置数据运行参数
    ALTER SYSTEM SET listen_addresses = '*';
    ALTER SYSTEM SET port = 5432;
    ALTER SYSTEM SET password_encryption = 'scram-sha-256';
    
    --  修改默认用户密码
    ALTER USER postgres with encrypted password '你的密码';
    
    -- 退出数据库
    \q
    
    -- 退出用户
    exit    
    

    重启服务

    systemctl restart postgresql-10
    
    postgresql centos Created Fri, 19 Jan 2024 13:37:15 +0800