SSL模式下使用psql连接PostgreSQL [英] Using psql to connect to PostgreSQL in SSL mode

查看:38
本文介绍了SSL模式下使用psql连接PostgreSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 PostgreSQL 服务器配置 ssl 证书.我在数据目录中创建了一个证书文件 (server.crt) 和密钥 (server.key),并将参数 SSL 更新为on".启用安全连接.

I am trying to configure ssl certificate for PostgreSQL server. I have created a certificate file (server.crt) and key (server.key) in data directory and update the parameter SSL to "on" to enable secure connection.

我只希望服务器在客户端使用服务器证书进行身份验证,而不需要服务器端客户端的真实性.我使用 psql 作为客户端来连接和执行命令.

I just want only the server to be authenticated with server certificates on the client side and don't require the authenticity of client at server side. I am using psql as a client to connect and execute the commands.

我正在使用 PostgreSQL 8.4 和 Linux.我尝试使用以下命令连接到启用 SSL 的服务器

I am using PostgreSQL 8.4 and Linux. I tried with the below command to connect to server with SSL enabled

       psql "postgresql://localhost:2345/postgres?sslmode=require"

但我得到了

       psql: invalid connection option "postgresql://localhost:2345/postgres?sslmode"

这里做错了什么?我尝试连接到启用 SSL 模式的服务器的方式是否正确?只验证服务器而不验证客户端可以吗?

What am doing wrong here? Is the way I am trying to connect to server with SSL mode enabled is correct? Is it fine to authenticate only server and not the client ?

推荐答案

psql 9.2 以下的选项不接受这种类似 URL 的语法.

psql below 9.2 does not accept this URL-like syntax for options.

可以通过命令行上的 sslmode=value 选项或 PGSSLMODE 环境变量,但默认为 prefer,SSL 连接将首先自动尝试,无需指定任何内容.

The use of SSL can be driven by the sslmode=value option on the command line or the PGSSLMODE environment variable, but the default being prefer, SSL connections will be tried first automatically without specifying anything.

conninfo 字符串示例(已针对 psql 8.4 更新)

Example with a conninfo string (updated for psql 8.4)

psql "sslmode=require host=localhost dbname=test"

阅读手册页了解更多选项.

这篇关于SSL模式下使用psql连接PostgreSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