Patoshizzle

Patoshizzle

(Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user “postgres”

After calling mix ecto.create I get this error:

17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
    (db_connection 2.4.1) 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

17:00:32.215 [error] GenServer #PID<0.420.0> terminating
** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
    (db_connection 2.4.1) 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

I thought the database creates the default user postgres are created automatically, why would it fail
authentication. The password according to the config files is postgres

Thanks! :smiley:

Most Liked

silverdr

silverdr

FWIW - I just tried to set a quick test project up and I recalled the discussion here so I thought I’d check it. Therefore I left both user and password at the default “postgres” and encountered the same issue/errors OP described in his first post. The solution in my case:

silverdr$ sudo -u postgres psql
psql (12.9 (Ubuntu 12.9-0ubuntu0.20.04.1))
Type "help" for help.

postgres=# \password postgres
Enter new password: 
Enter it again: 
postgres=# \q
silverdr$ mix ecto.create
Compiling 29 files (.ex)
Generated testapp app
The database for Testapp.Repo has been created

IOW - altering the ROLE “postgres” to have password “postgres” helped immediately. This is basically the same what @inko mentioned: if you want to use the “postgres” role, give it the password you have cofigured in the Elixir application config.

silverdr

silverdr

You need to check what “ROLES” your Postgres installation has available, and possibly create a suitable one. PostgreSQL docs say:

In order to bootstrap the database system, a freshly initialized system always contains one predefined role. This role is always a “superuser”, and by default (unless altered when running initdb ) it will have the same name as the operating system user that initialized the database cluster. Customarily, this role will be named postgres .

This means it is neither guaranteed for every PostgreSQL installation to have the postgres “role” nor it is guaranteed for it to have “postgres” as password, even if it exists.

Patoshizzle

Patoshizzle

I have confirmed thru \du that indeed a user postgres exists, i created (i am not sure if actually ecto was the one supposed to create) a database with the same name in the dev.exs in the config directory and logged in using the password postgress and the log in was successful.

I returned to my elixir/phoenix app and run mix ecto.create and the same error “password authentication failed for user postgres”.

Any other hint or solution is welcome.

silverdr

silverdr

“postgress” or “postgres”? Make sure the spelling is correct.

What environment is that? OS? Showing the config section and the relevant parts of pg_hba.conf can help too.

Yes, mix ecto.create should create the database for you.

silverdr

silverdr

Here’s my config that works on a similar (Debian based) system. I am on v12 here but things should work well with earlier versions too. Certainly no need to go v14 (are you sure you didn’t mess anything up with your cluster’s config when mixing the versions?):

Config files/permissions

$ ll /etc/postgresql/12/main/
total 64
drwxr-xr-x 3 postgres postgres  4096 Sep 30 07:51 ./
drwxr-xr-x 3 postgres postgres  4096 Sep 30 07:42 ../
drwxr-xr-x 2 postgres postgres  4096 Sep 30 07:42 conf.d/
-rw-r--r-- 1 postgres postgres   315 Sep 30 07:42 environment
-rw-r--r-- 1 postgres postgres   143 Sep 30 07:42 pg_ctl.conf
-rw-r----- 1 postgres postgres  4933 Sep 30 07:42 pg_hba.conf
-rw-r----- 1 postgres postgres  1636 Sep 30 07:42 pg_ident.conf
-rw-r--r-- 1 postgres postgres 26864 Sep 30 07:42 postgresql.conf
-rw-r--r-- 1 postgres postgres   317 Sep 30 07:42 start.conf

pg_hba.conf

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

Example Phoenix app config:

# Configure your database
config :myapp, Myapp.Repo,
  username: "silverdr",
  password: "silverdr",
  database: "myapp_dev",
  hostname: "localhost",
  show_sensitive_data_on_connection_error: true,
  pool_size: 10
  [...]

Yes, I have my “system user” there - that’s what I typically do rather than running as “root” / “superuser” in Postgres terminology. But I believe it should work with “superuser” too. Yet - if everything else fails you could try adding your own user (“ROLE”) with appropriate password and privileges. In any case - that works (and always worked) for me flawlessly on a Debian based systems.

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement