Connecting to Supabase database

When I try to connect to our Supabase database instance I get following error:

2022-04-26T14:40:52.358 app[3f13593c] lax [info] 14:40:52.357 [error] Postgrex.Protocol (#PID<0.2106.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (db.xxx.supabase.co:5432): non-existing domain - :nxdomain

2022-04-26T14:40:55.630 app[3f13593c] lax [info] 14:40:55.629 [error] Postgrex.Protocol (#PID<0.2114.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (db.xxx.supabase.co:5432): non-existing domain - :nxdomain

2022-04-26T14:40:57.079 app[3f13593c] lax [info] 14:40:57.077 [error] Postgrex.Protocol (#PID<0.2112.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (db.xxx.supabase.co:5432): non-existing domain - :nxdomain

I am not able to figure why it won’t resolve the DNS. Anyone who can provide any information on this?

I have been fiddling with:

  • inet6 stuff
  • recreated the instance

can you share your repo config from config/runtime.exs? (pruned sensitive info if necessary)

It is basically the default one:

import Config

if System.get_env("PHX_SERVER") do
  config :xxx, Xxx.Endpoint, server: true
end

if config_env() == :prod do
  database_url =
    System.get_env("DATABASE_URL") ||
      raise """
      environment variable DATABASE_URL is missing.
      For example: ecto://USER:PASS@HOST/DATABASE
      """

  maybe_ipv6 = if System.get_env("ECTO_IPV6"), do: [:inet6], else: []

  config :xxx, Xxx.Repo,
    ssl: true,
    url: database_url,
    pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
    socket_options: maybe_ipv6

  secret_key_base =
    System.get_env("SECRET_KEY_BASE") ||
      raise """
      environment variable SECRET_KEY_BASE is missing.
      You can generate one by calling: mix phx.gen.secret
      """

  host = System.get_env("PHX_HOST") || "example.com"
  port = String.to_integer(System.get_env("PORT") || "4000")

  config :xxx, Xxx.Endpoint,
    url: [host: host, port: 443, scheme: "https"],
    http: [
      ip: {0, 0, 0, 0, 0, 0, 0, 0},
      port: port
    ],
    secret_key_base: secret_key_base
end

Found the problem: Following was being appended in the Docker file

# Appended by flyctl
ENV ECTO_IPV6 true
ENV ERL_AFLAGS "-proto_dist inet6_tcp"

The database did not support IPv6

1 Like