Wednesday, December 25, 2019

Resize Redo log files

Oracle Database did not allow to resize redo log files since we need to drop and re-create to overcome the situation.
Following points need to be considered when we drop the redo log files
  1. Can not drop redo log files if it's in Current or Active status
  2. Database requires at least two redo log groups regardless number of members
  3. OS files are wont delete when we drop redo log files. So delete from OS to create redo log files with same name
  
   Steps

1. Check the redo log status
SQL> select group#,bytes,archived,status,members from v$log;

    GROUP#      BYTES ARC STATUS              MEMBERS
---------- ---------- --- ---------------- ----------
         1  209715200 YES INACTIVE                  2
         2  209715200 YES INACTIVE                  2
         3  209715200 NO  CURRENT                   2
In this case we are try to resize group#3, but we can not drop as the status is CURRENT


2. Switch CURRENT redo log group
SQL> alter system switch logfile;
SQL> select group#,bytes,archived,status,members from v$log;

    GROUP#      BYTES ARC STATUS              MEMBERS
---------- ---------- --- ---------------- ----------
         1  209715200 NO  CURRENT                   2
         2  209715200 YES INACTIVE                  2
         3  209715200 YES ACTIVE                    2
Need to change status from ACTIVE to INACTIVE for drop redo log file


3. Change the status of redo log group. checkpoint force to write all changes from the database buffers to data files.
SQL> alter system checkpoint global;
SQL>  select group#,bytes,archived,status,members from v$log;

    GROUP#      BYTES ARC STATUS              MEMBERS
---------- ---------- --- ---------------- ----------
         1  209715200 NO  CURRENT                   2
         2  209715200 YES INACTIVE                  2
         3  209715200 YES INACTIVE                  2

4. Check the members of group and drop the redo log group
SQL> select member from v$logfile where group#=3;
MEMBER
--------------------------------
C:\ORADATA\DEVCDB\REDO030.LOG
C:\ORADATA\DEVCDB\REDO031.LOG 
SQL> alter database drop logfile group 3;

5. Delete specific redo log files from Operating system

6. Create the redo log files with changes

For Multiple File
SQL> alter database add logfile group 3 ('C:\ORADATA\DEVCDB\REDO030.LOG','C:\ORADATA\DEVCDB\REDO031.LOG') size 500M;
For Single File
SQL> alter database add logfile group 3 'C:\ORADATA\DEVCDB\REDO031.LOG' size 500M;
7. Check whether added redo log files are available
SQL> select member from v$logfile where group#=3;
MEMBER
--------------------------------
C:\ORADATA\DEVCDB\REDO030.LOG
C:\ORADATA\DEVCDB\REDO031.LOG 
SQL>  select group#,bytes,archived,status,members from v$log;

    GROUP#      BYTES ARC STATUS              MEMBERS
---------- ---------- --- ---------------- ----------
         1  209715200 NO  CURRENT                   2
         2  209715200 YES INACTIVE                  2
         3  209715200 YES UNUSED                  2

Tuesday, July 23, 2019

Migrate database across platform-12c (Different Endian)

We can use either 'TO PLATFORM' or 'FOR TRANSPORT' clause during the backup and restoration.

TO PLATFORM - Perform  conversion on the source database.

FOR TRANSPORT - Performs conversion on the target database.


1. Find the Platform details of both source and target database

   Source DB
SQL> select name,platform_id,platform_name from v$database;

NAME PLATFORM_ID PLATFORM_NAME
--------- ----------- ------------------------------
TESTCDB 12 Microsoft Windows x86 64-bit
   Target DB
SQL> select name,platform_id,platform_name from v$database;

NAME PLATFORM_ID PLATFORM_NAME
--------- ----------- ------------------------------
UATCDB 2 Solaris[tm] OE (64-bit)

2. Make sure both source and target databases are in the Different endian format
SQL> select PLATFORM_ID,PLATFORM_NAME,ENDIAN_FORMAT from v$transportable_platform order by platform_id;

PLATFORM_ID PLATFORM_NAME ENDIAN_FORMAT
----------- ------------- --------------
1 Solaris[tm] OE (32-bit) Big 
2 Solaris[tm] OE (64-bit) Big 
3 HP-UX (64-bit) Big 
4 HP-UX IA (64-bit) Big 
5 HP Tru64 UNIX Little 
6 AIX-Based Systems (64-bit) Big 
7 Microsoft Windows IA (32-bit) Little 
8 Microsoft Windows IA (64-bit) Little 
9 IBM zSeries Based Linux Big 
10 Linux IA (32-bit) Little 
11 Linux IA (64-bit) Little 
12 Microsoft Windows x86 64-bit Little 
13 Linux x86 64-bit Little 
15 HP Open VMS Little 
16 Apple Mac OS Big 
17 Solaris Operating System (x86) Little 
18 IBM Power Based Linux Big 
19 HP IA Open VMS Little 
20 Solaris Operating System (x86-64) Little 
21 Apple Mac OS (x86-64) Little 

