Oracle Database Physical standby Starting and Shutting down

Starting Up a Physical Standby Database
========================================

1.Start and mount the physical standby database:
————————————————-

SQL> STARTUP MOUNT;

2.Start Redo Apply or real-time apply:
————————————–

To start Redo Apply, issue the following statement:
—————————————————

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

To start real-time apply, issue the following statement:
——————————————————–

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE;

Note: On the primary database, query the RECOVERY_MODE column in the V$ARCHIVE_DEST_STATUS view,
which displays the standby database’s operation as MANAGED_RECOVERY for Redo Apply
and MANAGED REAL TIME APPLY for real-time apply.

Shutting Down a Physical Standby Database
==========================================

1.Issue the following query to find out if the standby database is performing Redo Apply or real-time apply.
If the MRP0 or MRP process exists, then the standby database is applying redo.

SQL> SELECT PROCESS, STATUS FROM V$MANAGED_STANDBY;

2.If Redo Apply is running, cancel it as shown in the following example:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

3.Shut down the standby database.

SQL> SHUTDOWN IMMEDIATE;

ORA-09817 IBM AIX RISC System/6000 Error: 89

ORA-09817 IBM AIX RISC System/6000 Error: 89

Oracle 11.2.0.2
AIX 5.3

Related Errors:-

Mon Nov 05 18:33:51 2012
ARC3 started with pid=30, OS id=954622
ARC1: Becoming the ‘no FAL’ ARCH
ARC1: Becoming the ‘no SRL’ ARCH
ARC2: Becoming the heartbeat ARCH
Errors in file /clmst01/UAT/oracode/app/oracle/diag/rdbms/clmst/clmst/trace/clmst_ora_2514960.trc (incident=17053):
ORA-00600: internal error code, arguments: [kccugg_end], [], [], [], [], [], [], [], [], [], [], []

Errors in file /clmst01/UAT/oracode/app/oracle/diag/rdbms/clmst/clmst/trace/clmst_m000_2105586.trc:
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: ‘/clmst02/UAT/oradata/redo/redo03A.log’
ORA-27037: unable to obtain file status
IBM AIX RISC System/6000 Error: 2: No such file or directory

CREATE CONTROLFILE REUSE DATABASE “CLMST” RESETLOGS NOARCHIVELOG
*
ERROR at line 1:
ORA-01503: CREATE CONTROLFILE failed
ORA-00200: control file could not be created
ORA-00202: control file: ‘/clmst02/UAT/oradata/control/control01.ctl’
ORA-27044: unable to write the header block of file
IBM AIX RISC System/6000 Error: 89: Invalid file system control data detected
Additional information: 3
Additional information: -1
Additional information: 1

Cause:-
Your /clmst02/ mount point might be corrupted.

Check:-
fsck /clmst02
The current volume is: /dev/fslv00
File system is currently mounted.
Primary superblock is valid.
fsck: Performing read-only processing does not produce dependable results.
*** Phase 1 – Initial inode scan
*** Phase 2 – Process remaining directories
*** Phase 3 – Process remaining files
*** Phase 4 – Check inode allocation map
File system inode map is corrupt (NOT FIXED)
fsck: 0507-278 Cannot continue.
File system is currently mounted.
fsck: Performing read-only processing does not produce dependable results.

Fix:-
Either you can change the file location to another mount points or shutdown the database and run the fsck on /clmst02 mount point to fix the corrupted one & start the database.

Fix:-
Recreate the affected Redolog files

alter database add logfile group 3 (
‘/clmst02/UAT/oradata/redo/redo03A.log’,
‘/clmst03/UAT/oradata2/redo/redo03B.log’,
‘/clmst04/UAT/oradata3/redo/redo03C.log’) size 50m reuse;

ORA-1652

The quick fix for temp tablespace issue (ORA-1652) which is to add temporary datafile and then find root cause of temp tablespace issue.

Extent – An extent is a logical unit of database storage space allocation made up of a number of contiguous data blocks.One or more extents make up segment.
Segment – A segment is a set of extents that contains all the data for a specific logical storage structure within a tablespace.
Temporary Tablespace – contains transient data that persists only for the duration of the session.

Quick Fix for ORA-1652
=======================

1. Identify temporary datafile details :
SQL> select file_name , TABLESPACE_NAME from DBA_TEMP_FILES;
—–
/u01/oradata/VIS11i/temp01.dbf TEMP

2. Check if there is any space available in temporary tablespace (segment)

SQL> SELECT A.tablespace_name tablespace, D.mb_total,
SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_used,
D.mb_total – SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_free
FROM v$sort_segment A,
(
SELECT B.name, C.block_size, SUM (C.bytes) / 1024 / 1024 mb_total
FROM v$tablespace B, v$tempfile C
WHERE B.ts#= C.ts#
GROUP BY B.name, C.block_size
) D
WHERE A.tablespace_name = D.name
GROUP by A.tablespace_name, D.mb_total;

—-
output like

TABLESPACE MB_TOTAL MB_USED MB_FREE
——————————- ———- ———- ———-
TEMP 2548 2536 12

(in above case out of 2 GB only 12 MB is free)

3. Temporary fix

a) Resize temporary file as
SQL> ALTER DATABASE TEMPFILE ‘/u01/oradata/VIS11i/temp01.dbf’ RESIZE 3072M;

or

b) Add temp datafile to temporary tablespace as

SQL> ALTER TABLESPACE TEMP ADD TEMPFILE ‘/u01/oradata/VIS11i/temp02.dbf’
SIZE 1024M REUSE AUTOEXTEND ON NEXT 50M MAXSIZE 1024M;

.

Root Cause Analysis
===================

1. Identify temp segment usages per session


– Temp segment usage per session.

SQL> SELECT S.sid || ‘,’ || S.serial# sid_serial, S.username, S.osuser, P.spid, S.module,
P.program, SUM (T.blocks) * TBS.block_size / 1024 / 1024 mb_used, T.tablespace,
COUNT(*) statements
FROM v$sort_usage T, v$session S, dba_tablespaces TBS, v$process P
WHERE T.session_addr = S.saddr
AND S.paddr = P.addr
AND T.tablespace = TBS.tablespace_name
GROUP BY S.sid, S.serial#, S.username, S.osuser, P.spid, S.module,
P.program, TBS.block_size, T.tablespace
ORDER BY mb_used;

