From a06fd975ef14930bbef2dac3597272289d6b10eb Mon Sep 17 00:00:00 2001
From: Vik Fearing <vik@postgresfriends.org>
Date: Fri, 13 Nov 2020 11:55:58 +0100
Subject: [PATCH 1/2] Add catalog version to pg_config

---
 doc/src/sgml/ref/pg_config-ref.sgml | 9 +++++++++
 src/bin/pg_config/pg_config.c       | 2 ++
 src/common/config_info.c            | 7 ++++++-
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/doc/src/sgml/ref/pg_config-ref.sgml b/doc/src/sgml/ref/pg_config-ref.sgml
index e177769188..826cd5bf07 100644
--- a/doc/src/sgml/ref/pg_config-ref.sgml
+++ b/doc/src/sgml/ref/pg_config-ref.sgml
@@ -268,6 +268,15 @@ PostgreSQL documentation
      </listitem>
     </varlistentry>
 
+    <varlistentry>
+     <term><option>--catversion</option></term>
+     <listitem>
+      <para>
+       Print the version number of <productname>PostgreSQL</productname>'s catalog.
+      </para>
+     </listitem>
+    </varlistentry>
+
     <varlistentry>
      <term><option>--version</option></term>
      <listitem>
diff --git a/src/bin/pg_config/pg_config.c b/src/bin/pg_config/pg_config.c
index c40bb3282e..ca048f6eff 100644
--- a/src/bin/pg_config/pg_config.c
+++ b/src/bin/pg_config/pg_config.c
@@ -64,6 +64,7 @@ static const InfoItem info_items[] = {
 	{"--ldflags_sl", "LDFLAGS_SL"},
 	{"--libs", "LIBS"},
 	{"--version", "VERSION"},
+	{"--catversion", "CATALOG_VERSION"},
 	{NULL, NULL}
 };
 
@@ -99,6 +100,7 @@ help(void)
 	printf(_("  --ldflags_ex          show LDFLAGS_EX value used when PostgreSQL was built\n"));
 	printf(_("  --ldflags_sl          show LDFLAGS_SL value used when PostgreSQL was built\n"));
 	printf(_("  --libs                show LIBS value used when PostgreSQL was built\n"));
+	printf(_("  --catversion          show the PostgreSQL catalog version\n"));
 	printf(_("  --version             show the PostgreSQL version\n"));
 	printf(_("  -?, --help            show this help, then exit\n"));
 	printf(_("\nWith no arguments, all known items are shown.\n\n"));
diff --git a/src/common/config_info.c b/src/common/config_info.c
index e72e7292a0..30c3168890 100644
--- a/src/common/config_info.c
+++ b/src/common/config_info.c
@@ -20,6 +20,7 @@
 #include "postgres_fe.h"
 #endif
 
+#include "catalog/catversion.h"
 #include "common/config_info.h"
 
 
@@ -38,7 +39,7 @@ get_configdata(const char *my_exec_path, size_t *configdata_len)
 	int			i = 0;
 
 	/* Adjust this to match the number of items filled below */
-	*configdata_len = 23;
+	*configdata_len = 24;
 	configdata = (ConfigData *) palloc(*configdata_len * sizeof(ConfigData));
 
 	configdata[i].name = pstrdup("BINDIR");
@@ -191,6 +192,10 @@ get_configdata(const char *my_exec_path, size_t *configdata_len)
 #endif
 	i++;
 
+	configdata[i].name = pstrdup("CATALOG_VERSION");
+	configdata[i].setting = pstrdup(psprintf("%d", CATALOG_VERSION_NO));
+	i++;
+
 	configdata[i].name = pstrdup("VERSION");
 	configdata[i].setting = pstrdup("PostgreSQL " PG_VERSION);
 	i++;
-- 
2.25.1

