I connect to a PostgreSQL DB via RPostgres to perform queries.
My current workflow is the following:
In the terminal, I create a tunnel via ssh.
ssh -L PORT:host:25060
On top of my R script, I create the DB connection:
# use RPostgres library require(RPostgres) # create db instance db = dbConnect( Postgres(), user = 'user', password = 'password', dbname = 'dbname', host = '127.0.0.1', port = 5433, sslmode = 'require' )
I then query the database.
Every time I relaunch the R session or connect to a different tunnel, or I want to schedule a script, this procedure doesn't work.
Is there a way to incorporate the tunnel creation in thee R script? Moreover, how to properly encrypt the password and sensitive information?
Best,