Skip to Main Content
  • Questions
  • dataguard standby read only lag tolerance

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Eduardo.

Asked: August 29, 2023 - 10:35 pm UTC

Last updated: September 04, 2023 - 1:25 am UTC

Version: 19.8

Viewed 1000+ times

You Asked

Oracle 19c, Primary and Active Dataguard standby database.
Not having luck to automatically change the session parameter STANDBY_MAX_DATA_DELAY when a user logs in to the database:

We want users connected in read only mode to the Standby DB to get an error when synchronization lag is greater than a certain threshold (5min).

Tried this logon trigger created on primary and replicated to standby:

CREATE OR REPLACE TRIGGER STANDBY_MAX_DATA_DELAY
AFTER LOGON ON database 
WHEN
     (SYS_CONTEXT('USERENV','DATABASE_ROLE') in ('PHYSICAL STANDBY') and           
      SYS_CONTEXT('USERENV','SESSION_USER')!='SYS' and 
      SYS_CONTEXT('USERENV','SERVICE_NAME')='serv_name.sn.vcn.oraclevcn.com')
BEGIN
  execute immediate 'ALTER SESSION SET STANDBY_MAX_DATA_DELAY=300'; 
END;


However, whenever a non SYS user connects to the standby using the service specified, the trigger executes and fails with this error:

ORA-04088: error during execution of trigger 'SYS.STANDBY_MAX_DATA_DELAY'
ORA-00604: error occurred at recursive SQL level 1
ORA-03174: STANDBY_MAX_DATA_DELAY does not apply to SYS users
ORA-06512: at line 204088. 00000 - "error during execution of trigger '%s.%s'"
*Cause: A runtime error occurred during execution of a trigger.
*Action: Check the triggers which were involved in the operation.
Vendor code 4088


By testing different ways and parameters to use the logon trigger, I concluded the trigger is always doing the execute immediate as SYS, no matter who is logging in. I also tried changing the CURRENT_SCHEMA session parameter on the same ALTER SESSION statement but that does not work, the session needs to change or some variable needs to be set to target the SESSION_USER environment to change the parameter.

and Connor said...

I concluded the trigger is always doing the execute immediate as SYS, no matter who is logging in

You concluded wrong :-)

If you *created* the trigger as SYS then yes. But don't create things as SYS - we don't recommend that.

Create it as a schema that has the appropriate ADMINISTER DATABASE TRIGGER priv and you should be fine.

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library