Skip to content

Instantly share code, notes, and snippets.

@jonathanpike
Last active February 28, 2018 00:59
Show Gist options
  • Save jonathanpike/7d1aca88cc5dffc0cfa7 to your computer and use it in GitHub Desktop.
Save jonathanpike/7d1aca88cc5dffc0cfa7 to your computer and use it in GitHub Desktop.
Cloud9 Postgres Setup with Standard Postgres and Rails Settings

Set Up Postgresql on Cloud9 Online IDE

Start Postgresql on Cloud9

Type sudo service postgresql start

Set Up User

A default Postgres installation has a user account with the following information:

Username: username

Password: password

There are 2 problems to solve with the Cloud9 (C9) Postgres installation:

  1. The Postgres on C9 doesn't have password as the password for the root user
  2. The Postgres on C9 is encoded in ASCII instead of UTF8

To fix #1, do the following:

Type sudo sudo -u postgres psql into the console, which will bring you into the Postgres interactive terminal

Then, you type ALTER USER postgres WITH PASSWORD 'password';. It should spit out ALTER ROLE if you did it right.

To fix #2, do the following:

Copy and paste these commands into the Postgres interactive terminal one by one:

UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';

DROP DATABASE template1;

CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';

UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';

\c template1

VACUUM FREEZE;

UPDATE pg_database SET datallowconn = FALSE WHERE datname = 'template1';

Once your done, just type \q to get out of the Postgres interactive terminal

Set Up Rails Databases

Type rake db:create:all

@GHAC3388
Copy link

That fixed the new encoding (UTB8) is incompatible with the encoding of the template database issue. Thanks!
However there's still a FATAL: Peer authentication failed for user "XXXX" error showing. How should I go about in fixing this error?

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