v6-0005-GUC-names-make-common-translatable-message-string.patch

application/octet-stream

Filename: v6-0005-GUC-names-make-common-translatable-message-string.patch
Type: application/octet-stream
Part: 1
Message: Re: GUC names in messages

Patch

Format: format-patch
Series: patch v6-0005
Subject: GUC names - make common translatable message strings
File+
contrib/pg_prewarm/autoprewarm.c 1 1
src/backend/access/transam/xlog.c 50 29
src/backend/access/transam/xlogrecovery.c 1 1
src/backend/commands/variable.c 7 4
src/backend/port/sysv_shmem.c 2 1
src/backend/postmaster/bgworker.c 2 1
src/backend/postmaster/checkpointer.c 2 1
src/backend/replication/syncrep.c 2 1
src/backend/storage/file/fd.c 6 3
src/backend/storage/lmgr/predicate.c 4 2
src/backend/tcop/postgres.c 9 6
src/backend/utils/fmgr/dfmgr.c 8 8
From 4d37a563e0bff3b984e87ab4929156c2fb8469c3 Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.b.smith@fujitsu.com>
Date: Thu, 4 Jan 2024 17:36:23 +1100
Subject: [PATCH v6] GUC names - make common translatable message strings

---
 contrib/pg_prewarm/autoprewarm.c          |  2 +-
 src/backend/access/transam/xlog.c         | 79 +++++++++++++++++++------------
 src/backend/access/transam/xlogrecovery.c |  2 +-
 src/backend/commands/variable.c           | 11 +++--
 src/backend/port/sysv_shmem.c             |  3 +-
 src/backend/postmaster/bgworker.c         |  3 +-
 src/backend/postmaster/checkpointer.c     |  3 +-
 src/backend/replication/syncrep.c         |  3 +-
 src/backend/storage/file/fd.c             |  9 ++--
 src/backend/storage/lmgr/predicate.c      |  6 ++-
 src/backend/tcop/postgres.c               | 15 +++---
 src/backend/utils/fmgr/dfmgr.c            | 16 +++----
 12 files changed, 94 insertions(+), 58 deletions(-)

