anon36077568

anon36077568

Cannot Get Ecto/Postgrex to Connect to PostgreSQL

The Problem

I am following the Getting Started Guide at https://hexdocs.pm/ecto/getting-started.html, trying to set up in a docker container. The steps in the guide work on my physical machine, but when I follow them for the container, I get the following error when I run mix ecto.create at the appropriate step:

04:48:05.579 [error] GenServer #PID<0.177.0> terminating
** (RuntimeError) Connect raised a FunctionClauseError error. The exception details are hidden, as
they may contain sensitive data such as database credentials.

    (postgrex) lib/postgrex/messages.ex:371: Postgrex.Messages.decode_auth_type/1
    (postgrex) lib/postgrex/messages.ex:64: Postgrex.Messages.parse/3
    (postgrex) lib/postgrex/protocol.ex:2004: Postgrex.Protocol.msg_decode/1
    (postgrex) lib/postgrex/protocol.ex:1978: Postgrex.Protocol.msg_recv/3
    (postgrex) lib/postgrex/protocol.ex:589: Postgrex.Protocol.auth_recv/3
    (postgrex) lib/postgrex/protocol.ex:504: Postgrex.Protocol.handshake/2
    (db_connection) lib/db_connection/connection.ex:135: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
Last message: nil
** (Mix) The database for Friends.Repo couldn't be created: an exception was raised:
    ** (RuntimeError) Connect raised a FunctionClauseError error. The exception details are hidden, as
they may contain sensitive data such as database credentials.

        (postgrex) lib/postgrex/messages.ex:371: Postgrex.Messages.decode_auth_type/1
        (postgrex) lib/postgrex/messages.ex:64: Postgrex.Messages.parse/3
        (postgrex) lib/postgrex/protocol.ex:2004: Postgrex.Protocol.msg_decode/1
        (postgrex) lib/postgrex/protocol.ex:1978: Postgrex.Protocol.msg_recv/3
        (postgrex) lib/postgrex/protocol.ex:589: Postgrex.Protocol.auth_recv/3
        (postgrex) lib/postgrex/protocol.ex:504: Postgrex.Protocol.handshake/2
        (db_connection) lib/db_connection/connection.ex:135: DBConnection.Connection.connect/2
        (connection) lib/connection.ex:622: Connection.enter_connect/5

The Situation/Configuration

I have set up Postgres in my docker container so that the postgres user has a password, and I have used that password in the config/config.exs file. I know the password works, as I can use psql with it. The config file mentioned looks like this:

use Mix.Config

config :friends, Friends.Repo,
  adapter: Ecto.Adapters.Postgres,
  database: "friends_repo",
  username: "postgres",
  password: "<password>",
  hostname: "localhost"


config :friends, ecto_repos: [Friends.Repo]

Now, since there is always a request for the pg_hba.conf file in similar situations, I provide that below. (As this is a development machine, I am less concered about security than I am about getting something working in the first place.)

local   all             postgres                                md5
# 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
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

Finally, the following are the versions of related applications and tools.

Postgres

                                                    version
-----------------------------------------------------------------------------------------------------------------------------
     PostgreSQL 10.5 (Ubuntu 10.5-0ubuntu0.18.04) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.3.0-16ubuntu3) 7.3.0, 64-bit

Elixir

Erlang/OTP 21 [erts-10.0.5] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Elixir 1.7.2 (compiled with Erlang/OTP 20)

Running Command: mix deps.update

Resolving Hex dependencies...
Dependency resolution completed:
Unchanged:
  connection 1.0.4
  db_connection 1.1.3
  decimal 1.5.0
  ecto 2.2.10
  poolboy 1.5.1
  postgrex 0.13.5

Final Notes

I’ve read similar topics and problems on this forum, on github, and other places found from Google, but the answers I found did not help. Thus, my hope is that someone here can provide some direction and help get things working.

Thank you in advance.

Most Liked

pedromvieira

pedromvieira

I just followed the guide and it seems pretty good.
Can you verify your connections ports or share a git with only the parts needed?

Where Next?

Popular in Questions Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
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
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
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
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
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
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
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement