R postgres 连接到 RS-DBI 驱动程序中的远程测量错误

R postgres connection to remote survey error in RS-DBI driver

我这辈子都无法获得远程 postgres 数据库的 postgres 连接。

"Error in postgresqlNewConnection(drv, ...) : 
  RS-DBI driver: (could not connect"

我安装了 RPostgreSQL,后台有 postgres 运行,我的 macbook 是最新的 10.12.5 macOS sierra。

仍然无法连接

  drv <- dbDriver("RPostgreSQL")
 > con <- dbConnect(drv, host=hostName, 
 +                  port=portName,
+                  dbname=databaseName, 
+                  user=userName, 
+                  password=passwordName)
Error in postgresqlNewConnection(drv, ...) : 
  RS-DBI driver: (could not connect

值得注意的是..我可以通过 postico 应用程序连接所有相同的凭据。

我遇到了同样的问题。我最终使用了 RPostgres 包。

免责声明:我无法完全按照 git_hub 说明安装软件包;

以下是我在 windows 上成功安装它的方法:

1) 按照说明安装 Rtools here:

2) 安装 devtools:

install.packages("devtools")

3) 按照说明安装RcppDBI

devtools::install_github("RcppCore/Rcpp")
devtools::install_github("rstats-db/DBI")

4) 通过单击 克隆和下载 下载 github 上的 RPostgres 源文件;将其解压到一个文件夹;

5) 从源文件夹安装 RPostgres

install.packages("path_to_downloads/Downloads/RPostgres-master/", repos = NULL, type="source")

我正在使用 Windows,下面是对我来说效果很好的代码: 我认为我需要 RPostgreSQL 和 RPostgres 这两个东西真的很奇怪。我尝试仅使用 RPostgreSQL 或 RPostgres,但由于您遇到的错误或其他原因而失败。但是下面的顺序是必要的并且有效。

install.packages("RPostgreSQL")
require(RPostgreSQL)
install.packages("RPostgres")
require(RPostgres)
install.packages("DBI")
require(DBI)

#Create a connection
con <- dbConnect(RPostgres::Postgres(),
                 dbname = "REMOTE_DB_NAME",
                 host = "xx-redshift-xx.yyy.com",
                 port = "XXXX",
                 user = "****", password = "****")

dbListTables(con)

如果您运行遇到问题,请告诉我。