Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install PostgreSQL on Amazon AMI
#!/bin/bash
###############################################
# To use:
# https://raw.github.com/gist/2776351/???
# chmod 777 install_postgresql.sh
# ./install_postgresql.sh
###############################################
echo "*****************************************"
echo " Installing PostgreSQL"
echo "*****************************************"
sudo yum -y install postgresql postgresql-server postgresql-devel postgresql-contrib postgresql-docs
sudo service postgresql initdb
# Use MD5 Authentication
sudo sed -i.bak -e 's/ident$/md5/' -e 's/peer$/md5/' /var/lib/pgsql9/data/pg_hba.conf
#start
sudo /sbin/chkconfig --levels 235 postgresql on
sudo service postgresql start
# http://imperialwicket.com/aws-install-postgresql-on-amazon-linux-quick-and-dirty
@framp

This comment has been minimized.

Copy link

@framp framp commented Apr 22, 2013

Thank you

@ye

This comment has been minimized.

Copy link

@ye ye commented Aug 1, 2013

Is there a default way to login after this install? Or all login credentials must be added afterwards manually for best practices?

@arturosalgado

This comment has been minimized.

Copy link

@arturosalgado arturosalgado commented Apr 27, 2015

how to access to it?, it keeps telling me: authentication failed

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Sep 27, 2016

Thank you

@alvirtuoso

This comment has been minimized.

Copy link

@alvirtuoso alvirtuoso commented Nov 21, 2016

how to access to it?, it keeps telling me: authentication failed
To login after install, login with the systems sudo

  1. sudo su - postgres
  2. Next psql -U postgres to login as the default user postgres. You should see "postgres=#" which tells you that you're in.
@francisrod01

This comment has been minimized.

Copy link

@francisrod01 francisrod01 commented Mar 11, 2017

Thanks!

@ccbenavides

This comment has been minimized.

Copy link

@ccbenavides ccbenavides commented Sep 12, 2017

password authentication failed for user "postgres"

@Tectract

This comment has been minimized.

Copy link

@Tectract Tectract commented Sep 28, 2017

psql: FATAL: database "ec2-user" does not exist

@jayemiuesesou

This comment has been minimized.

Copy link

@jayemiuesesou jayemiuesesou commented Dec 16, 2017

Just remove the following

# Use MD5 Authentication
sudo sed -i.bak -e 's/ident$/md5/' -e 's/peer$/md5/' /var/lib/pgsql9/data/pg_hba.conf

because it changes the way postgres will authenticate to the local server. Just skip it for the moment.

Now, you could change the postgres password:

$ sudo -u postgres psql postgres
postgres=# \password postgres

You'll see:

Enter new password:
Enter it again:

Then go back to ec2-user and now change the pg_hba.conf to activate the MD5 Authentication:

# Use MD5 Authentication
sudo sed -i.bak -e 's/ident$/md5/' -e 's/peer$/md5/' /var/lib/pgsql9/data/pg_hba.conf

Restart the service, so the changes to be applied:
sudo service postgresql start

Finally, you will be able to login using your new password for postgres user:
psql -U postgres

@worldofprasanna

This comment has been minimized.

Copy link

@worldofprasanna worldofprasanna commented Sep 8, 2018

Useful script ... And FYI - with psql (PostgreSQL) 9.2.23, the recommended way to initialise the database cluster is sudo postgresql-setup initdb instead of sudo service postgresql initdb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment