How to add SSL Certificate to postgresql

Hi! I am trying to connect to a Postgres database which requires a client SSL certificate to access instead of a password. Using pgAdmin, I specify a username and the file that contains my SSL certificate. I have the following code which when run, gives the error: "R Session Aborted. R encountered a fatal error. The session was terminated" in a white pop-up box, with the only option to "Start New Session"

I appreciate all and any help! Thank you!


library(DBI)
library(RPostgres)

rt_cert <- paste0("PATH_OF_ROOT_CERTIFICATE/root-ca.crt")
cl_cert <- paste0("PATH_OF_ROOT_CERTIFICATE/xxx.crt")
cl_key <- paste0("PATH_OF_ROOT_CERTIFICATE/xxx.key")

pg_dsn = paste0(
    'dbname=', 'NAME_OF_DB', ' ',
    'Root certificate=', rt_cert, ' ',
    'Client certificate=', cl_cert, ' ',
    'Client certificate key=', cl_key, ' ',
    'ssl mode=verify-full'
)

con <- dbConnect(drv = RPostgreSQL::PostgreSQL(), 
          dbname=pg_dsn, 
          host='PATH_OF_HOST', 
          port=5432, 
          user = rstudioapi::askForPassword("Database user"))

2 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.