I'm new to R and RPostgreSQL, and I guess I was encountered the same situation.
I have tried two ways to attempt enabling SSL, but RPostgreSQL did not accept my connection string as followings. (Sorry, these error messages are written in Japanese, because I'm not sure how I can switch the language to English.)
----------------------------------------------------------------
> con <- dbConnect(PostgreSQL(), host= "dbhost", port="5432", user="snaga", password="", dbname="snaga", sslmode="require")
以下にエラー postgresqlNewConnection(drv, ...) :
使われていない引数 (sslmode = "require
> con <- dbConnect(PostgreSQL(), host= "dbhost", port="5432", user="snaga", password="", dbname="snaga")
以下にエラー postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect snaga@dbhost on dbname "snaga"
)
----------------------------------------------------------------
I looked into the source code of RPostgreSQL, and I found that a connection function, RS_PostgreSQL_connectionInfo(), does not accept several connection options, which are allowed in the libpq (PostgreSQL native connection library) functions.
----------------------------------------------------------------
s_object *
RS_PostgreSQL_connectionInfo(Con_Handle * conHandle)
{
S_EVALUATOR PGconn * my_con;
RS_PostgreSQL_conParams *conParams;
RS_DBI_connection *con;
s_object *output;
Sint i, n = 7 /*8 */ , *res, nres;
char *conDesc[] = { "host", "user", "dbname",
"serverVersion", "protocolVersion",
"backendPId", "rsId"
};
Stype conType[] = { CHARACTER_TYPE, CHARACTER_TYPE, CHARACTER_TYPE,
/* CHARACTER_TYPE, */ CHARACTER_TYPE, INTEGER_TYPE,
INTEGER_TYPE, INTEGER_TYPE
};
----------------------------------------------------------------
This function allows "host", "user", "dbname", etc, but there are more options being allowed in the libpq, including ones related to SSL features.
PostgreSQL: Documentation: 9.1: Database Connection Control Functions
http://www.postgresql.org/docs/9.1/static/libpq-connect.htmlAFAIK, at least, "sslmode" and "requiressl" must be accepted in the connection function, RS_PostgreSQL_connectionInfo(), to support SSL connections.
And, PQsetdbLogin(), which is used in RS_PostgreSQL_newConnection() function, would set many connection options to the defaults for convenience, including "sslmode" and "requiressl". So, to allow SSL options in RPostgreSQL, PQconnectdb() should be used instead of PQsetdbLogin().
----------------------------------------------------------------
my_connection = PQsetdbLogin(host, port, options, tty, dbname, user, password);
if (PQstatus(my_connection) != CONNECTION_OK) {
char buf[1000];
sprintf(buf, "could not connect %s@%s on dbname \"%s\"\n", PQuser(my_connection), host?host:"local", PQdb(my_conne\
ction));
RS_DBI_errorMessage(buf, RS_DBI_ERROR);
}
----------------------------------------------------------------
Would it be possible to support these options for SSL in the near future?
Regards,
--
Satoshi Nagayasu <
sn...@uptime.jp>
Uptime Technologies, LLC.
http://www.uptime.jp