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
Ah that explains why when using Rails it works fine - because I guess they use your account name user rather than āpostgresā.
I wonder if Ecto could detect whether youāre using OSX and do the same? Otherwise every Mac user who have installed PG via homebrew will get the same.
Alternatively maybe hombrew could create the postgres role on installation too?
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 | {}