Postgresql server 9.1 installation from source code

This document will tell you how to install postgresql server 9.1 from source code.

1. Download postgres 9.1
wget http://ftp9.us.postgresql.org/pub/mirrors/postgresql/source/v9.0.1/postgresql-9.0.1.tar.bz2

2. Extract postgres
tar xjvf postgresql-9.0.1.tar.bz2

3. Install following dependent packages which are needed for installation
sudo apt-get install build-essential libreadline-dev zlib1g-dev

4. To install, go inside of the extracted folder
./configure
make
sudo make install # This will install postgresql in /usr/local/pgsql

5. Copy server startup script under services
sudo cp contrib/start-scripts/linux /etc/init.d/postgresql

6. Then make the startup script executable.
sudo chmod 775 /etc/init.d/postgresql  

7. add the script to the Server's startup routine (init) with update-rc.d like
 sudo update-rc.d postgresql defaults

8. Add A Postgres User (service account)
Now, we need to add a postgres user. This user runs the postgresql server. Postgres will not run as root.
sudo adduser postgres --home /usr/local/pgsql

9. Add Paths to Binaries and Man Pages
1. sudo nano /etc/profile.d/postgresql.sh
add lines

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

2. sudo nano /etc/profile.d/pgmanual.sh
add lines

MANPATH=$MANPATH:/usr/local/pgsql/man
export MANPATH

Note : These configs can also be done in /home/<username>/.bashrc

3. Make above file executable
sudo chmod 775 /etc/profile.d/postgresql.sh
sudo chmod 775 /etc/profile.d/pgmanual.sh

10. Create the PostgreSQL Database Cluster
1. Make a directory to contain the databases
sudo mkdir /usr/local/pgsql/data
sudo chown -R postgres:postgres /usr/local/pgsql/data

2. Execute the initdb script
su postgres
initdb -D /usr/local/pgsql/data

Note: If initdb command not found, use full path i.e '/usr/local/pgsql/bin/initdb'
OR
Load the postgres commands into shell environment using,

source /etc/profile.d/postgresql.sh

11. Start and stop serve
sudo /etc/init.d/postgresql start
sudo /etc/init.d/postgresql stop

創作者介紹
創作者 graciasnana 的頭像
graciasnana

graciasnana的部落格

graciasnana 發表在 痞客邦 留言(0) 人氣()