tortoise / tortoise/tortoise-orm

Cannot connect to PosgreSQL using unix domain socket

Open
#396 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.