Connecting to a google cloud SQL from an app engine instance
Asked Answered
N

1

6

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

Neat answered 13/5, 2017 at 22:21 Comment(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.Shippy
K
1

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
Karttikeya answered 26/5, 2017 at 19:57 Comment(3)
I am having the same issue, I think it could be just that google is not adding the postgres socket to App Engine.Keon
yeah possibly. I'm just leaving it in container engine for now, but one of these days i'll have the free cycles to jump into google office hours and get them to help me figure it out.Karttikeya
I am going to look into container engine... Do you have a push hook in your source code hosting that triggers the container builder to re-create it?Keon

© 2022 - 2024 — McMap. All rights reserved.