GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — django cloud sql sample for postgresql · Issue #870 · GoogleCloudPlatform/python-docs-samples

django cloud sql sample for postgresql #870

New issue
Copy link
New issue
Copy link
Closed
Closed
django cloud sql sample for postgresql#870
Copy link
Assignees
kurtisvg

Description

@staticmetal
staticmetal
opened on Mar 22, 2017
Issue body actions

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

Activity

Next
  1. theacodes
    assigned
    ryanmats
    on Mar 22, 2017
  2. theacodes commented on Mar 22, 2017

    @theacodes
    theacodes
    on Mar 22, 2017
    Contributor
    More actions

    /cc @waprin

  3. agmathew commented on Mar 23, 2017

    @agmathew
    agmathew
    on Mar 23, 2017
    More actions

    I am also experiencing a similar issue. See here: http://stackoverflow.com/questions/42836927/error-connecting-django-to-google-cloudsql-postgres-database-in-google-app-engin

  4. ryanmats commented on Mar 23, 2017

    @ryanmats
    ryanmats
    on Mar 23, 2017
    Contributor
    More actions

    @KushGoyal @agmathew thanks for the feedback. i'll take a look at this today.

  5. ryanmats commented on Mar 24, 2017

    @ryanmats
    ryanmats
    on Mar 24, 2017
    Contributor
    More actions

    @KushGoyal @agmathew So I was able to get it to work when deployed, and wasn't able to reproduce your error message :/

    I would recommend doing the Django on App Engine Flexible tutorial (https://cloud.google.com/python/django/flexible-environment) from the beginning step-by-step with these PostgreSQL specific changes:

    1. When you get to 'Create a Cloud SQL Instance' step 1, use https://cloud.google.com/sql/docs/postgres/create-instance and make sure you create a PostgreSQL instance instead of a Cloud SQL instance. When you create the instance, you'll be asked to create a password. This password is for the 'postgres' default user for this PostgreSQL instance.

    2. Skip step 2 of 'Create a Cloud SQL Instance,' since you set the password when creating the instance.

    3. In 'Initialize your Cloud SQL instance' step 1, use this command to use port 5432 instead of 3306: "./cloud_sql_proxy -instances="[YOUR_INSTANCE_CONNECTION_NAME]"=tcp:5432"

    4. In 'Configure the Database Settings,' when you are editing mysite/settings.py, also change 'ENGINE': 'django.db.backends.mysql' to 'ENGINE':'django.db.backends.postgresql'

    5. While you are configuring database settings here, also edit your requirements.txt file and add psycopg2==2.7.1

    If you do this and still have difficulties, let us know along with more details about where you got stuck and what error messages you got!

  6. staticmetal commented on Mar 24, 2017

    @staticmetal
    staticmetal
    on Mar 24, 2017
    Author
    More actions

    @ryanmats it worked! Although I didn't change a thing 😲
    Thanks for the help

    Reacted by Daniel Khashabi
  7. agmathew commented on Mar 24, 2017

    @agmathew
    agmathew
    on Mar 24, 2017
    More actions

    @ryanmats Same for me, it's working now, but I haven't touched anything. Do you know if any changes were made to GAE or CloudSQL Postgres in the last few days? Is there somewhere where we can track changes like this? We're currently evaluating whether to use GAE for a new product and I'm a little concerned about a service "fixing" itself.

    Reacted by Kush Goyal
  8. ryanmats commented on Mar 24, 2017

    @ryanmats
    ryanmats
    on Mar 24, 2017
    Contributor
    More actions

    @KushGoyal @agmathew Great to hear that it works! I just filed a bug for the Cloud SQL / Postgres team to ask them about this - will let you know what they say.

    @jonparrott do you know if there are any resources for customers to track product changes? (see @agmathew 's comment above)

  9. theacodes commented on Mar 24, 2017

    @theacodes
    theacodes
    on Mar 24, 2017
    Contributor
    More actions

    @agmathew @KushGoyal
    Postgres for Cloud SQL is in beta, so it's expected that things will be changing rapidly as we approach GA, especially things around reliability. I highly recommend joining the user group so that you can provide us with feedback on the beta.

    For Cloud SQL, we have release notes published here:
    https://cloud.google.com/sql/docs/release-notes

    For GAE flexible, we have release notes published here: https://cloud.google.com/appengine/docs/flexible/python/release-notes

  10. theacodes
    closed this as completedon Mar 24, 2017
  11. theacodes commented on Mar 24, 2017

    @theacodes
    theacodes
    on Mar 24, 2017
    Contributor
    More actions

    (Closing as this appears to be resolved, but feel free to comment if you have any more questions/issues).

  12. staticmetal commented on Apr 19, 2017

    @staticmetal
    staticmetal
    on Apr 19, 2017
    Author
    More actions

    The issue is repeating again on a new project. I have followed the exact steps which are:

    1. create a postgresql instance

    2. create a db

    3. get name of connection using command: gcloud sql instances describe <instance-name>

    4. add connection name to app.yaml

    beta_settings:
      cloud_sql_instances: <connection-name>
    1. use host as /cloudsql/<connection-name>
    Reacted by Ramiel and Alexander Kell
  13. staticmetal commented on Apr 19, 2017

    @staticmetal
    staticmetal
    on Apr 19, 2017
    Author
    More actions

    I tried to deploy the project again and this time it worked without changing anything.

    I don't know what changed. Perhaps this issue is related to app engine not detecting the presence of postgresql db.

  14. ryanmats commented on Apr 19, 2017

    @ryanmats
    ryanmats
    on Apr 19, 2017
    Contributor
    More actions

    @KushGoyal we'll ping the CloudSQL engineering team about this. thanks for the feedback.

  15. ankushagarwal commented on Apr 19, 2017

    @ankushagarwal
    ankushagarwal
    on Apr 19, 2017
    More actions

    @KushGoyal :

    1. What was the error message that you received?
    2. What was the format of the SQLALCHEMY_DATABASE_URI that you used (eg: postgresql+psycopg2://username:password@/databasename?host=connection-name)
    3. Did you try connecting to the instance from your local machine by using cloud-sql-proxy? (look at the Setting up your local environment instructions here : https://cloud.google.com/appengine/docs/flexible/python/using-cloud-sql-postgres)
  16. 18 remaining items

  17. DanielJoyce commented on Feb 23, 2018

    @DanielJoyce
    DanielJoyce
    on Feb 23, 2018
    More actions

    Encountered this bug as well, with a ruby app

    Reacted by jo and Patrick Nollet
  18. DaskJeeves commented on May 2, 2018

    @DaskJeeves
    DaskJeeves
    on May 2, 2018
    More actions

    Still getting this issue. What is the solution here?

    Reacted by jo
  19. japhiaolson commented on May 4, 2018

    @japhiaolson
    japhiaolson
    on May 4, 2018
    More actions

    Still getting this issue here as well.

  20. ClubOfRome commented on May 16, 2018

    @ClubOfRome
    ClubOfRome
    on May 16, 2018
    More actions

    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.

  21. DaskJeeves commented on May 17, 2018

    @DaskJeeves
    DaskJeeves
    on May 17, 2018
    More actions

    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

  22. ClubOfRome commented on May 17, 2018

    @ClubOfRome
    ClubOfRome
    on May 17, 2018 via email
    More actions
    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 ***@***.***> 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 <#870 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AafMSx8TCdx83jopK86f_ozz12Knpdkzks5tzgjDgaJpZM4MlIt3> .
  23. AngelosP commented on May 18, 2018

    @AngelosP
    AngelosP
    on May 18, 2018
    More actions

    @ryanmats I ran into the exact same problem as @KushGoyal because of a bug on this Google Cloud Console page:

    image
    Link to 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:

    image

    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.

  24. ryanmats
    assigned
    kurtisvg
    and unassigned
    ryanmats
    on May 18, 2018
  25. kurtisvg commented on May 18, 2018

    @kurtisvg
    kurtisvg
    on May 18, 2018
    Contributor
    More actions

    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.

  26. Dean-Christian-Armada commented on Sep 28, 2018

    @Dean-Christian-Armada
    Dean-Christian-Armada
    on Sep 28, 2018
    More actions

    In my case, it was solved when I put the configuration below in app.yml

    beta_settings:
      cloud_sql_instances: "<connection-name>"
    
  27. Dean-Christian-Armada commented on Sep 28, 2018

    @Dean-Christian-Armada
    Dean-Christian-Armada
    on Sep 28, 2018
    More actions

    Another tip is to check the logs of the container of your cloud_sql when you are in a flex environment like

    docker logs --tail=100 -f 810ae3237e94
    2018/09/28 10:40:29 Ready for new connections
    2018/09/28 10:40:30 errors parsing config:
            googleapi: Error 403: Access Not Configured. Cloud SQL Admin API has not been used in project 636840238029 
    before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sqladmin.googleapis.
    com/overview?project=636840238029 then retry. If you enabled this API recently, wait a few minutes for the action t
    o propagate to our systems and retry., accessNotConfigured
    
  28. ibci commented on Jan 20, 2020

    @ibci
    ibci
    on Jan 20, 2020
    More actions

    I'm still getting this error... I've tried everything I've seen so far:

    • enabling SQL APIs (admin and component) + credentials
    • psycopg2==2.8.4
    • set 'ENGINE': 'django.db.backends.postgresql_psycopg2',
    • set beta_settings at the end of the app.yaml
    • checked 'docker logs --tail' and just seeing "Ready for new connections" without any error

    I can connect to the DB if I run cloud_sql_proxy locally, and it works perfectly.
    My django version is: Django-3.0.
    I'm desperate... if somebody could help... :)

  29. ibci commented on Jan 21, 2020

    @ibci
    ibci
    on Jan 21, 2020
    More actions

    Solved, the problem was that in my HOST i used the region as "eu-west6" instead of "europe-west6"

  30. GoogleCloudPlatform
    locked as resolved and limited conversation to collaborators on Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @kurtisvg
    kurtisvg

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.