Skip to content

Instantly share code, notes, and snippets.

@th0j
Last active June 10, 2018 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save th0j/ac910e46918c3496a9f0c8bf35f04b7c to your computer and use it in GitHub Desktop.
Save th0j/ac910e46918c3496a9f0c8bf35f04b7c to your computer and use it in GitHub Desktop.
How to connect PostgreSQL on EC2

Update pg_hba.conf as described in the previous section:

sudo vim /etc/postgresql/9.1/main/pg_hba.conf

Update the bottom of the file, which will read something like this, by default:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     ident
# IPv4 local connections:
host    all             all             127.0.0.1/32            ident
# IPv6 local connections:
host    all             all             ::1/128                 ident

To read this:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             power_user      0.0.0.0/0               md5
host    all             other_user      0.0.0.0/0               md5
host    all             storageLoader   0.0.0.0/0               md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

Update postgresql.conf as in the previous section

sudo vim /etc/postgresql/9.1/main/postgresql.conf

Uncomment line 59:

#listen_addresses = 'localhost'          # what IP address(es) to listen on;

And update the line to enable connections from any IP address:

listen_addresses='*'

And uncomment line 63:

#port = 5432

So it reads

port = 5432

Then restart PostgreSQL:

 sudo /etc/init.d/postgresql restart

Log into PostgreSQL:

$ sudo su - postgres
$ psql

Update your Postres user credentials:

Now we need to create user credentials for our different users. Power users will be able to do anything (these are really admins.) "Other users" will be suitable for analysts who wish to query the data. We also create a particular user with limited access for the storageloader - these credentials will be used just to load Snowplow data into Postgres.

CREATE USER power_user SUPERUSER;
ALTER USER power_user WITH PASSWORD '$poweruserpassword';
CREATE USER other_user NOSUPERUSER;
ALTER USER other_user WITH PASSWORD '$otheruserpassword';
CREATE DATABASE snowplow WITH OWNER other_user;
CREATE USER storageloader PASSWORD '$storageloaderpassword';
\q

READ MORE at: https://github.com/snowplow/snowplow/wiki/Setting-up-PostgreSQL

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