Skip to content

Instantly share code, notes, and snippets.

@yoyozi
Last active July 29, 2017 20:09
Show Gist options
  • Save yoyozi/39c5d490fbbeda70d83f88a1503e52b8 to your computer and use it in GitHub Desktop.
Save yoyozi/39c5d490fbbeda70d83f88a1503e52b8 to your computer and use it in GitHub Desktop.
Create a Postgres user for the Rails app, switch into the Postgres user:
> sudo su postgres
Then login to the databse "postgres" with the adn\min of "postgres"
> psql -d postgres -U postgres
or > sudo -u postres psql
Then create a user (or a "role", as Postgres calls it):
create role myapp with createdb login password 'password1';
> ALTER user myapp with superuser;
> psql postgres
# create database test;
\l list databases
\c connect to database
To drop \c to another ie: postgres then : drop database test;
\q
If "peer authentication" does not work, try md5 authenticaion by editing conf file
vim /etc/postgresql/"pg_version"/main/pg_hba.conf
peer is local socket MD5 is using postgres username
To specify host try something like this:
> psql -d <dbname> -U <username> -h <hostname>
or this:
> psql -d <dbname> -U <username> -h <hostname> -W
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment