django cloud sql sample for postgresql
Please add sample for django postgresql settings.
I tried the instructions at: https://cloud.google.com/appengine/docs/flexible/python/using-cloud-sql-postgres
But they are not working. I am getting unix socket error. More details: http://stackoverflow.com/questions/42950418/postgres-settings-for-django-on-google-app-engine-flexi
@KushGoyal Can you confirm that your instance connection name (used twice in your app.yaml) has the SQL instance name (not the database name) as the last part?
Also, can you confirm that your connection string is the right one for the project pointed to by gcloud? (run gcloud config list project)
While you confirm this, I'll be looking into other potential sources of the problem. (Just asking because these are mistakes I've made in the past).
@ryanmats I have double checked all the values. The last part is my db instance name. I am using the correct project id. The connection name is as is from the describe command.
@KushGoyal I just tried another deployment and it worked again :/
Hmm can you check to make sure the Google Cloud SQL API is enabled for your project? (See https://cloud.google.com/python/django/flexible-environment and click on 'Enable API') Also make sure you have 'psycopg2==2.7.1' in your requirements.txt.
Another potential thing to try is to change your mysite/settings.py to use the new username/password (not the default postgres username/password) that our tutorial (https://cloud.google.com/python/django/flexible-environment) says to create in 'Initialize your Cloud SQL Instance' step #2.
Another thing we might want to try is to have you share your project (that does not work when deployed) with a Google engineer or SRE to see if they can dig in a bit deeper. But only if you're comfortable and this is just a sample project without sensitive data.
@ryanmats The project is working now. I had not enabled the google cloud sql api. I saw that Google Cloud SQL api is enabled so I skipped the step. I found the correct api when I clicked on enable api.
There are 2 APIs in the api manager dashboard one is called Google Cloud SQL API which is the sqladmin.googleapis.com api and the other is called Google Cloud SQL which is sql-component.googleapis.com.
I apologise for the trouble caused. Thank you for being patient and helping me out.
Some feedback from the experience: The documentation has provided the name of the api as Cloud SQL Administration but it does not match the actual api names. Suggested names for the current apis: Google Cloud SQL Admin API and Google Cloud SQL Component API
Although I still think that there might be a bug in postgres deployment which needs to be examined. I got the same error in my other project and it worked on redeploying without changing anything, even the sql api.
@KushGoyal no problem. Our job here is to help developers, collect feedback, and work to improve the developer experience.
Thanks for feedback about the API in the tutorial. We will fix the step to say "Enable the Google Cloud SQL API." We'll also look into clarifying our API names to be more user friendly and avoid confusion.
Regarding postgres deployment, there was definitely a problem before but from my experience it looks like it has been working well the past week. Now that I have a 100% verified correct project, I'll keep re-deploying it at regular intervals for a while to monitor for potential problems.
Thanks for your patience during our beta period. Let us know if you have any more problems or questions.
This seems to still be an issue. I'm still getting this exact error and it hasn't resolved itself after waiting and re-deploying.
When I ssh to the instances, the /cloudsql directory is empty which seems like a problem.
patrick@<redacted>:~$ ls -al /cloudsql/
total 8
drwxr-xr-x 2 root root 4096 Jun 9 16:20 .
drwxr-xr-x 26 root root 4096 Jun 9 16:20 ..
I'm noticing that the directory doesn't have write permissions opened up as described here.
update: in the logs for the instance, I noticed this error: googleapi: Error 403: Access Not Configured. Cloud SQL Administration API has not been used in project ### before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sqladmin.googleapis.com/overview?project=### then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry., accessNotConfigured
That URL didn't actually work, if I recall correctly, but I noticed the 'Enable the API' button on one of the tutorials that I skipped because I thought I had already followed those directions. https://console.cloud.google.com/flows/enableapi?apiid=sqladmin
After enabling that, the log message has gone away and the /cloudsql directory has a file representing the connection. That looks like it has fixed the issue.. so hopefully this comment helps someone in the future!
I've got same issue now with django 2.0 app and gcloud PostgreSQL 9.6. SQL APIs - enabled yaml:
beta_settings:
cloud_sql_instances: <my-instance>
settings.py: DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'my-db-name',
'USER': os.environ.get('DB_USER'),
'PASSWORD': os.environ.get('DB_PASSWORD'),
'PORT': '5432',
'HOST': '/cloudsql/<my-instance>
}
Error on app engine:
Exception Value: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/cloudsql/<my-instance>/.s.PGSQL.5432"?
Does anyone know how to fix it?
Figured out how to fix issue. Guide advises to use:
'ENGINE': 'django.db.backends.postgresql'
but it works with
'ENGINE': 'django.db.backends.postgresql_psycopg2',
After deploying a new version (no changes relating to DB) we started to get the connections on Unix domain socket "/cloudsql/<my-instance>/.s.PGSQL.5432 error. I have tried @Ypurek solution but we still get the error. Any suggestions?
Well, after dozen tries to run my app on App Engine without random issues :) I've set up Compute Engine VM from Launcher - https://console.cloud.google.com/launcher/details/bitnami-launchpad/djangostack?project=circus-ticket-app It already has Python and Postgres withing and guide how to run your app. And FTP access to make deployment faster and easier
I seem to be randomly hitting this error as well.
Trying to follow the tutorial at:
https://cloud.google.com/python/django/flexible-environment
OperationalError at /admin/
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/cloudsql/project_name:australia-southeast1:project_name/.s.PGSQL.5432"?
Is there a categorical answer on whether this is a configuration error, or just some intermittent failure in GAE?
Encountered this bug as well, with a ruby app
Still getting this issue. What is the solution here?
Still getting this issue here as well.
MacOS 10.13.4 Django 1.11.10 Postgres 9.6.3
I have not been able to connect to cloud_sql_proxy at other than port 5432. So, I have to stop my local postgres server to free the port.
Strangely enough, my cloud_sql_proxy connects on 5434, while my local db connects at 5433. And when I deploy I have it set to 5432. Quite the system
Makes sense to me. I have to shut down my local postgres to use the proxy.
On Thu, May 17, 2018, 7:33 PM David Soth-Kimmel [email protected] wrote:
Strangely enough, my cloud_sql_proxy connects on 5434, while my local db connects at 5433. And when I deploy I have it set to 5432. Quite the system
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/GoogleCloudPlatform/python-docs-samples/issues/870#issuecomment-390045911, or mute the thread https://github.com/notifications/unsubscribe-auth/AafMSx8TCdx83jopK86f_ozz12Knpdkzks5tzgjDgaJpZM4MlIt3 .
@ryanmats I ran into the exact same problem as @KushGoyal because of a bug on this Google Cloud Console page:
In this page it's impossible to unselect Woo-Server. Because I didn't want to enable the SQL API on Woo-Server I cancelled out of this dialog and tried to enable it through the API library:

Now, I'm not 100% sure what happened next but somehow I had the API enabled (it was listed as enabled), but as far as App Engine was concerned it was disabled ... hence the "could not connect to server: No such file or directory" error message.
After reading @ryanmats reply I remembered cancelling out of the first dialog in Google Cloud Console. So I went back to the tutorial, used it despite the bug of not allowing me to unselect Woo-Server and now it works fine. So for everyone running into the same issue, just make sure you enable the Google SQL API this way.
You should be able to customize the port the proxy connects on by editing the instance connection string: <INSTANCE_CONNECTION_NAME>=tcp:<PORT>.
There are probably differences in the connection string needed depending on using TCP sockets or using Unix sockets, but these will depend on the library being used.
In my case, it was solved when I put the configuration below in app.yml
beta_settings:
cloud_sql_instances: "<connection-name>"