postgresql 如何在 cygwin 中设置 psql 命令?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14489594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:45:12  来源:igfitidea点击:

how to set up the psql command in cygwin?

apachepostgresqlcygwinpsql

提问by chaonextdoor

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?

我的机器上有一个本地开发站点,带有 Apache 服务器和 PostgreSQL 9.1 数据库。因为我使用的是 Windows,所以我还安装了 Cygwin。我想访问数据库并通过 pgAdmin III 的 Cygwin insead 进行一些查询,但它告诉我找不到 psql 命令。我应该如何在 cygwin 中设置 psql 命令?

回答by Cao Minh Tu

As of today, you just have to install postgresql-clientpackage in cygwin:

截至今天,您只需要在 cygwin 中安装postgresql-client包:

  • Run your cygwin setup.exefile (this can be run multiple times to add more packages).
  • Type postgresqlinto the search box, select postgresql-clientand press "next" to install.
  • 运行您的 cygwin setup.exe文件(这可以运行多次以添加更多包)。
  • 类型的PostgreSQL在搜索框中,选择PostgreSQL的客户端,然后按“下一步”进行安装。

enter image description here

在此处输入图片说明

Now you can open Cygwin terminal and type psqlto run!

现在您可以打开 Cygwin 终端并输入psql来运行!

enter image description here

在此处输入图片说明

回答by Barry Kelly

The best combo for Cygwin on Windows, I've found, is the normal Windows Postgres installation combined with Cygwin psql.

我发现,Windows 上 Cygwin 的最佳组合是与 Cygwin psql 相结合的普通 Windows Postgres 安装。

Cygwin psql (and other command-line tools) can be compiled from source fairly easily. Here's the steps for 9.2.4:

Cygwin psql(和其他命令行工具)可以很容易地从源代码编译。以下是 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:

这将创建一个适用于 Cygwin 的 psql.exe 二进制文件。但是,默认情况下,它会尝试使用 Unix 套接字而不是 TCP 连接到本地实例。所以使用 -h 来指定主机名并强制使用 TCP,例如:

$ ./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.

将此 psql.exe 移动到您路径上的某个位置(例如 ~/bin),并可能在没有提供其他参数时包装在脚本中以添加“-h localhost”以方便使用。

The source could be modified to change the default, but that takes actual work ;)

可以修改源以更改默认值,但这需要实际工作;)

回答by Chris Travers

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,因为您想在 Windows 上通过 bash 和 psql 对 PostgreSQL 运行查询,对吗?

Cygwin can run Windows binaries from bash, so install the native Windows builds and make sure psql.exe is in the PATHYou should be able to copy the executable if necessary.

Cygwin 可以从 bash 运行 Windows 二进制文件,因此安装本机 Windows 版本并确保 psql.exe 位于PATH您应该能够在必要时复制可执行文件。

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.

无需安装 PostgreSQL 的本机 Cygwin 版本。只需使用现有的 psql 工具,并确保您可以访问 Windows 原生 psql.exe。