pgquery

pgquery / Connect to local or Docker Postgres

Guide · Connect

Connect to a Postgres on your machine or in Docker

Inside a container, localhost means the container itself, not your computer. That is the one thing to get right.

Postgres installed on your computer

Start pgquery and point it at host.docker.internal:

docker run -p 54280:54280 --add-host=host.docker.internal:host-gateway ghcr.io/hxndrik/pgquery
postgres://postgres:YOUR-PASSWORD@host.docker.internal:5432/postgres

On Docker Desktop (macOS, Windows) host.docker.internal works without the --add-host flag; on Linux the flag adds it.

Postgres in Docker Compose

Put both in one Compose file and use the service name as the host:

services:
  db:
    image: postgres:17
    environment:
      POSTGRES_PASSWORD: example
  pgquery:
    image: ghcr.io/hxndrik/pgquery
    ports:
      - "54280:54280"
postgres://postgres:example@db:5432/postgres

Common errors

If you seeDo this
dial tcp 127.0.0.1:5432: connect: connection refusedlocalhost inside the container is the container. Use host.docker.internal or the Compose service name.
dial tcp …:5432: connect: connection refused (with host.docker.internal)Postgres only listens on 127.0.0.1. Set listen_addresses = '*' in postgresql.conf (or start the container with -p 5432:5432) and allow the Docker network in pg_hba.conf.
this server does not connect to private or local addressesYou are on a public instance (like pgquery.dev) that blocks private addresses. Run pgquery yourself to reach local databases.

Questions

Why can’t pgquery.dev connect to my local database?

The hosted app runs on a server on the internet, so it cannot reach your computer, and public instances block private addresses. Run pgquery locally with one docker run.

Does pgquery work without Docker?

Yes. Build it from source with Node and Go; see the README.

More chapters