【问题标题】:Connecting Rstudio to PostgresSQL将 Rstudio 连接到 PostgresQL
【发布时间】:2019-07-14 01:46:15
【问题描述】:

我正在尝试使用 DBI 和 RPostgres 从 Rstudio 连接到外部数据库 (PostgresSQL)。我定义了所有参数:

con <- DBI::dbConnect(RPostgres::Postgres(),
                      dbname = 'name', 
                      host = 'http://bi-warehouse.cngdka9w0zww.us-east-1.rds.amazonaws.com/',
                      port = 5432,
                      user = 'user',
                      password = 'passwd')

但仍然出现错误:

    Error in connection_create(names(opts), as.vector(opts)) : 
  could not translate host name "http://bi-warehouse.cngdka9w0zww.us-east-1.rds.amazonaws.com/" to address: Name or service not known

【问题讨论】:

  • http 不是数据库协议;)您必须删除错误信息;)
  • 所以,主机参数只有:bi-warehouse.cngdka9w0zww.us-east-1.rds.amazonaws.com/
  • 现在我得到了以下信息:Error in connection_create(names(opts), as.vector(opts)) : could not connect to server: No route to host Is the server running on host "bi-warehouse.cngdka9w0zww.us-east-1.rds.amazonaws.com" (10.0.1.103) and accepting TCP/IP connections on port 5432?
  • 在没有交易斜线的情况下,这不是网站的路线 :) 它只是您安装 postgreSQL 的服务器(主机)的域,您是否检查过,您的 postgreSQL 可以是从外部系统连接,默认只允许本地连接。

标签: rstudio dbi rpostgresql


【解决方案1】:

试用 RPostgreSQL 包

例子:-

library(RPostgreSQL)
library(dplyr)
library(dbplyr)
psql <- DBI::dbDriver("PostgreSQL")
con <- DBI::dbConnect(psql, 
                      dbname = "machine_db",
                      host = "192.168.13.213", 
                      port = 5432,
                      user = "user", 
                      password = 'user123')

machine_data <- dbGetQuery(con, "SELECT * from machine_db")

【讨论】:

    【解决方案2】:

    使用 RPostgres 包

    更多信息-https://github.com/r-dbi/RPostgres

    library(DBI)
    library(RPostgres)
    
    conn <- dbConnect(RPostgres::Postgres(),
                     host = "xyz-db-postgresql.postgres.database.aws.com",
                     port = 5432,
                     dbname = "xyz",
                     user = "xyz",
                     password = "password"
    )
    
    #==== Top 100 Records Of CommodityTable ====
     qr<- paste0('SELECT * from "Cxtable " LIMIT 100')
     Cxtable <- dbGetQuery(conn, qr)
     Cxtable
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-25
      • 2016-12-24
      • 1970-01-01
      • 1970-01-01
      • 2017-05-23
      相关资源
      最近更新 更多