3

My problem is that when I connect to a distant psql database with matlab I have the following error:

FATAL: password authentication failed for user "[username]"

But the password is correct. I've checked with the database manager.

I can connect to the database through the PSQL Shell, it works. It is just with matlab. I have to connect with SSL on, so I use the following code line:

conn = database('dbname','username','password','org.postgresql.Driver',
    'jdbc:postgresql:dm-userdb.geomar.de:users:ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory&');

Following the matlab documentation.

The database manager thinks that it must be a problem with the syntax I use in matlab since the connection works with the shell, but he is not fluent in matlab so he cannot help me.

Moreover when I create a local database on my computer I can connect to it with matlab. It is only the connection to that distant database in SSL mode with matlab (in SSL Off it is not working either).

Connecting to this database with R or python is working. With R the code is:

install.packages("rpostgres")
library(RPostgreSQL)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, host = "dm-userdb.geomar.de", dbname="users", tty = "NULL", user="****", password = "******", port = "5432")

But since we will have users of this DB using different software we have to make it works also with Matlab, and I don't know what is wrong with my script.

I have a mac book air with maverick and matlab R2013a.

Will be very nice if someone has a clue of what is wrong.

2
  • Have you checked pg_hba.conf file on DB server? This file defines a list of allowed hosts and connection types. Details: postgresql.org/docs/current/static/auth-pg-hba-conf.html Commented Aug 30, 2014 at 9:19
  • In general, using org.postgresql.ssl.NonValidatingFactory is not a good idea. You might want to import the server cert in your trust store instead. Commented Aug 30, 2014 at 17:15

1 Answer 1

1

I finally find a solution without using the database toolbox:

% Add jar file to classpath (ensure it is present in your current dir)
%javaclasspath('postgresql-9.0-801.jdbc4.jar');

% Username and password you chose when installing postgres
props=java.util.Properties;
props.setProperty('user', 'username');
props.setProperty('password', 'password');
props.setProperty('ssl','true');

% Create the database connection
driver=org.postgresql.Driver;
url = 'jdbc:postgresql://databaseURL/dbname';
conn=driver.connect(url, props);

But I cannot use the other functions of the database toolbox...

I've tried countless of possibilities with the database function of matlab, none of them ever worked!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.