0

I'm trying to connect from RStudio on my Mac to a PostgreSQL database. The following code chunk works successfully on the Windows and Mac RStudio installs of my colleagues.

blah.blah.rds.amazonaws.comblah.blah.rds.amazonaws.com"
dbport <- 5432
dbuser <- "my_username"
dbname <- "my_db_name"
dbpw <- "my_password"
library(DBI)
library(RPostgres)
conn <- dbConnect(RPostgres::Postgres(),
                  dbname = dbname,
                  host = dbhost,
                  port = dbport,
                  user = dbuser,
                  password = dbpw
)
df <- dbGetQuery(conn, "SELECT * FROM my_schema.my_table LIMIT 10;")
dbDisconnect(conn)

But using my machine I receive the following error from the dbConnect() call.

# Error: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request:

I can connect to the db in question through a client like PGAdmin and from python. Any ideas what the problem could be? My sessionInfo is:

R version 3.6.3 (2020-02-29)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6
Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
other attached packages:
[1] RPostgres_1.2.0 DBI_1.1.0      
loaded via a namespace (and not attached):
 [1] bit_1.1-15.2    compiler_3.6.3  hms_0.5.3       tools_3.6.3     Rcpp_1.0.4.6    bit64_0.9-7     vctrs_0.2.4     knitr_1.28     
 [9] blob_1.2.1      xfun_0.13       pkgconfig_2.0.3 rlang_0.4.5
N.A.K
  • 35
  • 6
  • Is this similar? https://stackoverflow.com/questions/15934364/psql-server-closed-the-connection-unexepectedly – 9314197 Apr 28 '20 at 16:24
  • Second the hint by user @9314197 -- was original maintainer of RPostgreSQL as well as of another piece of software connecting to PostgreSQL. You *must* allow for network connection; the fact that `psql` connects is not suffcient. In other words, it is likely the _server_ side not the macOS client side. – Dirk Eddelbuettel Apr 28 '20 at 20:16
  • Why should other users at the same time be connected through same clients/other clients (RStudio via `RPostgres` on macOS and Windows) whilst OP cannot form a connection? What other diagnostics can sought to identify issue with server and the OP's client install? – mark Apr 28 '20 at 20:30
  • That would indeed be odd. On new machines, or after upgrades, I usually set up the host/network settings for the PostgreSQL server such that another machine on my subnet (say, laptop) could connect. Then my server generally could too. I could paste my settings if it is considered helpful -- been doing this on the home linux server since the 1990s ... – Dirk Eddelbuettel Apr 28 '20 at 21:29
  • Oh, here is another one. Sometimes the `id` tools is used to check if user name on server and client is the same. For that the server calls back to the requesting client _which must have the appropriate RPC program installed_. That behavior can be turned off in the server but is, if memory serves, on my default. – Dirk Eddelbuettel Apr 28 '20 at 21:30

0 Answers0