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

Sopport socket:// URLs, needed for AppEngine+CloudSQL use #341

Closed
RP-3 opened this issue Apr 9, 2022 · 4 comments
Closed

Sopport socket:// URLs, needed for AppEngine+CloudSQL use #341

RP-3 opened this issue Apr 9, 2022 · 4 comments

Comments

@RP-3
Copy link

RP-3 commented Apr 9, 2022

Desired Behavior

  • When following the official App Engine Postgres CloudSQL connection instructions here to connect to a Postgres instance via a public IP in the App Engine Standard Environment, I expect a socket:// connection string passed to Slonik to work.
  • Currently, Slonik throws an the error [ERR_INVALID_URL]: Invalid URL, when given a connection string in any of the following forms:
    • socket://PASSWORD@/cloudsql/INSTANCE_CONNECTION_NAME/.s.PGSQL.5432?db=DB_NAME
    • socket://PASSWORD@/cloudsql/INSTANCE_CONNECTION_NAME?db=DB_NAME
    • socket://PASSWORD@/cloudsql/INSTANCE_CONNECTION_NAME/DB_NAME

Motivation

  • Google App Engine recommends this as the default way to connect to CloudSQL, and it is also the only way to connect if the database has a public IP address or is in a different region to the client initiating a connection.
  • Google/Firebase Cloud Functions only allow socket:// connections
  • A variety of other reasons have been proposed in this issue, however, they advocate passing a full-blown connection object which is not strictly necessary for this use case
  • Other issues imply that this previously worked, but was broken in subsequent updates.

Implementation

  • @gajus has previously recommended a solution here.
@dbousamra
Copy link

Any further updates on this? This feature is preventing me from upgrading slonik

@gajus
Copy link
Owner

gajus commented Sep 12, 2022

@mgreenw This was addressed by your PR, wasn't it?

#409

@mgreenw
Copy link
Contributor

mgreenw commented Sep 12, 2022

Yes, #409 should fix it! You need to url-encode the unix socket path, so the final connection uri should be passed like postgresql://<user>:<password>@%2Fcloudsql%2F<project-id>%3A<region-name>%3A<sql-instance>/<db-name>

v31.2.1

@gajus
Copy link
Owner

gajus commented Sep 13, 2022

Thank you

@gajus gajus closed this as completed Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants