Wednesday 3 June 2020

How to mirror database Privileges of a Oracle database user to another database user?

Script for Mirroring Privileges of a user:

Scenario: A Database schema named "TEST2" is created and business wants to grant the privileges for the user same as already existing Database user "TEST1".

Run the below queries as SYS or any Privileged user to get the DDL commands in Oracle for TEST1 user.

SELECT DBMS_METADATA.GET_GRANTED_DDL('ROLE_GRANT','TEST1') FROM DUAL;

 SELECT DBMS_METADATA.GET_GRANTED_DDL('SYSTEM_GRANT','TEST1') FROM DUAL;

 SELECT DBMS_METADATA.GET_GRANTED_DDL('OBJECT_GRANT','TEST1') FROM DUAL;


 The output will be a sequence of grant commands related to privileges assigned to TEST1 user. Now replace the string TEST1 with new user name "TEST2" and run the commands.

 This will grant all privileges same as TEST1 user to TEST2 user in Oracle Database.

Change Oracle Database to ArchiveLog Mode

Steps to change the database to Archivelog Mode:

1. Login to the database server. Connect to sqlplus as sysdba

$sqlplus / as sysdba

2. Shutdown the database

SQL> shutdown immediate

3. Take a full database Backup (Cold Backup in this case)

4. Startup the database in mount stage

SQL> startup mount

5. Enable Archivelog mode

SQL> alter database archivelog;

6. Open the Database.

SQL> Alter database open;

7. Verify the changes.

SQL> archive log list;

Enable ArchiveLog Mode on Oracle RAC database fails with ORA-00265

On a test RAC environment, while archiving is being enabled, "ALTER DATABASE ARCHIVELOG" command errored with ORA-00265: instance recovery required, cannot set ARCHIVELOG mode

Below are the steps performed to enable Archivelog mode on a 3-node RAC database environment.

test0115:TEST1011 $ srvctl status database -d TEST101
Instance TEST1011 is running on node test0115
Instance TEST1012 is running on node test0116
Instance TEST1013 is running on node test0117
test0115:TEST1011 $
test0115:TEST1011 $ srvctl stop database -d TEST101


test0115:TEST1011 $ srvctl status database -d TEST101
Instance TEST1011 is not running on node test0115
Instance TEST1012 is not running on node test0116
Instance TEST1013 is not running on node test0117
test0115:TEST1011 $


test0115:TEST1011 $ srvctl start database -d TEST101 -o mount
test0115:TEST1011 $  srvctl status database -d TEST101
Instance TEST1011 is running on node test0115
Instance TEST1012 is running on node test0116
Instance TEST1013 is running on node test0117
test0115:TEST1011 $


test0115:TEST1011 $ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Sat May 9 14:13:54 2020

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters and Automatic Storage Management options

SQL> select name,open_mode from gv$database;

NAME      OPEN_MODE
--------- --------------------
TEST101   MOUNTED
TEST101   MOUNTED
TEST101   MOUNTED

SQL>SQL> alter database archivelog;
alter database archivelog
*
ERROR at line 1:
ORA-00265: instance recovery required, cannot set ARCHIVELOG mode

Solution:
=========

1. Shutdown the database cleanly

SQL> shutdown immediate (on 3 RAC nodes)

2. Startup the database in mount stage

SQL> startup mount

3. Enable Archivelog mode

SQL> Alter database archivelog;

Database altered.

4. Open the database

SQL> Alter database open.

5. Verify archielog mode is enabled.

SQL> ARCHIVE LOG LIST;