1

我无法使用 RPostgreSQL 连接到我的 AWS Redshift 数据库。

有没有人有一个可以工作的代码示例?

library (RPostgreSQL)
drv <- dbDriver("PostgreSQL")
conn <- dbConnect(drv, "database.us-east-1.redshift.amazonaws.com",  "jeffz", "PsWrd123")    
Error in postgresqlNewConnection(drv, ...) : 
  RS-DBI driver: (could not connect database.us-east-1.redshift.amazonaws.com@PsWrd123 on dbname "database.us-east-1.redshift.amazonaws.com"

在环境中设置了 jre7 的驱动程序路径中的 Windows 7 postgresql-8.4-703.jdbc4

4

2 回答 2

3

我有同样的问题 - 这是一个对我“有效”的代码示例

使用库 (RPostgreSQL)

library (RPostgreSQL)
drv <- dbDriver("PostgreSQL")
con1 <- dbConnect(drv, host="hydrogen2.YOURHOST.us-east-1.redshift.amazonaws.com", 
                 port="5439",
                 dbname="mydb", 
                 user="master_user", 
                 password=password)
con1 # check that you have a connection (e.g. <PostgreSQLConnection:(8892,0)>  )
### Make sure AWS has the security/access permissions opened up to allow Port 5439 access from YOUR IP (or all IPs)

使用库(RODBC)

password <- read.table(file="private.txt", header=FALSE) # where I'm holding pw
password <- paste(password[1,1], sep="") #

library(RODBC)
con2 <- odbcConnect("AWS_hydrogen2_source", uid = "master_user", pwd = password) # east region
con2 # works!  if a positive integer, you are connected
odbcGetInfo(con2)

完整代码在这里:

https://dreamtolearn.com/ryan/data_analytics_viz/93

https://github.com/rustyoldrake/AWS_Redshift_S3_R_Interface

* 正如其他人所说 - 如果系统无法连接- 确保 AWS 已打开安全/访问权限以允许从您的 IP(或所有 IP)访问端口 5439 - 默认情况下它们未打开,所以如果您不打开t打开它们,您将无法连接

于 2015-06-15T21:50:17.850 回答
0

通过为所有 IP 指定 0.0.0.0/0 确保您允许访问 RDS 安全组

于 2014-01-17T04:24:53.757 回答