Friday, February 11, 2011

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

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
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/ 
add lines

export PATH

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

export MANPATH

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

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

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'
Load the postgres commands into shell environment using, 

source /etc/profile.d/ 

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

For this I have referred a following link. Actually this link shows installation of  postgres 8.3.7 but you can change it appropriately

No comments:

Post a Comment