public inbox for [email protected]  
help / color / mirror / Atom feed
From: Fujii Masao <[email protected]>
To: Heikki Linnakangas <[email protected]>
To: [email protected]
Subject: Re: Improve error messages for database object stats manipulation functions during recovery
Date: Sat, 16 Nov 2024 02:36:54 +0900
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>



On 2024/11/13 6:09, Heikki Linnakangas wrote:
> On 25/10/2024 20:07, Fujii Masao wrote:
>> Hi,
>>
>> When database object stats manipulation functions like pg_set_relation_stats() are run,
>> they currently produce the following error and hint messages, which are "internal"
>> and make it hard for users to understand the issue:
>>
>>        ERROR:  cannot acquire lock mode ShareUpdateExclusiveLock on database objects while recovery is in progress
>>        HINT:  Only RowExclusiveLock or less can be acquired on database objects during recovery.
>>
>> So I'd like to propose updating these to clearer messages:
>>
>>        ERROR:  recovery is in progress
>>        HINT:  Database object statistics manipulation functions cannot be executed during recovery.
>>
>> Thought?
> 
> Makes sense.
> 
> "Database object statistics manipulation functions" is a bit of a mouthful". Maybe something like "statistics cannot be modified during recovery".

Sounds good! I've updated the hint messages as suggested and attached the revised patch.
Thanks for the review!

Unless there are any objections, I'll proceed with committing it.

Regards,

-- 
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

From 0d8711ff4a52a81c337c157177c423ce65bb3c20 Mon Sep 17 00:00:00 2001
From: Fujii Masao <[email protected]>
Date: Sat, 26 Oct 2024 01:09:46 +0900
Subject: [PATCH v2] Improve error message for database object stats
 manipulation functions.

Previously, database object statistics manipulation functions like
pg_set_relation_stats() reported unclear error and hint messages
when executed during recovery. These messages were "internal",
making it difficult for users to understand the issue:

  ERROR:  cannot acquire lock mode ShareUpdateExclusiveLock on database objects while recovery is in progress
  HINT:  Only RowExclusiveLock or less can be acquired on database objects during recovery.

This commit updates the error handling so that, if these functions
are called during recovery, they produce clearer messages:

  ERROR:  recovery is in progress
  HINT:  Statistics cannot be modified during recovery.

The related documentation has also been updated to explicitly
clarify that these functions are not available during recovery.

Author: Fujii Masao
Reviewed-by: Heikki Linnakangas, Maxim Orlov
Discussion: https://postgr.es/m/[email protected]
---
 doc/src/sgml/func.sgml                   |  1 +
 src/backend/statistics/attribute_stats.c | 12 ++++++++++++
 src/backend/statistics/relation_stats.c  |  6 ++++++
 3 files changed, 19 insertions(+)

diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 73979f20ff..1a0b85bb4d 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -30029,6 +30029,7 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset
    <para>
     <xref linkend="functions-admin-statsmod"/> lists functions used to
     manipulate statistics.
+    These functions cannot be executed during recovery.
     <warning>
      <para>
       Changes made by these statistics manipulation functions are likely to be
diff --git a/src/backend/statistics/attribute_stats.c b/src/backend/statistics/attribute_stats.c
index 4ae0722b78..686f2e639c 100644
--- a/src/backend/statistics/attribute_stats.c
+++ b/src/backend/statistics/attribute_stats.c
@@ -155,6 +155,12 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
 	stats_check_required_arg(fcinfo, attarginfo, ATTRELATION_ARG);
 	reloid = PG_GETARG_OID(ATTRELATION_ARG);
 
+	if (RecoveryInProgress())
+		ereport(ERROR,
+				(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+				 errmsg("recovery is in progress"),
+				 errhint("Statistics cannot be modified during recovery.")));
+
 	/* lock before looking up attribute */
 	stats_lock_check_privileges(reloid);
 
@@ -865,6 +871,12 @@ pg_clear_attribute_stats(PG_FUNCTION_ARGS)
 	stats_check_required_arg(fcinfo, attarginfo, ATTRELATION_ARG);
 	reloid = PG_GETARG_OID(ATTRELATION_ARG);
 
+	if (RecoveryInProgress())
+		ereport(ERROR,
+				(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+				 errmsg("recovery is in progress"),
+				 errhint("Statistics cannot be modified during recovery.")));
+
 	stats_lock_check_privileges(reloid);
 
 	stats_check_required_arg(fcinfo, attarginfo, ATTNAME_ARG);
diff --git a/src/backend/statistics/relation_stats.c b/src/backend/statistics/relation_stats.c
index ed5dea2e05..e619d5cf5b 100644
--- a/src/backend/statistics/relation_stats.c
+++ b/src/backend/statistics/relation_stats.c
@@ -72,6 +72,12 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel)
 	stats_check_required_arg(fcinfo, relarginfo, RELATION_ARG);
 	reloid = PG_GETARG_OID(RELATION_ARG);
 
+	if (RecoveryInProgress())
+		ereport(ERROR,
+				(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+				 errmsg("recovery is in progress"),
+				 errhint("Statistics cannot be modified during recovery.")));
+
 	stats_lock_check_privileges(reloid);
 
 	/*
-- 
2.47.0



Attachments:

  [text/plain] v2-0001-Improve-error-message-for-database-object-stats-m.patch (3.7K, ../[email protected]/2-v2-0001-Improve-error-message-for-database-object-stats-m.patch)
  download | inline diff:
From 0d8711ff4a52a81c337c157177c423ce65bb3c20 Mon Sep 17 00:00:00 2001
From: Fujii Masao <[email protected]>
Date: Sat, 26 Oct 2024 01:09:46 +0900
Subject: [PATCH v2] Improve error message for database object stats
 manipulation functions.

Previously, database object statistics manipulation functions like
pg_set_relation_stats() reported unclear error and hint messages
when executed during recovery. These messages were "internal",
making it difficult for users to understand the issue:

  ERROR:  cannot acquire lock mode ShareUpdateExclusiveLock on database objects while recovery is in progress
  HINT:  Only RowExclusiveLock or less can be acquired on database objects during recovery.

This commit updates the error handling so that, if these functions
are called during recovery, they produce clearer messages:

  ERROR:  recovery is in progress
  HINT:  Statistics cannot be modified during recovery.

The related documentation has also been updated to explicitly
clarify that these functions are not available during recovery.

Author: Fujii Masao
Reviewed-by: Heikki Linnakangas, Maxim Orlov
Discussion: https://postgr.es/m/[email protected]
---
 doc/src/sgml/func.sgml                   |  1 +
 src/backend/statistics/attribute_stats.c | 12 ++++++++++++
 src/backend/statistics/relation_stats.c  |  6 ++++++
 3 files changed, 19 insertions(+)

diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 73979f20ff..1a0b85bb4d 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -30029,6 +30029,7 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset
    <para>
     <xref linkend="functions-admin-statsmod"/> lists functions used to
     manipulate statistics.
+    These functions cannot be executed during recovery.
     <warning>
      <para>
       Changes made by these statistics manipulation functions are likely to be
diff --git a/src/backend/statistics/attribute_stats.c b/src/backend/statistics/attribute_stats.c
index 4ae0722b78..686f2e639c 100644
--- a/src/backend/statistics/attribute_stats.c
+++ b/src/backend/statistics/attribute_stats.c
@@ -155,6 +155,12 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
 	stats_check_required_arg(fcinfo, attarginfo, ATTRELATION_ARG);
 	reloid = PG_GETARG_OID(ATTRELATION_ARG);
 
+	if (RecoveryInProgress())
+		ereport(ERROR,
+				(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+				 errmsg("recovery is in progress"),
+				 errhint("Statistics cannot be modified during recovery.")));
+
 	/* lock before looking up attribute */
 	stats_lock_check_privileges(reloid);
 
@@ -865,6 +871,12 @@ pg_clear_attribute_stats(PG_FUNCTION_ARGS)
 	stats_check_required_arg(fcinfo, attarginfo, ATTRELATION_ARG);
 	reloid = PG_GETARG_OID(ATTRELATION_ARG);
 
+	if (RecoveryInProgress())
+		ereport(ERROR,
+				(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+				 errmsg("recovery is in progress"),
+				 errhint("Statistics cannot be modified during recovery.")));
+
 	stats_lock_check_privileges(reloid);
 
 	stats_check_required_arg(fcinfo, attarginfo, ATTNAME_ARG);
diff --git a/src/backend/statistics/relation_stats.c b/src/backend/statistics/relation_stats.c
index ed5dea2e05..e619d5cf5b 100644
--- a/src/backend/statistics/relation_stats.c
+++ b/src/backend/statistics/relation_stats.c
@@ -72,6 +72,12 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel)
 	stats_check_required_arg(fcinfo, relarginfo, RELATION_ARG);
 	reloid = PG_GETARG_OID(RELATION_ARG);
 
+	if (RecoveryInProgress())
+		ereport(ERROR,
+				(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+				 errmsg("recovery is in progress"),
+				 errhint("Statistics cannot be modified during recovery.")));
+
 	stats_lock_check_privileges(reloid);
 
 	/*
-- 
2.47.0



view thread (4+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Improve error messages for database object stats manipulation functions during recovery
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox