pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

Connection defaults to `localhost` despite `.env` configuration

Open natty-pluz opened this issue 1 year ago • 0 comments

The pgschema CLI (v1.1.1) does not appear to load database connection variables from a .env file. When the command is run, it ignores the PGHOST, PGPORT, and other variables defined in the .env file and attempts to connect to the default localhost:5432 instead.

This behavior was observed in a development environment using WSL (Windows Subsystem for Linux) while connecting to a remote Supabase PostgreSQL database.

Providing the connection details as command-line flags works perfectly, which isolates the issue to the dotenv file loading mechanism.

To Reproduce:

  1. Create a .env file in this directory with valid credentials for a remote PostgreSQL database, for example a Supabase project:
PGHOST=aws-1-ap-south-1.pooler.supabase.com
PGPORT=5432
PGDATABASE=postgres
PGUSER=postgres.xxxxxxxx
PGPASSWORD=xxxxxxxx
  1. Run any pgschema command that connects to the database:
pgschema dump --schema public
  1. The command fails with a connection error, showing that it is attempting to connect to 127.0.0.1:5432 instead of the host defined in the .env file. The exact error is:
Error: failed to ping database: failed to connect to `user=postgres.xxxxxxxx database=postgres`:
        127.0.0.1:5432 (localhost): dial error: dial tcp 127.0.0.1:5432: connect: connection refused
        127.0.0.1:5432 (localhost): dial error: dial tcp 127.0.0.1:5432: connect: connection refused

Environment

  • pgschema Version: v1.1.1
  • Go Version: go version go1.24.6 linux/amd64
  • Operating System / Environment: Windows 11 with WSL 2 (Ubuntu)
  • Database: Supabase (PostgreSQL)

natty-pluz avatar Sep 24 '25 20:09 natty-pluz