我这辈子都无法将 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 应用程序连接所有相同的凭据。
最佳答案
我使用的是 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)
如果您遇到问题,请告诉我。
关于R postgres 连接到 RS-DBI 驱动程序中的远程测量错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44401454/