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

How can i use PostgreSQL through Unix socket? #2614

Closed
MikalaiR opened this issue Aug 1, 2018 · 7 comments
Closed

How can i use PostgreSQL through Unix socket? #2614

MikalaiR opened this issue Aug 1, 2018 · 7 comments

Comments

@MikalaiR
Copy link

MikalaiR commented Aug 1, 2018

Issue type:

[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

I tried something like:

{
  "type": "postgres",
  "url": "postgresql://user:pass@%2Fcloudsql%2Fpath:5432/db",

  "entities": [
    "dist/**/**.entity.js"
  ],
  "synchronize": true
}

but it doesn't working.

@Kononnable
Copy link
Contributor

@MikalaiR
Did you resolve your issue? It doesn't look ORM related - can you connect with similar options using postgres driver directly?

@MikalaiR
Copy link
Author

@Kononnable I have resolved this issue using temporary 'crutch'.

{
  "type": "postgres",
  "url": "postgresql://user:pass@localhost:5432/db",

  "extra": {
    "host": "/cloudsql/...."
  },

It don't work in right way because TypeORM parses url itself instead of pass it to driver. And extra works because extra apllied to parsed object. But it's temporary crutch i think, TypeORM should support it through url.

@fullofcaffeine
Copy link

fullofcaffeine commented Oct 17, 2019

I'd also like the know if this is currently supported / the status of this issue. Currently I'm using password auth restricted by host and pgsql is protected by a frewall, but it'd much more convenient if I had a unix user per db/app and could use pg_ident through socket instead.

@paeolo
Copy link
Contributor

paeolo commented May 1, 2020

The issue is still present in the latest release. Why TypeORM couldn't pass the url to the driver directly?

@guillenotfound
Copy link

For anyone having the same issue, here are the variables I've set on my Cloud Run service:
image

It does connect via socket, here is how the variable looks like:
TYPEORM_HOST=/cloudsql/INSTANCE_CONNECTION_NAME

More info here about service account permissions & APIs to enable here: https://cloud.google.com/sql/docs/postgres/connect-run

@imnotjames
Copy link
Contributor

This is good to go in the next release.

@MrCube42
Copy link

Since I had a lot of research to do to find this out, I'll just let you know, that you can also use the following syntax here:

"url": "socket:<path-to-socket>?db=<databasename>",

for more details see:
https://github.com/brianc/node-postgres/tree/master/packages/pg-connection-string#unix-domain-sockets

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

7 participants