Thursday, 12 June 2025

Filled under:

Absolutely, Daidipya. Here's a deeper and broader breakdown of areas where Oracle tables can be identified, analyzed, and relocated or optimized, including the queries and approaches you can use. This helps not only with performance but also in backup optimization, data archiving, and storage planning.


📁 A. Identify Tables for Segregation or Movement


🔸 1. Read-Only Candidates (Static / Archival Data)

✅ Use Case:

Tables that are no longer updated (e.g., old financial years, logs, historical orders) can be moved to read-only tablespaces.

🔍 Query:

sql
SELECT owner, table_name, last_analyzed FROM dba_tables WHERE last_analyzed < SYSDATE - 180 AND table_name NOT LIKE '%TMP%' AND NUM_ROWS > 0;

📦 Next Step:

  • Move to a dedicated tablespace

  • Convert the tablespace to READ ONLY


🔸 2. Small, Unused, or Inactive Tables (Clean-up / Tier 3)

✅ Use Case:

Tables with very low row counts or no recent access (and no FK references) might be candidates for archiving or removal.

🔍 Query:

sql
SELECT owner, table_name, num_rows FROM dba_tables WHERE num_rows < 100 AND last_analyzed < SYSDATE - 365;

Optionally: cross-check for foreign keys via dba_constraints.


🔸 3. Large Tables with High Update/Insert Frequency (Hot Data)

✅ Use Case:

High DML tables should be:

  • Partitioned

  • Placed in high-performance tablespaces

  • Possibly segregated by module/application

🔍 Query:

sql
SELECT s.owner, s.table_name, t.num_rows, s.inserts, s.updates, s.deletes FROM dba_tab_modifications s JOIN dba_tables t ON s.table_name = t.table_name AND s.table_owner = t.owner ORDER BY (s.inserts + s.updates + s.deletes) DESC;

🔸 4. LOB-heavy Tables (Move to separate LOB tablespaces)

✅ Use Case:

Large unstructured data like documents or images can benefit from:

  • SECUREFILE with compression/deduplication

  • Moving LOBs to a dedicated tablespace

🔍 Query:

sql
SELECT owner, table_name, column_name, segment_name, tablespace_name, securefile FROM dba_lobs WHERE segment_name IS NOT NULL;

🔸 5. Tables with Frequent Full Table Scans (Tuning Required)

✅ Use Case:

Tables accessed via FTS may need better indexing or partitioning.

🔍 Query:

sql
SELECT owner, object_name, value AS full_table_scans FROM v$segment_statistics WHERE statistic_name = 'table scans (long tables)' AND object_type = 'TABLE' ORDER BY value DESC;

Pair this with execution plans from AWR/ASH or SQL Monitor.


🛠️ B. Suggested Actions and Movement Techniques


🔁 1. Move to Separate Tablespace

sql
ALTER TABLE <owner>.<table_name> MOVE TABLESPACE <new_tbs>;

Rebuild indexes after moving.


🔄 2. Shrink Space or Reorg Table

sql
ALTER TABLE <owner>.<table_name> ENABLE ROW MOVEMENT; ALTER TABLE <owner>.<table_name> SHRINK SPACE COMPACT;

🔂 3. Partition Table

sql
CREATE TABLE sales_partitioned ( sale_id NUMBER, sale_date DATE, ... ) PARTITION BY RANGE (sale_date) ( PARTITION p_2023 VALUES LESS THAN (TO_DATE('01-JAN-2024','DD-MON-YYYY')), PARTITION p_max VALUES LESS THAN (MAXVALUE) );

💾 4. Create Read-Only Tablespace

sql
ALTER TABLESPACE archive_data READ ONLY;

🧩 C. Advanced Identification (Optional)


🔬 1. Query Usage from AWR (with License)

sql
SELECT parsing_schema_name, object_name, COUNT(*) AS exec_count FROM dba_hist_sqltext t JOIN dba_hist_sqlstat s ON t.sql_id = s.sql_id WHERE object_name IS NOT NULL GROUP BY parsing_schema_name, object_name ORDER BY exec_count ASC;

🧮 2. Estimate Space Saved After Moving/Compressing

sql
SELECT table_name, segment_name, segment_type, bytes/1024/1024 AS MB FROM dba_segments WHERE segment_type = 'TABLE' AND tablespace_name = '<current_tablespace>';

Compare before and after for MOVE/SHRINK.


📌 Summary Table: What to Identify & Where to Move

Use CaseIdentify With Query OnMove To / Action
Historical, inactive tablesdba_tables, dba_tab_modificationsRead-only tablespace
LOB-heavy tablesdba_lobsDedicated LOB tablespace, enable SecureFile
Hot DML tablesdba_tab_modifications, statsPartitioned + faster storage
Small/unreferenced tablesdba_tables, dba_constraintsArchive schema / drop
Tables with FTSv$segment_statisticsAdd indexes, partition or tune SQL
Low-usage over AWR perioddba_hist_seg_statArchive, shrink, or reorganize

Would you like a consolidated PL/SQL or shell-based report that gives this profiling for every table in a schema or across databases?

0 comments:

Post a Comment