diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 5f59a38..8b69ed1 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -7961,8 +7961,8 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir' - Reports the version number of the server. It is determined by the - value of PG_VERSION when building the server. + Reports the version number of the server as a short string. It is determined + by the value of PG_VERSION when building the server. @@ -7981,6 +7981,20 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir' + + server_version_raw (string) + + server_version_raw configuration parameter + + + + + Reports the version of the server as a long string. It is determined + by the value of PG_VERSION_STR when building the server. + + + + wal_block_size (integer) diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index 5bdbc1e..1be57d2 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -3690,11 +3690,14 @@ bar + SERVER_VERSION SERVER_VERSION_NAME SERVER_VERSION_NUM - The server's version number as a string, for + The server's version number as a long string, for + example PostgreSQL 11devel ..., + as a short string, for example 9.6.2, 10.1 or 11beta1, and in numeric form, for example 90602 or 100001. diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 246fea8..fd843d4 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -500,6 +500,7 @@ static char *locale_collate; static char *locale_ctype; static char *server_encoding_string; static char *server_version_string; +static char *server_version_raw_string; static int server_version_num; static char *timezone_string; static char *log_timezone_string; @@ -3298,6 +3299,18 @@ static struct config_string ConfigureNamesString[] = }, { + /* Can't be set in postgresql.conf */ + {"server_version_raw", PGC_INTERNAL, PRESET_OPTIONS, + gettext_noop("Shows the server version string."), + NULL, + GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE + }, + &server_version_raw_string, + PG_VERSION_STR, + NULL, NULL, NULL + }, + + { /* Not for general use --- used by SET ROLE */ {"role", PGC_USERSET, UNGROUPED, gettext_noop("Sets the current role."), diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index fe0b83e..e2ba8ee 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -3358,7 +3358,8 @@ void SyncVariables(void) { char vbuf[32]; - const char *server_version; + const char *server_version, + *server_version_raw; /* get stuff from connection */ pset.encoding = PQclientEncoding(pset.db); @@ -3385,6 +3386,17 @@ SyncVariables(void) snprintf(vbuf, sizeof(vbuf), "%d", pset.sversion); SetVariable(pset.vars, "SERVER_VERSION_NUM", vbuf); + server_version_raw = PQparameterStatus(pset.db, "server_version_raw"); + /* fall back again */ + if (!server_version_raw) + { + snprintf(vbuf, sizeof(vbuf), "PostgreSQL "); + formatPGVersionNumber(pset.sversion, true, vbuf + strlen(vbuf), + sizeof(vbuf) - strlen(vbuf)); + server_version_raw = vbuf; + } + SetVariable(pset.vars, "SERVER_VERSION", server_version_raw); + /* send stuff to it, too */ PQsetErrorVerbosity(pset.db, pset.verbosity); PQsetErrorContextVisibility(pset.db, pset.show_context); @@ -3403,6 +3415,7 @@ UnsyncVariables(void) SetVariable(pset.vars, "HOST", NULL); SetVariable(pset.vars, "PORT", NULL); SetVariable(pset.vars, "ENCODING", NULL); + SetVariable(pset.vars, "SERVER_VERSION", NULL); SetVariable(pset.vars, "SERVER_VERSION_NAME", NULL); SetVariable(pset.vars, "SERVER_VERSION_NUM", NULL); } diff --git a/src/interfaces/libpq/fe-protocol2.c b/src/interfaces/libpq/fe-protocol2.c index a58f701..4aa18fd 100644 --- a/src/interfaces/libpq/fe-protocol2.c +++ b/src/interfaces/libpq/fe-protocol2.c @@ -281,6 +281,10 @@ pqSetenvPoll(PGconn *conn) { char *ptr; + /* keep returned value */ + pqSaveParameterStatus(conn, "server_version_raw", + val); + /* strip off PostgreSQL part */ val += 11; diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out index 43ac5f5..eabb990 100644 --- a/src/test/regress/expected/guc.out +++ b/src/test/regress/expected/guc.out @@ -767,3 +767,14 @@ NOTICE: text search configuration "no_such_config" does not exist select func_with_bad_set(); ERROR: invalid value for parameter "default_text_search_config": "no_such_config" reset check_function_bodies; +-- check consistency of SERVER_VERSION +-- which is transmitted as GUC "server_version_raw" +SELECT :'SERVER_VERSION' = VERSION() + AND :'SERVER_VERSION' = current_setting('server_version_raw') + AND :'SERVER_VERSION' = :'VERSION' + AS "SERVER_VERSION is consistent"; + SERVER_VERSION is consistent +------------------------------ + t +(1 row) + diff --git a/src/test/regress/sql/guc.sql b/src/test/regress/sql/guc.sql index 23e5029..af2e353 100644 --- a/src/test/regress/sql/guc.sql +++ b/src/test/regress/sql/guc.sql @@ -288,3 +288,10 @@ set default_text_search_config = no_such_config; select func_with_bad_set(); reset check_function_bodies; + +-- check consistency of SERVER_VERSION +-- which is transmitted as GUC "server_version_raw" +SELECT :'SERVER_VERSION' = VERSION() + AND :'SERVER_VERSION' = current_setting('server_version_raw') + AND :'SERVER_VERSION' = :'VERSION' + AS "SERVER_VERSION is consistent";