My machine: AMD64x2 4400 + + 1 GB memory
Phase 1-compilation and installation:
1. Download postgresql-9.1.3.tar.bz2 from sqlsql.
2, copy the source code to the/usr/src/postgresql-9.1.3.tar.bz2 and cd/usr/src
3, decompression: tar xjvf postgresql-9.1.3.tar.bz2
4, enter the source Directory: cd postgresql-9.1.3
5. Create the pgsql installation directory. Here I select: mkdir/usr/pgsql-9.1.3
6, install the required tool run: aptitude install build-essential zlib1g-dev libpam0g-dev libssl-dev libperl-dev kernel-package libncurses5-dev flex bison gawk chkconfig the system will automatically install the software
7. Execute the following command in the source code directory:
. /Configure CFLAGS = '-DLINUX_OOM_ADJ = 0-O2-pipe-march = athlon64-fomit-frame-pointer-fstack-protector' -- prefix =/usr/pgsql-9.1.3 -- with-perl -- with-openssl -- with-pam -- enable-nls -- disable-debug
8. Start Compilation: make-j 4
9. After the installation is successful, run make install
10. Create a general permission user for postgresql database: adduser psqlroot
11, switch to the installation directory: cd/usr/pgsql-9.1.3 build initialization Database Cluster Folder: mkdir date
12. Change the date permission to chown psqlroot: psqlroot date.
13, execute database initialization (must use the psqlroot user): su-psqlroot-c './initdb/usr/pgsql-9.1.3/date'
14. Now, go to the date directory and check the initialized files, such as the conf configuration file.
Phase 2-Prepare the startup script:
1. Copy the original boot script from the source code directory:
Cp/usr/src/postgresql-9.1.3/contrib/start-scripts/linux/etc/init. d/postgresql
2. grant execution permission: chmod 700/etc/init. d/postgresql
3. Establish various levels of startup connections in s 2 3 4 5 6 (/etc/rc. d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d)
Use: chkconfig/etc/init. d/postgresql for automatic creation!
4. Modify the/etc/init. d/postgresql file, which is based on/bin/sh and changed to/bin/bash:
#! /Bin/bash
# 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 =/usr/pgsql-9.1.3
# Data directory
PGDATA = $ PREFIX/date
# Who to run the postmaster as, usually "ally S". (NOT "root ")
PGUSER = psqlroot
# Where to keep a log file
PGLOG =/var/log/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_ADJ value
#-17 will disable OOM kill altogether. If you enable this, you probably want
# To compile PostgreSQL with "-DLINUX_OOM_ADJ = 0", so that individual backends
# Can still be killed by the OOM killer.
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_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
5. Note that the OOM_ADJ =-17 mentioned above is used to escape OOM automatic blocking. OK! Run the/etc/init. d/postgresql start stop restart command and so on !!
6. Copy the conf configuration file in the installation directory to/etc/postgresql for later configuration changes.
Mkdir/etc/postgresql
Mv/usr/pgsql-9.1.3/date/* conf/etc/postgresql/
Cd/usr/pgsql-9.1.3/date
Su-psqlroot-c 'ln-s/etc/postgresql/pg_assist.conf'
Su-psqlroot-c 'ln-s/etc/postgresql/pg_ident.conf'
Su-psqlroot-c 'ln-s/etc/postgresql. conf postgresql. conf'
Stage 3-Optimization