4
votes

I am trying to setup django with postgres on app engine flexible environment.

I followed the instructions from here: https://cloud.google.com/appengine/docs/flexible/python/using-cloud-sql-postgres

My django settings:

DATABASES = {
    'default': {
            'ENGINE': 'django.db.backends.postgresql',
            'NAME': '<db-name>',
            'USER': '<user-name>',
            'PASSWORD': '<password>',
            'HOST': '/cloudsql/<instance-connection-name>,
            'PORT': '5432'
        },
}

app.yaml:

beta_settings:
    cloud_sql_instances: <instance-connection-name>

Error I am getting is:

could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/cloudsql/<instance-connection-name>/.s.PGSQL.5432"?

Please help with the correct settings.

3

3 Answers

4
votes

The problem resolved itself. I didn't change anything in my code. Here are the steps to use postgresql with django in app engine flexible environment:

https://github.com/GoogleCloudPlatform/python-docs-samples/issues/870

EDIT:

You have to enable the cloud sql api to get it running properly.

checkout this comment: https://github.com/GoogleCloudPlatform/python-docs-samples/issues/870#issuecomment-298152847

3
votes

I had a similar problem, it ends up that I had skipped enabling the sqladmin API.

To see if this is the problem you can check the logs for the instance. Near the top (before gunicorn starts) there will be an error along the lines of:

googleapi: Error 403: Access Not Configured. Cloud SQL Administration API has not been used in project ######## before or it is disabled.

That check is made only when the instance first starts, so once you've enabled the API, you need to re-deploy or otherwise restart your instances. Many of the people reporting this issue elsewhere talk about it magically fixing itself, and I'm guessing the instances got restarted.

-1
votes

If you turn on api and it does not help try to change database engine in Django

'ENGINE': 'django.db.backends.postgresql'

to

 'ENGINE': 'django.db.backends.postgresql_psycopg2'