## Tuesday, June 13, 2017

### PosgreSQL on Windows: could not find a "psql" to execute

I installed PostgreSQL 9.6.3 on a Windows host. After I had run batch file pg_env.bat on the host, I encountered the following error message when I ran psql

could not find a "psql" to execute
psql: could not find own program executable

It turns out that the quotation marks for path of the PostgreSQL binary from the batch file pg_env.bat is the culprit. For instance, the pg_env.bat batch file on my Windows host has the following content,

@ECHO OFF
REM The script sets environment variables helpful for PostgreSQL

@SET PATH="C:\Program Files\PostgreSQL\9.6\bin";%PATH%
@SET PGDATA=L:\stackoverflow\Data
@SET PGDATABASE=postgres
@SET PGUSER=postgres
@SET PGPORT=5432
@SET PGLOCALEDIR=C:\Program Files\PostgreSQL\9.6\share\locale

To correct the problem, we need to remove the quotation marks from the "SET PATH" line, i.e., to change the file to the following,

@ECHO OFF
REM The script sets environment variables helpful for PostgreSQL

@SET PATH=C:\Program Files\PostgreSQL\9.6\bin;%PATH%
@SET PGDATA=L:\stackoverflow\Data
@SET PGDATABASE=postgres
@SET PGUSER=postgres
@SET PGPORT=5432
@SET PGLOCALEDIR=C:\Program Files\PostgreSQL\9.6\share\locale