Skip to content

ivorysql.compatible_mode not work in user context #1357

Closed

Description

@jerome-peng

Bug Report

IvorySQL Version

5.4

OS Version (uname -a)

openEuler 22.03 arm

Linux pg 5.10.0-182.0.0.95.oe2203sp3.aarch64 #1 SMP Sat Dec 30 13:16:24 CST 2023 aarch64 aarch64 aarch64 GNU/Linux

Current Behavior

postgres=# alter user oracle set work_mem='128MB';
ALTER ROLE
postgres=# alter user oracle set ivorysql.compatible_mode=oracle;
ALTER ROLE
postgres=# \drds
List of settings
Role | Database | Settings
--------+----------+---------------------------------
oracle | | ivorysql.compatible_mode=oracle+
| | work_mem=128MB
(1 row)

postgres=# \c - oracle
You are now connected to database "postgres" as user "oracle".
postgres=# show ivorysql.compatible_mode ;
ivorysql.compatible_mode

pg
(1 row)

Expected behavior/code

user oracle should get value oracle with parameter ivorysql.compatible_mode.

Step to reproduce

create user oracle password 'xxxxx';

alter user oracle set work_mem='128MB';

alter user oracle set ivorysql.compatible_mode=oracle;

\c - oracle

show ivorysql.compatible_mode ;

Activity

  1. added
    bug
    on Jun 17, 2026
  2. jiaoshuntian commented on Jun 18, 2026

    @jiaoshuntian
    Collaborator

    Thanks for reporting the issue!

  3. 123123213weqw commented on Jul 12, 2026

    @123123213weqw
    Contributor

    Happy to dig in. First hypothesis: ivorysql.compatible_mode is likely read once during session init (or its role-level value is shadowed there), so unlike work_mem it doesn't pick up the per-role setting — I'll reproduce on 5.4, trace where the role GUC is read for compatible_mode vs a normal GUC, and report the exact cause + minimal fix. @jiaoshuntian let me know if someone's already looking.

  4. muzimu217 commented on Sep 15, 2026

    @muzimu217
    Contributor

    Thanks for the detailed report — the repro is clear and the behavior is real, at least for the version you tested. Looking at the current master sources, ALTER ROLE ... SET ivorysql.compatible_mode was never going to win, for a mechanical reason, and on recent master the statement is now rejected outright. Posting what we found in case it helps close the loop (this is a hypothesis from code reading, not a verdict — verification steps below).

    Why the role setting is ignored (5.x behavior)

    1. At login, InitPostgres() applies role/database-level GUCs via ApplySetting(..., PGC_S_DATABASE_USER) (src/backend/utils/init/postinit.c:1377-1380), so compatible_mode = oracle is briefly applied in your session.
    2. After InitPostgres() returns, PostgresMain() calls InitIvorysql() (src/backend/tcop/postgres.c:4600 → :4605), which unconditionally re-sets the same GUC with source PGC_S_OVERRIDE, choosing the value purely from MyProcPort->connmode (postgres.c:5539-5560).
    3. connmode is derived from which listener port the connection landed on (src/backend/tcop/backend_startup.c:227-271): the PG port → 'p', the Oracle port → 'o', anything else → 'u'.
    4. PGC_S_OVERRIDE outranks PGC_S_DATABASE_USER in set_config_option's source-priority ladder (src/include/utils/guc.h:113-128, check at src/backend/utils/misc/guc.c:3606), so the port-derived value silently replaces the role-level one. SHOW then reports the port's mode — pg in your session — with no hint that a role setting existed.

    So compatible_mode is effectively port-driven by design, and role-level defaults never had a reliable effect on connections that land on either dedicated port. Only connections whose connmode is neither ('u') leave the role value in place.

    What master does now

    Commit e8051ca0 (2026-06-22, "don't allow setting ivorysql.compatible_mode via ALTER USER/DATABASE SET", followed by b7479cf4/facfa2a2) added GUC_DISALLOW_IN_DB_ROLE_SETTING (src/include/utils/guc.h:233) to this GUC (src/backend/utils/misc/guc_parameters.dat:1454) and enforces it in AlterSetting() (src/backend/catalog/pg_db_role_setting.c:37-45). On current master your step ALTER USER oracle SET ivorysql.compatible_mode = oracle fails fast with ERRCODE_FEATURE_NOT_SUPPORTED instead of silently not working — likely why this issue never got a follow-up, though the commit does not reference this issue. For scope: this fail-fast currently exists only on master and the 6.x stable branch — it is not in the IvorySQL_5.4 tag nor anywhere on IVORY_REL_5_STABLE (through the current IvorySQL_5.6 tag), so on any 5.x release the statement still succeeds silently, exactly as you observed.

    Two residual gaps worth a look (questions, not demands)

    1. Legacy rows are still applied-then-overridden. The flag is only checked at DDL time. ApplySetting() (src/backend/catalog/pg_db_role_setting.c:243-289) applies any pre-existing pg_db_role_setting row — e.g. one carried over by pg_upgrade from ≤5.4 — and InitIvorysql() then overrides it exactly as in your report. The silent mismatch survives on master for stale rows, just harder to explain.
    2. No way to clean a stale row individually. The same check rejects a specific-name ALTER ROLE ... RESET ivorysql.compatible_mode (only RESET ALL bypasses it, at pg_db_role_setting.c:37), and RESET ALL wipes the role's other settings (like the work_mem in your repro). So a leftover row can only be removed wholesale.

    How to verify

    • On 5.4: connect as the affected role and run SELECT setting, source FROM pg_settings WHERE name = 'ivorysql.compatible_mode';. We'd expect source = override and setting = pg on a PG-port connection (vs user for a plain role-only setting, or database user if it was set IN DATABASE, if the theory is wrong). Connecting through the Oracle listener instead should show oracle — but that's the port forcing it, not the role setting. (The override mechanism itself is verified identical on the IvorySQL_5.4 tag — InitIvorysql() at postgres.c:4519/:5453 there, same PGC_S_OVERRIDE re-set after InitPostgres() — only the line numbers above drift.)
    • On master: re-run your repro — the ALTER ROLE should now error. As superuser, inserting a row directly into pg_db_role_setting with setconfig = '{ivorysql.compatible_mode=oracle}' (test-only) should reproduce the silent override at login, and a specific-name RESET should fail while RESET ALL succeeds.

    Possible directions (maintainers' call)

    • Filter keys flagged GUC_DISALLOW_IN_DB_ROLE_SETTING out during ApplySetting (or at least log a warning when one is present), so stale rows can't produce an unexplainable session mode.
    • Allow specific-name RESET for flagged GUCs so legacy rows can be cleaned without RESET ALL.
    • If per-role defaults are genuinely not supported for this GUC, linking e8051ca0 here and closing with a note would help future readers — the fast-fail is on master/6-stable but has not been backported to any 5.x release (5.4 through 5.6), so 5.x users still hit the silent behavior; if per-role defaults are desired for migration tooling, that's a design discussion of its own.

    Happy to provide more detail if useful.

  5. hs-liuxh commented on Sep 29, 2026

    @hs-liuxh
    Collaborator

    #1363 has already addressed this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions