为 Postgres 工具设置 Windows PATH

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11460823/
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-09-09 09:41:52  来源:igfitidea点击:

Setting Windows PATH for Postgres tools

windowspath

提问by umezo

I cannot access PostgreSQL through the command line in Windows.Although I am able to create and update the databases, access them through PGAdminIII, and push to Heroku, I am unable to access them directly through my command line using the psql command.

我无法通过 Windows 中的命令行访问 PostgreSQL。尽管我能够创建和更新数据库,通过 PGAdminIII 访问它们并推送到 Heroku,但我无法使用 psql 命令通过我的命令行直接访问它们。

When I try to create a database by using the command

当我尝试使用命令创建数据库时

$ createdb mydb

as explained in the PG documentation, I get the message

PG 文档中所述,我收到消息

createdb: command not found

The documentation suggests that in this case, "PostgreSQL was not installed properly. Try calling the command with an absolute path instead." Sure enough, I am able to create a database by entering the direct path to the file:

文档表明,在这种情况下,“PostgreSQL 安装不正确。请尝试使用绝对路径调用命令。” 果然,我可以通过输入文件的直接路径来创建数据库:

$ c:/postgreSQL/9.1/bin/createdb mydb

Does this mean that the path can be reconfigured to connect correctly? Or do I need to reinstall? I've reinstalled several times, and have not been able to set the correct path. I currently have both the /bin and /lib paths addedto my system and user(:Umezo) paths, but still no access from the command line.

这是否意味着可以重新配置路径以正确连接?还是我需要重新安装?我重装了好几次了,一直没能设置正确的路径。我目前已将 /bin 和 /lib 路径添加到我的系统和用户(:Umezo)路径中,但仍然无法从命令行访问。

User variables for umezo
variable name: Path
variable value: C:\PostgreSQL.1\bin; C:\PostgreSQL.1\lib

System variables
variable name: Path
variable value: C:\PostgreSQL.1\bin; C:\PostgreSQL.1\lib

Any information or feedback regarding how I can fix my installment would be appreciated.

任何有关我如何修复分期付款的信息或反馈将不胜感激。

My info is as below:

我的信息如下:

I mostly followed these sources hereand here. I installed a 32 bit version of 9.1 because some sources suggested issues with 64 bit.

我主要在这里这里遵循这些来源。我安装了 9.1 的 32 位版本,因为一些消息来源表明 64 位存在问题。

PG download version: Installer Version 9.1 Win x86-32
Operating System: Windows 7 (64 bit)

pg_hba.conf

pg_hba.conf

#TYPE     DATABASE     USER     CIER-ADDRESS     METHOD
# IPv4 local connections:
host      all          all      127.0.0.1/32     md5
# IPv6 local connections:
host      all          all      ::1/128          md5    

postgresql.conf

配置文件

# - Connection Settings -
listen_addresses = '*'
port = 5432
max_connections = 100

pg_ident.conf

pg_ident.conf

# *Everything is commented out*

Login Role Umezo#from properties window in PGAdminIII

登录角色 Umezo #from PGAdminIII 中的属性窗口

Properties/Role name: Umezo
Properties/Can login: "check"
Role privileges: all categories "check"

回答by Micah Stubbs

configuring postreSQL PATH variable on Windows 7

在 Windows 7 上配置 postreSQL PATH 变量

I encountered this issue too. I'm using Git Bash, hence the Unix-style $ prompt on Windows.

我也遇到了这个问题。我正在使用Git Bash,因此在 Windows 上使用Unix 风格的 $ 提示。

$ rails db
Couldn't find database client: psql, psql.exe.  Check your $PATH and try again.

Here's what I did:

这是我所做的:

In Windows 7, navigate to:

在 Windows 7 中,导航到:

Control Panel
  All Control Panel Items
    System
      Advanced System Settings
        Environment Variables
          from the System Variables box select "PATH"
              Edit...

Then append this string to the existing PATH Variable Value:

然后将此字符串附加到现有的 PATH 变量值:

;C:\Program Files\PostgreSQL\9.2\bin

;C:\Program Files\PostgreSQL\9.2\bin

and click "OK" three times to exit the menus.

并单击“确定”三下以退出菜单。

Now, close the console and restart it.

现在,关闭控制台并重新启动它。

Navigate back to the directory of your Rails app. In my case, this is accomplished with:

导航回您的 Rails 应用程序的目录。就我而言,这是通过以下方式完成的:

$ cd rails_projects/sample_app

$ cd rails_projects/sample_app

Then, try again:

然后,再试一次:

$ rails db

$ rails db

sources:

来源:

