Connect multiple cloud sql databases to one app engine service

742 views
Skip to first unread message

Mike Hardy

unread,
Nov 17, 2017, 12:06:49 AM11/17/17
to Google App Engine
Hi, we have an app that utilizes two databases. Previously, we had the two databases on the same instance in Cloud SQL, but we want to split the databases into separate instances. We're having issues connecting the databases to our Django app engine service. Is this even possible? If so, how would the app.yaml look?

old app.yaml
runtime: custom
env: flex
entrypoint: gunicorn --timeout 360 --graceful-timeout 360 -b :$8080 localinsights.wsgi

beta_settings:
    cloud_sql_instances: <CONNECTION>

runtime_config:
  python_version: 3.6

env_variables:
  SQLALCHEMY_DATABASE_URI: >-
      postgresql+psycopg2://<USER>:<PASSWORD>/<DB>?host=/cloudsql/<CONNECTION>


settings.py
DATABASES['default'] = {
    'HOST': '/cloudsql/<CONNECTION>',
    'ENGINE': 'psqlextra.backend',
    'NAME': '<USER_DB>',
    'USER': '<USER>',
    'PASSWORD': '<PASSWORD>'
}
DATABASES['NUMBER_2'] = {
    'HOST': '/cloudsql/<CONNECTION>',
    'ENGINE': 'psqlextra.backend',
    'NAME': 'NUMBER_2',
    'USER': '<USER>',
    'PASSWORD': '<PW>'
}


Jun (Cloud Platform Support)

unread,
Nov 17, 2017, 3:59:04 PM11/17/17
to Google App Engine
Hi Mike,

You should be able to connect to multiple Cloud SQL instances through Cloud SQL Proxy, and you can specify multiple instances in the instances parameter (comma separated). Please take a look at these two posts for more details: "A GCE instance connecting to two (or more) Cloud SQL databases via multiple cloud-sql-proxy-instances" and "Connecting to multiple CloudSQL instances using Cloud sql proxy?", which have the similar questions. 

- Jun

Mike Hardy

unread,
Nov 17, 2017, 4:37:38 PM11/17/17
to Google App Engine
Hi Jun, thanks for your response, but I am a little confused here. When deployed, GAE uses a built in cloud sql proxy connection with Cloud SQL so there is no way to specify the instance or any other parameter for cloud sql proxy. I think any fix will need to use app.yaml but please correct me if I'm wrong. Would love to solve this.

Jun (Cloud Platform Support)

unread,
Nov 20, 2017, 11:30:21 PM11/20/17
to Google App Engine
Hi Mike,

After some further search around, it looks there is no public documentation mentioning GAE connects to multiple Cloud SQL instances. From my point of view, config at app.yaml will not get to the purpose we want, so I suggest that you'll need to make a feature request at the issue tracker.
Reply all
Reply to author
Forward
0 new messages