Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection/Pooling Issue with Cloud SQL #20

Open
kjrocker opened this issue Dec 24, 2018 · 1 comment
Open

Connection/Pooling Issue with Cloud SQL #20

kjrocker opened this issue Dec 24, 2018 · 1 comment

Comments

@kjrocker
Copy link

I've gotten my app and my database talking to each other, but my SQL and App Engine logs are being absolutely flooded by connection errors anyway.

On the App Engine side, I'm seeing the usual /cloudsql/project:region:database/.s.PSQL.5432 not found error. But on the Cloud SQL side, I'm seeing FATAL: remaining connection slots are reserved for non-replication superuser connections

Again: I have pages that launch DB queries that I can load reliably without 500s, so they are actually talking to each other, but something else is clearly going on here.

My limited research has shown that a base PostgresQL instance can support up to 100 connections, and the default pool size I've seen for Phoenix in production is 20.

@zeroasterisk
Copy link

@kjrocker do you have a sample project which can replicate this for me?

Basic connection info:
https://cloud.google.com/sql/docs/postgres/external-connection-methods
And specific to Google App Engine:
https://cloud.google.com/sql/docs/postgres/connect-app-engine

That page has a callout which says:

App Engine Standard only supports connections to PostgreSQL from the following runtimes:
Python 3.7, Java 8, PHP 7.2, Go 1.11, Node.js

But @dazuma has a tutorial which connects in this same way:
https://cloud.google.com/community/tutorials/elixir-phoenix-on-google-app-engine

Access the production database from App Engine
The App Engine runtime also runs a Cloud SQL Proxy for you, and makes your databases available via Unix sockets. In the App Engine environment, these are located in the directory /cloudsql at the root of the file system. So, to prepare your app for deployment into App Engine, edit your config/prod.secret.exs file again, and modify the socket_dir database setting to point to the correct location for App Engine...
Note that if you need to run another Ecto migration or open another psql session from your local workstation, you can temporarily revert socket_dir to /tmp/cloudsql so that Phoenix can talk to your local Cloud SQL Proxy. If you do, make sure you change it back to /cloudsql before you deploy to App Engine. Alternatively, if you have the ability to create the directory /cloudsql on your local workstation, you can configure Cloud SQL Proxy to open its sockets there instead, and avoid the need to revert socket_dir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants