An error message when running the "mix ecto.create" command

Hi!

I’m new here.

I was reading this page:

https://hexdocs.pm/phoenix/up_and_running.html

And then, when I tried to run it, I’ve got this message:

19:26:35.127 [error] GenServer #PID<0.259.0> terminating
** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user “postgres”
(db_connection 2.3.0) lib/db_connection/connection.ex:99: DBConnection.Connection.connect/2
(connection 1.0.4) lib/connection.ex:622: Connection.enter_connect/5
(stdlib 3.13.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

===

Does anybody know how can I fix?

Thank you for any help.

Alexandre.

#phoenix #mix #ecto.create

I’m assuming you’re on windows, Go into Program Files/PostgreSQL/12/data . Find and open the pg_hba.conf . Scroll to the bottom, and change the row with 127.0.0.1/32. Change the method from md5 to trust. Obviously, don’t do this on a production setup.

Loopers97, hi!

Thank you so much for your answer to my problem!

My O. S. is Debian Unstable/Sid (a Linux distro).

I’ve searched for this file using this command:

psql -t -P format=unaligned -c ‘show hba_file’

I saw this tip in the following website:

https://askubuntu.com/questions/256534/how-do-i-find-the-path-to-pg-hba-conf-from-the-shell

And then, I found out where it is:

/etc/postgresql/13/main/pg_hba.conf

Well, I made the changes, but I’ve got the same error message:

===

debian@sid:~/hello/hello$ mix ecto.create

23:47:49.715 [error] GenServer #PID<0.259.0> terminating
** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user “postgres”
(db_connection 2.3.0) lib/db_connection/connection.ex:99: DBConnection.Connection.connect/2
(connection 1.0.4) lib/connection.ex:622: Connection.enter_connect/5
(stdlib 3.13.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

===

Alexandre.

I’m assuming you restarted the service after making the config change.

The logs makes it appear like the db is the issue, not ecto if that helps.

Try following this links guide. See if you can log in as postgres and get psql in the terminal. That’ll take ecto out from being a suspect.

Hi again Looper97!

today I made some progress!
I didn’t restarted the service, so, I googled to know how to do this. And then I followed the instructions on this page:
https://avroblog.com/en/blog/content/How-to-restart-PostgreSQL

And now, when I type the “mix ecto.create” command, the error message is different:

===

** (Mix) The database for Hello.Repo couldn’t be created: ERROR 22023 (invalid_parameter_value) encoding “UTF8” does not match locale “en_GB”

The chosen LC_CTYPE setting requires encoding “LATIN1”.

===

I will google again and try to find a solution, then I come back here and post what I found.

Thank you!

Hi again Loopers97!

Unfortunately, I was not sucessful… I regenerated my locales, using this command:

cd /usr/sbin

./dpkg-reconfigure locales

./locale-gen

But the error messages still are displayed to me:

===

** (Mix) The database for Hello.Repo couldn’t be created: ERROR 22023 (invalid_parameter_value) encoding “UTF8” does not match locale “en_GB”

The chosen LC_CTYPE setting requires encoding “LATIN1”.

===

I still need help …
Have you ever seen this problem before?

Progress is good. You’re dangerously close to getting postgres beat. The locale would have been set on the installation of postgres. I’m not sure what postgres locale defaults to. I’d recommend going digging into etc/lang.

Type locale and dump the output. I’m wondering if they’re all en_US.UTF-8

Here are the official docs for locale
https://www.postgresql.org/docs/13/locale.html

tl;dr
The values that are chosen by initdb are actually only written into the configuration file postgresql.conf to serve as defaults when the server is started. If you remove these assignments from postgresql.conf then the server will inherit the settings from its execution environment. (server)

Always have the option to Nuke and pick the locale, now that you have gained some more knowledge.

Hi again!

I have a lot of news to you!
Let’s go:

1) This is the what I get when I run the command locale:

debian@sid:~$ locale
LANG=en_GB
LANGUAGE=
LC_CTYPE=“en_GB”
LC_NUMERIC=“en_GB”
LC_TIME=“en_GB”
LC_COLLATE=“en_GB”
LC_MONETARY=“en_GB”
LC_MESSAGES=“en_GB”
LC_PAPER=“en_GB”
LC_NAME=“en_GB”
LC_ADDRESS=“en_GB”
LC_TELEPHONE=“en_GB”
LC_MEASUREMENT=“en_GB”
LC_IDENTIFICATION=“en_GB”
LC_ALL=
debian@sid:~$

2) Then I typed these commands in aterm:

root@sid:/usr/sbin# pg_dropcluster --stop 13 main
root@sid:/usr/sbin# pg_createcluster --locale en_GB.UTF-8 --start 13 main
Creating new PostgreSQL cluster 13/main …
/usr/lib/postgresql/13/bin/initdb -D /var/lib/postgresql/13/main --auth-local peer --auth-host md5 --locale en_GB.UTF-8
The files belonging to this database system will be owned by user “postgres”.
This user must also own the server process.

The database cluster will be initialized with locale “en_GB.UTF-8”.
The default database encoding has accordingly been set to “UTF8”.
The default text search configuration will be set to “english”.

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/13/main … ok
creating subdirectories … ok
selecting dynamic shared memory implementation … posix
selecting default max_connections … 100
selecting default shared_buffers … 128MB
selecting default time zone … America/Sao_Paulo
creating configuration files … ok
running bootstrap script … ok
performing post-bootstrap initialization … ok
syncing data to disk … ok

Success. You can now start the database server using:

pg_ctlcluster 13 main start

Ver Cluster Port Status Owner Data directory Log file
13 main 5432 online postgres /var/lib/postgresql/13/main /var/log/postgresql/postgresql-13-main.log
root@sid:/usr/sbin# pg_ctlcluster 13 main start

3) Then, I tried the mix command again, and guess what? The first error message, I almost died:

debian@sid:~/hello/hello$ mix ecto.create

11:52:57.370 [error] GenServer #PID<0.259.0> terminating
** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user “postgres”
(db_connection 2.3.0) lib/db_connection/connection.ex:99: DBConnection.Connection.connect/2
(connection 1.0.4) lib/connection.ex:622: Connection.enter_connect/5
(stdlib 3.13.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
debian@sid:~/hello/hello$

4) But then, I did what you’ve told, and changed the file called pg_hba.conf with the “trust” value;

5) Then I restarted the postgrsql using the command systemctl restart postgresql in Debian.

6) Then I came back to the “hello” directory and tried to type the “mix ecto.create” again… and then… Finally!!!

7) Everything is fine now!!!

I will try to paste a screenshot of my term in this post:

I couldn’t have done it without your help… Thank you so much for your patience…

Now I will be able to follow the other steps on the tutorial I was reading.

A BIG, BIG Thank you!

A bright and happy week for you and your family!!!

Alexandre.

That’s great news, happy coding.

Thanks a lot! I have found my PostgreSQL folder and changed which made it working!
My PostgreSQL was installed at a different derive which is surprising to me.

The default Phoenix setup uses username and password set to “postgres”. The problem is that vanilla PostgreSQL setup does not have this particular password set for the superuser role “postgres”. Either:

  • set the desired password (“postgres”) for the user/role “postgres”
  • add your own user (role) to the DB with your own username and password. Give it only necessary privileges, and update the dev.exs (or other, appropriate config file) accordingly

I always do the latter. YMMV.

1 Like

Thank you!! I was getting the same error as OP, and I was able to fix it with ALTER USER postgres WITH PASSWORD 'postgres'; (from SO) thanks to your comment.