Tuesday, 7 February 2023

Schema Refresh in QA/DEV step by step

 Schema Refresh step by step 



Below are the details step for schema refresh . The below steps are very helpful when you want to refresh schemas in QA/DEV and want to keep all the previous grants and privileges after refresh .


1. Take the backup of the schema in target database.



expdp directory=<directory_name> dumpfile=backup_%U.dmp logfile=Backup.log parllel=<n> compression=all

schemas=Schema_name


2. sys_privs.sql :

--------------- 


set echo off

set head off

set pagesize 0

set feedback off

set linesize 200

spool sys_privs.sql

select 'grant '||privilege||' to '||grantee||' ; '  from dba_sys_privs where grantee in ('schema_name');

spool off


3.owner.sql :

-----------


spool owner.sql

select 'grant '||privilege||' on '||OWNER||'.'||table_name||' to  '||grantee||' ; ' from dba_tab_privs WHERE OWNER in ('schema_name');

spool off


4.pre_refresh_role_privs.sql :

----------------------------


set echo off

set head off

set pagesize 0

set feedback off

set linesize 200

spool pre_refresh_role_privs.sql

select 'grant '||granted_role||' to '||grantee||' ; '  from dba_role_privs where grantee in ('schema_name');

spool off


5.Check the object count in the database under that schema

 SELECT object_type,COUNT(*) FROM DBA_OBJECTS WHERE OWNER in ('schema_name') group by object_type ;


6. check the table count

SELECT COUNT(*) FROM DBA_tables WHERE OWNER in ('schema_name');


7.drop all the object under that schema

select 'drop '||object_type||' '||owner||'."'||object_name||'";' from dba_objects where owner in ('schema_names');


8.drop all the tables under that schema

select 'drop table  '||owner||'.'||table_name||' cascade constraints;' from dba_tables where owner in('schema_names');


9.purge the recyclebin

select 'purge table '||owner||'."'||object_name||'";' FROM dba_RECYCLEBIN where owner='schema_name' ;


10.now import data into target database from source dumpfile.

 impdp dumpfile=<dumpfile_name> logfile=import.log directory=<directory_name> schemas=schema_name parallel=<n>


11.check the count of objects after refresh for each schema

SELECT COUNT(*) FROM DBA_OBJECTS WHERE OWNER in ('schema_name');


12.check the table count

SELECT COUNT(*) FROM DBA_tables WHERE OWNER='schema_name';


13.run the spool file

@sys_privs.sql


14. run the spool file

@owner.sql


15.run the spool file

pre_refresh_role_privs.sql

Friday, 18 November 2022

How to delete MGMTDB


Ref : 

  • How to Move/Recreate GI Management Repository (GIMR / MGMTDB) to Different Shared Storage  (Doc ID 1589394.1)
  • 12.2: How to Create GI Management Repository (Doc ID 2246123.1)
    MDBUtil: GI Management Repository configuration tool (Doc ID 2065175.1)


 MGMTDB:

. oraenv

+ASM1

as a root user for grid

crsctl stop res ora.crf -init  //node 1

crsctl stop res ora.crf -init  //node2

perfom in both the node:

crsctl modify res ora.crf -attr ENABLED=0 -init

crsctl modify res ora.crf -attr ENABLED=0 -init


srvctl status mgmtdb


as oracle user perform the below

$ORACLE_HOME/bin/dbca -silent -deleteDatabase -sourceDB -MGMTDB

$ORACLE_HOME/bin/dbca -silent -deleteDatabase -sourceDB -MGMTDB


SUCCESSFULLY DELETED MGMTDB


++++++++++++++++++++++++++++++++++++++++++++++++++++


TO  recreate the MGMTDB in Oracle Database (12.2) required to use a perl script mdbutil.pl 


REF : MDBUtil: GI Management Repository configuration tool (Doc ID 2065175.1)



./mdbutil.pl -h


./mdbutil.pl --addmdb --target=+DATA02


AS A ROOT USER FROM GRID HOME


crsctl modify res ora.crf -attr ENABLED=1 -init


crsctl start res ora.crf -init


REPEAT ON NODE 2


Prerequisite Check “CheckActiveFilesAndExecutables” Failed --19c -issue

 issues:



Patch: /u01/patch/33182768/33192793

Log: /u01/app/19c/cfgtoollogs/opatchauto/core/opatch/opatch2022-11-18_12-54-47PM_1.log

Reason: Failed during Patching: oracle.opatch.opatchsdk.OPatchException: Prerequisite check "CheckActiveFilesAndExecutables" failed.


Patch: /u01/patch/33182768/33208107

Log: /u01/app/19c/cfgtoollogs/opatchauto/core/opatch/opatch2022-11-18_12-54-47PM_1.log

Reason: Failed during Patching: oracle.opatch.opatchsdk.OPatchException: Prerequisite check "CheckActiveFilesAndExecutables" failed.


Patch: /u01/patch/33182768/33208123

Log: /u01/app/19c/cfgtoollogs/opatchauto/core/opatch/opatch2022-11-18_12-54-47PM_1.log

Reason: Failed during Patching: oracle.opatch.opatchsdk.OPatchException: Prerequisite check "CheckActiveFilesAndExecutables" failed.


Patch: /u01/patch/33182768/33239955

Log: /u01/app/19c/cfgtoollogs/opatchauto/core/opatch/opatch2022-11-18_12-54-47PM_1.log

Reason: Failed during Patching: oracle.opatch.opatchsdk.OPatchException: Prerequisite check "CheckActiveFilesAndExecutables" failed.


solution :


/sbin/fuser /u01/app/19c/lib/libclntsh.so.19.1

       

 /u01/app/19c/lib/libclntsh.so.19.1 29785M


ps -ef |grep 29785


kill -9 29785                             

/sbin/fuser /u01/app/19c/lib/libasmclntsh19.so

/u01/app/19c/lib/libasmclntsh19.so  98766M

kill -9 98766

After fixing the cause of failure Run opatchauto resume      



Thursday, 3 November 2022

How to create restore points for PDB and perform flashback at PDB level and when flashback is off

select * from database_properties where property_name='LOCAL_UNDO_ENABLED';

PROPERTY_NAME PROPERTY_VALUE

-------------------- ---------------

LOCAL_UNDO_ENABLED TRUE 



SQL> alter session set container=CDB$ROOT;

SQL> create restore point test2 for pluggable database hdprd;

SQL> create restore point test3 for pluggable database hdprd guarantee flashback database;


SQL> select NAME,TIME,SCN,PDB_RESTORE_POINT,GUARANTEE_FLASHBACK_DATABASE from V$RESTORE_POINT;

NAME                                     TIME                                            SCN PDB GUA

---------------------------------------- ---------------------------------------- ---------- --- ---

TEST3                                    03-NOV-22 02.10.11.000000000 PM             4706851 YES YES

TEST2                                    03-NOV-22 01.42.15.000000000 PM             4699251 YES NO


RMAN> list restore point all;


using target database control file instead of recovery catalog

SCN              RSP Time  Type       Time      Name

---------------- --------- ---------- --------- ----

4699251                               03-NOV-22 TEST2

4706851                    GUARANTEED 03-NOV-22 TEST3

if it using local undo

SQL> alter pluggable database hdprd close;

SQL> flashback pluggable database hdprd to restore point TEST2;

SQL> alter pluggable database test2 open resetlogs;


if it shared undo and restore point created when pdb was open;

RMAN> alter pluggable database hdprd close;

RMAN> flashback pluggable database hdprd to restore point TEST2 auxiliary destination '/U01/app/oracle/';

RMAN> alter pluggable database HDPRD open resetlogs;


SQL> alter pluggable database hdprd close;

SQL> flashback pluggable database hdprd to clean restore point TEST1;

SQL> alter pluggable database hdprd open resetlogs;


if flashback is off then we can restore only with guarantee flashback:

SQL> alter pluggable database hdprd close immediate instances=all;

RMAN> flashback pluggable database hdprd to restore point TEST3 auxiliary destination '+RECO_01';

RMAN> alter pluggable database hdprd open resetlogs;

once it is up ,drop the old restore point and create a new restore point then start the services




 







Wednesday, 3 August 2022

OEM alert 12c and 13c

Links for OEM alerts  


