设为首页 收藏本站
查看: 346|回复: 0

[经验分享] CentOS6.5 64位下源码安装PostgreSQL9.5.1

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-3-14 09:01:39 | 显示全部楼层 |阅读模式

1、官方下载源码文件

http://www.postgresql.org/ftp/source/v9.5.1/
2、添加用户

[iyunv@test1 ~]#  useradd postgres

[iyunv@test1 ~]#  passwd postgres

Changing password for user postgres.

New password:

Retype new password:

passwd: all authentication tokens updated successfully.

[iyunv@test1 ~]#
3、解压并安装

[iyunv@test1 ~]# tar -jxvf postgresql-9.5.1.tar.bz2

[iyunv@test1 ~]# cd postgresql-9.5.1

[iyunv@test1 postgresql-9.5.1]# ./configure --prefix=/usr/local/pgsql

[iyunv@test1 postgresql-9.5.1]# make

[iyunv@test1 postgresql-9.5.1]# make  install

[iyunv@test1 postgresql-9.5.1]# mkdir /usr/local/pgsql/data

[iyunv@test1 postgresql-9.5.1]# mkdir /usr/local/pgsql/log

[iyunv@test1 postgresql-9.5.1]# chown postgres /usr/local/pgsql/data
4、环境变量设置

[iyunv@test1 pgsql]# su - postgres

[postgres@test1 ~]$ vim .bash_profile

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

        . ~/.bashrc

fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/local/pgsql/bin

PGDATA=/usr/local/pgsql/data

export PATH PGDATA

[postgres@test1 ~]$ source .bash_profile
5、添加postgresql系统服务

[iyunv@test1 ~]#  vim /etc/init.d/postgresql

#!/bin/sh
#
# postgresql    This is the init script for starting up the PostgreSQL
#               server.
#
# chkconfig: - 64 36
# description: PostgreSQL database server.
# processname: postmaster
# pidfile: /var/run/postmaster.PORT.pid

# This script is slightly unusual in that the name of the daemon (postmaster)
# is not the same as the name of the subsystem (postgresql)

# PGVERSION is the full package version, e.g., 8.4.0
# Note: the specfile inserts the correct value during package build
PGVERSION=9.5.1
# PGMAJORVERSION is major version, e.g., 8.4 (this should match PG_VERSION)
PGMAJORVERSION=`echo "$PGVERSION" | sed 's/^\([0-9]*\.[0-9]*\).*$/\1/'`

# Source function library.
. /etc/rc.d/init.d/functions

# Get network config.
. /etc/sysconfig/network

# Find the name of the script
NAME=`basename $0`
if [ ${NAME:0:1} = "S" -o ${NAME:0:1} = "K" ]
then
        NAME=${NAME:3}
fi

# For SELinux we need to use 'runuser' not 'su'
if [ -x /sbin/runuser ]
then
    SU=runuser
else
    SU=su
fi


# Set defaults for configuration variables
PGENGINE=/usr/local/pgsql/bin
PGPORT=5432
PGDATA=/usr/local/pgsql/data
PGLOG=/usr/local/pgsql/log/pgstartup.log
# Value to set as postmaster process's oom_adj
PG_OOM_ADJ=-17

# Override defaults from /etc/sysconfig/pgsql if file is present
[ -f /etc/sysconfig/pgsql/${NAME} ] && . /etc/sysconfig/pgsql/${NAME}

export PGDATA
export PGPORT

lockfile="/var/lock/subsys/${NAME}"
pidfile="/var/run/postmaster.${PGPORT}.pid"

script_result=0

