ALTER COLLATION misses errcode

Started by Kirill Reshke23 days ago6 messageshackers
Jump to latest
#1Kirill Reshke
reshkekirill@gmail.com

Hello,

User running ALTER COLLATION receives an internal error:

ALTER COLLATION "default" REFRESH VERSION;
ERROR: cannot refresh version of default collation
HINT: Use ALTER DATABASE ... REFRESH COLLATION VERSION instead.

We do monitor our logs for XX00* error codes to check for data
corruptions etc, so sql-reachable XX000 gives us a red alert.

This simple one-liner should do:

diff --git a/src/backend/commands/collationcmds.c
b/src/backend/commands/collationcmds.c
index cfa0e4610d9..1f6156f379b 100644
--- a/src/backend/commands/collationcmds.c
+++ b/src/backend/commands/collationcmds.c
@@ -443,7 +443,8 @@ AlterCollation(AlterCollationStmt *stmt)
  if (collOid == DEFAULT_COLLATION_OID)
  ereport(ERROR,
- (errmsg("cannot refresh version of default collation"),
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot refresh version of default collation"),
  /* translator: %s is an SQL command */
  errhint("Use %s instead.",
  "ALTER DATABASE ... REFRESH COLLATION VERSION")));

--
Best regards,
Kirill Reshke

