I have a table VISIT_HIST
in an Oracle data warehouse. This table contains number of customer visits during every month and is rather big (~130 mn rows).
CREATE TABLE (
VALUE_MONTH DATE,
USER_ID NUMBER,
N_VISITS NUMBER
)
;
The data itself looks like:
VALUE_MONTH | USER_ID | N_VISITS |
---|---|---|
31.12.2022 | 43254 | 25 |
Every night a job executes a stored procedure, which updates this table. The data for last 3 months is deleted from table. After that, the procedure inserts new information about number of visits for each USER_ID
user during last 3 months (~10-12 mn rows inserted in total for all users for 3 months). The stored procedure looks like:
CREATE OR REPLACE PROCEDURE EXAMPLE_PROC IS
BEGIN
-- 1. delete old data for the last 3 months
DELETE FROM VISIT_HIST
WHERE VALUE_MONTH >= ADD_MONTHS(TRUNC(SYSDATE, 'dd.mm.yyyy'), -3)
;
COMMIT;
-- 2. insert new data
INSERT INTO VISIT_HIST
SELECT /*+ parallel(8)*/
LAST_DAY(VALUE_DAY) VALUE_MONTH,
USER_ID,
COUNT(DISTINCT VISIT_ID) N_VISITS
FROM ...
WHERE VALUE_DAY >= ADD_MONTHS(TRUNC(SYSDATE, 'dd.mm.yyyy'), -3)
GROUP BY
LAST_DAY(VALUE_DAY),
USER_ID
;
COMMIT;
END;
The data for the last 3 months is unavailable to the database users when the table is being updated. So how can I keep the older version of the data for the last 3 months available to the users of the table during update process?
I really don't want to create a temporary copy of VISIT_HIST
with another name every day before update process. Pretty sure there is some better way to solve my problem.
Any help is appreciated.