Dea*_*gor 7 windows r 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")
Run Code Online (Sandbox Code Playgroud)
如果我将 pg_hba.conf 设置为允许非 ssl 连接,那么这将起作用。当我将它设置为只允许 SSL 连接时,这将失败。不幸的dbConnect是没有verbose选择所以我什么也得不到could not connect postgres@192.168.1.179 on dbname "postgres"
我发现这个问题似乎表明我在做正确的事情,但是,不行。
编辑:
我做了更多的挖掘,发现这个讨论表明由于各种库/dll问题,这在 Windows 上不起作用。那个讨论在这一点上已经有几年了,所以也许它已经解决了。我可以确认从 linux 执行上述操作确实有效。
小智 2
我对这个问题的理解是 RPostgreSQL 使用不支持 SSL 的客户端。
我切换到 RPostgres 包并让它工作。我首先安装了 RPostgres,install.packages('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")
)
Run Code Online (Sandbox Code Playgroud)