• cento7 安装 postgresql12


    官方的centos7 安装说明

    https://www.postgresql.org/download/linux/redhat/

    推荐上官网看看安装方法

    安装脚本

    # Install the repository RPM:
    yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
    
    # Install PostgreSQL:
    yum install -y postgresql12-server
    
    # Optionally initialize the database and enable automatic start:
    /usr/pgsql-12/bin/postgresql-12-setup initdb
    systemctl enable postgresql-12
    systemctl start postgresql-12

    修改用户密码

        su - postgres  切换用户,执行后提示符会变为 '-bash-4.2$'
        psql -U postgres 登录数据库,执行后提示符变为 'postgres=#'
        ALTER USER postgres WITH PASSWORD 'postgres'  设置postgres用户密码为postgres
        q  退出数据库
    


    1. 创建数据库新用户,如 dbuser:
    
    postgres=# CREATE USER dbuser WITH PASSWORD '*****';
    2. 创建用户数据库,如exampledb:
    
    postgres=# CREATE DATABASE exampledb OWNER dbuser;
    3. 将exampledb数据库的所有权限都赋予dbuser:
    
    postgres=# GRANT ALL PRIVILEGES ON DATABASE exampledb TO dbuser;
    4. 使用命令 q 退出psql:
    
    postgres=# q
    5. 创建Linux普通用户,与刚才新建的数据库用户同名,如 dbuser:
    
    $ sudo adduser dbuser
    $ sudo passwd dbuser
    7、以dbuser的身份连接数据库exampledb:
    
    su - dbuser
    Password: ******
    [dbuser@localhost~]$ psql -d exampledb
    View Code

    开启远程访问

         vim /var/lib/pgsql/12/data/postgresql.conf
        修改#listen_addresses = 'localhost'  为  listen_addresses='*'
        当然,此处‘*’也可以改为任何你想开放的服务器IP
    

    信任远程连接

        vim /var/lib/pgsql/12/data/pg_hba.conf
        修改如下内容,信任指定服务器连接
        # IPv4 local connections:
        host    all            all      127.0.0.1/32      trust
        host    all            all      192.168.157.1/32(需要连接的服务器IP)  md5
    

    重启服务

    systemctl restart postgresql-12
    
  • 相关阅读:
    “爆奇葩”项目之索引页
    android 的生命周期自我理解
    Jquery Mobile 中文API站
    根据两点经纬度计算距离
    sql语句查询经纬度范围
    Asp.net core 笔记
    Docker 笔记
    IOC和DI
    PHP学习笔记十、图像处理
    PHP学习笔记九、cookie与session
  • 原文地址:https://www.cnblogs.com/faberbeta/p/13623514.html
Copyright © 2020-2023  润新知