问题描述
我无法终生获得Postgres连接到远程Postgres数据库。
i cannot for the life of me get postgres connection a remote postgres db.
"Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect"
我有RPostgreSQL安装后,我在后台运行了postgres,我的Macbook是最新的10.12.5 macOS sierra。
I have RPostgreSQL installed, i have postgres running in the background, my macbook is up to date 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
.. i可以通过Postico应用连接所有相同的凭据
notably..i CAN connect with all the same credentials via postico app.
推荐答案
我正在使用Windows,下面的代码对我来说很有效:
想到我需要RPostgreSQL和RPostgres真的很奇怪。我尝试仅使用RPostgreSQL或RPostgres,但由于出现错误或其他原因而失败。但是,以下顺序是必要且可行的。
I am using Windows and here is the code that worked well for me:Something I thought was really weird that I needed both RPostgreSQL and RPostgres. I tried using only RPostgreSQL or RPostgres and failed with the error you got or something else. But this following order is necessary and worked.
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)
让我知道您是否遇到问题。
Let me know if you run into issues.
这篇关于R Postgres连接到RS-DBI驱动程序中的远程测量错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!