Failed to connect: :nxdomain

Hey guys, I’m trying to deploy me phoenix app but for some reason I’m getting a DB connection error of

Postgrex.Protocol (#PID<0.2336.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (dpg-c6npuk7s437rbk6vm9bg:5432): non-existing domain - :nxdomain

I’ve checked and I made sure that:

so I have a feeling it has something to do with my deployment config. So here’s what I got

build.sh

#!/usr/bin/env bash

# exit on error

set -o errexit

# Initial setup

mix deps.get --only prod

MIX_ENV=prod mix compile

# Compile assets

npm install -f --prefix ./assets

npm run deploy --prefix ./assets

mix phx.digest

# Build the release and overwrite the existing release directory

MIX_ENV=prod mix release --overwrite

config/prod.exs

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

  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
      """
  config :serotana_ex, SerotanaExWeb.Endpoint,
    server: true,
    url: [host: System.get_env("RENDER_EXTERNAL_HOSTNAME") || "localhost", port: 80],
    http: [
      ip: {0, 0, 0, 0, 0, 0, 0, 0},
      port: String.to_integer(System.get_env("PORT") || "4000")
    ],
    secret_key_base: secret_key_base,
    cache_static_manifest: "priv/static/cache_manifest.json"

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

  config :serotana_ex, SerotanaEx.Repo,
    url: database_url,
    # IMPORTANT: Or it won't find the DB server
    socket_options: [:inet6],
    pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")

config/config.exs

import Config

config :serotana_ex,
  ecto_repos: [SerotanaEx.Repo]

# Configures the endpoint
config :serotana_ex, SerotanaExWeb.Endpoint,
  url: [host: System.get_env("RENDER_EXTERNAL_HOSTNAME") || "localhost", port: 80],
  render_errors: [view: SerotanaExWeb.ErrorView, accepts: ~w(html json), layout: false],
  pubsub_server: SerotanaEx.PubSub,
  live_view: [signing_salt: "yI1LL+Ed"]

config :serotana_ex, SerotanaEx.Mailer, adapter: Swoosh.Adapters.Local

config :swoosh, :api_client, false

config :esbuild,
  version: "0.12.18",
  default: [
    args: ~w(js/app.js --bundle --target=es2016 --outdir=../priv/static/assets),
    cd: Path.expand("../assets", __DIR__),
    env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
  ]

config :dart_sass,
  version: "1.43.1",
  default: [
    args: ~w(css/app.scss ../priv/static/assets/app.css),
    cd: Path.expand("../assets", __DIR__)
  ]

config :logger, :console,
  format: "$time $metadata[$level] $message\n",
  metadata: [:request_id]

config :phoenix, :json_library, Jason

import_config "#{config_env()}.exs"

repo.exs

use Ecto.Repo,
    otp_app: :serotana_ex,
    adapter: Ecto.Adapters.Postgres

Sorry for the long post, just wanted to cover my bases. Any help would be warmly welcomed!

Thank you in advance!

Hey Chris,

The first thing worth checking is that your webservice can communicate with your database, dropping into the shell tab for the service and running psql $DATABASE_URL - if this drops you into a Postgres session this I’m afraid confirms your suspicions that it’s an application/deployment config issue and not an issue related to the platform.

Your question might be better suited to the wider Phoenix community as it seems it comes up quite a lot with differing solutions - unless any of our other Phoenix customers can assist here?

John B

Have you solved this issue? I am having this issue right now. Thanks!

I was searching around and found this (which might be helpful)

Hi, I fixed my issue on this by adding the domains on check_origin: ["//yourdomain.com"] of my prod config.

I am having this same issue, but I have not set up custom domains yet.

Solution:

remove this line from your config.