Skip to content

Instantly share code, notes, and snippets.

@ray-sh
Forked from ibraheem4/postgres-brew.md
Last active October 6, 2020 13:55
Show Gist options
  • Save ray-sh/285d7a4621f1c5d434a2342b7aa9a26b to your computer and use it in GitHub Desktop.
Save ray-sh/285d7a4621f1c5d434a2342b7aa9a26b to your computer and use it in GitHub Desktop.
Prepare postgres for phoenix

Prepare Postgres for phoenix

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update

Installing

  1. In your command-line run the command: brew install postgresql
  2. mkdir /usr/local/var/postgres; initdb /usr/local/var/postgres
  3. pg_ctl -D /usr/local/var/postgres start/ pg_ctl -D /usr/local/var/postgres stop
  4. psql postgres # login mgmt console
  5. Create role for pheonix use create ROLE health WITH LOGIN PASSWORD 'health'; ALTER ROLE health CREATEDB; ##change default postgres password in ubuntu 1.sudo -u postgres psql 2.postgres=# ALTER USER postgres PASSWORD 'postgres'; ALTER ROLE

Configure your database

  1. update the config/dev.exs so that phoenix could init db repo for you
 config :health, Health.Repo,
  username: "health",
  password: "health",
  database: "health",
  hostname: "localhost",
  pool_size: 10
  1. check the db from psql
health-# \l #list the db
                           List of databases
   Name    |  Owner  | Encoding | Collate | Ctype |  Access privileges
-----------+---------+----------+---------+-------+---------------------
 health    | health  | UTF8     | C       | UTF-8 |
 postgres  | leiding | UTF8     | C       | UTF-8 |

postgres=# \c health #switch to the db
You are now connected to database "health" as user "leiding".

\dt # list the table

Details

As the default configuration of Postgres is, a user called postgres is made on and the user postgres has full superadmin access to entire PostgreSQL instance running on your OS by using psql postgres, by default, it don't require password

Details: https://www.postgresql.org/docs/9.3/sql-createrole.html https://www.postgresql.org/docs/9.3/sql-alterrole.html

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