#2Heikki Linnakangas
hlinnaka@iki.fi
In reply to: Kirill Reshke (#1)
Re: ALTER COLLATION misses errcode

On 30/10/2026 20:38, Kirill Reshke wrote:

User running ALTER COLLATION receives an internal error:

ALTER COLLATION "default" REFRESH VERSION;
ERROR: cannot refresh version of default collation
HINT: Use ALTER DATABASE ... REFRESH COLLATION VERSION instead.

We do monitor our logs for XX00* error codes to check for data
corruptions etc, so sql-reachable XX000 gives us a red alert.

This simple one-liner should do:

diff --git a/src/backend/commands/collationcmds.c
b/src/backend/commands/collationcmds.c
index cfa0e4610d9..1f6156f379b 100644
--- a/src/backend/commands/collationcmds.c
+++ b/src/backend/commands/collationcmds.c
@@ -443,7 +443,8 @@ AlterCollation(AlterCollationStmt *stmt)
if (collOid == DEFAULT_COLLATION_OID)
ereport(ERROR,
- (errmsg("cannot refresh version of default collation"),
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot refresh version of default collation"),
/* translator: %s is an SQL command */
errhint("Use %s instead.",
"ALTER DATABASE ... REFRESH COLLATION VERSION")));

Is ERRCODE_FEATURE_NOT_SUPPORTED correct here? Is this something that we
just don't currently support, but we potentially could, or is it
something that just doesn't make sense?

- Heikki

#3Kirill Reshke
reshkekirill@gmail.com
In reply to: Heikki Linnakangas (#2)
Re: ALTER COLLATION misses errcode

On Sat, 31 Oct 2026 at 13:56, Heikki Linnakangas <hlinnaka@iki.fi> wrote:

On 30/10/2026 20:38, Kirill Reshke wrote:

User running ALTER COLLATION receives an internal error:

ALTER COLLATION "default" REFRESH VERSION;
ERROR: cannot refresh version of default collation
HINT: Use ALTER DATABASE ... REFRESH COLLATION VERSION instead.

We do monitor our logs for XX00* error codes to check for data
corruptions etc, so sql-reachable XX000 gives us a red alert.

This simple one-liner should do:

diff --git a/src/backend/commands/collationcmds.c
b/src/backend/commands/collationcmds.c
index cfa0e4610d9..1f6156f379b 100644
--- a/src/backend/commands/collationcmds.c
+++ b/src/backend/commands/collationcmds.c
@@ -443,7 +443,8 @@ AlterCollation(AlterCollationStmt *stmt)
if (collOid == DEFAULT_COLLATION_OID)
ereport(ERROR,
- (errmsg("cannot refresh version of default collation"),
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot refresh version of default collation"),
/* translator: %s is an SQL command */
errhint("Use %s instead.",
"ALTER DATABASE ... REFRESH COLLATION VERSION")));

Is ERRCODE_FEATURE_NOT_SUPPORTED correct here? Is this something that we
just don't currently support, but we potentially could, or is it
something that just doesn't make sense?

- Heikki

I think this is something that simply doesn't make sense. But reading
errcodes.h using myself (not AI), I don't see any better option. maybe
ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ?

--
Best regards,
Kirill Reshke

#4Kirill Reshke
reshkekirill@gmail.com
In reply to: Kirill Reshke (#3)
Re: ALTER COLLATION misses errcode

On Sat, 31 Oct 2026 at 14:53, Kirill Reshke <reshkekirill@gmail.com> wrote:

On Sat, 31 Oct 2026 at 13:56, Heikki Linnakangas <hlinnaka@iki.fi> wrote:

On 30/10/2026 20:38, Kirill Reshke wrote:

User running ALTER COLLATION receives an internal error:

ALTER COLLATION "default" REFRESH VERSION;
ERROR: cannot refresh version of default collation
HINT: Use ALTER DATABASE ... REFRESH COLLATION VERSION instead.

We do monitor our logs for XX00* error codes to check for data
corruptions etc, so sql-reachable XX000 gives us a red alert.

This simple one-liner should do:

diff --git a/src/backend/commands/collationcmds.c
b/src/backend/commands/collationcmds.c
index cfa0e4610d9..1f6156f379b 100644
--- a/src/backend/commands/collationcmds.c
+++ b/src/backend/commands/collationcmds.c
@@ -443,7 +443,8 @@ AlterCollation(AlterCollationStmt *stmt)
if (collOid == DEFAULT_COLLATION_OID)
ereport(ERROR,
- (errmsg("cannot refresh version of default collation"),
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot refresh version of default collation"),
/* translator: %s is an SQL command */
errhint("Use %s instead.",
"ALTER DATABASE ... REFRESH COLLATION VERSION")));

Is ERRCODE_FEATURE_NOT_SUPPORTED correct here? Is this something that we
just don't currently support, but we potentially could, or is it
something that just doesn't make sense?

- Heikki

I think this is something that simply doesn't make sense. But reading
errcodes.h using myself (not AI), I don't see any better option. maybe
ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ?

--
Best regards,
Kirill Reshke

Also ERRCODE_WRONG_OBJECT_TYPE could do but is defined in /* Class 42
- Syntax Error or Access Rule Violation */. Not sure if we violating
something here

--
Best regards,
Kirill Reshke

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Kirill Reshke (#4)
Re: ALTER COLLATION misses errcode

Kirill Reshke <reshkekirill@gmail.com> writes:

On Sat, 31 Oct 2026 at 14:53, Kirill Reshke <reshkekirill@gmail.com> wrote:

On Sat, 31 Oct 2026 at 13:56, Heikki Linnakangas <hlinnaka@iki.fi> wrote:

Is ERRCODE_FEATURE_NOT_SUPPORTED correct here? Is this something that we
just don't currently support, but we potentially could, or is it
something that just doesn't make sense?

I think this is something that simply doesn't make sense. But reading
errcodes.h using myself (not AI), I don't see any better option. maybe
ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ?

Also ERRCODE_WRONG_OBJECT_TYPE could do but is defined in /* Class 42
- Syntax Error or Access Rule Violation */. Not sure if we violating
something here

I think FEATURE_NOT_SUPPORTED is fine here. Let's not spend too
much effort on the color of this bikeshed.

regards, tom lane

#6Alexander Lakhin
exclusion@gmail.com
In reply to: Tom Lane (#5)
Re: ALTER COLLATION misses errcode

Hello Kirill and Tom,

30.10.2026 20:38, Kirill Reshke wrote:

We do monitor our logs for XX00* error codes to check for data
corruptions etc, so sql-reachable XX000 gives us a red alert.

31.10.2026 18:46, Tom Lane wrote:

I think FEATURE_NOT_SUPPORTED is fine here. Let's not spend too
much effort on the color of this bikeshed.

FWIW, I spotted 6 other bikesheds on the same street [1]/messages/by-id/f2758799-b7c1-4baf-8593-8899802cf48c@gmail.com, maybe you would
to paint them all at once...

[1]: /messages/by-id/f2758799-b7c1-4baf-8593-8899802cf48c@gmail.com

Best regards.
Alexander