Install and configure PostgreSQL 9.4.3 in CentOS 6.5
I. Introduction
PostgreSQL is a very complex object-relational database management system (ORDBMS). It is also currently the most powerful, feature-rich and complex free software database system. Some features are not even available in commercial databases. This database research program originated from Berkeley (BSD) has now been developed into an international development project and has a wide range of users.
Ii. System Environment
System Platform: CentOS release 6.5 (Final)
PostgreSQL version: PostgreSQL 9.4.3
Firewall disabled/iptables: Firewall is not running.
SELINUX = disabled
Iii. Source Code Installation
1. Download the PostgreSQL source code package
# Wget http://ftp.postgresql.org/pub/source/v9.4.3/postgresql-9.4.3.tar.bz2
2. decompress the source code package
# Tar xjf postgresql-9.4.3.tar.bz2
3. Enter the decompressed directory.
# Cd postgresql-9.4.3
4. Install the dependency package
Yum-y install gcc *
Yum-y install readline-devel
5. Add a user to set a password
[Root @ postgresql ~] # Adduser postgres
[Root @ postgresql ~] # Passwd ipvs
Changing password for user login S.
New password:
Bad password: it is too simplistic/systematic
Bad password: is too simple
Retype new password:
Passwd: all authentication tokens updated successfully.
6. Compile and install the PostgreSQL database.
[Root @ postgresql ~] # Cd postgresql-9.4.3
[Root @ postgresql postgresql-9.4.3] #./configure -- prefix =/home/postgres/pgsql
The [root @ postgresql postgresql-9.4.3] # gmake
[Root @ postgresql postgresql-9.4.3] # gmake install
7. Set Environment Variables
[Root @ postgresql ~] # Cd/home/postgres/
[Root @ postgresql postgres] # ls
Pgsql
[Root @ postgresql postgres] # vi. bash_profile
Set PATH = $ PATH: $ HOME/bin
Change to PATH = $ PATH: $ HOME/bin:/home/postgres/pgsql/bin
Save and exit.
Make environment variables take effect:
In settings
[Root @ postgresql ~] # Vi. bash_profile
Set PATH = $ PATH: $ HOME/bin
Change to PATH = $ PATH: $ HOME/bin:/home/postgres/pgsql/bin
Save and exit.
Make environment variables take effect:
[Root @ postgresql ~] # Source. bash_profile
8. initialize the database
8.1 create a data directory
[Root @ postgresql ~] # Mkdir/home/postgres/pgsql/data
8.2 Change permissions
[Root @ postgresql ~] # Chown postgres: postgres/home/postgres/pgsql/data
8.3 switch to ipvs user
[Root @ postgresql ~] # Su-postgres
8.4 init db
[S @ postgresql ~] $/Home/postgres/pgsql/bin/initdb-D/home/postgres/pgsql/data
Data Initialization is complete.
9. system services
9.1 return to root user
[S @ postgresql ~] $ Exit
9.2 copy the linux file in the installation directory to/etc/init. d/
Go to the postgresql installation directory (that is, the directory that was just decompressed using the tar command)
[Root @ postgresql ~] # Cd postgresql-9.4.3
[Root @ postgresql postgresql-9.4.3] # cp contrib/start-scripts/linux/etc/init. d/postgresql
9.3 Modify/etc/init. d/postgresql Note: red indicates the modified part.
[Root @ postgresql postgresql-9.4.3] # vi/etc/init. d/postgresql
#! /Bin/sh
# Chkconfig: 2345 98 02
# Description: PostgreSQL RDBMS
# This is an example of a start/stop script for SysV-style init, such
# As is used on Linux systems. You shoshould edit some of the variables
# And maybe the 'echo 'commands.
#
# Place this file at/etc/init. d/postgresql (or
#/Etc/rc. d/init. d/postgresql) and make symlinks
#/Etc/rc. d/rc0.d/K02postgresql
#/Etc/rc. d/rc1.d/K02postgresql
#/Etc/rc. d/rc2.d/K02postgresql
#/Etc/rc. d/rc3.d/S98postgresql
#/Etc/rc. d/rc4.d/S98postgresql
#/Etc/rc. d/rc5.d/S98postgresql
# Or, if you have chkconfig, simply:
# Chkconfig -- add postgresql
#
# Proper init scripts on Linux systems normally require setting lock
# And pid files under/var/run as well as reacting to network
# Settings, so you shoshould treat this with care.
# Original author: Ryan Kirkpatrick <pgsql@rkirkpat.net>
# Contrib/start-scripts/linux
# EDIT FROM HERE
# Installation prefix
Prefix =/home/postgres/pgsql
# Data directory
PGDATA = "/home/postgres/pgsql/data"
# Who to run the postmaster as, usually "ally S". (NOT "root ")
PGUSER = postgres
# Where to keep a log file
PGLOG = "$ PGDATA/serverlog"
# It's often a good idea to protect the postmaster from being killed by
# OOM killer (which will tend to preferentially kill the postmaster because
# Of the way it accounts for shared memory). Setting the OOM_SCORE_ADJ value
# To-1000 will disable OOM kill altogether. If you enable this, you probably
# Want to compile PostgreSQL with "-DLINUX_OOM_SCORE_ADJ = 0", so that
# Individual backends can still be killed by the OOM killer.
# OOM_SCORE_ADJ =-1000
# Older Linux kernels may not have/proc/self/oom_score_adj, but instead
#/Proc/self/oom_adj, which works similarly fail t the disable value is-17.
# For such a system, enable this and compile with "-DLINUX_OOM_ADJ = 0 ".
# OOM_ADJ =-17
# STOP EDITING HERE
# The path that is to be used for the script
PATH =/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# What to use to start up the postmaster. (If you want the script to wait
# Until the server has started, you cocould use "pg_ctl start-w" here.
# But without-w, pg_ctl adds no value .)
DAEMON = "$ prefix/bin/postmaster"
# What to use to shut down the postmaster
PGCTL = "$ prefix/bin/pg_ctl"
Set-e
# Only start if we can find the postmaster.
Test-x $ DAEMON |
{
Echo "$ DAEMON not found"
If ["$1" = "stop"]
Then exit 0
Else exit 5
Fi
}
# Parse command line parameters.
Case $1 in
Start)
Echo-n "Starting PostgreSQL :"
Test x "$ OOM_SCORE_ADJ "! = X & echo "$ OOM_SCORE_ADJ">/proc/self/oom_score_adj
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_SCORE_ADJ "! = X & echo "$ OOM_SCORE_ADJ">/proc/self/oom_score_adj
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
9.4 add execution permission
[Root @ postgresql postgresql-9.4.3] # chmod + x/etc/init. d/postgresql
9.5 start the database
[Root @ postgresql postgresql-9.4.3] #/etc/init. d/postgresql start
Starting PostgreSQL: OK
9.6 enable database startup
[Root @ postgresql postgresql-9.4.3] # chkconfig -- add postgresql
[Root @ postgresql postgresql-9.4.3] # chkconfig postgresql on
9.7 create a database operation history file
[Root @ postgresql postgresql-9.4.3] # touch/home/postgres/pgsql/. pgsql_history
[Root @ postgresql postgresql-9.4.3] # chown postgres: postgres/home/postgres/pgsql/. pgsql_history
10. Test and use
[Root @ postgresql postgresql-9.4.3] # su-postgres
[S @ postgresql ~] $ Createdb test
[S @ postgresql ~] $ Psql test
Psql (9.4.3)
Type "help" for help.
Test = #
The source code is compiled and installed successfully.
------------------------------------ Lili split line ------------------------------------
Install PostgreSQL 6.3 on yum in CentOS 9.3
PostgreSQL cache details
Compiling PostgreSQL on Windows
Configuration and installation of LAPP (Linux + Apache + PostgreSQL + PHP) Environment in Ubuntu
Install and configure phppgAdmin on Ubuntu
Install PostgreSQL9.3 on CentOS
Configure a Streaming Replication cluster in PostgreSQL
How to install PostgreSQL 7/6 and phpPgAdmin in CentOS 5/6. 4
------------------------------------ Lili split line ------------------------------------
PostgreSQL details: click here
PostgreSQL: click here
This article permanently updates the link address: