Skip to content

psql: show whether the session is in Oracle compatibility mode in the prompt #1354

Description

@hanjianqiao

Summary

Add a psql prompt escape %o that shows whether the current session is in
Oracle compatibility mode. It expands to [ORA] when
ivorysql.compatible_mode = 'oracle', and to empty otherwise.

Motivation

When using psql interactively there is no easy way to tell whether the session
is in Oracle compatibility mode, which makes it easy to misjudge SQL behavior.

Proposed behavior

  • New prompt escape %o in both prompt.c and ora_prompt.c.
  • Reads the value via PQparameterStatus("ivorysql.compatible_mode"), so it
    reflects in-session SET changes in real time.
  • Requires marking ivorysql.compatible_mode as GUC_REPORT in the backend so
    the server pushes value changes to the client.
  • Off by default (default prompt unchanged); opt-in via:
    \set PROMPT1 '%o%/%R%x%# '
    

Example

ivorysql=# -- pg mode
[ORA]ivorysql=# -- oracle mode (prefix tracks SET in real time)

Notes / risks

  • Prompts are interactive-only → scripts/CI/pg_regress unaffected.
  • Default behavior unchanged; existing prompt-parsing tools unaffected unless
    the user opts in (and even then only the prefix changes, not the =# suffix).
  • Behind a connection pooler (e.g. PgBouncer), %o may not track SET unless
    the parameter is included (e.g. track_extra_parameters).
  • Requires server recompile + restart for GUC_REPORT to take effect; against
    an older server %o safely degrades to empty.

psql-oracle-mode-prompt.en.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions