Skip to content

fix(pglite-socket): Unix socket CLI docs incorrect — psql cannot connect #943

@gutenye

Description

@gutenye

Problem

The CLI usage docs show this for Unix socket connection:

# Start server on a Unix socket
pglite-server --path=/tmp/pglite.sock --run "npm run dev" --include-database-url

# Unix socket connection (if using --path)
PGSSLMODE=disable psql -h /tmp -d template1

This does not work because psql -h expects a directory, not a socket file. libpq always appends .s.PGSQL.<port> to the directory path, so it looks for /tmp/.s.PGSQL.5432 which doesn't exist.

What happens

$ pglite-server --path=/tmp/pglite.sock
$ PGSSLMODE=disable psql -h /tmp -d template1
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory

The actual socket file is /tmp/pglite.sock, but psql looks for /tmp/.s.PGSQL.5432.

Workaround

Symlink the socket file to the name psql expects:

pglite-server --path=/tmp/pglite.sock
mkdir -p /tmp/pglite-dir
ln -sf /tmp/pglite.sock /tmp/pglite-dir/.s.PGSQL.5432
PGSSLMODE=disable psql -h /tmp/pglite-dir -p 5432 -U postgres -d template1

Suggested fix

Either:

  1. Accept a directory path for --path and create the socket as <dir>/.s.PGSQL.<port> (matching Postgres convention), or
  2. Update the docs to note that psql cannot connect directly and show the symlink workaround

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions