美文网首页
PostgreSQL部署

PostgreSQL部署

作者: Gtlions_Lai | 来源:发表于2016-03-27 10:38 被阅读0次

    环境

    CentOS 6.6 x_64
    postgresql-9.4.4
    

    编译安装

    tar -jxf postgresql-9.4.4.tar.bz2;cd postgresql-9.4.4
    ./configure --prefix=/usr/local/pgsql
    make  && make install
    adduser postgres
    mkdir /usr/local/pgsql/data /usr/local/pgsql/data/pg_log
    chown postgres:postgres  -R /usr/local/pgsql/data
    cp /usr/local/pgsql/bin/* /usr/bin
    
    su - postgres
    /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
    #/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
    exit
    
    echo 'export PGSQL_HOME=/usr/local/pgsql
    export PGDATA=/usr/local/pgsql/data
    export PATH=$PGSQL_HOME/bin:$PATH
    export LD_LIBRARY_PATH=$PGSQL_HOME/lib:$LD_LIBRARY_PATH'>>~/.bash_profile
    source ~/.bash_profile
    

    启动脚本

    vi /etc/init.d/pgsql
    
    #! /bin/sh
    # chkconfig: 345 85 15
    # postgresql    This is the init script for starting up the PostgreSQL server
    # description: Starts and stops the PostgreSQL backend daemon that handles all database requests.
    
    PGSQL_HOME=/usr/local/pgsql
    PGDATA=/usr/local/pgsql/data
    PATH=$PGSQL_HOME/bin:$PATH
    LD_LIBRARY_PATH=$PGSQL_HOME/lib:$LD_LIBRARY_PATH
    PGUSER=postgres
    
    PGLOG=$PGDATA/pg_log/serverlog.log
    
    DAEMON=$PGSQL_HOME/bin/postmaster
    
    PGCTL=$PGSQL_HOME/bin/pg_ctl
    
    set -e
    
    
    test -x $DAEMON ||
    {
        echo "$DAEMON not found"
        if [ "$1" = "stop" ]
        then exit 0
        else exit 5
        fi
    }
    
    
    
    case $1 in
      start)
        echo -n "Starting PostgreSQL: "
        test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
        su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
        echo "ok"
        ;;
      stop)
        echo -n "Stopping PostgreSQL: "
        su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast"
        echo "ok"
        ;;
      restart)
        echo -n "Restarting PostgreSQL: "
        su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w"
        test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
        su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
        echo "ok"
        ;;
      reload)
            echo -n "Reload PostgreSQL: "
            su - $PGUSER -c "$PGCTL reload -D '$PGDATA' -s"
            echo "ok"
            ;;
      status)
        su - $PGUSER -c "$PGCTL status -D '$PGDATA'"
        ;;
      *)
        # Print help
        echo "Usage: $0 {start|stop|restart|reload|status}" 1>&2
        exit 1
        ;;
    esac
    
    exit 0
    
    chmod +x /etc/init.d/pgsql
    chkconfig --add pgsql
    service pgsql restart
    

    -EOF-

    相关文章

      网友评论

          本文标题:PostgreSQL部署

          本文链接:https://www.haomeiwen.com/subject/zlzdlttx.html