[Elixir/Ecto] Connect to Postgres using external url

I’m trying to connect to a Postgres instance from my Phoenix/Ecto app.

Postgres is already configured to accept connections from everywhere: 0.0.0.0/0

I did a first attempt with this basic configuration:

config :myapp, MyRepo,
  username: "-----",
  password: "-----",
  hostname: "---------.frankfurt-postgres.render.com",
  database: "----",
  pool_size: "10"

and trying to execute mix ecto.migrate it fails with this error [error] Postgrex.Protocol (#PID<0.208.0>) failed to connect: ** (Postgrex.Error) FATAL 28000 (invalid_authorization_specification) SSL/TLS required.

So I changed the config using some combination of SSL options, but it always fails.

Eg:

config :myapp, MyRepo,
  username: "-----",
  password: "-----",
  hostname: "---------.frankfurt-postgres.render.com",
  database: "----",
  pool_size: "10",
  ssl: true,
  ssl_opts: [
    verify: :verify_peer
  ]

[error] Postgrex.Protocol (#PID<0.207.0>) failed to connect: ** (DBConnection.ConnectionError) ssl connect: Options (or their values) can not be combined: [{verify,verify_peer}, {cacerts,undefined}] - {:options, :incompatible, [verify: :verify_peer, cacerts: :undefined]}
config :myapp, MyRepo,
  username: "-----",
  password: "-----",
  hostname: "---------.frankfurt-postgres.render.com",
  database: "----",
  pool_size: "10",
  ssl: true,
  ssl_opts: [
    verify: :verify_none
  ]

[error] Postgrex.Protocol (#PID<0.208.0>) failed to connect: ** (DBConnection.ConnectionError) ssl recv (idle): closed

What am I missing? Someone could help me?

ELIXIR_VERSION: 1.16.1
OTP_VERSION: 26.2.2

Hi lorenzomar,

Based on the :incompatible, [verify: :verify_peer, cacerts: :undefined] error you included, it sounds like you might try leaving out the ssl_opts altogether or consulting the docs for that library to get the right configs.

Regards,

Matt