Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DST16975-v3 store historical versions of data for up to 20 years #505

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fda_contents:
- owner_name: DELIUS_APP_SCHEMA
table_name: ND_PARAMETER
number_of_years: 3
number_of_years: 20
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#!/bin/bash
#
# Query which returns a CSV list of:
# Table Owner (input)
# Table Name (input)
# Whether flashback retention is set correctly

[[ -z ${OWNER_NAME} ]] && echo "Table OWNER_NAME must be specified" && exit 1
[[ -z ${TABLE_NAME} ]] && echo "TABLE_NAME must be specified" && exit 1
[[ -z ${NUMBER_OF_YEARS} ]] && echo "NUMBER_OF_YEARS must be specified" && exit 1

. ~/.bash_profile

Expand All @@ -11,7 +17,11 @@ SET PAGES 0
SET FEEDBACK OFF
SET HEADING OFF
WHENEVER SQLERROR EXIT FAILURE
SELECT owner_name||','||table_name
SELECT owner_name||','||table_name||','||
CASE WHEN REGEXP_REPLACE(flashback_archive_name,'DELIUS_(\d+)_YEAR_FDA','\1') = ${NUMBER_OF_YEARS}
THEN 'CORRECT_RETENTION'
ELSE 'INCORRECT_RETENTION'
END
FROM dba_flashback_archive_tables
WHERE owner_name = '${OWNER_NAME}'
AND table_name = '${TABLE_NAME}';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
# Proactive change to the SMON_SCN_TIME table as discussed here:
# https://jonathanlewis.wordpress.com/2014/03/03/flashback-fail/
# This is required for data retention beyond 3 years & 6 months.
# NOTE: THIS CAUSES A DATABASE OUTAGE
- name: Check if Table SMON_SCN_TIME is clustered
script: check_if_index_cluster_exists.sh
register: cluster_name
changed_when: false

- name: Recreate the table system.smon_scn_time_org
when: cluster_name.stdout is search("SMON_SCN_TO_TIME_AUX")
block:
- name: Shutdown database (prepare for upgrade mode)
shell: |
. ~/.bash_profile
[[ $(srvctl status database -d $ORACLE_SID) == "Database is running." ]] && srvctl stop database -d $ORACLE_SID

- name: Recreate the table system.smon_scn_time_org
script: recreate_smon_scn_time_table.sh

- name: Restart database (disable upgrade mode)
shell: |
. ~/.bash_profile
[[ $(srvctl status database -d $ORACLE_SID) == "Database is running." ]] && srvctl stop database -d $ORACLE_SID
srvctl start database -d $ORACLE_SID

- name: Check if Flashback Data Archive Tablespace Exists
script: check_if_fda_tablespace_exists.sh
register: tablespace_name
changed_when: false

- name: Create Flashback Data Archive Tablespace if Absent
script: create_fda_tablespace.sh
when: 'tablespace_name.stdout is not search("T_FLASHBACK_DATA_ARCHIVE")'

- name: Check if Flashback Data Archives Exists for All Required Numbers of Years
script: check_if_fda_exists.sh
register: flashback_archive_name
changed_when: false
environment:
NUMBER_OF_YEARS: "{{ number_of_years }}"
loop: "{{ fda_contents | map(attribute='number_of_years') | list | unique }}"
loop_control:
loop_var: number_of_years

- name: Create Flashback Data Archives Exists for All Required Numbers of Years
script: create_fda.sh
environment:
NUMBER_OF_YEARS: "{{ check_results.number_of_years }}"
loop: "{{ flashback_archive_name.results }}"
loop_control:
loop_var: check_results
when: check_results.stdout is not search("YEAR_FDA")

- name: Check if Required Tables in Flashback Archive
script: check_if_table_in_fda.sh
register: flashback_archive_tables
changed_when: false
environment:
OWNER_NAME: "{{ database_table.owner_name | upper }}"
TABLE_NAME: "{{ database_table.table_name | upper }}"
NUMBER_OF_YEARS: "{{ database_table.number_of_years }}"
loop: "{{ fda_contents }}"
loop_control:
loop_var: database_table

