pgschema
pgschema copied to clipboard
Connection defaults to `localhost` despite `.env` configuration
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:
- Create a
.envfile 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
- Run any
pgschemacommand that connects to the database:
pgschema dump --schema public
- The command fails with a connection error, showing that it is attempting to connect to
127.0.0.1:5432instead of the host defined in the.envfile. 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)