Skip to content

don't allow setting ivorysql.compatible_mode via ALTER USER/DATABASE SET - #1363

Merged
gaoxueyu merged 1 commit into
IvorySQL:masterfrom
bigplaice:not-allow-compatible-mode-change-in-alter-set
Jun 25, 2026
Merged

gaoxueyu merged 1 commit into
IvorySQL:masterfrom
bigplaice:not-allow-compatible-mode-change-in-alter-set

Conversation

@bigplaice

@bigplaice bigplaice commented Jun 22, 2026 •

Copy link
Copy Markdown
Collaborator

fix issue #1357

The value of ivorysql.compatible_mode is determined by port or can be set using SET command in session.
But it cannot be set via ALTER USER/DATABASE SET.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Introduces a new GUC flag bit GUC_DISALLOW_IN_DB_ROLE_SETTING (0x800000), adds enforcement inside AlterSetting that raises an error when a GUC carrying that flag is targeted by ALTER USER/ROLE/DATABASE SET, and marks ivorysql.compatible_mode with the new flag.

Changes

GUC disallow-in-db-role-setting mechanism

Layer / File(s) Summary
Flag definition and AlterSetting enforcement
src/include/utils/guc.h, src/backend/catalog/pg_db_role_setting.c
Defines the GUC_DISALLOW_IN_DB_ROLE_SETTING bit (0x800000) in guc.h. In pg_db_role_setting.c, adds utils/guc_tables.h and a guard in AlterSetting that calls find_option, checks the new flag, and raises ERRCODE_FEATURE_NOT_SUPPORTED with a hint to use session SET instead.
Apply flag to ivorysql.compatible_mode
src/backend/utils/misc/ivy_guc.c
Adds GUC_DISALLOW_IN_DB_ROLE_SETTING to the ivorysql.compatible_mode GUC registration flags, blocking its use with ALTER USER/ROLE/DATABASE SET.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A bunny hopped in, flag in paw,
"No ALTER SET for you!" — the law.
compatible_mode stands apart,
Only SET may touch its heart.
🐇 Bits and flags, a tidy art!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically describes the main change: preventing ivorysql.compatible_mode from being set via ALTER USER/DATABASE SET commands, which matches the PR's core objective.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/backend/catalog/pg_db_role_setting.c`:
- Around line 40-45: The ereport statement following the conditional check on
record and GUC_DISALLOW_IN_DB_ROLE_SETTING flag needs to be properly indented.
The ereport call with its errcode, errmsg, and errhint arguments should be
indented one tab level further to align as the body of the if statement,
matching the project's coding style conventions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0ecf81cf-2ac9-4322-a19a-72f6c187e987

📥 Commits

Reviewing files that changed from the base of the PR and between d35fc7b and e8051ca.

⛔ Files ignored due to path filters (1)
  • src/backend/utils/misc/guc_parameters.dat is excluded by !**/*.dat
📒 Files selected for processing (3)
  • src/backend/catalog/pg_db_role_setting.c
  • src/backend/utils/misc/ivy_guc.c
  • src/include/utils/guc.h

Comment on lines +40 to +45
if (record && (record->flags & GUC_DISALLOW_IN_DB_ROLE_SETTING))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot set parameter \"%s\" via ALTER USER/ROLE/DATABASE SET",
setstmt->name),
errhint("Use SET command in session instead.")));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix indentation for the ereport statement.

The ereport call should be indented to match the coding style of the surrounding code. Currently it appears to be at the wrong indentation level.

🔧 Proposed fix for indentation
 		record = find_option(setstmt->name, false, true, WARNING);
 		if (record && (record->flags & GUC_DISALLOW_IN_DB_ROLE_SETTING))
-		ereport(ERROR,
-			(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-			 errmsg("cannot set parameter \"%s\" via ALTER USER/ROLE/DATABASE SET",
-				setstmt->name),
-			 errhint("Use SET command in session instead.")));
+			ereport(ERROR,
+					(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+					 errmsg("cannot set parameter \"%s\" via ALTER USER/ROLE/DATABASE SET",
+							setstmt->name),
+					 errhint("Use SET command in session instead.")));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (record && (record->flags & GUC_DISALLOW_IN_DB_ROLE_SETTING))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot set parameter \"%s\" via ALTER USER/ROLE/DATABASE SET",
setstmt->name),
errhint("Use SET command in session instead.")));
if (record && (record->flags & GUC_DISALLOW_IN_DB_ROLE_SETTING))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot set parameter \"%s\" via ALTER USER/ROLE/DATABASE SET",
setstmt->name),
errhint("Use SET command in session instead.")));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/backend/catalog/pg_db_role_setting.c` around lines 40 - 45, The ereport
statement following the conditional check on record and
GUC_DISALLOW_IN_DB_ROLE_SETTING flag needs to be properly indented. The ereport
call with its errcode, errmsg, and errhint arguments should be indented one tab
level further to align as the body of the if statement, matching the project's
coding style conventions.

@gaoxueyu
gaoxueyu merged commit a4d51e8 into IvorySQL:master Jun 25, 2026
9 of 10 checks passed
hs-liuxh pushed a commit to hs-liuxh/IvorySQL that referenced this pull request Sep 2, 2026
…mode-change-in-alter-set

don't allow setting ivorysql.compatible_mode via ALTER USER/DATABASE SET

(cherry picked from commit a4d51e8)
hs-liuxh pushed a commit to hs-liuxh/IvorySQL that referenced this pull request Sep 2, 2026
…mode-change-in-alter-set

don't allow setting ivorysql.compatible_mode via ALTER USER/DATABASE SET

(cherry picked from commit a4d51e8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants