I have a local dev site on my machine with Apache server and PostgreSQL 9.1 database. As I'm using Windows, I also installed Cygwin. I want to access to database and make some queries via Cygwin insead of pgAdmin III, but it tells me that psql command not found. How should I set up the psql command in cygwin?
-
cygwin is no longer "officially" supported by postgres ( see manual: "Cygwin is not recommended for running a production server, and it should only be used for running on older versions of Windows where the native build does not work,such as Windows 98.") Is there a specific reason you do not want to use pgAdmin, or the native windows psql provided? – Robert H Jan 23 '13 at 21:29
-
@RobertH Actually no specific reason, I just think it would be convenient to do all the things in cygwin instead of keeping another pgAdmin program next to it. By the way, what is the native windows psql you mentioned? – chaonextdoor Jan 23 '13 at 21:33
-
@RobertH One more thing, actually I can access to the database of our production site via cygwin using psql. But as I'm windows, I think maybe I need some extra setup thing to access to my local database. – chaonextdoor Jan 23 '13 at 21:37
-
You should have psql listed in the bin directory of your postgresql installation. I'm not sure why you can access a remote instance, but not local - is your local database located within a cygwin instance? or is it on the local machine ( windows ) but you are looking to connect via cygwin? – Robert H Jan 23 '13 at 21:40
-
@RobertH It's on my local machine and I'm trying to connect via cygwin. – chaonextdoor Jan 23 '13 at 21:42
-
I am unable to dig up any information on your situation - personally I have never used cygwin as I just use pgAdmin or psql, you may want to post to the mailing list located at http://www.postgresql.org/community/. – Robert H Jan 23 '13 at 21:58
-
The "*native Windows psql*" is part of the Postgres installation and can be found in its `bin` directory. Unfortunately there is no "client installation" package for Postgres, but you can simply download a ZIP archive and unzip it. Then you'll have the native psql client. – Jan 23 '13 at 22:44
-
The closest thing to a 'client' install of Postgres is the ODBC driver. That can be installed separately, and it contains psql.exe. You can get it here:[PostgreSQL ODBC Driver](http://www.postgresql.org/ftp/odbc/versions/msi/). @chaonextdoor What command are you using to connect to your local instance, and what is it responding with? – Brian.D.Myers Jan 31 '13 at 01:00
3 Answers
As of today, you just have to install postgresql-client package in cygwin:
- Run your cygwin setup.exe file (this can be run multiple times to add more packages).
- Type postgresql into the search box, select postgresql-client and press "next" to install.
Now you can open Cygwin terminal and type psql to run!

- 553
- 5
- 12
The best combo for Cygwin on Windows, I've found, is the normal Windows Postgres installation combined with Cygwin psql.
Cygwin psql (and other command-line tools) can be compiled from source fairly easily. Here's the steps for 9.2.4:
$ wget http://ftp.postgresql.org/pub/source/v9.2.4/postgresql-9.2.4.tar.bz2
$ tar xjf postgresql-9.2.4.tar.bz2
$ cd postgresql-9.2.4/
$ ./configure
$ cd src/bin/psql
$ make
This creates a psql.exe binary that works well with Cygwin. However, by default, it tries to connect to the local instance using a Unix socket instead of TCP. So use -h to specify the hostname and force TCP, for example:
$ ./psql -h localhost -U postgres
Move this psql.exe to someplace on your path (e.g. ~/bin) and possibly wrap in a script to add '-h localhost' for convenience when no other arguments supplied.
The source could be modified to change the default, but that takes actual work ;)

- 41,404
- 5
- 117
- 189
If I understand your question correctly you are running cygwin because you want to run queries against PostgreSQL via bash and psql on Windows, right?
Cygwin can run Windows binaries from bash, so install the native Windows builds and make sure psql.exe is in the PATH
You should be able to copy the executable if necessary.
There is no need to install a native Cygwin build of PostgreSQL. Just use the existing psql tool, and make sure you can access the Windows-native psql.exe.

- 25,424
- 6
- 65
- 182
-
1Windows psql uses Windows console functions; Cygwin runs best in a terminal like Console2, which doesn't support Windows console API. So psql doesn't work well with Cygwin at all. What's needed is a Cygwin build of client tools like psql. – Barry Kelly May 25 '13 at 17:36