r - 无法使用 SSL 创建到 Postgres 的 dbConnect

标签 r windows libpq rpostgresql

我正在运行需要 SSL 的 Postgres-9.4 服务器。当我使用 pgadmin 或 windows odbc 连接从我的笔记本电脑连接到 Postgres 服务器时,它可以使用 SSL。但是,当我尝试使用 SSL 连接 R 时,它失败了。

library(RPostgreSQL)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, 
                 user = "postgres", 
                 password = mypasswd, 
                 dbname = "dbname=postgres sslmode=prefer",
                 host = "192.168.1.179")

如果我将 pg_hba.conf 设置为允许非 ssl 连接,那么这将起作用。当我将它设置为只允许 SSL 连接时,这将失败。不幸的是dbConnect没有 verbose选项,所以除了 could not connect postgres@192.168.1.179 on dbname "postgres" 我什么也得不到

我找到了 this question这似乎表明我在做正确的事情,但是,不行。

编辑:

我做了更多的挖掘,发现了 this discussion这表明由于各种库/dll 问题,这在 Windows 上不起作用。那个讨论在这一点上已经有几年了,所以也许它已经解决了。我可以确认从 linux 执行上述操作确实有效。

最佳答案

我对这个问题的理解是 RPostgreSQL 使用了一个不支持 SSL 的客户端。

我切换到包 RPostgres 并让它工作。我首先用 install.packages('RPostgres') 安装了 RPostgres然后使用此包与 sslmode="require"连接。

library('RPostgres') #Instead of library('RPostgreSQL')
con <- dbConnect(RPostgres::Postgres(),
                 user = "postgres", 
                 password = mypasswd, 
                 dbname = "postgres",
                 host = "192.168.1.179",
                 sslmode = "require")
)

关于r - 无法使用 SSL 创建到 Postgres 的 dbConnect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34244210/

相关文章:

python - Fedora30 上 libpq.so.5 和 PQencryptPasswordConn 版本 RHPG_10 的问题

c - 未定义对 `PQconnectdb' 的引用

go - 我可以在生产中使用 master libpq 吗

ROCR 错误 : Format of predictions is invalid

c - 在 WOW64 上运行的 32 位进程的实际页面大小是多少?

node.js - 使用app.relaunch后,如何阻止Electron应用重新启动?

windows - 模拟用户交互

r - 从 R 中的环境中删除对象

r - 在列中添加最后填写的字段(r 语言)

r - 提取树状图或集群中节点的层次结构