2. Identify temp segment usages per statement

– Temp segment usage per statement.

SQL> SELECT S.sid || ‘,’ || S.serial# sid_serial, S.username, Q.hash_value, Q.sql_text,
T.blocks * TBS.block_size / 1024 / 1024 mb_used, T.tablespace
FROM v$sort_usage T, v$session S, v$sqlarea Q, dba_tablespaces TBS
WHERE T.session_addr = S.saddr
AND T.sqladdr = Q.address
AND T.tablespace = TBS.tablespace_name
ORDER BY mb_used;
Depending on outcome of temp segment usage per session and per statement focus on problematic session/statement.

.
References/Related

•793380.1 ORA-1652 Error Troubleshooting
•258941.1 RAC databases and ORA-1652: Unable To Extend Temp Segment By %s In Tablespace TEMP

=============================Real workaround========================

SQL> SELECT tablespace_name,SUM(bytes_used/1024/1024),SUM(bytes_free/1024/1024) FROM v$temp_space_header GROUP BY tablespace_name;

Tablespace SUM(BYTES_USED/1024/1024) SUM(BYTES_FREE/1024/1024)
——————– ————————- ————————-
GX_TEMP 84 2916
NAS30_TMP 196 804
PROSOD_TMP01 10592 37408
TEMP 5000 0
TIVOLI_TEMP 250 0

SQL> select bytes/1024/1024,FILE_NAME from DBA_TEMP_FILES where TABLESPACE_NAME=’TEMP’;

BYTES/1024/1024
—————
FILE_NAME
——————————————————————————————————————————————————
5000
/uat_u03/oradata/odrmu/data/temp_01.dbf

SQL> alter DATABASE TEMPFILE ‘/uat_u03/oradata/odrmu/data/temp_01.dbf’ resize 6000m;

Database altered.

SQL> select bytes/1024/1024,FILE_NAME from DBA_TEMP_FILES where TABLESPACE_NAME=’TEMP’;

BYTES/1024/1024
—————
FILE_NAME
——————————————————————————————————————————————————
6000
/uat_u03/oradata/odrmu/data/temp_01.dbf

SQL> SELECT tablespace_name, SUM (bytes_used/1024/1024),SUM (bytes_free/1024/1024) FROM v$temp_space_header GROUP BY tablespace_name;

Tablespace SUM(BYTES_USED/1024/1024) SUM(BYTES_FREE/1024/1024)
——————– ————————- ————————-
GX_TEMP 84 2916
NAS30_TMP 196 804
PROSOD_TMP01 10592 37408
TEMP 5000 1000
TIVOLI_TEMP 250 0

Oracle Database: ORA-00604 and ORA-20000

***************************************************************************************
* ORA-00604: error occurred at recursive SQL level 1
* ORA-20000: Trigger xdb_installation_trigger does not support object creation of type SNAPSHOT *
***************************************************************************************

Solution:

A trigger named xdb_installation_trigger that prevent you from creating your sequence.
Disable it before the import, you reeanable it after, if you really need it.

What is XDB ?

Oracle XML DB is a feature of the Oracle Database. It provides a high-performance,
native XML storage and retrieval technology. It fully absorbs the W3C XML data model
into the Oracle Database, and provides new standard access methods for navigating
and querying XML. With Oracle XML DB, you get all the advantages of relational
database technology plus the advantages of XML.

In Oracle Database 11g Release 2, new capabilities, such as XMLIndex structured
component and partitioning, as well as numerous enhancements of Oracle XML DB are
introduced to dramatically improve its performance, scalability,
XML schema management, and XML information lifecycle management.

$ su – orancmst
orancmst’s Password:

$ export ORACLE_SID=ctstrng
$ sqlplus

SQL*Plus: Release 11.2.0.1.0 Production on Wed Jun 27 17:22:29 2012

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

Enter user-name: /as sysdba

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select name,open_mode from v$database;

NAME OPEN_MODE
——— ——————–
CTSTRNG READ WRITE

SQL> select name,open_mode from v$database;

NAME OPEN_MODE
——— ——————–
CTSTRNG READ WRITE

SQL> desc dba_triggers
Name Null? Type
———————————————————————————– ——– ——————————————————–
OWNER VARCHAR2(30)
TRIGGER_NAME VARCHAR2(30)
TRIGGER_TYPE VARCHAR2(16)
TRIGGERING_EVENT VARCHAR2(227)
TABLE_OWNER VARCHAR2(30)
BASE_OBJECT_TYPE VARCHAR2(16)
TABLE_NAME VARCHAR2(30)
COLUMN_NAME VARCHAR2(4000)
REFERENCING_NAMES VARCHAR2(128)
WHEN_CLAUSE VARCHAR2(4000)
STATUS VARCHAR2(8)
DESCRIPTION VARCHAR2(4000)
ACTION_TYPE VARCHAR2(11)
TRIGGER_BODY LONG
CROSSEDITION VARCHAR2(7)
BEFORE_STATEMENT VARCHAR2(3)
BEFORE_ROW VARCHAR2(3)
AFTER_ROW VARCHAR2(3)
AFTER_STATEMENT VARCHAR2(3)
INSTEAD_OF_ROW VARCHAR2(3)
FIRE_ONCE VARCHAR2(3)
APPLY_SERVER_ONLY VARCHAR2(3)

SQL> select OWNER,TRIGGER_NAME,TRIGGER_TYPE,TABLE_NAME from dba_triggers where TRIGGER_NAME=’XDB_INSTALLATION_TRIGGER’;

OWNER TRIGGER_NAME TRIGGER_TYPE TABLE_NAME
—————————— —————————— —————- ——————————
SYS XDB_INSTALLATION_TRIGGER BEFORE EVENT

