Is it mandatory to use PQinitOpenSSL and PQinitSSL in postgreSQL 9.4?
The controlling document is 31.18.5. SSL Library Initialization:
If your application initializes libssl and/or libcrypto libraries and
libpq is built with SSL support, you should call PQinitOpenSSL to tell
libpq that the libssl and/or libcrypto libraries have been initialized
by your application, so that libpq will not also initialize those
libraries.
void PQinitOpenSSL(int do_ssl, int do_crypto);
When do_ssl is non-zero, libpq will initialize the OpenSSL library
before first opening a database connection. When do_crypto is
non-zero, the libcrypto library will be initialized. By default (if
PQinitOpenSSL is not called), both libraries are initialized. When SSL
support is not compiled in, this function is present but does nothing.
If your application uses and initializes either OpenSSL or its
underlying libcrypto library, you must call this function with zeroes
for the appropriate parameter(s) before first opening a database
connection. Also be sure that you have done that initialization before
opening a database connection.
So, if your application calls OpenSSL's SSL_library_init
and SSL_load_error_strings
, then you call Postgres' PQinitOpenSSL
with 0's. Also see Library Initialization on the OpenSSL wiki.
If your application does not initialize the OpenSSL library, then you should call call Postgres' PQinitOpenSSL
with non-0's.
The corner case appears to be: you include a second library such that the second library does in fact initialize the OpenSSL library. In this case, you need to ensure the second library loads before libpq
, and then your app calls PQinitOpenSSL
with 0's because the second library invokes the initialization.
It also appears PQinitSSL(int do_ssl)
with 0 or non-0 will work, too. There's no explicit libcrypto
initialization in OpenSSL as far as I know, so PQinitOpenSSL
's do_crypto
is simply not needed in this case. Other libraries may need it, and OpenSSL 1.1.0 may change that. But I don't think it applies in this case.