start(){
        [ -x "$PGENGINE/postmaster" ] || exit 5

        PSQL_START=$"Starting ${NAME} service: "

        # Make sure startup-time log file is valid
        if [ ! -e "$PGLOG" -a ! -h "$PGLOG" ]
        then
                touch "$PGLOG" || exit 4
                chown postgres:postgres "$PGLOG"
                chmod go-rwx "$PGLOG"
                [ -x /sbin/restorecon ] && /sbin/restorecon "$PGLOG"
        fi

        # Check for the PGDATA structure
        if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ]
        then
                # Check version of existing PGDATA
                if [ x`cat "$PGDATA/PG_VERSION"` != x"$PGMAJORVERSION" ]
                then
                        SYSDOCDIR="(Your System's documentation directory)"
                        if [ -d "/usr/doc/postgresql-$PGVERSION" ]
                        then
                                SYSDOCDIR=/usr/doc
                        fi
                        if [ -d "/usr/share/doc/postgresql-$PGVERSION" ]
                        then
                                SYSDOCDIR=/usr/share/doc
                        fi
                        if [ -d "/usr/doc/packages/postgresql-$PGVERSION" ]
                        then
                                SYSDOCDIR=/usr/doc/packages
                        fi
                        if [ -d "/usr/share/doc/packages/postgresql-$PGVERSION" ]
                        then
                                SYSDOCDIR=/usr/share/doc/packages
                        fi
                        echo
                        echo $"An old version of the database format was found."
                        echo $"You need to upgrade the data format before using PostgreSQL."
                        echo $"See $SYSDOCDIR/postgresql-$PGVERSION/README.rpm-dist for more information."
                        exit 1
                fi
        else
                # No existing PGDATA! Warn the user to initdb it.
                echo
                echo "$PGDATA is missing. Use \"service postgresql initdb\" to initialize the cluster first."
                echo_failure
                echo
                exit 1
        fi

        echo -n "$PSQL_START"
        test x"$PG_OOM_ADJ" != x && echo "$PG_OOM_ADJ" > /proc/self/oom_adj
        $SU -l postgres -c "$PGENGINE/postmaster -p '$PGPORT' -D '$PGDATA' ${PGOPTS} &" >> "$PGLOG" 2>&1 < /dev/null
        sleep 2
        pid=`head -n 1 "$PGDATA/postmaster.pid" 2>/dev/null`
        if [ "x$pid" != x ]
        then
                success "$PSQL_START"
                touch "$lockfile"
                echo $pid > "$pidfile"
                echo
        else
                failure "$PSQL_START"
                echo
                script_result=1
        fi
}

stop(){
        echo -n $"Stopping ${NAME} service: "
        if [ -e "$lockfile" ]
        then
            $SU -l postgres -c "$PGENGINE/pg_ctl stop -D '$PGDATA' -s -m fast" > /dev/null 2>&1 < /dev/null
            ret=$?if [ $ret -eq 0 ]
            then
                echo_success
                rm -f "$pidfile"
                rm -f "$lockfile"
            else
                echo_failure
                script_result=1fi
        else
            # not running; per LSB standards this is "ok"
            echo_success
        fi
        echo
}

restart(){
    stop
    start
}

condrestart(){
    [ -e "$lockfile" ] && restart || :
}

reload(){
    $SU -l postgres -c "$PGENGINE/pg_ctl reload -D '$PGDATA' -s" > /dev/null 2>&1 < /dev/null
}

initdb(){
    if [ -f "$PGDATA/PG_VERSION" ]
    then
        echo -n "Data directory is not empty!"
        echo_failure
        echo
        script_result=1else
        echo -n $"Initializing database: "
        if [ ! -e "$PGDATA" -a ! -h "$PGDATA" ]
        then
                mkdir -p "$PGDATA" || exit 1
                chown postgres:postgres "$PGDATA"
                chmod go-rwx "$PGDATA"
        fi
        # Clean up SELinux tagging for PGDATA
        [ -x /sbin/restorecon ] && /sbin/restorecon "$PGDATA"

        # Make sure the startup-time log file is OK, too
        if [ ! -e "$PGLOG" -a ! -h "$PGLOG" ]
        then
                touch "$PGLOG" || exit 1
                chown postgres:postgres "$PGLOG"
                chmod go-rwx "$PGLOG"
                [ -x /sbin/restorecon ] && /sbin/restorecon "$PGLOG"
        fi

        # Initialize the database
        $SU -l postgres -c "$PGENGINE/initdb --pgdata='$PGDATA' --auth='ident'" >> "$PGLOG" 2>&1 < /dev/null

        # Create directory for postmaster log
        mkdir "$PGDATA/pg_log"
        chown postgres:postgres "$PGDATA/pg_log"
        chmod go-rwx "$PGDATA/pg_log"

        if [ -f "$PGDATA/PG_VERSION" ]
        then
            echo_success
        else
            echo_failure
            script_result=1fi
        echo
    fi
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status -p "$pidfile" postmaster
        script_result=$?;;
  restart)
        restart
        ;;
  condrestart|try-restart)
        condrestart
        ;;
  reload)
        reload
        ;;
  force-reload)
        restart
        ;;
  initdb)
        initdb
        ;;
  *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|initdb}"
        exit 2
esac

exit $script_result

chkconfig --add postgresql

chkconfig postgresql  on



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-190493-1-1.html 上篇帖子: centos 7的用户和权限管理相关内容 下篇帖子: 【转】linux 客户端 Socket 非阻塞connect编程(正文)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表