rphl-snts

rphl-snts

Hi folks, hope you are all doing well.
I’m having trouble to deploy my app on heroku using two databases.

[error] GenServer #PID<0.268.0> terminating
** (Postgrex.Error) FATAL 42501 (insufficient_privilege) permission denied for database "postgres"

User does not have CONNECT privilege.
    (db_connection 2.4.2) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.14.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

My prod.exs:

import Config

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

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

config :multi_repo, MultiRepo.Repo,
  ssl: true,
  url: database_url,
  pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")

config :multi_repo, MultiRepo.Repo2,
  ssl: true,
  url: database_url_2,
  pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")

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 :multi_repo, MultiRepoWeb.Endpoint,
  http: [
    port: String.to_integer(System.get_env("PORT") || "4000"),
    transport_options: [socket_opts: [:inet6]]
  ],
  secret_key_base: secret_key_base

It works when I use only one database and locally both works.
I created a NodeJs app that connects to two databases on Heroku and it worked fine, so I believe there may be something wrong with Postgrex.
Has anyone had the same error?

Showing Posts 1 to 10

rphl-snts

rphl-snts OP

I had consulted this page but unfortunately I didn’t find a solution.
The error happens when I try to create the database, that is, when I run the command mix ecto.setup.

(I use elixir release, so I created a task for creating/migrating the database)

evadne

evadne

Well there you go, do not create the DB, it is already created by Heroku when you added that add-on, only run migrations

In the page:

We typically see CONNECT privilege issues where applications try to create database

rphl-snts

rphl-snts OP

Yes, I know that. I didn’t mean literally create the DB

evadne

evadne

ecto.setup contains code to create the db with pg

rphl-snts

rphl-snts OP

Yes, you’re right about that, but I use Elixir Release on Heroku.
I just mentioned the mix ecto.setup to try to make it understand that the error is related to the database setup, I apologize if I didn’t make myself understood.
And I run my migrations in production with the command: _build/prod/rel/my_app/bin/my_app eval "MyApp.Release.migrate"

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

If you are using releases, the prod.exs is evaluated when the release is built not when the release is executed. Are you setting those environment variables in the build environment or in the environment when the release is being run?

rphl-snts

rphl-snts OP

In the build environment.
I logged the opts paramenters from DBConnection.Connection.init/1
(I just remove the credentials to post here)

[
  pool_index: 1,
  types: Postgrex.DefaultTypes,
  max_restarts: 0,
  backoff_type: :stop,
  database: "postgres",
  force_drop: false,
  telemetry_prefix: [:multi_repo, :repo],
  otp_app: :multi_repo,
  timeout: 15000,
  ssl: true,
  hostname: "ec2-...",
  username: "adew...",
  password: "9dd5...",
  port: 5432
]

looks like the database is being replaced by “postgres”, the other options are correct like password, hostname and username.
The database name only appears when I use the :maintenance_database option.
Exmaple:

config :multi_repo, MultiRepo.Repo,
  ssl: true,
  url: database_url,
  maintenance_database: database_name,
  pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")
benbonnet

benbonnet

coming from rails, the following is relatively common within the Procfile :

web: ...run the server...
release: ...run the migrations on each deployment...

If prod.exs is evaluated when the release is built not when the release is executed, what’s the best place to run mix ecto.migrate for each deployment ?

thomas.fortes

thomas.fortes

Mix is not available in releases, one strategy for handling migrations is listed here:

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews