Может подключаться к контейнеру Postgres через оболочку, но не через приложение Phoenix - PullRequest
0 голосов
/ 11 июня 2019

У меня запущен контейнер postgres с этой конфигурацией:

# Version of docker-compose
version: '3'

# Containers we are going to run
services:
  db:
    # We use the predefined Postgres image
    image: postgres:12
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: postgres_db
    ports:
      - 5432:5432
    restart: on-failure

И я могу подключиться через локальную оболочку за пределами контейнера, как и ожидалось, поскольку порты 5432 открыты:

psql -h localhost postgres_db postgres

Но странно, что Phoenix не может подключиться, конфигурация Phoenix следующая:

# Configure your database
config :phoenix_chat, PhoenixChat.Repo
  username: "postgres",
  password: "postgres",
  database: "postgres_db",
  hostname: "localhost",
  pool_size: 10,
  # Help diagnose connection errors:
  show_sensitive_data_on_connection_error: true

Вылетает с этим:

Generated phoenix_chat app
[error] GenServer #PID<0.382.0> terminating
** (ArgumentError) argument error
    :erlang.binary_to_integer("12beta1")
    (elixir) lib/enum.ex:1327: Enum."-map/2-lists^map/1-0-"/2
    (postgrex) lib/postgrex/utils.ex:68: Postgrex.Utils.parse_version/1
    (postgrex) lib/postgrex/protocol.ex:796: Postgrex.Protocol.bootstrap_send/6
    (postgrex) lib/postgrex/protocol.ex:577: Postgrex.Protocol.handshake/2
    (db_connection) lib/db_connection/connection.ex:66: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
[error] GenServer #PID<0.414.0> terminating
** (ArgumentError) argument error
    :erlang.binary_to_integer("12beta1")
    (elixir) lib/enum.ex:1327: Enum."-map/2-lists^map/1-0-"/2
    (postgrex) lib/postgrex/utils.ex:68: Postgrex.Utils.parse_version/1
    (postgrex) lib/postgrex/protocol.ex:796: Postgrex.Protocol.bootstrap_send/6
    (postgrex) lib/postgrex/protocol.ex:577: Postgrex.Protocol.handshake/2
    (db_connection) lib/db_connection/connection.ex:66: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
[error] Postgrex.Protocol (#PID<0.380.0>) failed to connect: ** (DBConnection.ConnectionError) awaited on another connection that failed to bootstrap types
[error] Postgrex.Protocol (#PID<0.384.0>) failed to connect: ** (DBConnection.ConnectionError) awaited on another connection that failed to bootstrap types
[error] Postgrex.Protocol (#PID<0.383.0>) failed to connect: ** (DBConnection.ConnectionError) awaited on another connection that failed to bootstrap types
[error] Postgrex.Protocol (#PID<0.388.0>) failed to connect: ** (DBConnection.ConnectionError) awaited on another connection that failed to bootstrap types
[error] Postgrex.Protocol (#PID<0.385.0>) failed to connect: ** (DBConnection.ConnectionError) awaited on another connection that failed to bootstrap types
[error] Postgrex.Protocol (#PID<0.389.0>) failed to connect: ** (DBConnection.ConnectionError) awaited on another connection that failed to bootstrap types
[error] Postgrex.Protocol (#PID<0.381.0>) failed to connect: ** (DBConnection.ConnectionError) awaited on another connection that failed to bootstrap types
[error] Postgrex.Protocol (#PID<0.387.0>) failed to connect: ** (DBConnection.ConnectionError) awaited on another connection that failed to bootstrap types
[error] Postgrex.Protocol (#PID<0.386.0>) failed to connect: ** (DBConnection.ConnectionError) awaited on another connection that failed to bootstrap types
[error] GenServer #PID<0.416.0> terminating
** (ArgumentError) argument error
    :erlang.binary_to_integer("12beta1")
    (elixir) lib/enum.ex:1327: Enum."-map/2-lists^map/1-0-"/2
    (postgrex) lib/postgrex/utils.ex:68: Postgrex.Utils.parse_version/1
    (postgrex) lib/postgrex/protocol.ex:796: Postgrex.Protocol.bootstrap_send/6
    (postgrex) lib/postgrex/protocol.ex:577: Postgrex.Protocol.handshake/2
    (db_connection) lib/db_connection/connection.ex:66: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
[error] GenServer #PID<0.417.0> terminating
** (ArgumentError) argument error
    :erlang.binary_to_integer("12beta1")
    (elixir) lib/enum.ex:1327: Enum."-map/2-lists^map/1-0-"/2
    (postgrex) lib/postgrex/utils.ex:68: Postgrex.Utils.parse_version/1
    (postgrex) lib/postgrex/protocol.ex:796: Postgrex.Protocol.bootstrap_send/6
    (postgrex) lib/postgrex/protocol.ex:577: Postgrex.Protocol.handshake/2
    (db_connection) lib/db_connection/connection.ex:66: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
[info] Running PhoenixChatWeb.Endpoint with cowboy 2.6.3 at 0.0.0.0:4000 (http)
[info] Access PhoenixChatWeb.Endpoint at http://localhost:4000
[error] GenServer #PID<0.524.0> terminating
** (ArgumentError) argument error
    :erlang.binary_to_integer("12beta1")
    (elixir) lib/enum.ex:1327: Enum."-map/2-lists^map/1-0-"/2
    (postgrex) lib/postgrex/utils.ex:68: Postgrex.Utils.parse_version/1
    (postgrex) lib/postgrex/protocol.ex:796: Postgrex.Protocol.bootstrap_send/6
    (postgrex) lib/postgrex/protocol.ex:577: Postgrex.Protocol.handshake/2
    (db_connection) lib/db_connection/connection.ex:66: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
[error] GenServer #PID<0.530.0> terminating
** (ArgumentError) argument error
    :erlang.binary_to_integer("12beta1")
    (elixir) lib/enum.ex:1327: Enum."-map/2-lists^map/1-0-"/2
    (postgrex) lib/postgrex/utils.ex:68: Postgrex.Utils.parse_version/1
    (postgrex) lib/postgrex/protocol.ex:796: Postgrex.Protocol.bootstrap_send/6
    (postgrex) lib/postgrex/protocol.ex:577: Postgrex.Protocol.handshake/2
    (db_connection) lib/db_connection/connection.ex:66: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
[error] GenServer #PID<0.527.0> terminating
** (ArgumentError) argument error
    :erlang.binary_to_integer("12beta1")
    (elixir) lib/enum.ex:1327: Enum."-map/2-lists^map/1-0-"/2
    (postgrex) lib/postgrex/utils.ex:68: Postgrex.Utils.parse_version/1
    (postgrex) lib/postgrex/protocol.ex:796: Postgrex.Protocol.bootstrap_send/6
    (postgrex) lib/postgrex/protocol.ex:577: Postgrex.Protocol.handshake/2
    (db_connection) lib/db_connection/connection.ex:66: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: nil

Я также пытался подключиться через iex оболочку, используя postgrex

{:ok, pid} = Postgrex.start_link(hostname: "localhost", username: "postgres", password: "postgres", database: "postgres_db")

Но это также выдает ту же ошибку.

контейнер postgres выводит следующие ошибки:

db_1  | 2019-06-11 12:38:05.127 UTC [542] LOG:  PID 528 in cancel request did not match any process
db_1  | 2019-06-11 12:38:05.205 UTC [557] LOG:  PID 549 in cancel request did not match any process
db_1  | 2019-06-11 12:38:05.244 UTC [575] LOG:  PID 570 in cancel request did not match any process

1 Ответ

0 голосов
/ 11 июня 2019
iex(1)> :erlang.binary_to_integer("12beta1")
** (ArgumentError) argument error
    :erlang.binary_to_integer("12beta1")

iex(1)> :erlang.binary_to_integer("12")     
12

iex(2)> :erlang.binary_to_integer("12a")
** (ArgumentError) argument error
    :erlang.binary_to_integer("12a")

iex(2)> 

Вы назвали что-то "12beta1"? Если это поможет, вот мой конфигурационный файл:

config :auction, ecto_repos: [Auction.Repo]

config :auction, Auction.Repo,
  database: "auction",
  username: "7stud",
  password: "",
  hostname: "localhost",
  port: "5432"

Мое приложение является зонтичным приложением, в котором приложение phoenix auction_web не использует базу данных, а приложение auction и его пользовательский интерфейс используют базу данных, и эта конфигурация БД находится в auction_umbrella/apps/auction/config/config.exs. Приложение auction_web является другим приложением в каталоге auction_umbrella/apps.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...