Cant connect R and PostgreSQL throught Putty -


i have problem integration postgresql , r. unload outputs sql queries .txt file , download em r using read.table() function. need outputs queries directly in r. know sql? it's postgresql, use putty connect db know such information putty connection as

  1. host name(or ip adress)
  2. port
  3. saved session ='dbcenter'
  4. connectiontype = ssh
  5. key -- file .ppk extension
  6. passphrase key

also, before writing queries, choose in opened window

  1. region
  2. databases

this full information know putty , have no idea how write queries directly in r script. tried rpostgresql package, no success.

can me?

firstly, make sure can connect remote db without r, example, using pgadmin3 or psql (see link1 , link2 more idea pgadmin/psql/remote/port forwarding).

then, try along these lines:

dbname <- "myname"; dbuser <- "myname"; dbpass <- "iwillnottell"; dbhost <- "remotehostname"; dbport <- 5432; 

if remote host withing same local network (ie, local host myhost.host.edu), then, following should work well:

dbhost <- "remote"  library(rpostgresql) drv <- dbdriver("postgresql") con <- dbconnect(drv, host=dbhost, port=dbport, dbname=dbname,                  user=dbuser, password=dbpass) query = 'select * tablename' dbgetquery(con, query) sqldata<-dbgetquery(con, query) summary(sqldata) 

sqldata dataframe

the important thing firewall , access db. suggest, using pgadmin3 make sure can connect server.

if local firewall not allow connection postgresql server port you'll need use ssh tunneling - connection can pretty slow depending on how remote remote host is. example:

assuming sever allows listens "localhost" (this wrt server), then:

ssh -l 22222:localhost:5432 myname@remotehostname

will forward 22222 port on client remote's 5432 port. again, use pgadmin3 @ point make can connect.

then set

dbhost <- "localhost"; dbport <- "22222"

and use same dbconnect call. once dbconnect call successfull sql results in r local


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -