|||

Rake Routes

by Stephen Ball

Elixir Phoenix and role postgres does not exist”

If you’re trying to follow along the Elixir Phoenix Up and Running guide you may run straight into this error if you’re using homebrew’s Postgres install when you run mix ecto.create

$ mix ecto.create
18:54:52.762 [error] GenServer #PID<0.292.0> terminating
** (Postgrex.Error) FATAL 28000 (invalid_authorization_specification) role "postgres" does not exist
    (db_connection 2.4.0) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.15.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

18:54:52.773 [error] GenServer #PID<0.299.0> terminating
** (Postgrex.Error) FATAL 28000 (invalid_authorization_specification) role "postgres" does not exist
    (db_connection 2.4.0) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.15.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
** (Mix) The database for Hello.Repo couldn't be created: killed

That’s not ideal! The core issue in that stack trace error is role "postgres" does not exist

There’s a couple of ways to fix the problem.

One: Fix the Phoenix config to match up with homebrew

Open config/dev.exs and change the config to have your username and a blank password.

By default Phoenix assumes postgres” for the username and password.

config :hello, Hello.Repo,
  username: "sdball",
  password: "",
  database: "hello_dev",
  hostname: "localhost",
  show_sensitive_data_on_connection_error: true,
  pool_size: 10

Two: Fix the postgres config to match up with Phoenix

  1. Connect to postgres
$ psql -d postgres
  1. Create the postgres” user
CREATE ROLE postgres LOGIN CREATEDB;
  1. (ctrl-d) to close the connection to postgres

Things should be working!

After either fix you should be able to create the postgres database!

$ mix ecto.create

The database for Hello.Repo has been created
Up next From awk to a Dockerized Ruby Script For a programming project I wanted to easily get a list of the printable ASCII characters such that I could easily loop through them and do some Containers in the real world and backpressure in distributed systems Did you ever think that a city’s zoning laws could potentially affect the entire global economy? This fascinating Twitter thread goes into details
Latest posts Where did the recent Elixir posts go? A subtle Go bug that types cannot help with swapcase with the tr command nice go test output See where vim settings came from Containers in the real world and backpressure in distributed systems Elixir Phoenix and “role postgres does not exist” From awk to a Dockerized Ruby Script Finding leap years with the cal command The Problem of State Clojure Functions in Four Ways See Some Clojure A simple language spec isn’t a feature when you’re building applications The Fastest Possible Tests Shrink your data into bitfields (and out again) Every “if” statement is an object waiting to be extracted Choose Generic Tools Hyperlinks you might find interesting — #4 Running bundle install on rails master Use tldr for command line examples Friday Lunch Links — #3 Friday Lunch Links — #2 Logical Solver: Turn facts into conclusions Programming with jq Command line tools - jq Friday Lunch Links — #1 Why diversity matters Music for coding - October 2019 Code puzzles are a poor way to gauge technical candidates Add vim to a pipeline with vipe Connecting Objects with Observable