6
votes

I want to run an elixir application in google app engine flexible environment.

I also have a postgresql server running on google cloud SQL.

I am able to deploy the application inside the docker container. The problem is that I can't find how to configure the connection to the postgresql server.

As far as I understand the app engine instances run the cloud SQL proxy but I keep getting the following error inside the instance: [error] Postgrex.Protocol (#PID<0.232.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused

1
You need to add some sample code that shows how are you attempting to connect it, so that we can tell you where you're going wrong.dsignr

1 Answers

1
votes

i'm getting the same errors with a phoenix/elixir app that i'm trying to move out of container engine and into app engine flexible environment, just can't figure out what to use as the hostname.

in my php app in app engine i can just use :/cloudsql/projectname:region:dbname for the same database, but it doesn't seem to work that way for elixir

I also tried using the IP address of the cloud sql instance directly, but that wasn't working either.

in my app.yaml i have

env_variables:
  MIX_ENV: staging
  port: 8080
  DB_ENV_POSTGRES_HOST: :/cloudsql/projectname:region:dbame
  DB_ENV_POSTGRES_USER: userman
  DB_ENV_POSTGRES_PASSWORD: password

and in conf/staging.exs i have

config :guidebooks_api, GuidebooksApi.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: System.get_env("DB_ENV_POSTGRES_USER") || "postgres",
  password: System.get_env("DB_ENV_POSTGRES_PASSWORD") || "postgres",
  hostname: System.get_env("DB_ENV_POSTGRES_HOST") || "localhost",
  database: "databasename",
  pool_size: 10,
  types: GuidebooksApi.PostgresTypes