• Postgresql配置


    YUM安装:

    ------------------------------------------------------------------------------------------

    1、安装Postgresql安装源:

    # yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/pgdg-redhat-repo-latest.noarch.rpm
    # yum clean all
    # yum makecache
    

    2、安装数据库:

    # yum install postgresql12 postgresql12-server
    

    3、始化数据库:

    # service postgresql-12 initdb
    

    4、启动数据库服务:

    # service postgresql-12 start
    # chkconfig postgresql-12 on
    

    5、登录数据库:

    # su postgres
    $ psql
    

    6、修改管理员账号密码:

    =# alter user postgres with encrypted password 'mypass';
    

    7、退出数据库:

    =# q 或者 quit
    

    源码编译安装:

    ------------------------------------------------------------------------------------------

    1、官网下载Postgresql:

    # wget https://ftp.postgresql.org/pub/source/v12.3/postgresql-12.3.tar.gz
    

    2、安装依赖包:

    # yum -y install bison flex readline-devel zlib-devel
    

    3、解压源码包:

    # tar -xzvf postgresql-12.3.tar.gz
    

    4、编译源码包:

    # ./configure --prefix=/usr/local/postgresql
    # make
    # make install
    

    5、增加postgres账户:

    # groupadd postgres
    # useradd -g postgres postgres
    

    6、新增DATA目录:

    # mkdir /usr/local/postgresql/data
    # chown -R postgres.postgres /usr/local/postgresql
    

    7、数据库系统初始化:

    $ /usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data/
    

    8、增加环境变量:

    $ vim /home/postgres/.bash_profile
    export PGHOME=/usr/local/postgresql
    export PGDATA=/usr/local/postgresql/data
    export PATH=$PATH:$HOME/bin:$PGHOME/bin
    
    $ source /home/postgres/.bash_profile
    

    9、启动数据库服务:

    $ /usr/local/postgresql/bin/pg_ctl -D /usr/local/postgresql/data/ -l logfile start
    $ /usr/local/postgresql/bin/pg_ctl -D /usr/local/postgresql/data/ stop
    $ /usr/local/postgresql/bin/pg_ctl -D /usr/local/postgresql/data/ -m fast restart
    

    10、添加开机启动项目:

    $ /usr/local/src/postgresql-12.3/contrib/start-scripts/linux /etc/init.d/postgresql
    $ chmod a+x /etc/init.d/postgresql
    
    $ vim /etc/init.d/postgresql
    按实际情况修改如下项目:
    # Installation prefix
    prefix=/usr/local/postgresql
    # Data directory
    PGDATA="/usr/local/postgresql/data"
    

    添加开机项目:

    $ chkconfig --add postgresql
    

    11、设置管理员用户密码:

    $ psql -U postgres
    =# ALTER USER postgres with encrypted password '17track';
    =# quit
    

    常用命令:

    --------------------------------------------------------------------------

    查看所有数据库:

    =# l 或者 list
    

    列出当前数据库的表:

    =# d
    

    创建数据库:

    =# create database mydb;
    

    切换数据库:

    =# c mydb
    

    在当前数据库插入表:

    =# create table test(id int,body varchar(100));
    

    新建用户:

    =# create user test with password 'test';
    

    修改账号密码:

    =# alter user postgres with encrypted password 'mypass';
    

    赋予指定账号到指定数据库权限:

    =# grant all privileges on database mydb to test;
    

    移除指定账号到指定数据库权限:

    =# revoke all privileges on database mydb to test;
    

    [THE END]

  • 相关阅读:
    Js整理备忘(06)——函数基础(二) 作用域与闭包
    asp.net——网站发布后xml文件拒绝写入操作
    使用xsd.exe命令 根据指定的xml文件生成对应的xsd架构文件
    Sql Server 导入
    EF 的“根据 Edmx 架构生成数据库”和“根据数据库生成 Edmx 架构”真是强大啊
    生成需要注意的。
    CSS之Position详解
    CSS3阴影
    css ::selection改变文字选择的背景颜色
    reset
  • 原文地址:https://www.cnblogs.com/configure/p/13398662.html
Copyright © 2020-2023  润新知