CentOS6.5 64-bit under source installation PostgreSQL9.5.1

Source: Internet
Author: User
Tags chmod create directory postgresql psql

1, the official download source files

Http://www.postgresql.org/ftp/source/v9.5.1/

2. Add Users

[Email protected] ~]# Useradd postgres

[Email protected] ~]# passwd postgres

Changing password for user postgres.

New Password:

Retype new Password:

Passwd:all authentication tokens updated successfully.

[Email protected] ~]#

3. Unzip and install

[Email protected] ~]# TAR-JXVF postgresql-9.5.1.tar.bz2

[Email protected] ~]# CD postgresql-9.5.1

[Email protected] postgresql-9.5.1]#/configure--prefix=/usr/local/pgsql

[[email protected] postgresql-9.5.1]# make

[[email protected] postgresql-9.5.1]# make install

[Email protected] postgresql-9.5.1]# Mkdir/usr/local/pgsql/data

[Email protected] postgresql-9.5.1]# Mkdir/usr/local/pgsql/log

[Email protected] postgresql-9.5.1]# chown Postgres/usr/local/pgsql/data

4. Environment variable Setting

[Email protected] pgsql]# Su-postgres

[[email protected] ~]$ vim. Bash_profile

#. bash_profile# Get the aliases and Functionsif [-f ~/.BASHRC]; Then        . ~/.bashrcfi# User specific environment and startup Programspath= $PATH: $HOME/bin:/usr/local/pgsql/binpgdata =/usr/local/pgsql/dataexport PATH PGDATA
[[email protected] ~]$ source. Bash_profile5, add PostgreSQL system Services

[Email protected] ~]# Vim/etc/init.d/postgresql

#!/bin/sh## PostgreSQL This was 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 was slightly unusual in that the name of the Daemon (postmaster) # was 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 D Uring package buildpgversion=9.5.1# pgmajorversion are major version, e.g., 8.4 (this should match pg_version) Pgmajorversio N= ' 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 Scriptname= ' basename $ ' if [${name:0:1} = "S"-o ${name:0:1} = "K"]then name=${name:3}fi# for SELinux We need the use of ' runuser ' not ' su ' if [-x/sbin/runuser]then su=runuserelse Su=suf i# Set defaults for configuration variablespgengine=/usr/local/pgsql/binpgport=5432pgdata=/usr/local/pgsql/datapglog=/usr/local/pgsql/log/ pgstartup.log# Value to set as Postmaster process ' s oom_adjpg_oom_adj=-17# Override defaults from/etc/sysconfig/pgsql if File is present[-f/etc/sysconfig/pgsql/${name}] &&. /etc/sysconfig/pgsql/${name}export pgdataexport pgportlockfile= "/var/lock/subsys/${name}" pidfile= "/var/run/ Postmaster.${pgport}.pid "Script_result=0start () {[-X" $PGENGINE/postmaster "] | | Exit 5 psql_start=$" Starti ng ${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/rest Orecon] &&/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 "] th En sysdocdir= "(Your System ' s documentation directory)" If [-D "/usr/doc/pos                        tgresql-$PGVERSION "] then Sysdocdir=/usr/doc                                fi if [-D "/usr/share/doc/postgresql-$PGVERSION"] Then Sysdocdir=/usr/share/doc fi if [-d '/usr/doc/packages/postgres                        ql-$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 "$l Ockfile "] then $SU-L postgres-c" $PGENGINE/pg_ctl stop-d ' $PGDATA '-s-m fast ' >/dev/null 2>< /c7>&1 </ Dev/null ret=$? if [$ret-eq 0] then echo_success rm-f "$pidfile" Rm-f "$l Ockfile "Else echo_failure script_result=1fi else # 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 was 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 STA Rtup-time log file is OK, too if [!-e "$PGLOG"-H "$PGLOG"] then Touch "$PGLOG" | | Exit 1 chown postgres:postgres "$PGLOG" chmod go-rwx "$PGLOG" [-x/sbin/rest Orecon] &&/sbin/restorecon "$PGLOG" FI # Initialize the database $SU-L POSTGRES-C "$PGENG Ine/initdb--pgdata= ' $PGDATA '--auth= ' ident '" >> "$PGLOG" 2>&1 </ Dev/null # Create directory for postmaster log mkdir "$PGDATA/pg_log" Chown postgres:postgres "$PGDA        Ta/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 "$" 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: $ start|stop|status|restart|condrestart|try-restart|reload|force-reload|initdb}" Exit 2es Acexit $script _result

Chkconfig PostgreSQL on

CentOS6.5 64-bit under source installation PostgreSQL9.5.1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.