Migrate to Cloud

Postgresql on EC2

If you are looking forward to migrating your PostgreSQL database to AWS EC2 cloud servers, you can do so by following the simple steps we have posted below. You can make it more reliable and secure from accidental  EC2 instance crashing by allowing the postgresql server to run from an EBS volume. You can also take  a snapshot of the EBS volume which will be stored on AWS storage service s3 which will  make it highly reliable by making it available on multiple AWS availability zones that spans across datacenters.

1 ) Sign up for AWS    EC2 and  S3 services .

2 ) Launch an EC2  instance using AWS  EC2  API tool  or  GUI’s  like  Elastic fox or  AWS   Management Console

3 ) Launch an EBS  and attach it to the instance

4) Check if the attached EBS  is present on the instance

[bash]fdisk -l[/bash]

if /dev/sdh is the name of the EBS volume , it will be present without a valid partition table , so format the  EBS volume  .

[bash]mkfs  -t ext3  /dev/sdh    ( or   mkfs.ext3 /dev/sdh )[/bash]

5 ) Create a directory  /ebs  and mount the EBS volume to   it

[bash]
mkdir  /ebs
mount /dev/sdh /ebs
[/bash]

6 ) Install postgresql server

[bash]yum  install   postgresql-libs   postgresql    postgresql-server[/bash]

7 ) Create  a  new data directory  for postgresql  database  in EBS volume

[bash]mkdir /ebs/pgsql[/bash]

8 ) Stop Postgresql server if it is already running on your instance

[bash]/etc/init.d/postgresql   stop[/bash]

9 ) Move the Postgresql data  directory to the EBS volume

[bash]mv /var/lib/pgsql  /ebs[/bash]

10) Edit the init script  for Postgresql  and give the correct path for  PGDATA and PGLOG

[bash]
vi   /etc/init.d/postgresql
PGDATA=/ebs/pgsql
PGLOG=/ebs/pgsql/pgstartup.log
[/bash]

11 ) Edit  Postgresql  configuration files  to give access to database client , database , & database user .

[bash]
vi   /ebs/pgsql/data/pg_hba.conf
host    all    all    10.250.51.0/32   trust
vi  /ebs/pgsql/data/postgresql.conf
listen_addresses = ‘*’
port = 5432
[/bash]

12) Start the Postgresql server

[bash] /etc/init.d/postgresql start[/bash]


Associated Links

  • Cloud infrastructure
  • Cloud computing
  • Web services
  • Amazon Elastic Compute Cloud
  • EBS
  • Amazon Web Services
  • Eucalyptus

  • Exit mobile version