Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set up the psql command in cygwin?

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?

like image 583
chaonextdoor Avatar asked Jan 23 '13 21:01

chaonextdoor


People also ask

What is psql command line?

psql is a terminal-based front-end to PostgreSQL. It enables you to type in queries interactively, issue them to PostgreSQL, and see the query results. Alternatively, input can be from a file or from command line arguments.

How do I start psql EXE?

open command prompt first ( Winkey+R ), then type C:\Program Files\PostgreSQL\10\bin\psql.exe , then press enter and type in password. This is different from what you did by not closing psql.exe after you get error.


2 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.

enter image description here

Now you can open Cygwin terminal and type psql to run!

enter image description here

like image 120
Cao Minh Tu Avatar answered Sep 28 '22 22:09

Cao Minh Tu


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 ;)

like image 32
Barry Kelly Avatar answered Sep 28 '22 22:09

Barry Kelly