SQL> desc dba_registry
Name Null? Type
———————————————————————————– ——– ——————————————————–
COMP_ID NOT NULL VARCHAR2(30)
COMP_NAME VARCHAR2(255)
VERSION VARCHAR2(30)
STATUS VARCHAR2(11)
MODIFIED VARCHAR2(20)
NAMESPACE NOT NULL VARCHAR2(30)
CONTROL NOT NULL VARCHAR2(30)
SCHEMA NOT NULL VARCHAR2(30)
PROCEDURE VARCHAR2(61)
STARTUP VARCHAR2(8)
PARENT_ID VARCHAR2(30)
OTHER_SCHEMAS VARCHAR2(4000)

SQL> select COMP_ID,STATUS from dba_registry;

COMP_ID STATUS
—————————— ———–
XDB LOADING
CATALOG VALID
CATPROC VALID
JAVAVM VALID
XML VALID
CATJAVA VALID
APS VALID
XOQ INVALID

8 rows selected.

SQL> alter trigger XDB_INSTALLATION_TRIGGER disable;

Trigger altered.

SQL> select OWNER,TRIGGER_NAME,TRIGGER_TYPE,TABLE_NAME from dba_triggers where TRIGGER_NAME=’XDB_INSTALLATION_TRIGGER’;

OWNER TRIGGER_NAME TRIGGER_TYPE TABLE_NAME
—————————— —————————— —————- ——————————
SYS XDB_INSTALLATION_TRIGGER BEFORE EVENT

SQL> select OWNER,TRIGGER_NAME,TRIGGER_TYPE,TABLE_NAME,STATUS from dba_triggers where TRIGGER_NAME=’XDB_INSTALLATION_TRIGGER’;

OWNER TRIGGER_NAME TRIGGER_TYPE TABLE_NAME STATUS
—————————— —————————— —————- —————————— ——–
SYS XDB_INSTALLATION_TRIGGER BEFORE EVENT DISABLED

Oracle Database – Enableing Trace for a concurrent request

Step 1 :
=======

Get Concurrent Request ID of long running concurrent request from Application(fronted).

Navigation : Application >> System administrator>> concurrent>request>

Step 2 :
========

Find session associated with concurrent request .i.e SID

By using the above Query we can get sid,serial#,spid of the concurrent Request..

SELECT a.request_id, d.sid, d.serial# , c.SPID
FROM apps.fnd_concurrent_requests a,
apps.fnd_concurrent_processes b,
v$process c,
v$session d
WHERE a.controlling_manager = b.concurrent_process_id
AND c.pid = b.oracle_process_id
AND b.session_id=d.audsid
AND a.request_id = &Request_ID
AND a.phase_code = ‘R’;

For Example:
————
Output of above query returned

REQUEST_ID SID SERIAL# SPID
———- — ——- —-
678901 1973 89 1100

Here Conurrent Request id is 678901 & Asoociated Session is 1973.

SPID is the process that Running on DB node Because of This Request..

oracle@acer $ ps -ef|grep -i 1100

oracle1100 1 0 3:30:43 0:03 oracle (LOCAL=NO)

Note : before Using Oradebug make sure that spid shoud exist on DB node..

Step 3 :
========

Enable event 10046 trace with level 12 using oradebug .

Syntax : oradebug setospid SPID

Here SPID is the process id that we are getting from step 2

Coming to My Case

SQL> oradebug setospid 1100

Oracle pid: 79, Unix process pid: 1100, image: oracle@Acer

Step 3.3 :
==========

Enable trace for 10046 event with level 12
SQL> oradebug event 10046 trace name context forever, level 12

Step 3.4 :
==========

Locate Trace file as
SQL>oradebug tracefile_name

/ORADB/acerdb/9.2.0/admin/DELL_ACER/udump/ACER_ora_1100.trc

Wait for 30 Min to get the Trace file to find the Root Cause

Step 4 :
========

Disable trace if u r thinking that trace is enough to find the root cause..

SQL> oradebug event 10046 trace name context off

Step 5 :
========

Convert raw trace To Understandable tracefile By using tkprof/Traceanalyzer

tkprof ‘ /ORADB/acerdb/9.2.0/admin/DELL_ACER/udump/ACER_ora_1100.trc’ ’ /ORADB/acerdb/9.2.0/admin/DELL_ACER/udump/ACER_ora_1100.txt ’ explain=apps/[apps_passwd] prsela.

Step 6 :
========

Check TKPROF out file to find root cause of slow concurrent request.

Oracle – Temporarily disabling the log shipping to standby database

Temporarily disabling the log shipping to standby database

$ sqlplus

SQL*Plus: Release 10.2.0.3.0 – Production on Wed Jul 25 21:07:57 2012

Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

Enter user-name: /as sysdba

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 – 64bit Production
With the Partitioning, OLAP and Data Mining options

SQL> select name,open_mode from v$database;

NAME OPEN_MODE
——— ———-
AIRMAN READ WRITE

SQL> select max(sequence#) from v$log_history;

MAX(SEQUENCE#)
————–
8941

SQL> alter system switch logfile;

System altered.

SQL> select max(sequence#) from v$log_history;

MAX(SEQUENCE#)
————–
8942

SQL> select status, DEST_NAME, DESTINATION from v$archive_dest where status = ‘VALID’;

STATUS
———
DEST_NAME
——————————————————————————–
DESTINATION
——————————————————————————–
VALID
LOG_ARCHIVE_DEST_1
/u01/oradata/airman/archive

VALID
LOG_ARCHIVE_DEST_2
airman_sj

STATUS
———
DEST_NAME
——————————————————————————–
DESTINATION
——————————————————————————–

SQL> show parameter LOG_ARCHIVE_DEST_2

NAME TYPE VALUE
———————————— ———– ——————————
log_archive_dest_2 string SERVICE=airman_sj LGWR ASYNC V
ALID_FOR=(ONLINE_LOGFILE, PRIM
ARY_ROLE) db_unique_name=airma
n_sj

SQL> show parameter log_archive

NAME TYPE VALUE
———————————— ———– ——————————
log_archive_config string DG_CONFIG=(airman_kj,airman_sj
)
log_archive_dest string
log_archive_dest_1 string LOCATION=/u01/oradata/airman/a
rchive VALID_FOR=(ALL_LOGFILES
, ALL_ROLES) db_unique_name=ai
rman_kj
log_archive_dest_10 string
log_archive_dest_2 string SERVICE=airman_sj LGWR ASYNC V
ALID_FOR=(ONLINE_LOGFILE, PRIM
ARY_ROLE) db_unique_name=airma

NAME TYPE VALUE
———————————— ———– ——————————
n_sj
log_archive_dest_3 string
log_archive_dest_4 string
log_archive_dest_5 string
log_archive_dest_6 string
log_archive_dest_7 string
log_archive_dest_8 string
log_archive_dest_9 string
log_archive_dest_state_1 string enable
log_archive_dest_state_10 string enable
log_archive_dest_state_2 string ENABLE
log_archive_dest_state_3 string enable
log_archive_dest_state_4 string enable
log_archive_dest_state_5 string enable
log_archive_dest_state_6 string enable
log_archive_dest_state_7 string enable
log_archive_dest_state_8 string enable
log_archive_dest_state_9 string enable
log_archive_duplex_dest string
log_archive_format string %t_%s_%r.arc
log_archive_local_first boolean TRUE
log_archive_max_processes integer 2
log_archive_min_succeed_dest integer 1
log_archive_start boolean FALSE
log_archive_trace integer 0

SQL> alter system set log_archive_dest_state_2=defer scope=both;

System altered.

SQL> show parameter log_archive_dest_state_2

NAME TYPE VALUE
———————————— ———– ——————————
log_archive_dest_state_2 string DEFER

SQL> select max(sequence#) from v$log_history;

MAX(SEQUENCE#)
————–
8942

SQL> alter system switch logfile;

System altered.

SQL> select max(sequence#) from v$log_history;

MAX(SEQUENCE#)
————–
8943

SQL> alter system switch logfile;

System altered.

SQL> select max(sequence#) from v$log_history;

MAX(SEQUENCE#)
————–
8944

SQL> alter system switch logfile;

System altered.

SQL> select max(sequence#) from v$log_history;

MAX(SEQUENCE#)
————–
8945

Oracle Activating the Standby Database – Switchover Method

Activating the Standby Database – Switchover Method

The main advantage of a graceful switchover is that it avoids the resetlogs operation. By avoiding the resetlogs operation, the source database can resume its role as the standby database almost immediately with no data loss. Another feature to a graceful switchover is that it does not invalidate previous backups.

1. Prerequisites :-

There is no loss of any archive logs that haven’t been (yet) applied to the standby database.

2. Set job_queue_processes value to 0 in both (PRIMARY and STANDBY) (ABCD02 & ABCD03)

SQL>SHOW PARAMETER JOB_QUEUE_PROCESS

NAME TYPE VALUE
———————————— ———– ————-
job_queue_processes integer 10

SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0 scope=both;

3. In PRIMARY database check the database role. (ABCD02 server)

SQL> select NAME,DATABASE_ROLE,GUARD_STATUS,SWITCHOVER_STATUS, SWITCHOVER#,OPEN_MODE,PROTECTION_MODE from v$database;

NAME DATABASE_ROLE GUARD_S SWITCHOVER_STATUS SWITCHOVER# OPEN_MODE PROTECTION_MODE
——— —————- ——- ——————– ———– ———- ——————–
AIRMAN PRIMARY NONE SESSIONS ACTIVE 4106602309 READ WRITE MAXIMUM PERFORMANCE

4. In STANDBY database check the database role. (ABCD03 server)

SQL> select NAME,DATABASE_ROLE,GUARD_STATUS,SWITCHOVER_STATUS, SWITCHOVER#,OPEN_MODE,PROTECTION_MODE from v$database;

NAME DATABASE_ROLE GUARD_S SWITCHOVER_STATUS SWITCHOVER# OPEN_MODE PROTECTION_MODE
——— —————- ——- ——————– ———– ———- ——————–
AIRMAN PHYSICAL STANDBY NONE SESSIONS ACTIVE 4106602309 MOUNTED MAXIMUM PERFORMANCE

5. Shutdown the PRIMARY database. (ABCD02 server)

SQL> shutdown immediate

Database closed.
Database dismounted.
ORACLE instance shut down.

6. Open the PRIMARY database in RESTRICTED mode. (ABCD02 server)

SQL> startup restrict

ORACLE instance started.

Total System Global Area 252777660 bytes
Fixed Size 451772 bytes
Variable Size 218103808 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.

7. Archive the current log on the PRIMARY database. (ABCD02 server)

SQL> alter system archive log current;

System altered.

8. Make sure the primary database and standby database are in sync. On both the primary and standby instances, issue the following. (ABCD02 & ABCD03)

SQL> select thread#, max (sequence#) from v$archived_log where APPLIED=’YES’ group by thread#;

THREAD# MAX(SEQUENCE#)
———- ————–
1 1934

Now, compare the results and make sure the Thread and Sequence # are the same. If the standby instance is ahead by 1 or none, you are in sync.
9. Initiate the switchover on the PRIMARY database. (ABCD02)
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN;
10. Once the step above has completed, log on to the STANDBY database and issues the following command. (ABCD03)
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
11. Immediately return to the FORMER PRIMARY database and issue a shutdown and mount the NEW STANDBY database. (ABCD02 server)
SQL> shutdown immediate
SQL> startup mount;
12. On the NEW PRIMARY/OLD STANDBY, you can now open the database as the PRIMARY database. (ABCD03 server)
SQL> alter database open;
Database opened.

13. Verify the new STANDBY’S status. (ABCD02 server)
SQL> select name, database_role from v$database;
NAME DATABASE_ROLE
——— —————-
PHYSICAL STANDBY
14. Set job_queue_processes value to 10 in both (PRIMARY and STANDBY) (ABCD02 & ABCD03)

SQL>SHOW PARAMETER JOB_QUEUE_PROCESS

NAME TYPE VALUE
———————————— ———– ————-
job_queue_processes integer 0

SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=10 scope=both;
15. Put the NEW STANDBY/FORMER PRIMARY database into managed recovery mode. (ABCD02)
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Database altered.
16. Test the communications for archive by performing a log switch. (ABCD03 server)
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
System altered.
Now check whether these logs are applying in the NEW STANDBY and also check the listener status.
17. On the NEW PRIMARY database instance, take a backup if possible. (ABCD03 server)
Switch back from SZB location (ABCD03) to KJ location orginal primary sever (ABCD02)
Switch back to Orginal Primary Database – Switchover Method
1. Prerequisites :-

There is no loss of any archive logs that haven’t been (yet) applied to the standby database.

2. Set job_queue_processes value to 0 in both (PRIMARY and STANDBY) (ABCD02 & ABCD03)

SQL>SHOW PARAMETER JOB_QUEUE_PROCESS

NAME TYPE VALUE
———————————— ———– ————-
job_queue_processes integer 10

SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0 scope=both;

3. In New PRIMARY database check the database role. (ABCD03 server)

SQL> select NAME,DATABASE_ROLE,GUARD_STATUS,SWITCHOVER_STATUS, SWITCHOVER#,OPEN_MODE,PROTECTION_MODE from v$database;

NAME DATABASE_ROLE GUARD_S SWITCHOVER_STATUS SWITCHOVER# OPEN_MODE PROTECTION_MODE
——— —————- ——- ——————– ———– ———- ——————–
AIRMAN PRIMARY NONE SESSIONS ACTIVE 4106602309 READ WRITE MAXIMUM PERFORMANCE

4. In New STANDBY database check the database role. (ABCD02 server)

SQL> select NAME,DATABASE_ROLE,GUARD_STATUS,SWITCHOVER_STATUS, SWITCHOVER#,OPEN_MODE,PROTECTION_MODE from v$database;

NAME DATABASE_ROLE GUARD_S SWITCHOVER_STATUS SWITCHOVER# OPEN_MODE PROTECTION_MODE
——— —————- ——- ——————– ———– ———- ——————–
AIRMAN PHYSICAL STANDBY NONE SESSIONS ACTIVE 4106602309 MOUNTED MAXIMUM PERFORMANCE

5. Shutdown the New PRIMARY database. (ABCD03 server)

SQL> shutdown immediate

Database closed.
Database dismounted.
ORACLE instance shut down.

6. Open the New PRIMARY database in RESTRICTED mode. (ABCD03 server)

SQL> startup restrict

ORACLE instance started.

Total System Global Area 252777660 bytes
Fixed Size 451772 bytes
Variable Size 218103808 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.

7. Archive the current log on the New PRIMARY database. (ABCD03 server)

SQL> alter system archive log current;

System altered.

8. Make sure the primary database and standby database are in sync. On both the primary and standby instances, issue the following. (ABCD02 & ABCD03)

SQL> select thread#, max (sequence#) from v$archived_log where APPLIED=’YES’ group by thread#;

THREAD# MAX(SEQUENCE#)
———- ————–
1 1934

Now, compare the results and make sure the Thread and Sequence # are the same. If the standby instance is ahead by 1 or none, you are in sync.
9. Initiate the switchover on the New PRIMARY database. (ABCD03)
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN;
10. Once the step above has completed, log on to the New STANDBY database/Orginal Primary and issues the following command. (ABCD02)
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
11. Immediately return to the FORMER PRIMARY database/Orginal STANDBY and issue a shutdown and mount the Orginal STANDBY database. (ABCD03 server)
SQL> shutdown immediate
SQL> startup mount;
12. On the Orginal PRIMARY/OLD STANDBY, you can now open the database as the PRIMARY database. (ABCD02 server)
SQL> alter database open;
Database opened.

13. Verify the orginal STANDBY’S status. (ABCD03 server)
SQL> select name, database_role from v$database;
NAME DATABASE_ROLE
——— —————-
PHYSICAL STANDBY
14. Set job_queue_processes value to 10 in both (PRIMARY and STANDBY) (ABCD02 & ABCD03)

SQL>SHOW PARAMETER JOB_QUEUE_PROCESS

NAME TYPE VALUE
———————————— ———– ————-
job_queue_processes integer 0

SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=10 scope=both;
15. Put the Orginal STANDBY/FORMER PRIMARY database into managed recovery mode. (ABCD03)
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Database altered.
16. Test the communications for archive by performing a log switch. (ABCD02 server)
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
System altered.
Now check whether these logs are applying in the Orginal STANDBY and also check the listener status.
17. On the Orginal PRIMARY database instance, take a backup if possible. (ABCD02 server)

Oracle Database Health Check Script

SPOOL OFF
CLEAR SCREEN
SPOOL /tmp/quickaudit.lst

–SELECT SYSDATE FROM DUAL;
–SHOW USER

PROMPT
PROMPT ———————————————————————–|
PROMPT

SET TERMOUT ON
SET VERIFY OFF
SET FEEDBACK ON

PROMPT
PROMPT Checking database name and archive mode, dbid
PROMPT

column NAME format A9
column LOG_MODE format A12

SELECT NAME,CREATED, LOG_MODE, DBID FROM V$DATABASE;

PROMPT
PROMPT ———————————————————————–|
PROMPT

PROMPT
PROMPT Checking Time since last RMAN backup
PROMPT

select (sysdate-min(t))*24 from
(
select max(b.CHECKPOINT_TIME) t
from v$backup_datafile b, v$tablespace ts, v$datafile f
where INCLUDED_IN_DATABASE_BACKUP=’YES’
and f.file#=b.file#
and f.ts#=ts.ts#
group by f.file#
);

PROMPT
PROMPT ———————————————————————–|
PROMPT

PROMPT
PROMPT Checking Tablespace name and status
PROMPT

column TABLESPACE_NAME format a30
column STATUS format a10
set pagesize 400

SELECT TABLESPACE_NAME, STATUS FROM DBA_TABLESPACES;

PROMPT
PROMPT ————————————————————————|
PROMPT

PROMPT
PROMPT Checking free space in tablespaces
PROMPT

column tablespace_name format a30

SELECT tablespace_name ,sum(bytes)/1024/1024 “MB Free” FROM dba_free_space WHERE
tablespace_name ‘TEMP’ GROUP BY tablespace_name;

PROMPT
PROMPT ————————————————————————|
PROMPT

PROMPT
PROMPT Checking freespace by tablespace
PROMPT

column dummy noprint
column pct_used format 999.9 heading “%|Used”
column name format a16 heading “Tablespace Name”
column bytes format 9,999,999,999,999 heading “Total Bytes”
column used format 99,999,999,999 heading “Used”
column free format 999,999,999,999 heading “Free”
break on report
compute sum of bytes on report
compute sum of free on report
compute sum of used on report

set linesize 132
set termout off
select a.tablespace_name name,
b.tablespace_name dummy,
sum(b.bytes)/count( distinct a.file_id||’.’||a.block_id ) bytes,
sum(b.bytes)/count( distinct a.file_id||’.’||a.block_id ) –
sum(a.bytes)/count( distinct b.file_id ) used,
sum(a.bytes)/count( distinct b.file_id ) free,
100 * ( (sum(b.bytes)/count( distinct a.file_id||’.’||a.block_id )) –
(sum(a.bytes)/count( distinct b.file_id ) )) /
(sum(b.bytes)/count( distinct a.file_id||’.’||a.block_id )) pct_used
from sys.dba_free_space a, sys.dba_data_files b
where a.tablespace_name = b.tablespace_name
group by a.tablespace_name, b.tablespace_name;

PROMPT
PROMPT ————————————————————————|
PROMPT

PROMPT
PROMPT Checking Size and usage in GB of Flash Recovery Area
PROMPT

SELECT
ROUND((A.SPACE_LIMIT / 1024 / 1024 / 1024), 2) AS FLASH_IN_GB,
ROUND((A.SPACE_USED / 1024 / 1024 / 1024), 2) AS FLASH_USED_IN_GB,
ROUND((A.SPACE_RECLAIMABLE / 1024 / 1024 / 1024), 2) AS FLASH_RECLAIMABLE_GB,
SUM(B.PERCENT_SPACE_USED) AS PERCENT_OF_SPACE_USED
FROM
V$RECOVERY_FILE_DEST A,
V$FLASH_RECOVERY_AREA_USAGE B
GROUP BY
SPACE_LIMIT,
SPACE_USED ,
SPACE_RECLAIMABLE ;

PROMPT
PROMPT ————————————————————————|
PROMPT

PROMPT
PROMPT ————————————————————————|
PROMPT

PROMPT
PROMPT Checking free space In Flash Recovery Area
PROMPT

column FILE_TYPE format a20

select * from v$flash_recovery_area_usage;

PROMPT
PROMPT ————————————————————————|
PROMPT

PROMPT
PROMPT ————————————————————————|
PROMPT

PROMPT
PROMPT Checking last sequence in v$archived_log
PROMPT

clear screen
set linesize 100

column STANDBY format a20
column applied format a10

–select max(sequence#), applied from v$archived_log where applied = ‘YES’ group by applied;

SELECT name as STANDBY, SEQUENCE#, applied, completion_time from v$archived_log WHERE DEST_ID = 2 AND NEXT_TIME > SYSDATE -1;

prompt
prompt—————-Last log on Primary————————————–|
prompt

select max(sequence#) from v$archived_log where NEXT_TIME > sysdate -1;

PROMPT
PROMPT ————————————————————————|
PROMPT

PROMPT
PROMPT Checking switchover status
PROMPT

select switchover_status from v$database;

PROMPT
PROMPT ————————————————————————|
PROMPT

PROMPT
PROMPT Checking for 20 Largest items in Database
PROMPT

column SEGMENT_NAME format A50

SELECT * FROM (
SELECT
OWNER, SEGMENT_NAME, BYTES/1024/1024 SIZE_MB
FROM
DBA_SEGMENTS
ORDER BY
BYTES/1024/1024 DESC ) WHERE ROWNUM <= 20;

PROMPT
PROMPT ————————————————————————|
PROMPT

PROMPT
PROMPT Checking for Failed jobs
PROMPT

SELECT
OWNER,
LOG_DATE,
JOB_NAME,
STATUS –,
— REQ_START_DATE,
— ACTUAL_START_DATE,
— RUN_DURATION
FROM
DBA_SCHEDULER_JOB_RUN_DETAILS
WHERE
STATUS ‘SUCCEEDED’
AND
LOG_DATE > SYSDATE -7;

PROMPT
PROMPT ————————————————————————|
PROMPT

PROMPT
PROMPT Checking for invalid objects
PROMPT

column owner format A15
column object_name format A30 heading ‘Object’
column object_id format 999999 heading “Id#”
column object_type format A15
column status format A8

select owner, object_name, object_id, object_type, status
from dba_objects where status != ‘VALID’ and object_type != ‘SYNONYM’;

PROMPT
PROMPT ————————————————————————|

PROMPT
PROMPT How large is the database
PROMPT

col “Database Size” format a20
col “Free space” format a20
col “Used space” format a20
select round(sum(used.bytes) / 1024 / 1024 / 1024 ) || ‘ GB’ “Database Size”
, round(sum(used.bytes) / 1024 / 1024 / 1024 ) –
round(free.p / 1024 / 1024 / 1024) || ‘ GB’ “Used space”
, round(free.p / 1024 / 1024 / 1024) || ‘ GB’ “Free space”
from (select bytes
from v$datafile
union all
select bytes
from v$tempfile
union all
select bytes
from v$log) used
, (select sum(bytes) as p
from dba_free_space) free
group by free.p;

PROMPT
PROMPT ————————————————————————|
PROMPT

PROMPT
PROMPT ————————————————————————|
PROMPT

PROMPT
PROMPT Checking the recycle Bin
PROMPT

SELECT
OWNER, SUM(SPACE) AS TOTAL_BLOCKS
FROM
DBA_RECYCLEBIN GROUP BY OWNER
ORDER BY OWNER;

PROMPT
PROMPT ————————————————————————|
PROMPT

PROMPT
PROMPT Checking database versions
PROMPT

column BANNER format A64
select * from v$version;

PROMPT
PROMPT ————————————————————————|
PROMPT

PROMPT
PROMPT Checking control file(s)
PROMPT

column STATUS format a7
column NAME format a68
column IS_RECOVERY_DEST_FILE format a3
set linesize 132

SELECT * FROM V$CONTROLFILE;

PROMPT
PROMPT ————————————————————————|
PROMPT

PROMPT
PROMPT Checking redo logs and group(s)
PROMPT

column member format a90

SELECT group#, member FROM v$logfile;

SPOOL OFF

exit

Create a Full Database Backup (SQL Server) Using SQL Server Management Studio

Create a Full Database Backup (SQL Server) Using SQL Server Management Studio:
———————————————————————————————————-

Recommendations

As a database increases in size full database backups take more time to finish and require more storage space. Therefore, for a large database, you might want to supplement a full database backup with a series of differential database backups. For more information, see Differential Backups (SQL Server).

You can estimate the size of a full database backup by using the sp_spaceused system stored procedure.

By default, every successful backup operation adds an entry in the SQL Server error log and in the system event log. If back up the log very frequently, these success messages accumulate quickly, resulting in huge error logs that can make finding other messages difficult. In such cases you can suppress these log entries by using trace flag 3226 if none of your scripts depend on those entries. For more information, see Trace Flags (Transact-SQL).

Permissions:

BACKUP DATABASE and BACKUP LOG permissions default to members of the sysadmin fixed server role and the db_owner and db_backupoperator fixed database roles.

To back up a database:

1.After connecting to the appropriate instance of the Microsoft SQL Server Database Engine, in Object Explorer, click the server name to expand the server tree.

2.Expand Databases, and depending on the database, either select a user database or expand System Databases and select a system database.

3.Right-click the database, point to Tasks, and then click Back Up. The Back Up Database dialog box appears.

4.In the Database list box, verify the database name. You can optionally select a different database from the list.

5.You can perform a database backup for any recovery model (FULL, BULK_LOGGED, or SIMPLE).

6.In the Backup type list box, select Full.

7.Note that after creating a full database backup, you can create a differential database backup; for more information, see Create a Differential Database Backup (SQL Server).

8.Optionally, you can select Copy Only Backup to create a copy-only backup. A copy-only backup is a SQL Server backup that is independent of the sequence of conventional SQL Server backups.

Note:
When the Differential option is selected, you cannot create a copy-only backup.

9.For Backup component, click Database.

10.Either accept the default backup set name suggested in the Name text box, or enter a different name for the backup set.

11.Optionally, in the Description text box, enter a description of the backup set.

12.Specify when the backup set will expire and can be overwritten without explicitly skipping verification of the expiration data:
To have the backup set expire after a specific number of days, click After (the default option), and enter the number of days after set creation that the set will expire. This value can be from 0 to 99999 days; a value of 0 days means that the backup set will never expire.

The default value is set in the Default backup media retention (in days) option of the Server Properties dialog box (Database Settings Page). To access this, right-click the server name in Object Explorer and select properties; then select the Database Settings page.

To have the backup set expire on a specific date, click On, and enter the date on which the set will expire.

13.Choose the type of backup destination by clicking Disk or Tape. To select the paths of up to 64 disk or tape drives containing a single media set, click Add. The selected paths are displayed in the Backup to list box.

To remove a backup destination, select it and click Remove. To view the contents of a backup destination, select it and click Contents.

14.To view or select the advanced options, click Options in the Select a page pane.

15.Select an Overwrite Media option, by clicking one of the following:

Back up to the existing media set :
For this option, click either Append to the existing backup set or Overwrite all existing backup sets. For more information, see Media Sets, Media Families, and Backup Sets (SQL Server).

Optionally, select Check media set name and backup set expiration to cause the backup operation to verify the date and time at which the media set and backup set expire.

Optionally, enter a name in the Media set name text box. If no name is specified, a media set with a blank name is created. If you specify a media set name, the media (tape or disk) is checked to see whether the actual name matches the name you enter here.

Back up to a new media set, and erase all existing backup sets

For this option, enter a name in the New media set name text box, and, optionally, describe the media set in the New media set description text box.

16.In the Reliability section, optionally check:

Verify backup when finished.

Perform checksum before writing to media, and, optionally, Continue on checksum error.
17.If you are backing up to a tape drive (as specified in the Destination section of the General page), the Unload the tape after backup option is active. Clicking this option activates the Rewind the tape before unloading option.

18.SQL Server 2008 Enterprise and later supports backup compression. By default, whether a backup is compressed depends on the value of the backup-compression default server configuration option. However, regardless of the current server-level default, you can compress a backup by checking Compress backup, and you can prevent compression by checking Do not compress backup.

Using Transact-SQL to create a full database backup:

1.Execute the BACKUP DATABASE statement to create the full database backup, specifying:

The name of the database to back up.

The backup device where the full database backup is written.

The basic Transact-SQL syntax for a full database backup is:

BACKUP DATABASE database

TO backup_device [ ,…n ]

[ WITH with_options [ ,…o ] ] ;

Examples:

A. Backing up to a disk device
The following example backs up the complete AdventureWorks2012 database to disk, by using FORMAT to create a new media set.

USE AdventureWorks2012;
GO
BACKUP DATABASE AdventureWorks2012
TO DISK = ‘Z:\SQLServerBackups\AdventureWorks2012.Bak’
WITH FORMAT,
MEDIANAME = ‘Z_SQLServerBackups’,
NAME = ‘Full Backup of AdventureWorks2012’;
GO

B. Backing up to a tape device
The following example backs up the complete AdventureWorks2012 database to tape, appending the backup to the previous backups.

USE AdventureWorks2012;
GO
BACKUP DATABASE AdventureWorks2012
TO TAPE = ‘\\.\Tape0’
WITH NOINIT,
NAME = ‘Full Backup of AdventureWorks2012’;
GO

C. Backing up to a logical tape device
The following example creates a logical backup device for a tape drive. The example then backs up the complete AdventureWorks2012 database to that device.

— Create a logical backup device,
— AdventureWorks2012_Bak_Tape, for tape device \\.\tape0.
USE master;
GO
EXEC sp_addumpdevice ‘tape’, ‘AdventureWorks2012_Bak_Tape’, ‘\\.\tape0’;
USE AdventureWorks2012;
GO
BACKUP DATABASE AdventureWorks2012
TO AdventureWorks2012_Bak_Tape
WITH FORMAT,
MEDIANAME = ‘AdventureWorks2012_Bak_Tape’,
MEDIADESCRIPTION = ‘\\.\tape0’,
NAME = ‘Full Backup of AdventureWorks2012’;
GO

Follow these steps to create the job and put your backup statement inside of it:

1.Expand the ‘SQL Server Agent’ tree and right-click on ‘Jobs’. Then choose the top item, ‘New Job…’

2.Now you’ve got the new job dialog box. Filling in the info is pretty easy. You need to give your job a name, and everything else is optional. Here I’m going to fill in the name of the job as ‘Backup user database’.

3.Next click on the ‘Steps’ pane on the left and you’ll be presented with this screen. It’s blank because you haven’t created any steps yet. So go ahead and click on the ‘New’ button at the bottom.

4. This is where the real magic happens. Again, you have to fill in a name so you know what the step is called. Make it something descriptive. There are several step types to choose from, but the default is T-SQL and since we’re running a T-SQL command that’s clearly the one we want to go with. The database defaults to ‘master’ and that’s just fine with us. Here’s what we have so far. You see the only thing we’ve had to do is fill in the step name.

5. The only thing left to do is to copy your backup statement into the query window. Of course it’s always a good idea to make sure your code will parse before you try to run it. Just click the ‘Parse’ button I’ve circled. Here’s what that looks like.

6.Now click OK and it’ll take you back to your new job window and now you’ll see your job step listed. And you can stack as many as you like inside there.

7. To schedule your job, just click on ‘Schedules’ on the left and then choose the schedule that’s right for you. It works similar to the the way it does in Windows so there’s really not much need for me to rehash it here.

8.Once you click OK all the way out until the new job box is closed, your job will be added to the job tree. You may have to right-click on ‘Jobs’ and refresh the display for it to show up.

Now that you’ve created the job to backup your database I’d like to go back to the command again and add one more part. See, when you backup a database to a file it won’t overwrite the file by default. By default it will append to the file, so your backup file will just get bigger and bigger. So what you want to do is add a special flag to the command that tells it to initialize (or overwrite) the file every time. That makes our backup command look like this now:

BACKUP Database Model
To disk = ‘c:\ModelBackup.bak’

With INIT

This is a good thing to keep in mind while you’re creating your job.

MOVING MASTER, MSSQL SYSTEMRESOURSE DB PRIMARY AND LOG FILES FROM ONE DRIVE TO ANOTHER DRIVE IN THE SAME MACHINE IN MSSQL Server 2005

MOVING MASTER, MSSQL SYSTEMRESOURSE DB PRIMARY AND LOG FILES FROM ONE DRIVE TO ANOTHER DRIVE IN THE SAME MACHINE IN MSSQL Server 2005

1.Goto Start > All programs > Microsoft sq l server 2005 > Configuration Tools > sq l server configuration manager.
2.Right Click on MSSQLSERVER service and click ADVANCED Tab.
Check the START PARAMETER and change the master primary and log file from old location to new location with the file name.(refer below command)

-dD:\MSSQLSystemDB\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG;-lD:\MSSQLSystemDB\mastlog.ldf

where -d is primary file path and -l is log file path

3.Stop the MSSQLSERVER Services.
4.Move the Master and Mssqlsystemresource DB Primary and Log file into New Location(As mentioned in the START PARAMETER)
5.Start the MSSQLSERVER SERVICE in Recovery-mode. Type below command in the cmd-Prompt
> NET START MSSQLSERVER /f /T3608

For a named instance, run the following command
> NET START MSSQL$instancename /f /T3608

6.Goto Start > All programs > Microsoft sq l server 2005 > MS server Managent Studio. Connect the Instance. Click on New Query.

7.Alter the Resource DB primary file and log file.Execute the Query.

–SYSTEMRESOURCE DB Primary File
ALTER DATABASE mssqlsystemresource
MODIFY FILE (NAME=data, FILENAME= ‘new_path_of_master\mssqlsystemresource.mdf’);
GO
–SYSTEMRESOURCE DB Log File
ALTER DATABASE mssqlsystemresource
MODIFY FILE (NAME=log, FILENAME= ‘new_path_of_master\mssqlsystemresource.ldf’);
GO

8.Set the MSSQLSYSTEMRESOURCE DB as READ-ONLY mode
alter database mssqlsystemresource set read_only;

9.Stop and Start the service the MSSQLSERVER service
10. Check the Master files.
sp_helpdb master

Note:Master and mssqlsystemresource primary and log files are in the same location.

Moving model,msdb,tempdb(SYSTEM Databases) from one location to another location in the same machine.(1 hour downtime)

1.For reference, Copy the primary,secondary and log files location of model,msdb and tempdb

USE master
Go

SELECT
DB_NAME(database_id) AS “Database Name”
, name AS “Logical File Name”
, physical_name AS “Physical File Location”
, state_desc AS “State”
FROM
sys.master_files
WHERE
database_id IN (DB_ID(N’msdb’), DB_ID(N’model’),DB_ID(N’tempdb’))
ORDER BY
DB_NAME(database_id);
Go

2.Modify the data and log filename for new location of db files by using Alter database. Have to done for each datbases of files.Execute the Query.

USE master
Go

ALTER DATABASE model
MODIFY FILE ( NAME = ‘modeldev’ , FILENAME = ‘D:\MSSQLSystemDB\model.mdf’ );
Go

ALTER DATABASE model
MODIFY FILE ( NAME = ‘modellog’ , FILENAME = ‘D:\MSSQLSystemDB\modellog.ldf’ );
Go

ALTER DATABASE msdb
MODIFY FILE ( NAME = ‘MSDBData’ , FILENAME = ‘D:\MSSQLSystemDB\MSDBData.mdf’ );
Go

ALTER DATABASE msdb
MODIFY FILE ( NAME = ‘MSDBLog’ , FILENAME = ‘D:\MSSQLSystemDB\MSDBLog.ldf’ );
Go

ALTER DATABASE tempdb
MODIFY FILE (NAME = ‘tempdev’, FILENAME = ‘D:\MSSQLSystemDB\tempdb.mdf’);
Go

ALTER DATABASE tempdb
MODIFY FILE (NAME = ‘templog’, FILENAME = ‘D:\MSSQLSystemDB\templog.ldf’);
Go

3.Stop MSSQLSERVER Services.
4.Move the model,msdb and tempdb primary and log files into new location.
5.Start MSSQLSERVER Services.
6.Check the System DB files.