I have a PostgreSQL database running which I want to access. It is stated that
By default, users are only allowed to login locally if the system username matches the PostgreSQL username.
So I created a user shiny in postgres. But I still see this error in the shiny-server logs:
Error in connection_create(names(opts), as.vector(opts)) :
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Calls: runApp ... <Anonymous> -> <Anonymous> -> .local -> connection_create
Execution halted
When running R as user root it works though. Any idea what is wrong?
Ok, I found the problem: The environment variables are empty for the user shiny.
I am creating the connection with
pool <- dbPool(RPostgres::Postgres(),
host = Sys.getenv("DB_HOST"),
user = Sys.getenv("DB_USER"),
password = Sys.getenv("DB_PASSWORD"),
port = 5432,
dbname = "postgres")
For the user root these variables are correctly resolved, but for the user shiny these are empty. I am setting the environment variables via the deployment.yaml file in Kubernetes.
How can I make sure that shiny-server can access these environment variables?