gvenzl / oci-oracle-free

Build scripts for Oracle Database FREE container/docker images
Apache License 2.0
138 stars 39 forks source link

Timezone mismatch between DBMS_SCHEDULER and Session #65

Open zachy opened 2 months ago

zachy commented 2 months ago

Hey, We are facing an issue: Suppose table PRODUCT with column VERSION TIMESTAMP(6) WITH LOCAL TIME ZONE when I call SELECT * FROM PRODUCT as user with SESSIONTIMEZONE=Europe/Prague it returns 24.09.24 15:13

We have a periodic DBMS_SCHEDULER JOB where we rely on same timezone=Europe/Prague, which can be simulated as

BEGIN
  DBMS_SCHEDULER.RUN_JOB('JEF_Prosperita_Calc', FALSE); -- means USE_CURRENT_SESSION = false, resulting taking from system settings
END; 
/

The query inside scheduler returns 24.09.24 13:13, meaning it does not respect the value of DBTIMEZONE

I tried to set it up using docker environment variables

  database:
    image: gvenzl/oracle-free:latest
    ...
    environment:
      ...
      TZ: Europe/Prague
      ORA_SDTZ: Europe/Prague
    volumes:
      - ./oracle/data:/opt/oracle/oradata
      - ../build/oracle/init_scripts:/container-entrypoint-initdb.d
    ...

Also i tried to use init sh script

sqlplus -s / as sysdba << EOF
-- Root container setup

SET SERVEROUTPUT ON;
SELECT SYS_CONTEXT('USERENV', 'CON_NAME') AS current_container FROM DUAL;

ALTER DATABASE SET TIME_ZONE = 'Europe/Prague';

BEGIN
  DBMS_SCHEDULER.SET_SCHEDULER_ATTRIBUTE (
    attribute => 'default_timezone',
    value     => 'Europe/Prague'); -- Replace with your preferred timezone
END;
/

SELECT DBTIMEZONE FROM DUAL;
DECLARE
  val VARCHAR2(100);
BEGIN
  DBMS_SCHEDULER.GET_SCHEDULER_ATTRIBUTE('default_timezone', val);
  DBMS_OUTPUT.PUT_LINE('Root Default Timezone: ' || val);
END;
/

   -- Commit the change
   SHUTDOWN IMMEDIATE;
   STARTUP;

SET SERVEROUTPUT ON;
SELECT SYS_CONTEXT('USERENV', 'CON_NAME') AS current_container FROM DUAL;

SELECT DBTIMEZONE FROM DUAL;
DECLARE
  val VARCHAR2(100);
BEGIN
  DBMS_SCHEDULER.GET_SCHEDULER_ATTRIBUTE('default_timezone', val);
  DBMS_OUTPUT.PUT_LINE('Root Default Timezone: ' || val);
END;
/
   exit;
EOF

Is there another way to set it up?

Thanks for any advice.