I am going to break this into two articles. The first article will use yum (and the default amazon repositories) for the installation, all defaults, and the ec2 instance EBS root device. Some more in-depth installation techniques are in the next post (Install PostgreSQL 9.0 on Amazon Linux). It seems likely to me that you want some hybrid of the two versions, but this one will get you up and running in a few minutes.
The goal is to install a PostgreSQL server on Amazon Linux, and to allow external access to that database server.
Security group config
Launch the instance.
Connect with something like: ssh -i .ssh/myKey.pem ec2-user@ec2-11-11-11-111.compute-1.amazonaws.com
Use yum to install the PostgreSQL utils, libs, and server. Next, initialize a database cluster and make some necessary updates to the pg_hba.conf file.
sudo yum install postgresql postgresql-server postgresql-devel postgresql-contrib postgresql-docs [Confirm the installation and accept the key] sudo service postgresql initdb sudo vim /var/lib/pgsql/data/pg_hba.conf
At the bottom of pg_hba.conf, change:
To read:“local” is for Unix domain socket connections only
local all all ident
IPv4 local connections:
host all all 127.0.0.1/32 ident
“local” is for Unix domain socket connections only
local all all trust
IPv4 local connections:
host all all 0.0.0.0/0 md5
Note: Do not use these pg_hba.conf settings on a production server.
Now edit the postgresql.conf file to get the server to listen for requests from other locations.
sudo vim /var/lib/pgsql/data/postgresql.conf
Uncomment the line (line 59 at time of writing) with “listen_addresses = ‘localhost’ … “ and change the value from ‘localhost’ to ‘’. The file should now read:
listen_addresses = ‘
’ # what IP address(es) to listen on;
After making the appropriate updates to pg_hba.conf and postgresql.conf, we can launch the server. If you started the server prior to making the configuration changes, you will need to restart the server before you can connect.
sudo service postgresql start
Congratulations, you now have a PostgreSQL server up and running. We just need to set a password for the postgres user, and you will be able to connect to the server from other locations. On the server, continue with:
psql -U postgres postgres=# ALTER USER postgres WITH PASSWORD 'password'; postgres=# \q
This gets you up and running, and externally accessible. If you are experimenting with PostgreSQL, or need to get a proof of concept up immediately, this may suffice. I can not stress enough that this configuration is inappropriate for production use. Some reasons are:
I will post a more extensive installation (of PostgreSQL 9.0) later this week.