Wednesday, November 13, 2013

script to do full restore on Netezza database

2013-08-02 12:55:09.428218 PDT Info: NZ-00022: --- program 'restoresvr' (4080) starting on host 'nsdwt03' ... ---
2013-08-02 12:55:09.454282 PDT Info: Restore command: nzrestore -u admin -db XYZ -sourcedb ABC -dir /netback_old/backup/july -backupset 20130721195736 -npshost VIP
2013-08-02 12:55:09.454302 PDT Info: Setting the command line options
2013-08-02 12:55:09.776227 PDT Info: Restoring from base directory '/netback_old/backup/july'
2013-08-02 12:55:09.776362 PDT Info: Starting the restore process
2013-08-02 12:57:24.888546 PDT Info: Reading locations file
2013-08-02 12:57:25.459500 PDT Info: Warning: Invalid backupset, found /Netezza/VIP.petc.com/ABC/20130721195736/1/FULL in locations.txt, expected /Netezza/VIP/ABC/20130721195736/1/FULL.
2013-08-02 12:57:26.871784 PDT Info: Reading schema from /netback_old/backup/july/Netezza/<VIP>/ABC/20130721195736/1/FULL/md
2013-08-02 12:57:26.872418 PDT Info: Opening pipe for schema read ...
2013-08-02 12:57:27.252432 PDT Info: Restoring a 4.0 backup from NPS Release 6.0.2 (P-1) [Build 17433] created on xs system 'nsdwp01'
2013-08-02 12:57:27.252454 PDT Info: Restore of 92 dataslice backupset to 46 dataslice system
2013-08-02 12:57:27.657741 PDT Info: Operation txid and history table record 2773474
2013-08-02 12:57:27.669672 PDT Info: Restoring schema
2013-08-02 12:58:24.897130 PDT Info: Start restoring the data, compressed format.

script to check standby sync status with primary oracle database?

SET PAGESIZE 124
COL DB_NAME FORMAT A8
COL HOSTNAME FORMAT A12
COL LOG_ARCHIVED FORMAT 999999
COL LOG_APPLIED FORMAT 999999
COL LOG_GAP FORMAT 9999
COL APPLIED_TIME FORMAT A12
SELECT DB_NAME, HOSTNAME, LOG_ARCHIVED, LOG_APPLIED,APPLIED_TIME,
LOG_ARCHIVED-LOG_APPLIED LOG_GAP
FROM
(
SELECT NAME DB_NAME
FROM V$DATABASE
),
(
SELECT UPPER(SUBSTR(HOST_NAME,1,(DECODE(INSTR(HOST_NAME,'.'),0,LENGTH(HOST_NAME),
(INSTR(HOST_NAME,'.')-1))))) HOSTNAME
FROM V$INSTANCE
),
(
SELECT MAX(SEQUENCE#) LOG_ARCHIVED
FROM V$ARCHIVED_LOG WHERE DEST_ID=1 AND ARCHIVED='YES'
),
(
SELECT MAX(SEQUENCE#) LOG_APPLIED
FROM V$ARCHIVED_LOG WHERE DEST_ID=2 AND APPLIED='YES'
),
(
SELECT TO_CHAR(MAX(COMPLETION_TIME),'DD-MON/HH24:MI') APPLIED_TIME
FROM V$ARCHIVED_LOG WHERE DEST_ID=2 AND APPLIED='YES'
);

script to identify the corrupted block name in oracle database?

select segment_name,segment_type,owner
from sys.dba_extents
where file_id=180
and (133571) between block_id and block_id + blocks -1;

script to list fragmented tables on oracle database schema?

select owner,table_name,round((blocks*8192),2)/1024/1024 "size (MB)" , round((num_rows*avg_row_len/1024/1024),2) "actual_data (MB)",
round((round((blocks*8192),2)/1024/1024 - round((num_rows*avg_row_len/1024/1024),2)),1) "wasted_space (MB)"
from dba_tables where (round((blocks*8192),2)/1024/1024 > round((num_rows*avg_row_len/1024/1024),2))
and (round((round((blocks*8192),2)/1024/1024 - round((num_rows*avg_row_len/1024/1024),2)),1)) > 100 and owner='ABC'
order by 5 desc;

script to compile all invalid object on oracle database?

select 'alter view man.'||object_name||' compile;' from dba_objects where owner='man' and status='INVALID' and object_type='VIEW';

select 'alter package man.'||object_name||' compile body;' from dba_objects where owner='man' and status='INVALID' and object_type='PACKAGE BODY';
select 'alter function man.'||object_name||' compile ;' from dba_objects where owner='man' and status='INVALID' and object_type='FUNCTION';
select 'alter procedure man.'||object_name||' compile ;' from dba_objects where owner='man' and status='INVALID' and object_type='PROCEDURE';
select 'alter view stage.'||object_name||' compile;' from dba_objects where owner='stage' and status='INVALID' and object_type='VIEW';
select 'alter procedure stage.'||object_name||' compile ;' from dba_objects where owner='stage' and status='INVALID' and object_type='PROCEDURE';

scrip to list top 10 hottest object in oracle database

col owner  format a20 trunc
col object_name format a30
col touches  format 9,999,999
select *
from (
 select count(*)
 , sum(tch) TOUCHES
 , u.name OWNER
 , o.name OBJECT_NAME
 from  x$bh x
 , obj$ o
 , user$ u
 where x.obj = o.obj#
 and o.owner# = u.user#
 group  by u.name, o.name
   order by 2 desc
 )
where rownum < 11;

script to find who is using UNDO tablespace in oracle?

SELECT TO_CHAR(s.sid)||','||TO_CHAR(s.serial#) sid_serial,
           NVL(s.username, 'None') orauser,
           s.program,
           r.name undoseg,
           t.used_ublk * TO_NUMBER(x.value)/1024||'K' "Undo"
      FROM sys.v_$rollname    r,
           sys.v_$session     s,
           sys.v_$transaction t,
           sys.v_$parameter   x
    WHERE s.taddr = t.addr
      AND r.usn   = t.xidusn(+)
      AND x.name  = 'db_block_size';

script to find who is using temp tablespace in oracle?

SELECT b.tablespace,
           ROUND(((b.blocks*p.value)/1024/1024),2)||'M' "SIZE",
           a.sid||','||a.serial# SID_SERIAL,
           a.username,
           a.program
      FROM sys.v_$session a,
           sys.v_$sort_usage b,
           sys.v_$parameter p
     WHERE p.name  = 'db_block_size'
      AND a.saddr = b.session_addr
   ORDER BY b.tablespace, b.blocks;

script to find lon running queries on oracle database?

select sid,
message || '(' || time_remaining || ')' "Long Ops"
from v$session_longops
where time_remaining > 600;

important views in oracle database

Object related
dba_tables,
dba_views
dba_packages
dba_synonyms
dba_functions
dba_sequences
dba_triggers

roles related
dba_roles
dba_role_privs
dba_sys_privs
dba_tab_privs
role_role_privs

System related
v$backup
V$controlfile
V$log
V$archived_log
v$archived_gap
v$recover_file
v$session
v$session_longops