how to set up the psql command in cygwin?

对着背影说爱祢 提交于 2019-12-03 07:22:45

问题


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?


回答1:


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!




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/14489594/how-to-set-up-the-psql-command-in-cygwin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!