zoukankan      html  css  js  c++  java
  • PostgreSQL学习笔记(一)-安装PostgreSQL

    PostgreSQL官网:https://www.postgresql.org/docs/11/index.html
    1、如何安装
    2、如何修改配置文件
    3、如何设置自动启动
    4、如何修改数据用户密码

    本文环境 :
    系统:CentOS7
    zlib-devel,gcc,
    readline-devel


    已经安装Python3.6
    //下载
    wget https://ftp.postgresql.org/pub/source/v11.1/postgresql-11.1.tar.gz
    //解压
    tar -xzvf postgresql-11.1.tar.gz
    //安装
    ./configure
    make
    su
    make install
    //新增用户 postgres
    adduser postgres
    mkdir /usr/local/pgsql/data
    chown postgres /usr/local/pgsql/data
    
    //切换用户
    su - postgres
    //初始化数据库
    /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data -E UTF8
    //启动数据库
    /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
    //创建数据库 testdb
    /usr/local/pgsql/bin/createdb testdb
    //进入testdb
    /usr/local/pgsql/bin/psql testdb
    
    
    //如果连接无效,可以重新设置连接
    cd /usr/bin
    rm psql
    ln -s /usr/local/pgsql/bin/psql /usr/bin/psql
    ln -s /usr/local/pgsql/bin/createdb /usr/bin/createdb
    ln -s /usr/local/pgsql/bin/createuser /usr/bin/createuser

    这时候数据库还不能通过远程访问,需要修改两个配置文件postgresql.conf和pg_hba.conf。文件位于指定初始化数据库的位置。
    本案列中在/usr/local/pgsql/data 下

    • postgresql.conf的修改
    vi /usr/local/pgsql/data/postgresql.conf

    将 #listen_addresses = 'localhost' 前的#号去掉,然后将后面的localhost改为*,然后将 #port = 5432 前的#去掉,最后再将 #password_encryption = md5 前面的#号去掉

    • 对pg_hba.conf内容进行配配置
    vi /usr/local/pgsql/data/pg_hba.conf
    将下图红框内的ident改为md5,然后再在最下面加入 host all all 0.0.0.0/0 md5 

    如何配置自动启动

    //创建postgresql.service文件
    /etc/systemd/system/postgresql.service

    添加一下内容

    [Unit]
    Description=PostgreSQL database server
    Documentation=man:postgres(1)
    
    [Service]
    Type=notify
    User=postgres
    ExecStart=/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
    ExecReload=/bin/kill -HUP $MAINPID
    KillMode=mixed
    KillSignal=SIGINT
    TimeoutSec=0
    
    [Install]
    WantedBy=multi-user.target

    自动启动服务

    //启用postgresql.service
    systemctl enable postgresql.service
    //启动postgresql.service
    systemctl start postgresql.service
    //查看运行状态 
    systemctl status postgresql.service 

    如何修改用户名密码

    alter user postgres with password 'password';
  • 相关阅读:
    软工实践个人总结
    第06组 Beta版本演示
    第06组 Beta冲刺(5/5)
    第06组 Beta冲刺(4/5)
    第06组 Beta冲刺(3/5)
    第06组 Beta冲刺(2/5)
    第06组 Beta冲刺(1/5)
    第06组 Alpha事后诸葛亮
    第06组 Alpha冲刺(6/6)
    第06组 Alpha冲刺(5/6)
  • 原文地址:https://www.cnblogs.com/Evan-fanfan/p/PostgreSQL.html
Copyright © 2011-2022 走看看