我正在运行需要 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/