mix ecto.create times out on Ubuntu 16.04

I’m following the guide to setting up Phoenix here

This is my dev.exs file:

use Mix.Config

# Configure your database
config :api, Api.Repo,
  username: <username>,
  password: <password>,
  database: <dbname>,
  hostname: "localhost",
  show_sensitive_data_on_connection_error: true,
  pool_size: 10,
  timeout: 120_000,
  queue_target: 5000,
  queue_interval: 100_000

# For development, we disable any cache and enable
# debugging and code reloading.
#
# The watchers configuration can be used to run external
# watchers to your application. For example, we use it
# with webpack to recompile .js and .css sources.
config :api, ApiWeb.Endpoint,
  http: [port: 4000],
  debug_errors: true,
  code_reloader: true,
  check_origin: false,
  watchers: [
    node: [
      "node_modules/webpack/bin/webpack.js",
      "--mode",
      "development",
      "--watch-stdin",
      cd: Path.expand("../assets", __DIR__)
    ]
  ]

When I run

ecto.create

I get the following error:

The database for Api.Repo couldn't be created: connection not available and request was dropped from queue after 2994ms. You can configure how long requests wait in the queue using :queue_target and :queue_interval. See DBConnection.start_link/2 for more information

To my knowledge I’m already using queue_target and queue_interval. What am I doing wrong?

My database is running. I’m able to run

psql -U <username>

and access a psql console.

postgres-# \conninfo
You are connected to database postgres as user <username> via socket in "/var/run/postgresql" at port "5432".

Is your user allowed to connect via network?

As @NobbZ indicated your server, firewall, or routing may not be allowing network access - run on the same machine as the RDBMS connection may be via Unix domain sockets (a local only feature).

Determine upon which IP address/port your database is running then connect from the machine hosting the phoenix application using nc, netcat, telnet - whatever tool you have available and see if a postgres message appears in the terminal.