Cannot connect to PosgreSQL using unix domain socket
See original GitHub issueI can connect to PostgreSQL database using asyncpg with specifying DSN string as follows:
conn = await asyncpg.connect(
'postgres:///sampledb?host=/cloudsql/xxx:asia-northeast1:yyy/.s.PGSQL.5432&user=postgres&password=pass')
(This PostgreSQL database is GCP Cloud SQL)
UsingTortoise.init()
, however, I cannot connect to the database with the same DSN string.
await Tortoise.init(
config={
'connections': {
'default': 'postgres:///sampledb?host=/cloudsql/xxx:asia-northeast1:yyy/.s.PGSQL.5432&user=postgres&password=pass'
},
'apps': {
'models': {
'models': ['__main__'],
'default_connection': 'default',
}
}})
The code above raises OSError: Multiple exceptions: [Errno 61] Connect call failed ('::1', 5432, 0, 0), [Errno 61] Connect call failed ('127.0.0.1', 5432)
I also tried the following connection settings, but TypeError: __init__() missing 1 required positional argument: 'port'
occurred.
await Tortoise.init(
config={
'connections': {
'default': {
"engine": "tortoise.backends.asyncpg",
"credentials": {
"database": 'sampledb',
"host": '/cloudsql/xxx:asia-northeast1:yyy/.s.PGSQL.5432',
"password": "pass",
"user": "postgres",
}
}
'apps': {
'models': {
'models': ['__main__'],
'default_connection': 'default',
}
}})
How can I connect to the database using unix socket?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Cannot connect to PostgreSQL unix domain socket
I've resolved the problem. The initial cause of it was in systemd service file for php-fpm /usr/lib/systemd/system/php-fpm.service:
Read more >How to fix "psql: error: xxx and accepting connections on Unix ...
First, you need to make sure the socket file is located in /var/run/postgresql/.s.PGSQL.5432 . To check that $ cat /var/run/postgresql/.s.
Read more >Can't connect to default unix socket (tries to connect to localhost)
The default behavior when host is not specified, or is empty, is to connect to a Unix-domain socket in /tmp (or whatever socket...
Read more >BUG #16086: Cannot connect using psql, however I can ...
BUG #16086: Cannot connect using psql, however I can connect using pgadmin ... connections on Unix domain socket "/var/run/postgresql/.s.
Read more >Apache cannot connect to PostgreSQL via Unix domain socket
Description of problem: When running under SELinux, Apache cannot connect to the unix domain socket PostgreSQL runs on.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Lets fix the issue of expecting a port at least?
I found that I can connect by giving
port
key to thecredentials
dict. Any number is ok for its value.I have solved my problem.
If it’s not a bug that we can’t connect using a unix domain socket’s DSN, it’s ok to close this issue.