# Run this task if the table is not in any flashback archive
- name: Add Table to Flashback Archive
script: add_table_to_fda.sh
environment:
OWNER_NAME: "{{ check_results.database_table.owner_name | upper }}"
TABLE_NAME: "{{ check_results.database_table.table_name | upper }}"
NUMBER_OF_YEARS: "{{ check_results.database_table.number_of_years }}"
loop: "{{ flashback_archive_tables.results }}"
loop_control:
loop_var: check_results
when: check_results.stdout is not search(check_results.database_table.owner_name + ',' + check_results.database_table.table_name | upper)

- name: Move Table to Different Flashback Archive
script: move_table_to_different_fda.sh
environment:
OWNER_NAME: "{{ check_results.database_table.owner_name | upper }}"
TABLE_NAME: "{{ check_results.database_table.table_name | upper }}"
NUMBER_OF_YEARS: "{{ check_results.database_table.number_of_years }}"
loop: "{{ flashback_archive_tables.results }}"
loop_control:
loop_var: check_results
when: check_results.stdout is search(check_results.database_table.owner_name + ',' + check_results.database_table.table_name + ',INCORRECT_RETENTION' | upper)
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash
#
# Move an existing table which is in the wrong flashback archive (due to retention requirements)
#

[[ -z ${OWNER_NAME} ]] && echo "Table OWNER_NAME must be specified" && exit 1
[[ -z ${TABLE_NAME} ]] && echo "TABLE_NAME must be specified" && exit 1
[[ -z ${NUMBER_OF_YEARS} ]] && echo "NUMBER_OF_YEARS of retention must be specified" && exit 1

. ~/.bash_profile

sqlplus -s / as sysdba <<EOF
SET LINES 1000
SET PAGES 0
SET FEEDBACK OFF
SET HEADING OFF
WHENEVER SQLERROR EXIT FAILURE

-- Create table to export existing history
-- Note: this is hardcoded to TEMP_HISTORY by Oracle
BEGIN
DBMS_FLASHBACK_ARCHIVE.create_temp_history_table(
owner_name1=>'${OWNER_NAME}',
table_name1=>'${TABLE_NAME}');
END;
/

-- Get name of existing flashback history table
COLUMN archive_table_name NEW_VALUE flashback_history_table

SELECT archive_table_name
FROM dba_flashback_archive_tables
WHERE owner_name = '${OWNER_NAME}'
AND table_name = '${TABLE_NAME}';

-- Run export of existing history
INSERT /*+ append */
INTO ${OWNER_NAME}.temp_history
SELECT *
FROM ${OWNER_NAME}.&&flashback_history_table;

-- Disassociate table with existing archive
ALTER TABLE ${OWNER_NAME}.${TABLE_NAME} NO FLASHBACK ARCHIVE;

-- Need to pause before adding table back into flashback archive
-- to abvoid ORA-55624 error
BEGIN
DBMS_SESSION.sleep(2);
END;
/

-- Associate table with new archive
ALTER TABLE ${OWNER_NAME}.${TABLE_NAME} FLASHBACK ARCHIVE delius_${NUMBER_OF_YEARS}_year_fda;

-- Reimport the data history
BEGIN
DBMS_FLASHBACK_ARCHIVE.import_history (
owner_name1 => '${OWNER_NAME}',
table_name1 => '${TABLE_NAME}',
temp_history_name => 'TEMP_HISTORY');
END;
/

EXIT
EOF
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@

# Source oracle bash profile
. ~/.bash_profile

# Shutdown the database
srvctl stop database -d $ORACLE_SID

# Start the database in upgrade mode
srvctl start database -d $ORACLE_SID -o upgrade

# Wait for 60 seconds
sleep 60

# Modify the table and indexes
sqlplus -s / as sysdba <<EOF
Expand All @@ -20,6 +11,8 @@ SET FEEDBACK OFF
SET HEADING OFF
WHENEVER SQLERROR EXIT FAILURE

startup upgrade;

rename smon_scn_time to smon_scn_time_org;

create table smon_scn_time tablespace sysaux as select * from smon_scn_time_org;
Expand All @@ -33,10 +26,4 @@ drop index smon_scn_time_scn_idx;
create unique index smon_scn_time_scn_idx on smon_scn_time(scn) tablespace SYSAUX;

exit
EOF

# Shutdown the database
srvctl stop database -d $ORACLE_SID

# Start the database
srvctl start database -d $ORACLE_SID
EOF