Monday, July 29, 2024

In Oracle How to shrink Securefile LOB tables


As per Oracle support, if the table uses securefile LOB the traditional shrink method ALTER TABLE MODIFY LOB (XMLRECORD) (SHRINK SPACE) will not shrink the LOB/table. The support recommends using the Online Redefinition method to shrink the table after purging or deletion activity. The same has been tested and sample steps have been shared below.

Step 1: We used the FBNK_CUSTOMER database, which has 5L records and 305 MB in size. The table uses Securefile LOB.




Step 2: Removing half of the records using the below delete command but the size remains the same after deletion.delete from FBNK_CUSTOMER where rownum <= 250000;


Step 3: Determine if the table can be redefined online.
SET SERVEROUTPUT ON
BEGIN
    DBMS_REDEFINITION.CAN_REDEF_TABLE('TAFJ','FBNK_CUSTOMER', DBMS_REDEFINITION.CONS_USE_ROWID);
END;
/


Step 4: Create the interim table

The redefinition procedure uses materialized view and fast refresh concept. In order to load the data from the original table an interim table has to be created. The interim and original tables must coexist until the redefinition is completed and the interim table is removed. As a result, there must be enough space in the tablespace(s) to hold both tables at that moment.


CREATE TABLE INTERIM AS SELECT * FROM TEST WHERE 1=2;



Step 5: Start the redefinition

BEGIN

DBMS_REDEFINITION.START_REDEF_TABLE(

             uname => 'TAFJ',

             orig_table => 'FBNK_CUSTOMER',

             int_table => 'INTERIM',

             options_flag => DBMS_REDEFINITION.CONS_USE_ROWID);

END;

/



Step 6: Finish the redefinition

exec DBMS_REDEFINITION.FINISH_REDEF_TABLE('TAFJ','FBNK_CUSTOMER','INTERIM');



Step 7: Recheck the size of the table after the redefinition

select bytes/1024/1024 MB from dba_segments where segment_name='FBNK_CUSTOMER';



Step 8: Drop the interim table and purge it from the recycle bin, if possible, purge the recycle bin to bring the disk usage down.

drop table interim purge ;

purge recyclebin ;

 

3. Compression option :


During the INTERIM table creation process (Step 4), you can also experiment with the compress option. Here is a sample DDL; the Bank DBA must make the appropriate adjustments to the environment.

CREATE TABLE "TAFJ"."INTERIM"

   ("RECID" VARCHAR2(255) NOT NULL ENABLE,

        "XMLRECORD" BLOB) SEGMENT CREATION DEFERRED

  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255

 COMPRESS BASIC LOGGING

  TABLESPACE "T24DATA"

 LOB ("XMLRECORD") STORE AS SECUREFILE "LOB_TEST157" (

  TABLESPACE "T24DATA" ENABLE STORAGE IN ROW CHUNK 8192

  NOCACHE LOGGING  NOCOMPRESS  KEEP_DUPLICATES );

4. Notes to DBAs :

We have referred to the Oracle documents How to Shrink a Securefile LOB Using Online Redefinition (DBMS_REDEFINITION)? (Doc ID 1394613.1) and Primary Note: Overview of Online Redefinition of Tables (DBMS_REDEFINITION) (Doc ID 1357825.1) to successfully shrink the Securefiles LOB. If you have any concerns or difficulties while performing the procedure, please raise a case with Oracle Support and work with them to resolve the same.







 

Wednesday, June 26, 2024

PL/SQL PACKAGE SYS.DBMS_BACKUP_RESTORE VERSION IS NOT CURRENTPL/SQL PACKAGE SYS.DBMS_RCVMAN VERSION 19.03.00.00 IS TOO OLD

 


Recently, I undertook the task of upgrading an Oracle database from version 19.03 to 19.22. As the process progressed, I began to encounter a series of errors that were consistently appearing in the alert log.


ARC3 (PID:3646): Archived Log entry 3829 added for T-1.S-6 ID 0xbc253a92 LAD:1

2024-06-27T06:12:14.930888+02:00

PL/SQL package SYS.DBMS_BACKUP_RESTORE version  is not current

PL/SQL package SYS.DBMS_RCVMAN version 19.03.00.00 is too old

PL/SQL package SYS.DBMS_BACKUP_RESTORE version  is not current

PL/SQL package SYS.DBMS_RCVMAN version 19.03.00.00 is too old


After diving deep into the issue, it was discovered that running a series of scripts after the upgrade would effectively solve the problem. Furthermore, it was necessary to recompile the invalid packages. Without any delay, I proceeded to execute the specified scripts and recompile the invalid objects.

1
2
3
4
SQL> @$ORACLE_HOME/rdbms/admin/dbmsrman.sql
SQL> @$ORACLE_HOME/rdbms/admin/dbmsbkrs.sql
SQL> @$ORACLE_HOME/rdbms/admin/prvtrmns.plb
SQL> @$ORACLE_HOME/rdbms/admin/prvtbkrs.plb


SQL*Plus: Release 19.0.0.0.0 - Production on Tue May 23 06:15:14 2023
Version 19.03.0.0.0
 
Copyright (c) 1982, 2022, Oracle.  All rights reserved.
 
 
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.22.0.0.0
 
SQL> @$ORACLE_HOME/rdbms/admin/dbmsrman.sql
 
Session altered.
 
 
Package created.
 
 
PL/SQL procedure successfully completed.
 
 
PL/SQL procedure successfully completed.
 
 
PL/SQL procedure successfully completed.
 
 
Grant succeeded.
 
 
Grant succeeded.
 
 
Grant succeeded.
 
 
Grant succeeded.
 
 
Grant succeeded.
 
 
PL/SQL procedure successfully completed.
 
 
Synonym dropped.
 
 
View dropped.
 
 
Function dropped.
 
 
Type dropped.
 
 
Type dropped.
 
 
Type dropped.
 
 
Type created.
 
 
Type created.
 
 
Type created.
 
 
Type body created.
 
 
Function created.
 
 
View created.
 
 
Synonym created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
Synonym dropped.
 
 
View dropped.
 
 
Synonym dropped.
 
 
View dropped.
 
 
Synonym dropped.
 
 
View dropped.
 
 
Function dropped.
 
 
Type dropped.
 
 
Type dropped.
 
 
Type dropped.
 
 
Type created.
 
 
Type created.
 
 
Type created.
 
 
Type body created.
 
 
Function created.
 
 
View created.
 
 
View created.
 
 
Synonym created.
 
 
Synonym created.
 
 
View created.
 
 
View created.
 
 
Synonym created.
 
 
Synonym created.
 
 
View created.
 
 
View created.
 
 
Synonym created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
Grant succeeded.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
View created.
 
 
Synonym created.
 
 
Grant succeeded.
 
 
Session altered.
 
SQL> @$ORACLE_HOME/rdbms/admin/dbmsbkrs.sql
 
Session altered.
 
 
Package created.
 
 
Session altered.
 
SQL> @$ORACLE_HOME/rdbms/admin/prvtrmns.plb
 
Session altered.
 
 
Package body created.
 
 
Session altered.
 
SQL> @$ORACLE_HOME/rdbms/admin/prvtbkrs.plb
 
Session altered.
 
 
Package body created.
 
 
Session altered.
 
SQL>    set pagesize 1000
          select 'alter '||decode(object_type,'PACKAGE BODY','PACKAGE',object_type)||'
'||owner||'.'||object_name||' compile '||
          decode(object_type,'PACKAGE BODY','body','PACKAGE','BODY')||';'
          from  dba_objects
          where  status      =  'INVALID' AND object_type <>'SYNONYM';
SQL>   2    3    4
'ALTER'||DECODE(OBJECT_TYPE,'PACKAGEBODY','PACKAGE',OBJECT_TYPE)||''||OWNER||'.'
--------------------------------------------------------------------------------
alter VIEW BACKUP_MGR.RMAN_BACKUP_ARCHIVELOG_DETAILS compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_ARCHIVELOG_SUMMARY compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_CONTROLFL_DETAILS compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_CONTROLFL_SUMMARY compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_DATAFILE_DETAILS compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_DATAFILE_SUMMARY compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_FILES compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_JOB_DETAILS compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_SET_DETAILS compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_SET_SUMMARY compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_SPFILE_DETAILS compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_SPFILE_SUMMARY compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_SUBJOB_DETAILS compile ;
alter VIEW BACKUP_MGR.RMAN_UNUSABLE_BACKUP_DETAILS compile ;
 
14 rows selected.
 
SQL> alter VIEW BACKUP_MGR.RMAN_BACKUP_ARCHIVELOG_DETAILS compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_ARCHIVELOG_SUMMARY compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_CONTROLFL_DETAILS compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_CONTROLFL_SUMMARY compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_DATAFILE_DETAILS compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_DATAFILE_SUMMARY compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_FILES compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_JOB_DETAILS compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_SET_DETAILS compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_SET_SUMMARY compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_SPFILE_DETAILS compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_SPFILE_SUMMARY compile ;
alter VIEW BACKUP_MGR.RMAN_BACKUP_SUBJOB_DETAILS compile ;
alter VIEW BACKUP_MGR.RMAN_UNUSABLE_BACKUP_DETAILS compile ;
 
View altered.
 
SQL>
View altered.
 
SQL>
View altered.
 
SQL>
View altered.
 
SQL>
View altered.
 
SQL>
View altered.
 
SQL>
View altered.
 
SQL>
View altered.
 
SQL>
View altered.
 
SQL>
View altered.
 
SQL>
View altered.
 
SQL>
View altered.
 
SQL>
View altered.
 
SQL>
View altered.


And voila, problem solved! I hope this post comes in handy for you!

References:

MOS note: PL/SQL package SYS.DBMS_BACKUP_RESTORE Version is Not Current (Doc ID 2741760.1)

    

In Oracle How to shrink Securefile LOB tables

As per Oracle support, if the table uses securefile LOB the traditional shrink method ALTER TABLE MODIFY LOB (XMLRECORD) (SHRINK SPACE) will...