tortoise / tortoise/tortoise-orm
Cannot connect to PosgreSQL using unix domain socket
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
I 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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at Tortoise.init connection handling and the tortoise.backends.asyncpg credentials path; compare them with the working asyncpg DSN example. Done means a PostgreSQL Unix-domain socket connection works through the supported configuration without the reported connection or missing-port errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100