EM 12c, EM 13c: How to Configure a Incident Rule to Send a Notification When a Target is marked as UP / Down? ( Doc ID 1936555.1 )

EM 12c, EM 13c : Steps to Use Incident Rule Simulator for Events in Enterprise Manager Cloud Control ( Doc ID 2083126.1 )

EM 12c, EM 13c: How to Configure a Incident Rule to Send a Notification for a Tablespace Space Used (%) Metric Alert? ( Doc ID 1936559.1 )

EM 12c, EM 13c : Steps for Subscribing or Unsubscribing to Email or Page Notifications in the Incident Management Rule Set in Enterprise Manager Cloud Control ( Doc ID 1389460.1 )

EM 12c, EM 13c: How to Configure Incident Rules to Send Notifications for Job Executions (Status Changes) in Enterprise Manager Cloud Control ( Doc ID 1386816.1 )



For incident rule:

https://docs.oracle.com/en/enterprise-manager/cloud-control/enterprise-manager-cloud-control/13.4/emadm/using-incident-management.html#GUID-2689210F-C5B6-475B-86F4-7DA667095CD1

Setting Up Rule Sets

For monitoring template:

https://docs.oracle.com/en/enterprise-manager/cloud-control/enterprise-manager-cloud-control/13.4/emadm/using-monitoring-templates.html#GUID-647036A5-DF3B-4FFD-9F5C-A43A247A4EFA



monitoring rule 


- https://www.oracle.com/a/otn/docs/enterprise-manager/wp_enterprisemanager13c_monitoringstrategies.pdf

Sunday, 19 December 2021

clone non-cdb to another container pdb in 19c

User request to clone for specific pdb from non cdb prod database 

source :SELECT name,network_name,pdb FROM   v$active_services ORDER BY 1;

target : SELECT name,network_name,pdb FROM   v$active_services ORDER BY 1;

SOURCE :

   srvctl status database -d PROD

    srvctl status service database -d PROD

Target :

srvctl status service database -d xbduat -s xcuatsrv

srvctl config service -d xdbuat -s xcuatsrv

Target :

SRVCTL status service -d xdbuat

srvctl stop service -d xdbuat -s xcuatsrv

srvctl remove service -d xdbuat -s xcuatsrv

alter pluggable database xdbuat close immediate instances=all;

drop pluggable database xdbuat including datafiles;


Source:

create user ram identified by *****;

grant create session,create pluggable database to ram;

Target :

drop database link cdb_dblink;

create database link cdb_dblink connect to ram identified by ****** using '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = prod-vip)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = PROD)))'

select * from dual@cbd_dblink;

create pluggable database xdbuat from NON$CDB@cdb_dblink standbys=none;

----on standby side:

col name format a20

select name, recovery_status from v$pdbs;

select name,open_mode from v$pdbs;

ALTER SESSION SET CONTAINER=xdbuat;

@?/rdbms/admin/noncdb_to_pdb.sql

ALTER PLUGGABLE DATABASE xdbuat OPEN instances=all;

col cause for a15

col name for a15

col message for a35 word_wrapped

set line 200

set head off

select name,cause,type,message,status from PDB_PLUG_IN_VIOLATIONS where name='xdbuat';

alter pluggable database xdbuat open;

alter session set container=xdbuat;

select count(*) from dba_objects where status='INVALID'

@?/rdbms/admin/utlrp.sql

shut immediate    // inside the pdb

startup     //inside the pdb

select network_name from dba_services;

remove the service if not required.

BEGIN DBMS_SERVICE.STOP_SERVICE (SERVICE_NAME => 'cdsrv'); END;

/

BEGIN DBMS_SERVICE.DELETE_SERVICE (SERVICE_NAME => 'cdsrv'); END;

/

[oracle@ed ~]$ srvctl status service -d xdbuat -s xdbuatsrv


srvctl add service -d xdbuat  -service cdbsrv -pdb xdbuat -preferred drod3,drod4

srvctl start service -d xdbuat  -service cdbsrv 

srvctl status service -d xdbuat  -service cdbtsrv 


_____________happy learning_____________

Featured post

Restircted session due to sync filed with ora-65177

Application is unable to connect the database due to restricted session. sql> show pdbs; SQL> show con_name CON_NAME -----------------...