20 rows selected.

3. Connect to Source database(Windows) and make the tablespace read only which need to transportable
RMAN target sys/manager@TESTPDB
RMAN> Alter tablespace USERS read only;

4. Backup tablespace. Make sure Database directory is available on given path

RMAN> BACKUP 
TO PLATFORM 'Solaris[tm] OE (64-bit)' 
FORMAT 'C:\Build\Backups\to_solaris\new\users.bkp' 
DATAPUMP FORMAT 'C:\Build\Backups\to_solaris\new\users_dmp.bkp'
TABLESPACE USERS;

5. Copy both backup and datapump files to target server

6. connect to target DB (Solaris) and drop specific Tablespace which need to restore
sqlplus sys/manager@UATPDB as sysdba
SQL> DROP TABLESPACE USERS INCLUDING CONTENTS AND DATAFILES;

7. Restore Tablespace
RMAN target sys/manager@UATPDB
RMAN> RESTORE
FOREIGN TABLESPACE USERS
format '/u02/oradata/UAT10CDB/UATPDB/%U'
FROM BACKUPSET '/u01/scripts/to_solaris/users.BKP'
DUMP FILE FROM BACKUPSET '/u01/scripts/to_solaris/users_dmp.BKP';

8. Check the tablespace status
sqlplus sys/manager@UATPDB as sysdba
SQL> select tablespace_name,status from dba_tablespaces where tablespace_name='USERS';
TABLESPACE_NAME STATUS
--------------- -------
USERS READ ONLY

9. Make the tablespace online
SQL> alter tablespace USERS read write;

Solution for 'ORA-12919: Can not drop the default permanent tablespace' while drop the USERS tablespace

1. Add the USERS temporary tablespace and make it dafault permanent
sqlplus sys/manager@UATPDB as sysdba
SQL> CREATE TABLESPACE USERS_TEMP DATAFILE '/u02/oradata/UAT10CDB/UATPDB/users_temp_01.dbf' size 100M;
SQL> alter database default tablespace USERS_TEMP;

2. Make sure Dafault permanent Tablespace changed to newly created tablespace
sqlplus sys/manager@UATPDB as sysdba
SQL> SELECT PROPERTY_VALUE
FROM DATABASE_PROPERTIES
WHERE PROPERTY_NAME = 'DEFAULT_PERMANENT_TABLESPACE';

PROPERTY_VALUE
-------------------------------------
USERS_TEMP

3. Then drop the USERS tablespace
sqlplus sys/manager@UATPDB as sysdba
SQL> DROP TABLESPACE USERS INCLUDING CONTENTS AND DATAFILES;

Monday, June 17, 2019

Rename Pluggable Database

1. Find the Connected Container
SQL> sho con_name;

CON_NAME
----------------------
CDB$ROOT

2. Find the List of Pluggable Databases
SQL> sho pdbs;

 CON_ID      CON_NAME        OPEN MODE  RESTRICTED
-------     ---------        ---------  ----------
   2         PDB$SEED        READ ONLY   NO
   3 UATPDB          READ WRITE NO

3. Connect to Specific Pluggable DB which need to rename
SQL>  alter session set container=UATPDB;

Session altered. 

4. Shutdown the pluggable Database
SQL> alter pluggable database UATPDB close;

Pluggable database altered.

5. Startup in Restricted Mode
SQL> alter pluggable database UATPDB open restricted;

Pluggable database altered.

6. Rename the pluggable database
SQL> alter pluggable database UATPDB rename global_name to MIGPDB;

Pluggable database altered.

7. Shutdown and start the pluggable database
SQL> shutdown immediate;

Pluggable Database closed.


SQL> startup;

Pluggable Database opened.

8. Check the Pluggable Database name
SQL> sho con_name;

CON_NAME
----------------------------
MIGPDB

9. The directory does not get renamed according to the new pluggable Database name. Have to create appropriate directory and move the datafile. From 12c onward we can move the datafile online
SQL> alter database move datafile '/u02/oradata/MIG10CDB/UATPDB/system01.dbf' to '/u02/oradata/MIG10CDB/MIGPDB/system01.dbf';

Database altered.