通过终端连接 Postgresql - pgadmin

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

Postgresql connection via terminal - pgadmin

postgresqlconnectionpostgresql-9.1

提问by Patric

I have a problem connecting (using SSH) to my virtualbox(ubuntu) postgres server. I set up all nice and correctly.

我在连接(使用 SSH)到我的 virtualbox(ubuntu) postgres 服务器时遇到问题。我设置得很好而且正确。

PostgreSQL settings:

PostgreSQL 设置:

  • postgresql.conf-> Allowed all incomming connection (*) and set ssl TRUE
  • pg_hba.conf -> after a lot of changes i came to the point where it seems to work with this settings:
  • postgresql.conf-> 允许所有传入连接 (*) 并设置 ssl TRUE
  • pg_hba.conf -> 经过大量更改后,我似乎可以使用此设置:

IP4

IP4

host all all 0.0.0.0/0 trust
hostssl all all 0.0.0.0/0 trust
host all all 192.168.x.x/32 trust 
hostssl all all 192.168.x.x/32 trust 

I tried:

我试过:

  1. Made restart of my postgres server on the virtual machine.

  2. Then i went to my host machine (Snow Leopard), build a ssh connection to the virtualbox (ubuntu) and it's working.

  3. ping my guest machine on port 5432 also works.

  4. Open pgadmin on my host machine (Snow Leopard) -> added server 192.68.56.1 and database pluto, user pippo. The connection worked and i see the DB.

  5. Tried open TERMINAL in Snow Leopard and executed following cmd:

    psql -h 192.168.56.1 -U pippo -d pluto
    

    with ERROR:

    psql: FATAL:  no pg_hba.conf entry for host "192.168.56.1", 
                  user "pippo", database "pluto", SSL off
    
  1. 在虚拟机上重新启动了我的 postgres 服务器。

  2. 然后我去了我的主机(Snow Leopard),建立到虚拟机(ubuntu)的 ssh 连接并且它正在工作。

  3. 在端口 5432 上 ping 我的访客机器也可以。

  4. 在我的主机(雪豹)上打开 pgadmin -> 添加服务器 192.68.56.1 和数据库pluto,用户pippo。连接有效,我看到了数据库。

  5. 尝试在 Snow Leopard 中打开 TERMINAL 并执行以下 cmd:

    psql -h 192.168.56.1 -U pippo -d pluto
    

    错误:

    psql: FATAL:  no pg_hba.conf entry for host "192.168.56.1", 
                  user "pippo", database "pluto", SSL off
    

I also tried to connect through my Java Program ans I got the same error.
What am I doing wrong?

我还尝试通过我的 Java 程序进行连接,但遇到了同样的错误。
我究竟做错了什么?

采纳答案by Erwin Brandstetter

pgAdmintries to connect with and without SSL by default.

pgAdmin默认情况下尝试使用和不使用 SSL 进行连接。

I suspect that you only try to connect withoutSSL via psql, while the server seems to require SSL for connections. Try:

我怀疑您只尝试通过不使用SSL 进行连接psql,而服务器似乎需要 SSL 进行连接。尝试:

psql "sslmode=require host=192.168.56.1 dbname=pluto" pippo

More about sslmodein the manual.

更多关于sslmode手册。

回答by profimedica

Open my query into pgAdmin from command line:

从命令行打开我对 pgAdmin 的查询:

-fThe file containing your SQL script to be loaded in the query window

-f包含要在查询窗口中加载的 SQL 脚本的文件

-qcThe connection string without password (you can also use ssl connections)

-qc没有密码的连接字符串(也可以使用ssl连接)

"C:\Program Files\PostgreSQL.4\bin\pgAdmin3.exe" -f "C:\slqFiles\FindFunctionByName.sql" -qc "host=localhost port=5432 dbname=myDatabase user=postgres"

The password will be collected from the passwordfile located in the application folder: %APPDATA%\postgresql\pgpass.conf

密码将从位于应用程序文件夹中的密码文件中收集: %APPDATA%\postgresql\pgpass.conf

You need permissionsfor connection. Try to add to C:\Program Files\PostgreSQL\9.6\data\pg_hba.conf next line:

您需要连接权限。尝试添加到 C:\Program Files\PostgreSQL\9.6\data\pg_hba.conf 下一行:

host all all ::/0 trust

托管所有 ::/0 信任