diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml
index 026b0ec46bb..3c9bd3d6730 100644
--- a/doc/src/sgml/libpq.sgml
+++ b/doc/src/sgml/libpq.sgml
@@ -2590,12 +2590,22 @@ const char *PQsslAttribute(const PGconn *conn, const char *attribute_name);
PQsslAttributeNamesPQsslAttributeNames
- Returns an array of SSL attribute names available.
+ Returns an array of SSL attribute names that can be used
+ in PQsslAttribute().
The array is terminated by a NULL pointer.
const char * const * PQsslAttributeNames(const PGconn *conn);
+
+
+ If conn is NULL, the attributes available for the
+ default SSL library are returned, or an empty list
+ if libpq was compiled without any SSL
+ support. If conn is not NULL, the attributes
+ available for the SSL library in use for the connection are returned,
+ or an empty list if the connection is not encrypted.
+
diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c
index 74b5c5987a6..b42a908733a 100644
--- a/src/interfaces/libpq/fe-secure-openssl.c
+++ b/src/interfaces/libpq/fe-secure-openssl.c
@@ -1730,7 +1730,7 @@ PQsslStruct(PGconn *conn, const char *struct_name)
const char *const *
PQsslAttributeNames(PGconn *conn)
{
- static const char *const result[] = {
+ static const char *const openssl_attrs[] = {
"library",
"key_bits",
"cipher",
@@ -1738,8 +1738,19 @@ PQsslAttributeNames(PGconn *conn)
"protocol",
NULL
};
+ static const char *const empty_attrs[] = {NULL};
- return result;
+ if (!conn)
+ {
+ /* Return attributes of default SSL library */
+ return openssl_attrs;
+ }
+
+ /* No attrs for unencrypted connection */
+ if (conn->ssl == NULL)
+ return empty_attrs;
+
+ return openssl_attrs;
}
const char *