2

I am trying to connect to redshift database using R. Since I upgraded my mac to Monterey I receive a message in R as " R Session Aborted -R encountered a fatal error - the session was terminated" here is the code that produces the error sourcing it from here

Any advice on how to fix this error?

Connecting to RPostgreSQL

library("RPostgreSQL")
drv <- dbDriver('PostgreSQL')  
db <- 'myDatabase'  
host_db <- 'aws-us-east-1-portal.234.dblayer.com'  
db_port <- '98939'  
db_user <- 'henryviii'  
db_password <- ‘happydays’
conn <- dbConnect(drv, dbname=db, host=host_db, port=db_port, user=db_user, password=db_password)

I receive the following error when trying on terminal:

 *** caught segfault ***
address 0x8247a800, cause 'memory not mapped'

Traceback:
 1: postgresqlNewConnection(drv, ...)
 2: dbConnect(drv, dbname = db, host = host_db, port = db_port, user = db_user,     password = db_password)
 3: dbConnect(drv, dbname = db, host = host_db, port = db_port, user = db_user,     password = db_password)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

and here is an output of sessionInfo()

R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.0.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7           rstudioapi_0.13      magrittr_2.0.1       hms_1.1.1            tidyselect_1.1.1     bit_4.0.4           
 [7] R6_2.5.1             rlang_0.4.12         fansi_0.5.0          blob_1.2.2           dplyr_1.0.7          tools_4.1.2         
[13] RPostgres_1.4.3.9000 sessioninfo_1.2.2    utf8_1.2.2           cli_3.1.0            DBI_1.1.2            ellipsis_0.3.2      
[19] bit64_4.0.5          assertthat_0.2.1     tibble_3.1.6         lifecycle_1.0.1      crayon_1.4.2         purrr_0.3.4         
[25] vctrs_0.3.8          glue_1.6.0           compiler_4.1.2       pillar_1.6.4         generics_0.1.1       pkgconfig_2.0.3     ```
  • What is `db2`? It isn't defined in the linked tutorial, either. – r2evans Dec 28 '21 at 19:16
  • Which expression triggers the error? If you rename `db2` to `db`, does the crash change? – r2evans Dec 28 '21 at 19:17
  • I don't know if this is related to the RStudio IDE, please confirm if it fails in Rterm/Rgui itself as well. – r2evans Dec 28 '21 at 19:19
  • the error is triggered by db (removed DB2 line it doesn't add value here) – user17783243 Dec 28 '21 at 19:19
  • @r2evans yes I am using RStudio IDE so I am not sure if it's R installation that causes this, macOS, the RPostgreSQL or a combination of all – user17783243 Dec 28 '21 at 19:21
  • Is this specific to AWS instances of postgres, or are you able to reproduce it on a local database as well? You can likely start up a quick docker postgres database for testing, if you're at least a little familiar with docker. – r2evans Dec 28 '21 at 19:21
  • I understand that you're using RStudio, that's one reason I'm recommending you try *elsewhere*. If it doesn't break in Rterm as well, then this is a bug report for RStudio. It's useful to know where to start troubleshooting. – r2evans Dec 28 '21 at 19:22
  • @r2evans yes I get the same error on another database - is there a way to debug this ? – user17783243 Dec 28 '21 at 19:23
  • After you've verified that it fails also outside of RStudio, then we can remove that tag (since at that point it'll be confirmed as not an IDE-related issue). It will be good to include the output from `sessionInfo()` (or `sessioninfo::session_info()`, your choice) for versions and such. Also, please test using `RPostgres::Postgres()` as opposed to `RPostgreSQL::PostgreSQL()`, different code-bases for the same purpose and DBMS. – r2evans Dec 28 '21 at 19:26
  • 1
    @r2evans I was able to replicate the same error through a different IDE - removed Rstudio from the Tag and add the session info. – user17783243 Dec 28 '21 at 20:05
  • Does it crash using `RPostgres` instead of `RPostgreSQL`? – r2evans Dec 28 '21 at 20:14
  • Crashes using RPostgreSQL – user17783243 Dec 29 '21 at 01:22
  • *Have you tried using `RPostgres` without `RPostgreSQL`?* – r2evans Dec 29 '21 at 01:23
  • no - I haven't used Rpostgres before, I am using RPostgreSQL in my old mac and it was working fine, and trying to use the same scripts that I have – user17783243 Dec 29 '21 at 01:43
  • 2
    There are certainly differences between the two, but most people will never notice them. They both provide drivers used for `DBI` methods, so it is a drop-in replacement. I've been trying to recommend ways to troubleshoot where the issue lies, but if you won't test `RPostgres`, then the only other thing I can suggest is to completely uninstall `RPostgreSQL` and all postgres-odbc (OS-level) drivers, download new versions of them (even if the same version, get a new copy of the downloads), and reinstall. After rebooting your OS. Good luck. – r2evans Dec 29 '21 at 01:52
  • Did you make any progress on this? – r2evans Jan 13 '22 at 12:47
  • not yet, I switched to python as I am not able to resolve this issue. Today, I installed everything again, and still face the same issue – user17783243 Mar 29 '22 at 05:19
  • I have the same problem on a Mac 12.3.1. No difference between RPostgres::Postgres() and RPostgreSQL::PostgreSQL(). Same Code runs on Debian 11. I suspect it must somehow be related to postgresql itself.... – bathyscapher Apr 07 '22 at 15:25
  • `Same Code runs on Debian 11.` If it works on debian 11 and doesn't work in macos, wouldn't it make more sense if the problem were with the os/drivers and not the dbms? – r2evans Apr 07 '22 at 15:33
  • Maybe. Maybe I was not clear enough. Instead of "postgresql" I meant "postgresql configuration" (I assumed the software to be fine). I found a solution (at least for my case): I needed to run `createdb` as for some reason there was no local db created during installation. And then create a db with the given name `create db_xy`. That fixed it :) – bathyscapher Apr 07 '22 at 16:29
  • 2
    FWIW, I had a similar error to OP. Changing from `RPostgreSQL::PostgreSQL()` to `RPostgres::Postgres()` fixed the issue. Thanks @r2evans for the tip. – spops Apr 29 '22 at 23:45

0 Answers0