【发布时间】:2018-01-09 11:01:24
【问题描述】:
目前我正在尝试在 Google App Engine(GAE) 上部署 Django 应用。一切顺利,应用程序已部署,但在部署时,它与 Postgres 实例的连接丢失。我不知道为什么会这样。以下是我的 settings.py 文件。
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'dbname',
'USER': 'username',
'PASSWORD': 'password',
}
}
# In the flexible environment, you connect to CloudSQL using a unix socket.
# Locally, you can use the CloudSQL proxy to proxy a localhost connection
# to the instance
DATABASES['default']['HOST'] = '/cloudsql/shopnroar-175407:us-central1:snr-instance1'
if os.getenv('GAE_INSTANCE'):
pass
else:
DATABASES['default']['HOST'] = '100.107.126.241'
当我在本地运行它时,它正在与谷歌云 Postgres 建立连接,因为我已经提供了 ipv4 地址来建立连接,但是一旦我将它部署到 GAE 上,访问数据库时就会出现以下错误。
Is the server running locally and accepting
connections on Unix domain socket "/cloudsql/shopnroar-175407:us-central1:snr-instance1/.s.PGSQL.5432"?
这是我的 app.yaml
# [START runtime]
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT SNR.wsgi
env_variables:
# Replace user, password, database, and instance connection name with the values obtained
# when configuring your Cloud SQL instance.
SQLALCHEMY_DATABASE_URI: >-
postgresql+psycopg2://amad.uddin:goingtoin1122@/shopnroar?host=/cloudsql/shopnroar-175407:us-central1:snr-instance1
beta_settings:
cloud_sql_instances: shopnroar-175407:us-central1:snr-instance1
runtime_config:
python_version: 2
# [END runtime]
谁能告诉我在 GAE 上部署 django 应用程序后如何与 postgres 实例建立连接?
我们将不胜感激任何帮助或建议。
【问题讨论】:
标签: django postgresql google-app-engine google-cloud-sql