无法使用RPostgreSQL连接到AWS Redshift

时间:2013-12-26 16:43:01

标签: r amazon-web-services amazon-redshift rpostgresql r-dbi

我无法使用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"

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

2 个答案:

答案 0 :(得分: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开放允许端口5439访问的安全/访问权限(或所有IP) - 默认情况下它们没有打开,所以如果你不打开它们,你将无法连接

答案 1 :(得分:0)

确保通过指定允许在RDS安全组中进行访问 所有IP均为0.0.0.0/0