You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ivorysql.compatible_mode not work in user context #1357
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;
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.
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)
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 = oracleis briefly applied in your session.
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).
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'.
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)
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.
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.
Activity
jiaoshuntian commentedon Jun 18, 2026
Thanks for reporting the issue!
123123213weqw commentedon Jul 12, 2026
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.
muzimu217 commentedon Sep 15, 2026
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_modewas 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)
InitPostgres()applies role/database-level GUCs viaApplySetting(..., PGC_S_DATABASE_USER)(src/backend/utils/init/postinit.c:1377-1380), socompatible_mode = oracleis briefly applied in your session.InitPostgres()returns,PostgresMain()callsInitIvorysql()(src/backend/tcop/postgres.c:4600→:4605), which unconditionally re-sets the same GUC with sourcePGC_S_OVERRIDE, choosing the value purely fromMyProcPort->connmode(postgres.c:5539-5560).connmodeis 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'.PGC_S_OVERRIDEoutranksPGC_S_DATABASE_USERinset_config_option's source-priority ladder (src/include/utils/guc.h:113-128, check atsrc/backend/utils/misc/guc.c:3606), so the port-derived value silently replaces the role-level one.SHOWthen reports the port's mode —pgin your session — with no hint that a role setting existed.So
compatible_modeis effectively port-driven by design, and role-level defaults never had a reliable effect on connections that land on either dedicated port. Only connections whoseconnmodeis 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 byb7479cf4/facfa2a2) addedGUC_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 inAlterSetting()(src/backend/catalog/pg_db_role_setting.c:37-45). On current master your stepALTER USER oracle SET ivorysql.compatible_mode = oraclefails fast withERRCODE_FEATURE_NOT_SUPPORTEDinstead 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 theIvorySQL_5.4tag nor anywhere onIVORY_REL_5_STABLE(through the currentIvorySQL_5.6tag), so on any 5.x release the statement still succeeds silently, exactly as you observed.Two residual gaps worth a look (questions, not demands)
ApplySetting()(src/backend/catalog/pg_db_role_setting.c:243-289) applies any pre-existingpg_db_role_settingrow — e.g. one carried over bypg_upgradefrom ≤5.4 — andInitIvorysql()then overrides it exactly as in your report. The silent mismatch survives on master for stale rows, just harder to explain.ALTER ROLE ... RESET ivorysql.compatible_mode(onlyRESET ALLbypasses it, atpg_db_role_setting.c:37), andRESET ALLwipes the role's other settings (like thework_memin your repro). So a leftover row can only be removed wholesale.How to verify
SELECT setting, source FROM pg_settings WHERE name = 'ivorysql.compatible_mode';. We'd expectsource = overrideandsetting = pgon a PG-port connection (vsuserfor a plain role-only setting, ordatabase userif it was setIN DATABASE, if the theory is wrong). Connecting through the Oracle listener instead should showoracle— but that's the port forcing it, not the role setting. (The override mechanism itself is verified identical on theIvorySQL_5.4tag —InitIvorysql()atpostgres.c:4519/:5453there, samePGC_S_OVERRIDEre-set afterInitPostgres()— only the line numbers above drift.)ALTER ROLEshould now error. As superuser, inserting a row directly intopg_db_role_settingwithsetconfig = '{ivorysql.compatible_mode=oracle}'(test-only) should reproduce the silent override at login, and a specific-nameRESETshould fail whileRESET ALLsucceeds.Possible directions (maintainers' call)
GUC_DISALLOW_IN_DB_ROLE_SETTINGout duringApplySetting(or at least log a warning when one is present), so stale rows can't produce an unexplainable session mode.RESETfor flagged GUCs so legacy rows can be cleaned withoutRESET ALL.e8051ca0here 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.
hs-liuxh commentedon Sep 29, 2026
#1363 has already addressed this issue.