Thursday, 20 June 2019

RMAN Backup Shell Script for Oracle

Option 1

vi rmanbackup.sh

#!/bin/bash
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
BACKUP_LOG_PATH=/home/oracle/myproject
export ORACLE_BASE
export ORACLE_HOME
export ORACLE_SID=ORCL
export BACKUP_LOG_PATH
LOG_FILE=${BACKUP_LOG_PATH}/backup_db.log
$ORACLE_HOME/bin/rman msglog=${LOG_FILE} << EOF
connect target /
run {
allocate channel t1 type disk;
allocate channel t2 type disk;
allocate channel t3 type disk;
backup database format '/u02/oracle/backup/ORCL/database_%d_%u_%s';
release channel t1;
release channel t2;
release channel t3;
sql 'alter system archive log current';
allocate channel a1 type disk;
allocate channel a2 type disk;
allocate channel a3 type disk;
backup archivelog all format '/u02/oracle/backup/ORCL/arch_%d_%u_%s';
release channel a1;
release channel a2;
release channel a3;
allocate channel c1 type disk;
backup current controlfile for standby format '/u02/oracle/backup/ORCL/Control_%d_%u_%s';
release channel c1;
}
exit;
EOF

Wednesday, 19 June 2019

How to check last modified table in Oracle 10g and Above

As a DBA, application team sometimes might ask you to provide details of last modified table in oracle. The table modification can be insert, update or delete. Below queries get details of last or latest modified table in oracle database. Run the queries depending upon the database version.
 
SQL> conn
Enter user-name: scott
Enter password:
Connected.

SQL> create table emp_new as select * from emp where 1=1;

Table created.

SQL> insert into emp_new values (2790,'alam','SMITH',7698,sysdate,5600,340,30);

1 row created.

SQL> commit;

Commit complete.


SQL> conn
Enter user-name: / as sysdba
Connected.


SQL>exec DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO;
 

PL/SQL procedure successfully completed.

SQL>


set linesize 500;
select TABLE_OWNER, TABLE_NAME, INSERTS, UPDATES, DELETES,TRUNCATED,
to_char(TIMESTAMP,'YYYY-MON-DD HH24:MI:SS')
from all_tab_modifications
where table_owner='SCOTT' and
EXTRACT(YEAR FROM TO_DATE(TIMESTAMP, 'DD-MON-RR')) > 2010
order by 6;SQL> SQL> SQL> SQL>   2    3    4    5    6

TABLE_OWNER                    TABLE_NAME                        INSERTS    UPDATES    DELETES TRU TO_CHAR(TIMESTAMP,'Y
------------------------------ ------------------------------ ---------- ---------- ---------- --- --------------------
SCOTT                          EMP_NEW                                 1          0          0 NO  2019-JUN-20 11:55:02

SQL>

Rename Oracle database using NID

  SQL> set pages 999 lines 999; col instance_name for a10; col host_name for a20; col startup_time for a30; set colsep | set underline = ...