Saturday, December 05, 2009

PostgreSQL on EBS

Following are the steps to run PostgreSQL database on EBS drive on Amazon EC2 instance

1) from the Amazon EC2 console, create a new colume and attach that to the running instance.

[consider this example when you attached that on /dev/sdi from the console]

2) Format & Mount the disk using the following commands from the Terminal
sudo modprobe xfs
sudo mkfs.xfs /dev/sdi

echo "/dev/sdi /media/PostgresLiveDB xfs noatime 0 0" | sudo tee -a /etc/fstab
sudo mkdir /media/PostgresLiveDB
sudo mount /media/PostgresLiveDB
copy paste the data folder from the postgres installation diretory to this EBS drive

3) make sure you give the file permission of the EBS to postgres user
# change to the data directory
cd /media/PostgresLiveDB/data
# chown the files
find . -type f -exec chown postgres:postgres {} \;
# chown the directories
find . -type d -exec chown postgres:postgres {} \;
# and then the data directory itself
chown postgres:postgres /media/PostgresLiveDB/data
#and
sudo chmod 700 /media/PostgresLiveDB/data

check the permissions at each directory using ls -l

4)- stop the postgresql server using /etc/init.d/postgresql-8.3 stop
- you can rename the data folder presents in installation directory to databackup or so. just to maintain a backup folder to cross check.
- open the file /etc/init.d/postgresql-8.3 and edit the data paths properly
- edit the data directory path properly in /etc/postgresql/8.3/main/postgresql.conf

5) - start the postgresql server using /etc/init.d/postgresql-8.3 start

Cheers! you are done..

No comments: