Setup PostgreSQL database

PostgresSQL, or simply Postgres, is a relational database. It's the de facto standard for SQL databases, and is the preferred SQL database of Mashup Garage.

postgres credentials

Phoenix projects default to connecting to Postgres with the username postgres and password postgres. This isn't so easy to override, so let's just keep that as the default.

macOS setup

The easiest way to install PostgreSQL is through Homebrew.

Install postgres

In macOS, use Homebrew to install it.

# OSX only
brew install postgres

Start postgres

Use homebrew/services to start Postgres. Optional but recommended.

# OSX only
brew tap homebrew/services
brew services start postgres

Create a postgres user

Use PostgreSQL's createuser to create a new user. Give it a password postgres.

$ createuser --superuser postgres -P
  Enter password for new role:
  Enter it again:

Linux/Windows (via Docker)

The preferred way to get PostgreSQL working on Linux is through Docker.

Install Docker

See the Docker playbook page for details.

Create docker-compose.yml

Create a file called docker-compose.yml in the root of your project:

version: '3'
services:
  db:
    image: postgres
    ports:
      - '5432:5432'
    volumes:
      - 'pgdata:/var/lib/postgresql/data'
    environment:
      POSTGRES_PASSWORD: postgres
volumes:
  pgdata:

Run it

Run it using docker-compose:

docker-compose up