How do I put PostgreSQL /bin directory on my path in Windows?

如何将 PostgreSQL /bin 目录放在 Windows 中的路径上?

http://railscasts.com/episodes/342-migrating-to-postgresql?view=asciicast

http://railscasts.com/episodes/342-migrating-to-postgresql?view=asciicast

回答by Transformer

Settings Windows Path For Postgresql

Postgresql 的设置 Windows 路径

open my Computer ==>
  right click inside my computer and select properties ==>
    Click on Advanced System Settings ==>
       Environment Variables ==>
          from the System Variables box select "PATH" ==>
             Edit... ==>

then add this at the end of whatever you find their

然后在你找到他们的任何东西的末尾添加这个

 ;C:\PostgreSQL.2\bin; C:\PostgreSQL.2\lib

after that continue to click OK

之后继续单击确定

open cmd/command prompt.... open psql in command prompt with this

打开 cmd/命令提示符.... 用这个在命令提示符下打开 psql

psql -U username database

eg. i have a database name FRIENDS and a user MEE.. it will be

例如。我有一个数据库名称 FRIENDS 和一个用户 MEE ..它将是

psql -U MEE FRIENDS

you will be then prompted to give the password of the user in question. Thanks

然后系统会提示您提供相关用户的密码。谢谢

回答by a_horse_with_no_name

All you need to do is to change the PATH variable to include the bindirectory of your PostgreSQL installation.

您需要做的就是更改 PATH 变量以包含binPostgreSQL 安装目录。

An explanation on how to change environment variables is here:

关于如何更改环境变量的说明如下:

http://support.microsoft.com/kb/310519
http://www.computerhope.com/issues/ch000549.htm

http://support.microsoft.com/kb/310519
http://www.computerhope.com/issues/ch000549.htm

To verify that the path is set correctly, you can use:

要验证路径设置是否正确,您可以使用:

echo %PATH%

on the commandline.

在命令行上。

回答by zhrist

On Postgres 9.6(PgAdmin 4) , this can be set up in Preferences->Paths->Binary paths: - set PostgreSQL Binary Path variable to "C:\Program Files\PostgreSQL\9.6\bin" or where you have installed

在 Postgres 9.6(PgAdmin 4) 上,这可以在 Preferences->Paths->Binary paths 中设置: - 将 PostgreSQL Binary Path 变量设置为 "C:\Program Files\PostgreSQL\9.6\bin" 或您安装的位置

回答by Mustafa Hayati

In order to connect my git bash to the postgreSQL, I had to add at least 4 environment variables to the windows. Git, Node.js, System 32 and postgreSQL. This is what I set as the value for the Path variable: C:\Windows\System32;C:\Program Files\Git\cmd;C:\Program Files\nodejs;C:\Program Files\PostgreSQL\12\bin;and It works perfectly.

为了将我的 git bash 连接到 postgreSQL,我必须向 windows 添加至少 4 个环境变量。Git、Node.js、System 32 和 postgreSQL。这就是我为 Path 变量设置的值:C:\Windows\System32;C:\Program Files\Git\cmd;C:\Program Files\nodejs;C:\Program Files\PostgreSQL\12\bin;它完美地工作。

回答by Jatin Chauhan

Set path For PostgreSQL in Windows:

在 Windows 中为 PostgreSQL 设置路径:

  1. Searching for envwill show Edit environment variablesfor your account
  2. Select Environment Variables
  3. From the System Variables box select PATH
  4. Click New(to add new path)
  1. 搜索env将显示Edit environment variablesfor your account
  2. 选择环境变量
  3. 从系统变量框中选择PATH
  4. 单击新建(添加新路径)

Change the PATH variable to include the bindirectory of your PostgreSQL installation.
then add new path their....[for example]

更改 PATH 变量以包含PostgreSQL 安装的bin目录。
然后添加新路径他们的....[例如]

C:\Program Files\PostgreSQL\bin

After that click OK

之后点击确定

Open CMD/Command Prompt. Type this to open psql

打开CMD/命令提示符。键入此以打开psql

psql -U username database_name

For Example psql -U postgres test

例如 psql -U postgres test

Now, you will be prompted to give Passwordfor the User. (It will be hidden as a security measure).

现在,系统将提示您为用户提供密码(它将被隐藏作为安全措施)。

Then you are good to go.

然后你就可以走了。

回答by Vignesh

I am using Windows 8 and the above solutions did not work out for me. I downgraded Postgres from 9.4 to 9.3. Man,it worked :)

我使用的是 Windows 8,上述解决方案对我不起作用。我将 Postgres 从 9.4 降级到 9.3。伙计,它奏效了:)