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
- host name(or ip adress)
- port
- saved session ='dbcenter'
- connectiontype = ssh
- key -- file .ppk extension
- passphrase key
also, before writing queries, choose in opened window
- region
- 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
Post a Comment