diff --git a/contrib/pg_prewarm/autoprewarm.c b/contrib/pg_prewarm/autoprewarm.c
index 6c9cd22..6fd1767a 100644
--- a/contrib/pg_prewarm/autoprewarm.c
+++ b/contrib/pg_prewarm/autoprewarm.c
@@ -877,7 +877,7 @@ apw_start_database_worker(void)
 		ereport(ERROR,
 				(errcode(ERRCODE_INSUFFICIENT_RESOURCES),
 				 errmsg("registering dynamic bgworker autoprewarm failed"),
-				 errhint("Consider increasing configuration parameter \"max_worker_processes\".")));
+				 errhint("Consider increasing configuration parameter \"%s\".", "max_worker_processes")));
 
 	/*
 	 * Ignore return value; if it fails, postmaster has died, but we have
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index becb32b..e40a2bc 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -4222,16 +4222,22 @@ ReadControlFile(void)
 	if (ControlFile->catalog_version_no != CATALOG_VERSION_NO)
 		ereport(FATAL,
 				(errmsg("database files are incompatible with server"),
-				 errdetail("The database cluster was initialized with CATALOG_VERSION_NO %d,"
-						   " but the server was compiled with CATALOG_VERSION_NO %d.",
-						   ControlFile->catalog_version_no, CATALOG_VERSION_NO),
+				 /*- translator: %s is a variable name and %d is its value */
+				 errdetail("The database cluster was initialized with %s %d,"
+						   " but the server was compiled with %s %d.",
+						   "CATALOG_VERSION_NO",
+						   ControlFile->catalog_version_no,
+						   "CATALOG_VERSION_NO",
+						   CATALOG_VERSION_NO),
 				 errhint("It looks like you need to initdb.")));
 	if (ControlFile->maxAlign != MAXIMUM_ALIGNOF)
 		ereport(FATAL,
 				(errmsg("database files are incompatible with server"),
-				 errdetail("The database cluster was initialized with MAXALIGN %d,"
-						   " but the server was compiled with MAXALIGN %d.",
-						   ControlFile->maxAlign, MAXIMUM_ALIGNOF),
+				 /*- translator: %s is a variable name and %d is its value */
+				 errdetail("The database cluster was initialized with %s %d,"
+						   " but the server was compiled with %s %d.",
+						   "MAXALIGN", ControlFile->maxAlign,
+						   "MAXALIGN", MAXIMUM_ALIGNOF),
 				 errhint("It looks like you need to initdb.")));
 	if (ControlFile->floatFormat != FLOATFORMAT_VALUE)
 		ereport(FATAL,
@@ -4241,51 +4247,64 @@ ReadControlFile(void)
 	if (ControlFile->blcksz != BLCKSZ)
 		ereport(FATAL,
 				(errmsg("database files are incompatible with server"),
-				 errdetail("The database cluster was initialized with BLCKSZ %d,"
-						   " but the server was compiled with BLCKSZ %d.",
-						   ControlFile->blcksz, BLCKSZ),
+				 /*- translator: %s is a variable name and %d is its value */
+				 errdetail("The database cluster was initialized with %s %d,"
+						   " but the server was compiled with %s %d.",
+						   "BLCKSZ", ControlFile->blcksz, "BLCKSZ", BLCKSZ),
 				 errhint("It looks like you need to recompile or initdb.")));
 	if (ControlFile->relseg_size != RELSEG_SIZE)
 		ereport(FATAL,
 				(errmsg("database files are incompatible with server"),
-				 errdetail("The database cluster was initialized with RELSEG_SIZE %d,"
-						   " but the server was compiled with RELSEG_SIZE %d.",
-						   ControlFile->relseg_size, RELSEG_SIZE),
+				 /*- translator: %s is a variable name and %d is its value */
+				 errdetail("The database cluster was initialized with %s %d,"
+						   " but the server was compiled with %s %d.",
+						   "RELSEG_SIZE", ControlFile->relseg_size,
+						   "RELSEG_SIZE", RELSEG_SIZE),
 				 errhint("It looks like you need to recompile or initdb.")));
 	if (ControlFile->xlog_blcksz != XLOG_BLCKSZ)
 		ereport(FATAL,
 				(errmsg("database files are incompatible with server"),
-				 errdetail("The database cluster was initialized with XLOG_BLCKSZ %d,"
-						   " but the server was compiled with XLOG_BLCKSZ %d.",
-						   ControlFile->xlog_blcksz, XLOG_BLCKSZ),
+				 /*- translator: %s is a variable name and %d is its value */
+				 errdetail("The database cluster was initialized with %s %d,"
+						   " but the server was compiled with %s %d.",
+						   "XLOG_BLCKSZ", ControlFile->xlog_blcksz,
+						   "XLOG_BLCKSZ", XLOG_BLCKSZ),
 				 errhint("It looks like you need to recompile or initdb.")));
 	if (ControlFile->nameDataLen != NAMEDATALEN)
 		ereport(FATAL,
 				(errmsg("database files are incompatible with server"),
-				 errdetail("The database cluster was initialized with NAMEDATALEN %d,"
-						   " but the server was compiled with NAMEDATALEN %d.",
-						   ControlFile->nameDataLen, NAMEDATALEN),
+				 /*- translator: %s is a variable name and %d is its value */
+				 errdetail("The database cluster was initialized with %s %d,"
+						   " but the server was compiled with %s %d.",
+						   "NAMEDATALEN", ControlFile->nameDataLen,
+						   "NAMEDATALEN", NAMEDATALEN),
 				 errhint("It looks like you need to recompile or initdb.")));
 	if (ControlFile->indexMaxKeys != INDEX_MAX_KEYS)
 		ereport(FATAL,
 				(errmsg("database files are incompatible with server"),
-				 errdetail("The database cluster was initialized with INDEX_MAX_KEYS %d,"
-						   " but the server was compiled with INDEX_MAX_KEYS %d.",
-						   ControlFile->indexMaxKeys, INDEX_MAX_KEYS),
+				 /*- translator: %s is a variable name and %d is its value */
+				 errdetail("The database cluster was initialized with %s %d,"
+						   " but the server was compiled with %s %d.",
+						   "INDEX_MAX_KEYS", ControlFile->indexMaxKeys,
+						   "INDEX_MAX_KEYS", INDEX_MAX_KEYS),
 				 errhint("It looks like you need to recompile or initdb.")));
 	if (ControlFile->toast_max_chunk_size != TOAST_MAX_CHUNK_SIZE)
 		ereport(FATAL,
 				(errmsg("database files are incompatible with server"),
-				 errdetail("The database cluster was initialized with TOAST_MAX_CHUNK_SIZE %d,"
-						   " but the server was compiled with TOAST_MAX_CHUNK_SIZE %d.",
-						   ControlFile->toast_max_chunk_size, (int) TOAST_MAX_CHUNK_SIZE),
+				 /*- translator: %s is a variable name and %d is its value */
+				 errdetail("The database cluster was initialized with %s %d,"
+						   " but the server was compiled with %s %d.",
+						   "TOAST_MAX_CHUNK_SIZE", ControlFile->toast_max_chunk_size,
+						   "TOAST_MAX_CHUNK_SIZE", (int) TOAST_MAX_CHUNK_SIZE),
 				 errhint("It looks like you need to recompile or initdb.")));
 	if (ControlFile->loblksize != LOBLKSIZE)
 		ereport(FATAL,
 				(errmsg("database files are incompatible with server"),
-				 errdetail("The database cluster was initialized with LOBLKSIZE %d,"
-						   " but the server was compiled with LOBLKSIZE %d.",
-						   ControlFile->loblksize, (int) LOBLKSIZE),
+				 /*- translator: %s is a variable name and %d is its value */
+				 errdetail("The database cluster was initialized with %s %d,"
+						   " but the server was compiled with %s %d.",
+						   "LOBLKSIZE", ControlFile->loblksize,
+						   "LOBLKSIZE", (int) LOBLKSIZE),
 				 errhint("It looks like you need to recompile or initdb.")));
 
 #ifdef USE_FLOAT8_BYVAL
@@ -4321,11 +4340,13 @@ ReadControlFile(void)
 	/* check and update variables dependent on wal_segment_size */
 	if (ConvertToXSegs(min_wal_size_mb, wal_segment_size) < 2)
 		ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-						errmsg("\"min_wal_size\" must be at least twice \"wal_segment_size\"")));
+						errmsg("\"%s\" must be at least twice \"%s\"",
+							   "min_wal_size", "wal_segment_size")));
 
 	if (ConvertToXSegs(max_wal_size_mb, wal_segment_size) < 2)
 		ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-						errmsg("\"max_wal_size\" must be at least twice \"wal_segment_size\"")));
+						errmsg("\"%s\" must be at least twice \"%s\"",
+							   "max_wal_size", "wal_segment_size")));
 
 	UsableBytesInSegment =
 		(wal_segment_size / XLOG_BLCKSZ * UsableBytesInPage) -
diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index 23449ff..ed3304d 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -4730,7 +4730,7 @@ check_recovery_target(char **newval, void **extra, GucSource source)
 {
 	if (strcmp(*newval, "immediate") != 0 && strcmp(*newval, "") != 0)
 	{
-		GUC_check_errdetail("The only allowed value is \"immediate\".");
+		GUC_check_errdetail("The only allowed value is \"%s\".", "immediate");
 		return false;
 	}
 	return true;
diff --git a/src/backend/commands/variable.c b/src/backend/commands/variable.c
index a72db8b..2325045 100644
--- a/src/backend/commands/variable.c
+++ b/src/backend/commands/variable.c
@@ -182,7 +182,7 @@ check_datestyle(char **newval, void **extra, GucSource source)
 
 	if (!ok)
 	{
-		GUC_check_errdetail("Conflicting \"DateStyle\" specifications.");
+		GUC_check_errdetail("Conflicting \"%s\" specifications.", "DateStyle");
 		return false;
 	}
 
@@ -717,7 +717,8 @@ check_client_encoding(char **newval, void **extra, GucSource source)
 		else
 		{
 			/* Provide a useful complaint */
-			GUC_check_errdetail("Cannot change \"client_encoding\" now.");
+			GUC_check_errdetail("Cannot change \"%s\" now.",
+								"client_encoding");
 		}
 		return false;
 	}
@@ -1202,7 +1203,8 @@ check_effective_io_concurrency(int *newval, void **extra, GucSource source)
 #ifndef USE_PREFETCH
 	if (*newval != 0)
 	{
-		GUC_check_errdetail("\"effective_io_concurrency\" must be set to 0 on platforms that lack posix_fadvise().");
+		GUC_check_errdetail("\"%s\" must be set to 0 on platforms that lack posix_fadvise().",
+							"effective_io_concurrency");
 		return false;
 	}
 #endif							/* USE_PREFETCH */
@@ -1215,7 +1217,8 @@ check_maintenance_io_concurrency(int *newval, void **extra, GucSource source)
 #ifndef USE_PREFETCH
 	if (*newval != 0)
 	{
-		GUC_check_errdetail("\"maintenance_io_concurrency\" must be set to 0 on platforms that lack posix_fadvise().");
+		GUC_check_errdetail("\"%s\" must be set to 0 on platforms that lack posix_fadvise().",
+							"maintenance_io_concurrency");
 		return false;
 	}
 #endif							/* USE_PREFETCH */
diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c
index a145615..f0a787a 100644
--- a/src/backend/port/sysv_shmem.c
+++ b/src/backend/port/sysv_shmem.c
@@ -580,7 +580,8 @@ check_huge_page_size(int *newval, void **extra, GucSource source)
 	/* Recent enough Linux only, for now.  See GetHugePageSize(). */
 	if (*newval != 0)
 	{
-		GUC_check_errdetail("\"huge_page_size\" must be 0 on this platform.");
+		GUC_check_errdetail("\"%s\" must be 0 on this platform.",
+							"huge_page_size");
 		return false;
 	}
 #endif
diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c
index 4cc33fe..f646079 100644
--- a/src/backend/postmaster/bgworker.c
+++ b/src/backend/postmaster/bgworker.c
@@ -918,7 +918,8 @@ RegisterBackgroundWorker(BackgroundWorker *worker)
 								  "Up to %d background workers can be registered with the current settings.",
 								  max_worker_processes,
 								  max_worker_processes),
-				 errhint("Consider increasing the configuration parameter max_worker_processes.")));
+				 errhint("Consider increasing the configuration parameter \"%s\".",
+						 "max_worker_processes")));
 		return;
 	}
 
diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c
index 6cd9d9e..101fa52 100644
--- a/src/backend/postmaster/checkpointer.c
+++ b/src/backend/postmaster/checkpointer.c
@@ -443,7 +443,8 @@ CheckpointerMain(void)
 									   "checkpoints are occurring too frequently (%d seconds apart)",
 									   elapsed_secs,
 									   elapsed_secs),
