I have build up a postgresql 9.2 database. My table looks like that:
CREATE DATABASE "EURUSD_M1"
WITH OWNER = fadmin
ENCODING = 'UTF8'
TABLESPACE = pg_default
LC_COLLATE = 'German_Germany.1252'
LC_CTYPE = 'German_Germany.1252'
CONNECTION LIMIT = -1;
However when trying to connect thorugh the rpostgresql driver I get:
> drv <- dbDriver("PostgreSQL") ## loads the PostgreSQL driver
> con <- dbConnect(drv, port='5432', dbname='EURUSD_M1',
+ user='fadmin') ## Open a connection
Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect fadmin#local on dbname "EURUSD_M1"
)
btw to specify host = 'localhost' does not change anything! Also fadmin is a superuser in my db!
Here are further connection information:
Any ideas what I am doing wrong?
I appreciate your answers!
RPostgreSQL, just like the psql command-line tool, connect via tcp/ip network interface even when you have the server on the same machine.
For this to work, you must enable network access; see the various PostreSQL HOWTOs and guides. You probably have to edit / alter a file call pg_hba.conf or similar.
Related
I am trying to connect to a firebird DB via ODBC. I have an working ODBC Windows Connection (ODBC Data Sources 32 Bit) and also an established connection via Tableau. I tried using dbConnect but was not able to set the right parameters I guess. I tried
library(odbc)
con <- dbConnect(odbc::odbc(),
drv = "Firebird/InterBase(r) driver",
database = "VARIO",
uid = "xxx",
pwd = "xxx",
host = "192.xxx.xxx.xx",
port = "xxxxx")
in e.g. Excel I can access the database by using the established windows connection. Anyways, sorry for my beginner formulation!
To add here, it seems I am running on 64 bit R Version
> Sys.info()[["machine"]]
[1] "x86-64"
After your comments I tried
con <- dbConnect(odbc::odbc(),
dsn = "VARIO",
database = "192.168.XX.X/56300:VARIO8",
uid = "XXX",
pwd = "XXX",
host = "192.168.XX.X",
port = "56300")
>Error: nanodbc/nanodbc.cpp:983: 01S00: [ODBC Firebird Driver]Unable to connect to data source: library 'C:\Users\XXX\Desktop\fbclient.dll' failed to load [ODBC Firebird Driver]Invalid connection string attribute [ODBC Firebird Driver]Invalid connection string attribute
fbclient.dll is there where its supposed to be
What is more I did not put an driver. Whenever I ad
drv = "Firebird/InterBase(r) driver"
I get: Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘dbConnect’ for signature ‘"character"’
Maybe this helps? This is from the Windows ODBC Data Sources and says 32/64 Bit. Don't know if this is imprtant
Any further Ideas?
Checking against the list of odbc-known DB drivers, Firebird doesn't seem to be a known driver.
library(odbc)
odbc::odbcListDrivers()
(src: https://rdrr.io/cran/odbc/man/odbcListDrivers.html)
I guess you would have to install that driver on your machine and then register the Data Source Name (DSN) to make it available to R.
Once that's done, please change the drv in your function call to dsn. drv refers to the odbc::odbc() argument which you've provided above, while dsn should then refer to the installed driver by its registered name (unless I'm mixing up things badly here. I've luckily never had to leave the warm comfort of RPostgreSQL...).
So it would look something like this:
library(odbc)
con <- dbConnect(drv = odbc::odbc(),
dsn = "Firebird", # this should be the DSN you have set
database = "VARIO",
uid = "xxx",
pwd = "xxx",
host = "192.xxx.xxx.xx",
port = "xxxxx")
I have postgres installed locally in my ubuntu. The dbname is postgres and the user name is also postgres. When I'm trying to connect this database to my R script, I'm getting an error saying-
Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect postgres#localhost on dbname "postgres"
Here is the command that I'm running-
con <- dbConnect(drv, dbname = "postgres",
host = "localhost", port = 5432,
user = "postgres", password=pw)
I checked that this is the right command to run to make this connection and I have also used this to connect to an external server before. But somehow I'm not able to connect to my local postgres instance.
What do you think I'm missing out?
I'm running a Postgres-9.4 server that I would like to require SSL for. When I connect to the Postgres server from my laptop with either pgadmin or windows odbc connection, it works with SSL. However when I try to connect with R using SSL it fails.
library(RPostgreSQL)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv,
user = "postgres",
password = mypasswd,
dbname = "dbname=postgres sslmode=prefer",
host = "192.168.1.179")
If I set my pg_hba.conf to allow non-ssl connections then this will work. When I set it to only allow SSL connections then this will fail. Unfortunately dbConnect doesn't have a verbose option so I don't get anything more than could not connect postgres#192.168.1.179 on dbname "postgres"
I found this question which seems to suggest I'm doing the right thing but, no go.
Edit:
I did some more digging and found this discussion which suggests that this won't work on windows due to various library/dll issues. That discussion is a few years old at this point so perhaps it has been resolved. I can confirm that doing the above from linux does work.
My understanding of the problem is that RPostgreSQL uses a client that doesn't support SSL.
I switched to the package RPostgres and got it to work. I first installed RPostgres with install.packages('RPostgres') then used this package to connect with sslmode="require".
library('RPostgres') #Instead of library('RPostgreSQL')
con <- dbConnect(RPostgres::Postgres(),
user = "postgres",
password = mypasswd,
dbname = "postgres",
host = "192.168.1.179",
sslmode = "require")
)
I have a large data-set and I will preform some analysis in R software.
While I could not import the data properly to R.
I get this error:
Error in postgresqlNewConnection(drv, ...) : RS-DBI driver: (could not connect User#local on dbname "Intel"
I have used PostgreSQL to open data and somehow manage it. How can I import the existing data in the PostgreSQL to the R software?
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, host='localhost', port='5432', dbname='Swiss',
user='postgres', password='123456')
Moreover, "RPostgreSQL" package in R should be installed.
Try the R package RPostgreSQL http://cran.r-project.org/web/packages/RPostgreSQL/ .
You can see how to use it in http://code.google.com/p/rpostgresql/ .
Example:
library(RPostgreSQL)
drv <- dbDriver("PostgreSQL") ## loads the PostgreSQL driver
con <- dbConnect(drv, dbname="R_Project") ## Open a connection
rs <- dbSendQuery(con, "select * from R_Users") ## Submits a statement
fetch(rs,n=-1) ## fetch all elements from the result set
dbGetQuery(con, "select * from R_packages") ## Submit and execute the query
dbDisconnect(con) ## Closes the connection
dbUnloadDriver(drv) # Frees all the resources on the driver
You have to configure two things on the PostgreSQL server before you are able to connect remotely. This is a instruction how to configure this under Linux:
1. Find and configure postgresql.conf to allow the TCP service to accept connections from any host, not only localhost
find / -name "postgresql.conf"
In my linux OS the file is locate in /etc/postgresql/9.6/main/, so I modify it there. Add the line "listen_addresses = '*'" as follows:
/etc/postgresql/9.6/main/postgresql.conf
#listen_addresses = 'localhost' # what IP address(es) to listen on;
# insert the following line
listen_addresses = '*'
2. Find and configure pg_hba.conf to allow to connect with a client from any host
sudo find / -name "pg_hba.conf"
In my linux OS the file is locate in /etc/postgresql/9.6/main/, so I modify it there. Add the line "host all all 0.0.0.0/0" as follows:
sudo nano /etc/postgresql/9.6/main/pg_hba.conf
# Put your actual configuration here
# ----------------------------------
#
# If you want to allow non-local connections, you need to add more
# "host" records. In that case you will also need to make PostgreSQL
# listen on a non-local interface via the listen_addresses
# configuration parameter, or via the -i or -h command line switches.
#
# insert the following line
host all all 0.0.0.0/0 trust
3. Stop and start the server
sudo service postgresql stop
sudo service postgresql start
4. Connect with you client, now it should work.
GOOD LUCK!
I am making the move from RSQLite to RMySQL and I am confused by the user and password fields. FWIW, I'm running Windows 7, R 2.12.2, MySQL 5.5 (all 64 bit), and RMySQL 0.7-5.
I installed RMySQL as prescribed in this previous SO question, and as far as I know it works (i.e., I can load the package with library(RMySQL)). But when I try to run the tutorial from the R data import guide, I get a "failed to connect to database..." error. This is the code from the tutorial from the guide:
library(RMySQL) # will load DBI as well
## open a connection to a MySQL database
con <- dbConnect(dbDriver("MySQL"), user = "root", password = "root", dbname = "pookas")
## list the tables in the database
dbListTables(con)
## load a data frame into the database, deleting any existing copy
data(USArrests)
dbWriteTable(con, "arrests", USArrests, overwrite = TRUE)
dbListTables(con)
## get the whole table
dbReadTable(con, "arrests")
## Select from the loaded table
dbGetQuery(con, paste("select row_names, Murder from arrests",
"where Rape > 30 order by Murder"))
dbRemoveTable(con, "arrests")
dbDisconnect(con)
On the second line I get the following error:
> con <- dbConnect(dbDriver("MySQL"), user = "richard", password = "root", dbname = "pookas")
Error in mysqlNewConnection(drv, ...) :
RS-DBI driver: (Failed to connect to database: Error: Access denied for user 'richard'#'localhost' (using password: NO)
)
I have tried with and without user and password and with admin as user. I have also tried using a dbname that I made before with the command line and with one that doesn't exist.
Any tips? Is there a good reference here? Thanks!
That is most likely a setup issue on the server side. Make sure that networked access is enabled.
Also, a local test with the command-line client is not equivalent as that typically uses sockets. The mysql server logs may be helpful.
First try to connect to MySQL server using MySQL Workbench or command line mysql using the same parameter. If it connects then R should also be able to connect.
Typically this issue comes when MySQL server doesn't allow connections from remote machines.
As people have told you, you can try to connect to the host with other application as mysql workbench. How odd! When I have tried in RStudio to connect to my db with your code without indicate the host in the command I haven't been able to connect.
I have needed to indicate the host ( host = 'localhost' ) in the command.