Question

Elixir, Ecto / Phoenix + Managed Postgres Db

I’m trying to setup an Elixir / Phoenix / Ecto project on my droplet and connect to a DO managed postgresql. No matter what I do I can’t connect to my DB properly:

** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database “postgres” does not exist (db_connection) lib/db_connection/connection.ex:84: 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

My connection string is right, connectivity seems fine ( I setup my droplet to be able to access the db cluster) but Elixir/Ecto complains with the above error.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Brian Hogan
DigitalOcean Employee
DigitalOcean Employee badge
March 13, 2019
Accepted Answer

HI! Sorry to hear you ran into a snag. I just set up a brand new Elixir/Phoenix app myself and ran into the exact same issue you had.

I did a little digging and it seems that either Ecto or Postgres expects the postgres database to exist.

I logged into the db directly with my doadmin user and looked around, and surely enough there’s no postgres database. So I created one:

CREATE DATABASE postgres WITH OWNER doadmin

Then I disconnected from the console, re-ran mix ecto.create and was greeted with:

The database for Hello.Repo has been created

I hope that helps move you forward!

Ecto uses the ‘maintenance_database’ property to set the name of the database to connect to when creating or dropping the database. By default it’s “postgres”. In DigitalOcean, when a cluster is created, the default database is called “defaultdb”. So all you need to do is add the following config:

# Configure your database
config :elixir_app, ElixirApp.Repo,
  ...
  database: "elixir_app_dev",
  maintenance_database: "defaultdb",
  ...

Here is the documentation: https://hexdocs.pm/ecto_sql/Ecto.Adapters.Postgres.html

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel