Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c166454

Browse files
committed
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/6d313829-5f56-4a28-ae4b-bd01bf1ae791@oss.nttdata.com
1 parent a3699da commit c166454

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

doc/src/sgml/func.sgml

+1
Original file line numberDiff line numberDiff line change
@@ -30029,6 +30029,7 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset
3002930029
<para>
3003030030
<xref linkend="functions-admin-statsmod"/> lists functions used to
3003130031
manipulate statistics.
30032+
These functions cannot be executed during recovery.
3003230033
<warning>
3003330034
<para>
3003430035
Changes made by these statistics manipulation functions are likely to be

src/backend/statistics/attribute_stats.c

+12
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
155155
stats_check_required_arg(fcinfo, attarginfo, ATTRELATION_ARG);
156156
reloid = PG_GETARG_OID(ATTRELATION_ARG);
157157

158+
if (RecoveryInProgress())
159+
ereport(ERROR,
160+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
161+
errmsg("recovery is in progress"),
162+
errhint("Statistics cannot be modified during recovery.")));
163+
158164
/* lock before looking up attribute */
159165
stats_lock_check_privileges(reloid);
160166

@@ -865,6 +871,12 @@ pg_clear_attribute_stats(PG_FUNCTION_ARGS)
865871
stats_check_required_arg(fcinfo, attarginfo, ATTRELATION_ARG);
866872
reloid = PG_GETARG_OID(ATTRELATION_ARG);
867873

874+
if (RecoveryInProgress())
875+
ereport(ERROR,
876+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
877+
errmsg("recovery is in progress"),
878+
errhint("Statistics cannot be modified during recovery.")));
879+
868880
stats_lock_check_privileges(reloid);
869881

870882
stats_check_required_arg(fcinfo, attarginfo, ATTNAME_ARG);

src/backend/statistics/relation_stats.c

+6
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel)
7272
stats_check_required_arg(fcinfo, relarginfo, RELATION_ARG);
7373
reloid = PG_GETARG_OID(RELATION_ARG);
7474

75+
if (RecoveryInProgress())
76+
ereport(ERROR,
77+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
78+
errmsg("recovery is in progress"),
79+
errhint("Statistics cannot be modified during recovery.")));
80+
7581
stats_lock_check_privileges(reloid);
7682

7783
/*

0 commit comments

Comments
 (0)