Skip to content

Instantly share code, notes, and snippets.

@abelcallejo
Last active October 21, 2021 03:54
Show Gist options
  • Save abelcallejo/ff8f5e9c488aa0b7dcd254f19d54cfe6 to your computer and use it in GitHub Desktop.
Save abelcallejo/ff8f5e9c488aa0b7dcd254f19d54cfe6 to your computer and use it in GitHub Desktop.
RPostgreSQL errors

RPostgreSQL errors

RPostgreSQL package was not installed

Problem

You haven't installed the R package called RPostgreSQL. It will show the following error:

Error in library("RPostgreSQL") : there is no package called ‘RPostgreSQL’
Calls: source -> withVisible -> eval -> eval -> library
Execution halted

Solution

Install the R package called RPostgreSQL like so:

install.packages("RPostgreSQL")

Something is wrong with the PostgreSQL driver

Problem: The PostgreSQL driver was not properly setted up. It will show the following error:

Error: Couldn't find driver PostgreSQL. Looked in:
* global namespace
* in package called PostgreSQL
* in package called RPostgreSQL
Execution halted

Solution: Still unknown

PostgreSQL server is currently stopped or turned off

Problem: The PostgreSQL server was not started. It will show the following error:

Error in postgresqlNewConnection(drv, ...) : 
  RS-DBI driver: (could not connect cherry@localhost:5432 on dbname "database": could not connect to server: Connection refused
	Is the server running on host "localhost" (::1) and accepting
	TCP/IP connections on port 5432?
could not connect to server: Connection refused
	Is the server running on host "localhost" (127.0.0.1) and accepting
	TCP/IP connections on port 5432?
)
Calls: source ... eval -> dbConnect -> dbConnect -> postgresqlNewConnection
Execution halted

Solution: Start the PostgreSQL server

Hostname is wrong

Problem

You may have specified a wrong hostname. The chances are you simply just had a typo. Something like typing locahlostinstead of localhost. Another reason is that you could have specified a totally wrong hostname and not just a typo. Something like typing localhost instead of 192.169.1.2. In any of these reasons, it will show the following error:

Error in postgresqlNewConnection(drv, ...) : 
  RS-DBI driver: (could not connect cherry@locahlost:5432 on dbname "database": could not translate host name "locahlost" to address: nodename nor servname provided, or not known
)
Calls: source ... eval -> dbConnect -> dbConnect -> postgresqlNewConnection
Execution halted

Key phrases

could not translate host name to address
nodename nor servname provided, or not known

Solution

Supply the correct hostname. Check the hostname you specified like so:

ping <- function(x, stderr = FALSE, stdout = FALSE, ...) {
    pingvec <- system2("ping", paste0("-c1 ",x), stderr = FALSE, stdout = FALSE,...)
    if (pingvec == 0) TRUE else FALSE
}

# When the hostname is wrong
ping("locahlost")
[1] FALSE

# When the hostname is correct
ping("localhost")
[1] TRUE

When you specified a wrong port

Probably you had a typo. You typed 5342instead of 5432.

Error in postgresqlNewConnection(drv, ...) : 
  RS-DBI driver: (could not connect cherry@localhost:5342 on dbname "database": could not connect to server: Connection refused
	Is the server running on host "localhost" (::1) and accepting
	TCP/IP connections on port 5342?
could not connect to server: Connection refused
	Is the server running on host "localhost" (127.0.0.1) and accepting
	TCP/IP connections on port 5342?
)
Calls: source ... eval -> dbConnect -> dbConnect -> postgresqlNewConnection
Execution halted

When you specified a wrong user name

Probably you had a typo. You typed chreryinstead of cherry.

Error in postgresqlNewConnection(drv, ...) : 
  RS-DBI driver: (could not connect chrery@localhost:5432 on dbname "database": FATAL:  role "chrery" does not exist
)
Calls: source ... eval -> dbConnect -> dbConnect -> postgresqlNewConnection
Execution halted

When you specified a wrong database name

Probably you had a typo. You typed datbaaseinstead of database.

Error in postgresqlNewConnection(drv, ...) : 
  RS-DBI driver: (could not connect cherry@localhost:5432 on dbname "datbaase": FATAL:  database "datbaase" does not exist
)
Calls: source ... eval -> dbConnect -> dbConnect -> postgresqlNewConnection
Execution halted

When the DBI package was not installed

Error in library("DBI") : there is no package called ‘DBI’
Calls: source -> withVisible -> eval -> eval -> library
Execution halted

PostgreSQL-related

Error: fe_sendauth: no password supplied
Execution halted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment