Yeah something weird is going on. I haven’t done a clean install for a while, just update after (MacOS) update - I generally hate settling with updates as things always break and start to feel sluggish after a while. But Apple being Apple have made clean installs harder - last time a clean install totally broke my email settings and I had to report it as a bug to get an answer on fixing it! I’ll only do a clean install now if I have a week or two spare
Reason I posted the thread here is because when searching I noticed someone had commented they got the same error after running mix ecto.create too! So thought having it more easily and directly google-able might help others in future
Agreed, but the Homebrew installation creates a SQL user named after your OS user and no “postgres” user to go with it. Just something to document and be aware of like @AstonJ has done here
So for me the disconnect is that the generators hard-code the literal value of “postgres” for username on the Ecto connection, but really what it needs is a SQL user that is a superuser or that has DB creation rights. I would prefer some explicitness/agnosticism in that direction be included in the Phoenix generator output, and/or in the Hex docs, instead of assuming I’ve left the default “postgres” user intact and with superuser privileges.
I don’t do that on my dev workstation or my production DB either, so I wind up using a Repo.init/2 callback and a DATABASE_URL basically immediately on new projects.
Not sure. I installed PG through homebrew as well and I seem to remember it having the postgres user and a fresh Phoenix app working right away. But then again, that was a while ago, can’t swear the details on my life.
As for the Ecto default, you’re not wrong but then again they apply for local-only config so I see no harm done.
But if you’re working on a shared project, you’re probably better off with everyone using the postgres user locally, or not setting one at all (which I think will default to the logged in user)
Just create a user: createuser --superuser postgres
check with the psql:
$ psql default
psql (14.1)
Type "help" for help.
default=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB | {}
my_username | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
I just stumbled on this issue after returning to Elixir/Phoenix and reinstalling everything from scratch. The solution was to change the database config username in dev.exs from postgres to my macOS username.