-						 errhint("Consider increasing the configuration parameter \"%s\".", "max_wal_size")));
+						 errhint("Consider increasing the configuration parameter \"%s\".",
+								 "max_wal_size")));
 
 			/*
 			 * Initialize checkpointer-private variables used during
diff --git a/src/backend/replication/syncrep.c b/src/backend/replication/syncrep.c
index 172a750..cfb1f61 100644
--- a/src/backend/replication/syncrep.c
+++ b/src/backend/replication/syncrep.c
@@ -1016,7 +1016,8 @@ check_synchronous_standby_names(char **newval, void **extra, GucSource source)
 			if (syncrep_parse_error_msg)
 				GUC_check_errdetail("%s", syncrep_parse_error_msg);
 			else
-				GUC_check_errdetail("\"synchronous_standby_names\" parser failed");
+				GUC_check_errdetail("\"%s\" parser failed",
+									"synchronous_standby_names");
 			return false;
 		}
 
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index c0c65ea..e44c5fb 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -3924,7 +3924,8 @@ check_debug_io_direct(char **newval, void **extra, GucSource source)
 #if PG_O_DIRECT == 0
 	if (strcmp(*newval, "") != 0)
 	{
-		GUC_check_errdetail("\"debug_io_direct\" is not supported on this platform.");
+		GUC_check_errdetail("\"%s\" is not supported on this platform.",
+						   "debug_io_direct");
 		result = false;
 	}
 	flags = 0;
@@ -3971,14 +3972,16 @@ check_debug_io_direct(char **newval, void **extra, GucSource source)
 #if XLOG_BLCKSZ < PG_IO_ALIGN_SIZE
 	if (result && (flags & (IO_DIRECT_WAL | IO_DIRECT_WAL_INIT)))
 	{
-		GUC_check_errdetail("\"debug_io_direct\" is not supported for WAL because XLOG_BLCKSZ is too small");
+		GUC_check_errdetail("\"%s\" is not supported for WAL because %s is too small",
+						   "debug_io_direct", "XLOG_BLCKSZ");
 		result = false;
 	}
 #endif
 #if BLCKSZ < PG_IO_ALIGN_SIZE
 	if (result && (flags & IO_DIRECT_DATA))
 	{
-		GUC_check_errdetail("\"debug_io_direct\" is not supported for data because BLCKSZ is too small");
+		GUC_check_errdetail("\"%s\" is not supported for WAL because %s is too small",
+						   "debug_io_direct", "BLCKSZ");
 		result = false;
 	}
 #endif
diff --git a/src/backend/storage/lmgr/predicate.c b/src/backend/storage/lmgr/predicate.c
index e121c25..c8e45a5 100644
--- a/src/backend/storage/lmgr/predicate.c
+++ b/src/backend/storage/lmgr/predicate.c
@@ -1644,8 +1644,10 @@ GetSerializableTransactionSnapshot(Snapshot snapshot)
 		ereport(ERROR,
 				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
 				 errmsg("cannot use serializable mode in a hot standby"),
-				 errdetail("\"default_transaction_isolation\" is set to \"serializable\"."),
-				 errhint("You can use \"SET default_transaction_isolation = 'repeatable read'\" to change the default.")));
+				 errdetail("\"%s\" is set to \"%s\"."
+						   "default_transaction_isolation", "serializable"),
+				 errhint("You can use \"%s\" to change the default.",
+						"SET default_transaction_isolation = 'repeatable read'")));
 
 	/*
 	 * A special optimization is available for SERIALIZABLE READ ONLY
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 1aa5f5b..7ec6969 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -3571,7 +3571,8 @@ check_max_stack_depth(int *newval, void **extra, GucSource source)
 
 	if (stack_rlimit > 0 && newval_bytes > stack_rlimit - STACK_DEPTH_SLOP)
 	{
-		GUC_check_errdetail("\"max_stack_depth\" must not exceed %ldkB.",
+		GUC_check_errdetail("\"%s\" must not exceed %ldkB.",
+							"max_stack_depth",
 							(stack_rlimit - STACK_DEPTH_SLOP) / 1024L);
 		GUC_check_errhint("Increase the platform's stack depth limit via \"ulimit -s\" or local equivalent.");
 		return false;
@@ -3596,7 +3597,8 @@ check_client_connection_check_interval(int *newval, void **extra, GucSource sour
 {
 	if (!WaitEventSetCanReportClosed() && *newval != 0)
 	{
-		GUC_check_errdetail("\"client_connection_check_interval\" must be set to 0 on this platform.");
+		GUC_check_errdetail("\"%s\" must be set to 0 on this platform.",
+							"client_connection_check_interval");
 		return false;
 	}
 	return true;
@@ -3617,7 +3619,8 @@ check_stage_log_stats(bool *newval, void **extra, GucSource source)
 {
 	if (*newval && log_statement_stats)
 	{
-		GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true.");
+		GUC_check_errdetail("Cannot enable parameter when \"%s\" is true.",
+							"log_statement_stats");
 		return false;
 	}
 	return true;
@@ -3632,9 +3635,9 @@ check_log_stats(bool *newval, void **extra, GucSource source)
 	if (*newval &&
 		(log_parser_stats || log_planner_stats || log_executor_stats))
 	{
-		GUC_check_errdetail("Cannot enable \"log_statement_stats\" when "
-							"\"log_parser_stats\", \"log_planner_stats\", "
-							"or \"log_executor_stats\" is true.");
+		GUC_check_errdetail("Cannot enable \"%s\" when \"%s\", \"%s\", or \"%s\" is true.",
+							"log_statement_stats",
+							"log_parser_stats", "log_planner_stats", "log_executor_stats");
 		return false;
 	}
 	return true;
diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c
index b85d52c..24b71f3 100644
--- a/src/backend/utils/fmgr/dfmgr.c
+++ b/src/backend/utils/fmgr/dfmgr.c
@@ -358,8 +358,8 @@ incompatible_module_error(const char *libname,
 		if (details.len)
 			appendStringInfoChar(&details, '\n');
 		appendStringInfo(&details,
-						 _("Server has FUNC_MAX_ARGS = %d, library has %d."),
-						 magic_data.funcmaxargs,
+						 _("Server has %s = %d, library has %d."),
+						 "FUNC_MAX_ARGS", magic_data.funcmaxargs,
 						 module_magic_data->funcmaxargs);
 	}
 	if (module_magic_data->indexmaxkeys != magic_data.indexmaxkeys)
@@ -367,8 +367,8 @@ incompatible_module_error(const char *libname,
 		if (details.len)
 			appendStringInfoChar(&details, '\n');
 		appendStringInfo(&details,
-						 _("Server has INDEX_MAX_KEYS = %d, library has %d."),
-						 magic_data.indexmaxkeys,
+						 _("Server has %s = %d, library has %d."),
+						 "INDEX_MAX_KEYS", magic_data.indexmaxkeys,
 						 module_magic_data->indexmaxkeys);
 	}
 	if (module_magic_data->namedatalen != magic_data.namedatalen)
@@ -376,8 +376,8 @@ incompatible_module_error(const char *libname,
 		if (details.len)
 			appendStringInfoChar(&details, '\n');
 		appendStringInfo(&details,
-						 _("Server has NAMEDATALEN = %d, library has %d."),
-						 magic_data.namedatalen,
+						 _("Server has %s = %d, library has %d."),
+						 "NAMEDATALEN", magic_data.namedatalen,
 						 module_magic_data->namedatalen);
 	}
 	if (module_magic_data->float8byval != magic_data.float8byval)
@@ -385,8 +385,8 @@ incompatible_module_error(const char *libname,
 		if (details.len)
 			appendStringInfoChar(&details, '\n');
 		appendStringInfo(&details,
-						 _("Server has FLOAT8PASSBYVAL = %s, library has %s."),
-						 magic_data.float8byval ? "true" : "false",
+						 _("Server has %s = %s, library has %s."),
+						 "FLOAT8PASSBYVAL", magic_data.float8byval ? "true" : "false",
 						 module_magic_data->float8byval ? "true" : "false");
 	}
 
-- 
1.8.3.1