RPostgreSQL 无法连接到服务器 [英] RPostgreSQL cannot connect to the server
本文介绍了RPostgreSQL 无法连接到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过 R 访问 PostgreSQL 数据库.我尝试了以下代码:
I'm trying to access a PostgreSQL database through R. I tried the following code:
library(RPostgreSQL)
library(DBI)
drv <- dbDriver("PostgreSQL")
con = dbConnect(drv, #constructs SQL driver
host = MyHost,
port = MyPort,
dbname = MyDbname,
user = MyUser,
password = pw)
我的电脑上已经安装了 PostgreSQL.由于我的所有凭据都正确,我仍然收到此错误:
I already have PostgreSQL installed on my computer. With all my credentials being correct, I still get this Error:
Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect [MyUser]@[MyHost] on MyDbname
有什么想法会导致问题吗?同样的问题在这里没有解决方案呢.感谢您的帮助
any ideas what causes the problem? The same problem here has no solution yet. Thanks for your help
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)
卡西亚
推荐答案
最后,我用RPosgres
包成功连接到数据库
At the end, I managed to connect to the database with RPosgres
package
install.packages("devtools") and load them
devtools::install_github("RcppCore/Rcpp")
devtools::install_github("rstats-db/DBI")
devtools::install_github("rstats-db/RPostgres")
con <- dbConnect(RPostgres::Postgres(),
host = MyHost,
port = MyPort,
dbname = MyDbname,
user = MyUser,
password = pw)
res <- dbSendQuery(con, "SELECT * FROM orders LIMIT 10")
dbFetch(res)
dbClearResult(res)
这篇关于RPostgreSQL 无法连接到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文