Postgres via Cloudflare Tunnel

Postgres via Cloudflare Tunnel

Access your home Postgres from anywhere with Cloudflare Tunnels.

Start the PG Server using Docker

docker run -d --name pg16 \
  -e POSTGRES_PASSWORD=secret \
  -p 15432:5432 \
  -v pg16_data:/var/lib/postgresql/data \
  pgvector/pgvector:pg16

Test Local Connection using Docker

docker run -it --rm \
  -e PGPASSWORD=secret \
  pgvector/pgvector:pg16 \
  psql -h 192.168.86.250 -U postgres -p 15432 -c 'select version()'

Replace 192.168.86.250 with your machine’s private IP.

Create the Tunnel

Install cloudflared on the Docker host following the official guide.

Configure the tunnel to point to localhost:15432.

Connect from Remote

On any remote machine:

cloudflared access tcp --hostname pg16.dataturd.com --url localhost:15432

Then connect your client to localhost:15432 as if Postgres were local:

# With Docker
docker run -it --rm \
  -e PGPASSWORD=secret \
  --network host \
  pgvector/pgvector:pg16 \
  psql -h localhost -U postgres -p 15432 -c 'select version()'

# Or with local psql
PGPASSWORD=secret psql -h localhost -U postgres -p 15432 -c 'select version()'