• PgSQL基础之 安装postgresql数据系统


    参考这位仁兄的文章,真的非常好:https://blog.csdn.net/jerry_sc/article/details/76408116#创建数据目录

    后来我又自己写了一个shell脚本,来自动化安装pgsql10.5版本。

    #!/bin/bash
    #进入软件的制定安装目录
    echo "进入目录/usr/local,下载pgsql文件"
    cd /usr/local
    #判断是否有postgre版本的安装包
    if [ -d post* ]
    then
            rm -rf /usr/local/post*
            echo "安装包删除成功"
    fi
    #开始下载pgsql版本10.5并解压
    if [ ! -d /usr/local/src ]
    then
            mkdir /usr/local/src
    fi
    cd /usr/local/src
    wget https://ftp.postgresql.org/pub/source/v10.5/postgresql-10.5.tar.gz
    if [ $? == 0 ]
    thentar -zxf postgresql-10.5.tar.gz -C /usr/local/
    fi
    echo "pgsql文件解压成功"
    #判断用户是否存在
    id $postgres >& /dev/null
    echo "用户postgres已存在"
    if [ $? -ne 0 ]
    then
            echo "用户不存在,开始创建postgres用户"
            groupadd postgres
            useradd -g postgres postgres
    fi
    echo "重命名postgresql并且进入安装目录"
    mv /usr/local/post* /usr/local/pgsql
    cd /usr/local/pgsql
    #-------------------------------安装pgsql------------------------------------
    echo "安装一些库文件"
    yum install -y zlib zlib-devel >& /del/null
    echo "开始执行configure步骤"
    ./configure --prefix=/usr/local/pgsql --without-readline
    if [ $? == 0 ]
    then
            echo "configure配置通过,开始进行make编译"
            make
            if [ $? == 0 ]
            then
                    echo "make编译通过,开始进行make install安装步骤"
                    make install
                    if [ $? != 0 ];then
                            echo "make install安装失败"
                    fi
                    echo "安装成功"
            else
                    echo "make编译失败,检查错误。"
            fi
    else
            echo "configure检查配置失败,请查看错误进行安装库文件"
    fi
    echo "开始进行pgsql的配置"
    echo "给pgsql创建data目录"
    mkdir -p /usr/local/pgsql/data
    echo "修改用户组"
    chown -R postgres:postgres /usr/local/pgsql
    echo "添加环境变量,进入postgres用户的家目录"
    cd /home/postgres
    if [ -f .bash_profile ] ;then
            cp .bash_profile .bash_profile.bak
            echo "export PGHOME=/usr/local/pgsql" >> .bash_profile
            echo "export PGDATA=/usr/local/pgsql/data" >> .bash_profile
            echo "PATH=$PGHOME/bin:$PATH" >> .bash_profile
            echo "MANPATH=$PGHOME/share/man:$MANPATH" >> .bash_profile
            echo "LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH" >> .bash_profile
    fi
    alias pg_start='pg_ctl -D $PGDATA -l /usr/local/pgsql/logfile start'
    alias ps_stop='pg_ctl -D $PGDATA -l /usr/local/pgsql/logfile stop'
    echo "切换至postgres用户来初始化数据库"
    su - postgres -c "/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data"
    echo "---------------------------------------------------------------------------------------"
    echo "---------------------------------------------------------------------------------------"
    echo "----------------------------SUCCESS INSTALLATION OF POSTGRESQL-------------------------"
  • 相关阅读:
    __doPostBack的使用
    【转】function,new,constructor and prototye
    谈谈一些网页游戏失败的原因到底有哪些?(转)
    全面剖析页游巨头发家史(转)
    2013.02.20开通博客
    老子喜欢的女人
    如何成为强大的程序员?(转)
    注重健康
    学习方法总结
    数据库知识点滴积累
  • 原文地址:https://www.cnblogs.com/FengGeBlog/p/9884207.html
Copyright © 2020-2023  润新知