Oracle DBA Faq's
Oracle DBA Faq's
where extent maps of the segment are stored. Where can one find the high water mark for a table?
There is no single system table, which contains the high water mark (HWM) for a table. A tables HWM can be calculated using the results from the following SQL statements: SELECT BLOCKS FROM DBA_SEGMENTS WHERE OWNER=UPPER(owner) AND SEGMENT_NAME = UPPER(table);
ANALYZE TABLE owner.table ESTIMATE STATISTICS; SELECT EMPTY_BLOCKS FROM DBA_TABLES WHERE OWNER=UPPER(owner) AND SEGMENT_NAME = UPPER(table); Thus, the tables HWM = (query result 1) - (query result 2) - 1 NOTE: You can also use the DBMS_SPACE package and calculate the HWM = TOTAL_BLOCKS UNUSED_BLOCKS - 1.
The exception to this rule is locally managed tablespaces. If a tablespace is created with local extent management and the extent size is 64K, then Oracle allocates 64K or 8 blocks assuming 8K-block size. Oracle doesnt round it up to the multiple of 5 when a tablespace is locally managed. Can one rename a database user (schema)? No, this is listed as Enhancement Request 158508. Workaround: Do a user-level export of user A create new user B Import system/manager fromuser=A touser=B Drop user A Can one rename a tablespace? No, this is listed as Enhancement Request 148742. Workaround: Export all of the objects from the tablespace Drop the tablespace including contents Recreate the tablespace Import the objects Can one resize tablespaces and data files?
One can manually increase or decrease the size of a datafile from Oracle 7.2 using the command. ALTER DATABASE DATAFILE filename2 RESIZE 100M; Because you can change the sizes of datafiles, you can add more space to your database without adding more datafiles. This is beneficial if you are concerned about reaching the maximum number of datafiles allowed in your database. Manually reducing the sizes of datafiles allows you to reclaim unused space in the database. This is useful for correcting errors in estimations of space requirements. Also, datafiles can be allowed to automatically extend if more space is required. Look at the following command: CREATE TABLESPACE pcs_data_ts DATAFILE c:\ora_apps\pcs\pcsdata1.dbf SIZE 3M AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED DEFAULT STORAGE (INITIAL 10240 NEXT 10240 MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 0) ONLINE PERMANENT;
How does one create a standby database? While your production database is running, take an (image copy) backup and restore it on duplicate hardware. Note that an export will not work!!! On your standby database, issue the following commands: ALTER DATABASE CREATE STANDBY CONTROLFILE AS filename; ALTER DATABASE MOUNT STANDBY DATABASE; RECOVER STANDBY DATABASE;
On systems prior to Oracle 8i, write a job to copy archived redo log files from the primary database to the standby system, and apply the redo log files to the standby database (pipe it). Remember the database is recovering and will prompt you for the next log file to apply. Oracle 8i onwards provide an Automated Standby Database feature, which will send archived, log files to the remote site via NET8, and apply then to the standby database. When one needs to activate the standby database, stop the recovery process and activate it: ALTER DATABASE ACTIVATE STANDBY DATABASE;
How does one give developers access to trace files (required as input to tkprof)?
The alter session set sql_trace=true command generates trace files in USER_DUMP_DEST that can be used by developers as input to tkprof. On Unix the default file mask for these files are rwx r-- ---. There is an undocumented INIT.ORA parameter that will allow everyone to read (rwx rr--) these trace files: _trace_files_public = true
Include this in your INIT.ORA file and bounce your database for it to take effect. How does one see the uptime for a database?
Look at the following SQL query: SELECT to_char (startup_time,DD-MON-YYYY HH24: MI: SS) DB Startup Time FROM sys.v_$instance; Marco Bergman provided the following alternative solution: SELECT to_char (logon_time,Dy dd Mon HH24: MI: SS) DB Startup Time FROM sys.v_$session WHERE Sid=1 /* this is pmon */ / Users still running on Oracle 7 can try one of the following queries: Column STARTED format a18 head STARTUP TIME Select C.INSTANCE, to_date (JUL.VALUE, J) || to_char (floor (SEC.VALUE/3600), 09) || : -- || Substr (to_char (mod (SEC.VALUE/60, 60), 09), 2, 2) || Substr (to_char (floor (mod (SEC.VALUE/60, 60)), 09), 2, 2) || . || Substr (to_char (mod (SEC.VALUE, 60), 09), 2, 2) STARTED from SYS.V_$INSTANCE JUL, SYS.V_$INSTANCE SEC, SYS.V_$THREAD C Where JUL.KEY like %JULIAN% and SEC.KEY like %SECOND%; Select to_date (JUL.VALUE, J) || to_char (to_date (SEC.VALUE, SSSSS), HH24:MI:SS) STARTED from SYS.V_$INSTANCE JUL, SYS.V_$INSTANCE SEC where JUL.KEY like %JULIAN% and SEC.KEY like %SECOND%;
select to_char (to_date (JUL.VALUE, J) + (SEC.VALUE/86400), -Return a DATE DD-MON-YY HH24:MI:SS) STARTED from V$INSTANCE JUL, V$INSTANCE SEC where JUL.KEY like %JULIAN% and SEC.KEY like %SECOND%;
Where are my TEMPFILES, I dont see them in V$DATAFILE or DBA_DATA_FILE? Tempfiles, unlike normal datafiles, are not listed in v$datafile or dba_data_files. Instead query v$tempfile or dba_temp_files: SELECT * FROM v$tempfile; SELECT * FROM dba_temp_files; How do I find used/free space in a TEMPORARY tablespace? Unlike normal tablespaces, true temporary tablespace information is not listed in DBA_FREE_SPACE. Instead use the V$TEMP_SPACE_HEADER view: SELECT tablespace_name, SUM (bytes used), SUM (bytes free) FROM V$temp_space_header GROUP BY tablespace_name; How can one see who is using a temporary segment?
For every user using temporary space, there is an entry in SYS.V$_LOCK with type TS. All temporary segments are named ffff.bbbb where ffff is the file it is in and bbbb is first block of the segment. If your temporary tablespace is set to TEMPORARY, all sorts are done in one large temporary segment. For usage stats, see SYS.V_$SORT_SEGMENT From Oracle 8.0, one can just query SYS.v$sort_usage. Look at these examples: select s.username, u.USER, u.tablespace, u.contents, u.extents, u.blocks from sys.v_$session s, sys.v_$sort_usage u where s.addr = u.session_addr / select s.osuser, s.process, s.username, s.serial#, Sum (u.blocks)*vp.value/1024 sort_size from sys.v_$session s, sys.v_$sort_usage u, sys.v_$parameter VP where s.saddr = u.session_addr and vp.name = db_block_size and s.osuser like &1 group by s.osuser, s.process, s.username, s.serial#, vp.value /
backup and recovery scenarios carefully. It is better to be save than sorry. Regardless of your strategy, also remember to backup all required software libraries, parameter files, password files, etc. If your database is in ARCGIVELOG mode, you also need to backup archived log files.
Sql> RECOVER DATABASE UNTIL TIME 2001-03-06:16:00:00 USING BACKUP CONTROLFILE; How does one backup a database using the export utility?
Oracle exports are logical database backups (not physical) as they extract data and logical definitions from the database into a file. Other backup strategies normally back-up the physical data files. One of the advantages of exports is that one can selectively re-import tables, however one cannot rollforward from an restored export file. To completely restore a database from an export file one practically needs to recreate the entire database.
Always do full system level exports (FULL=YES). Full exports include more information about the database in the export file than user level exports. How does one do off-line database backups?
Shut down the database from sqlplus or server manager. Backup all files to secondary storage (eg. tapes). Ensure that you backup all data files, all control files and all log files. When completed, restart your database. Do the following queries to get a list of all files that needs to be backed up: select name from sys.v_$datafile; select member from sys.v_$logfile; select name from sys.v_$controlfile; Sometimes Oracle takes forever to shutdown with the immediate option. As workaround to this problem, shutdown using these commands: alter system checkpoint; shutdown abort startup restrict shutdown immediate Note that if you database is in ARCHIVELOG mode, one can still use archived log files to roll forward from an off-line backup. If you cannot take your database down for a cold (off-line) backup at a convenient time, switch your database into ARCHIVELOG mode and perform hot (on-line) backups.
! cp xyfFile1 /backupDir/ ALTER TABLESPACE xyz END BACKUP; It is better to backup tablespace for tablespace than to put all tablespaces in backup mode. Backing them up separately incurs less overhead. When done, remember to backup your control files. Look at this example: ALTER SYSTEM SWITCH LOGFILE; -- Force log switch to update control file headers ALTER DATABASE BACKUP CONTROLFILE TO /backupDir/control.dbf; NOTE: Do not run on-line backups during peak processing periods. Oracle will write complete database blocks instead of the normal deltas to redo log files while in backup mode. This will lead to excessive database archiving and even database freezes.
directory from filling-up. NOTE2: ARCHIVELOG mode was introduced with Oracle V6, and is essential for database point-intime recovery. Archiving can be used in combination with on-line and off-line database backups. NOTE3: You may want to set the following INIT.ORA parameters when enabling ARCHIVELOG mode: log_archive_start=TRUE, log_archive_dest=... and log_archive_format=... NOTE4: You can change the archive log destination of a database on-line with the ARCHIVE LOG START TO directory; statement. This statement is often used to switch archiving between a set of directories. NOTE5: When running Oracle Real Application Server (RAC), you need to shut down all nodes before changing the database to ARCHIVELOG mode.
From Oracle9i onwards, the following command can be used to take all of the datafiles out of hot backup mode: ALTER DATABASE END BACKUP;
The above commands need to be issued when the database is mounted. My database is down and I cannot restore. What now?
Recovery without any backup is normally not supported, however, Oracle Consulting can sometimes extract data from an offline database using a utility called DUL (Disk UnLoad). This utility reads data in the data files and unloads it into SQL*Loader or export dump files. DUL does not care about rollback segments, corrupted blocks, etc, and can thus not guarantee that the data is not logically corrupt. It is intended as an absolute last resort and will most likely cost your company a lot of money!!!
Caution is advised when enabling this parameter, as uncommitted transactions will be marked as committed. One can very well end up with lost or inconsistent data!!! Please contact Oracle Support before using it.
_Corrupted_rollback_segments = (rbs01, rbs01, rbs03, rbs04)
How does one create a RMAN recovery catalog? Start by creating a database schema (usually called rman). Assign an appropriate tablespace to it and grant it the recovery_catalog_owner role. Look at this example:
sqlplus sys SQL> create user rman identified by rman; SQL> alter user rman default tablespace tools temporary tablespace temp; SQL> alter user rman quota unlimited on tools; SQL> grant connect, resource, recovery_catalog_owner to rman; SQL> exit;
Next, log in to rman and create the catalog schema. Prior to Oracle 8i this was done by running the catrman.sql script.
rman catalog rman/rman RMAN> create catalog tablespace tools; RMAN> exit;
You can now continue by registering your databases in the catalog. Look at this example:
rman catalog rman/rman target backdba/backdba RMAN> register database;
Add to RMAN script: sql alter system archive log current; RMAN-06089: archived log xyz not found or out of sync with catalog
Execute from RMAN: change archivelog all validate;
What third party tools can be used with Oracle EBU/ RMAN?
The following Media Management Software Vendors have integrated their media management software packages with Oracle Recovery Manager and Oracle7 Enterprise Backup Utility. The Media Management Vendors will provide first line technical support for the integrated backup/recover solutions.
Veritas NetBackup EMC Data Manager (EDM) HP OMNIBack II IBMs Tivoli Storage Manager - formerly ADSM Legato Networker
ManageIT Backup and Recovery Sterling Softwares SAMS:Alexandria - formerly from Spectralogic Sun Solstice Backup .
Things that can cause bad performance: See question What tuning indicators can one use?.
10
Experience showed that approximately 80% of all Oracle system performance problems are resolved by coding optimal SQL. Also consider proper scheduling of batch tasks after peak working hours. Memory Tuning: Properly size your database buffers (shared pool, buffer cache, log buffer, etc) by looking at your buffer hit ratios. Pin large objects into memory to prevent frequent reloads. Disk I/O Tuning: Database files needs to be properly sized and placed to provide maximum disk subsystem throughput. Also look for frequent disk sorts, full table scans, missing indexes, row chaining, data fragmentation, etc. Eliminate Database Contention: Study database locks, latches and wait events carefully and eliminate where possible. Tune the Operating System: Monitor and tune operating system CPU, I/O and memory utilization. For more information, read the related Oracle FAQ dealing with your specific operating system.
Use Statspack:
sqlplus perfstat/perfstat exec statspack.snap; -- Take a performance snapshots exec statspack.snap; Get a list of snapshots select SNAP_ID, SNAP_TIME from STATS$SNAPSHOT; @spreport.sql -- Enter two snapshot ids for difference report
11
Its important to have statistics on all tables for the CBO (Cost Based Optimizer) to work correctly. If one table involved in a statement does not have statistics, Oracle has to revert to rule-based optimization for that statement. So you really want for all tables to have statistics right away; it wont help much to just have the larger tables analyzed. Generally, the CBO can change the execution plan when you: 1. Change statistics of objects by doing an ANALYZE; 2. Change some initialization parameters (for example: hash_join_enabled, sort_area_size, db_file_multiblock_read_count).
12
(unless you use a FAST FULL SCAN or SKIP SCANNING). There are many other factors that affect the cost, but sometimes the above can help to show why an index is not being used by the CBO. If from checking the above you still feel that the query should be using an index, try specifying an index hint. Obtain an explain plan of the query either using TKPROF with TIMED_STATISTICS, so that one can see the CPU utilization, or with AUTOTRACE to see the statistics. Compare this to the explain plan when not using an index.
13
Required Skills:
Good understanding of the Oracle database, related utilities and tools A good understanding of the underlying operating system A good knowledge of the physical database design Ability to perform both Oracle and operating system performance tuning and monitoring Knowledge of ALL Oracle backup and recovery scenarios A good knowledge of Oracle security management A good knowledge of how Oracle acquires and manages resources A good knowledge Oracle data integrity Sound knowledge of the implemented application systems Experience in code migration, database change management and data management through the various stages of the development life cycle A sound knowledge of both database and system performance tuning A DBA should have sound communication skills with management, development teams, vendors and systems administrators Provide a strategic database direction for the organisation A DBA should have the ability to handle multiple projects and deadlines A DBA should possess a sound understanding of the business
Interview Questions
Tell us about yourself/ your background. What are the three major characteristics that you bring to the job market? What motivates you to do a good job? What two or three things are most important to you at work? What qualities do you think are essential to be successful in this kind of work? What courses did you attend? What job certifications do you hold? What subjects/courses did you excel in? Why? What subjects/courses gave you trouble? Why? How does your previous work experience prepare you for this position?
14
How do you define success? What has been your most significant accomplishment to date? Describe a challenge you encountered and how you dealt with it. Describe a failure and how you dealt with it. Describe the ideal job... the ideal supervisor. What leadership roles have you held? What prejudices do you hold? What do you like to do in your spare time? What are your career goals (a) 3 years from now; (b) 10 years from now? How does this position match your career goals? What have you done in the past year to improve yourself? In what areas do you feel you need further education and training to be successful? What do you know about our company? Why do you want to work for this company. Why should we hire you? Where do you see yourself fitting in to this organization . . .initially? . . .in 5 years? Why are you looking for a new job? How do you feel about re-locating? Are you willing to travel? What are your salary requirements? When would you be available to start if you were selected? Did you use online or off-line backups? What version of Oracle were you running? Haw many databases and what sizes? If you have to advise a backup strategy for a new application, how would you approach it and what questions will you ask? If a customer calls you about a hanging database session, what will you do to resolve it? Compare Oracle to any other database that you know. Why would you prefer to work on one and not on the other?
15
The following query displays parameter names with their current value:
select a.ksppinm Parameter, b.ksppstvl Instance Value from x$ksppi a, x$ksppcv b, x$ksppsv c where a.indx = b.indx and a.indx = c.indx and substr(ksppinm,1,1)=_ order by a.ksppinm; Session Value, c.ksppstvl
The alter session method only affects the users current session, whereas changes to the INIT.ORA file will affect all sessions once the database has been restarted. What database events can be set?
The following events are frequently used by DBAs and Oracle Support to diagnose problems: 10046 trace name context forever, level 4 Trace SQL statements and show bind variables in trace output. 10046 trace name context forever, level 8 This shows wait events in the SQL trace files 10046 trace name context forever, level 12 This shows both bind variable names and wait events in the SQL trace files 1401 trace name errorstack, level 12 1401 trace name errorstack, level 4 1401 trace name processstate
16
Dumps out trace information if an ORA-1401 inserted value too large for column error occurs. The 1401 can be replaced by any other Oracle Server error code that you want to trace. 60 trace name errorstack level 10 Show where in the code Oracle gets a deadlock (ORA-60), and may help to diagnose the problem. The following lists of events are examples only. They might be version specific, so please call Oracle before using them: 10210 trace name context forever, level 10 10211 trace name context forever, level 10 10231 trace name context forever, level 10 These events prevent database block corruptions 10049 trace name context forever, level 2 Memory protect cursor 10210 trace name context forever, level 2 Data block check 10211 trace name context forever, level 2 Index block check 10235 trace name context forever, level 1 Memory heap check 10262 trace name context forever, level 300 Allow 300 bytes memory leak for connections
Note: You can use the Unix oerr command to get the description of an event. On Unix, you can type oerr ora 10053 from the command prompt to get event details. How can one dump internal database structures?
The following (mostly undocumented) commands can be used to obtain information about internal database structures. Dump control file contents alter session set events immediate trace name CONTROLF level 10 / Dump file headers alter session set events immediate trace name FILE_HDRS level 10 / Dump redo log headers alter session set events immediate trace name REDOHDR level 10 / Dump the system state NOTE: Take 3 successive SYSTEMSTATE dumps, with 10-minute intervals alter session set events immediate trace name SYSTEMSTATE level 10 / Dump the process state alter session set events immediate trace name PROCESSSTATE level 10 / Dump Library Cache details alter session set events immediate trace name library cache level 10 / Dump optimizer statistics whenever a SQL statement is parsed (hint: change statement or flush pool) alter session set events 10053 trace name context forever, level 1 / Dump a database block (File/ Block must be converted to DBA address) Convert file and block number to a DBA (database block address). Eg: variable x varchar2; exec :x := dbms_utility.make_data_block_address(1,12); print x alter session set events immediate trace name blockdump level 50360894 /
17
How does one use ORADEBUG from Server Manager/ SQL*Plus? Execute the ORADEBUG HELP command from svrmgrl or sqlplus to obtain a list of valid ORADEBUG commands. Look at these examples:
SQLPLUS> REM Trace SQL statements with bind variables SQLPLUS> oradebug setospid 10121 Oracle pid: 91, Unix process pid: 10121, image: oracleorcl SQLPLUS> oradebug EVENT 10046 trace name context forever, level 12 Statement processed. SQLPLUS> ! vi /app/oracle/admin/orcl/bdump/ora_10121.trc SQLPLUS> REM Trace Process Statistics SQLPLUS> oradebug setorapid 2 Unix process pid: 1436, image: ora_pmon_orcl SQLPLUS> oradebug procstat Statement processed. SQLPLUS> oradebug TRACEFILE_NAME /app/oracle/admin/orcl/bdump/pmon_1436.trc SQLPLUS> REM List semaphores and shared memory segments in use SQLPLUS> oradebug ipc SQLPLUS> REM Dump Error Stack SQLPLUS> oradebug setospid <pid> SQLPLUS> oradebug event immediate trace name errorstack level 3 SQLPLUS> REM Dump Parallel Server DLM locks SQLPLUS> oradebug lkdebug -a convlock SQLPLUS> oradebug lkdebug -a convres SQLPLUS> oradebug lkdebug -r <resource handle> (i.e 0x8066d338 from convres dump)
18
X$KDXST X$KGHLU X$KGLBODY X$KGLCLUSTER X$KGLINDEX X$KGLLC X$KGLPN X$KGLTABLE X$KGLTR X$KGLTRIGGER X$KGLXS X$KKMMD X$KKSBV X$KSMSP X$KSQDN X$KSQST X$KSUCF X$KSUPL X$KSURU X$KSQST X$KTTVS X$KVII X$KVIS X$KVIT X$KXFPCDS X$KXFPCMS X$KZDOS X$KZSRO X$LE X$MESSAGES
Statistics collection Fixed Table One-row summary of LRU statistics for the shared pool Derived from X$KGLOB (col kglhdnsp = 2) Derived from X$KGLOB (col kglhdnsp = 5) Derived from X$KGLOB (col kglhdnsp = 4) Latch Clean-up state for library cache objects Fixed Table Library cache pin Fixed Table Derived from X$KGLOB (col kglhdnsp = 1) Library Cache Translation Table entry Fixed Table Derived from X$KGLOB (col kglhdnsp = 3) Library Cache Access Table Fixed table to look at what databases are mounted and their status Cursor Cache Bind Variables Each row represents a piece of memory in the shared pool Global database name Enqueue statistics by type Cost function for each Kernel Profile (join to X$KSUPL) Resource Limit for each Kernel Profile Resource Usage for each Kernel Profile (join with X$KSUPL) Gets and waits for different types of enqueues Indicate tablespace that has valid save undo segments Internal instance parameters set at instance initialization Oracle Data Block (size_t type) variables Instance internal flags, variables and parameters that can change during the life of an instance Client Dequeue Statistics Client Messages Statistics Represent an os role as defined by the operating system Security state Role: List of enabled roles Lock Element: each PCM lock that is used by the buffer cache (gc_db_locks) Displays all the different messages that can be sent to the Background processes
Some handy queries based on the X$ memory tables: Largest # blocks you can write at any given time:
select kviival write_batch_size from x$kvii where kviitag = kcbswc; select * from x$ksqst where ksqstget > 0;
Listed below are some of the important subsystems in the Oracle kernel. This table might help you to read those dreaded trace files and internal messages. For example, if you see messages like this, you will at least know where they come from:
19
OPIRIP: Uncaught error 447. Error stack: KCF: write/open error block=0x3e800 online=1
Kernel Subsystems:
OPI KK KX K2 NPI KZ KQ RPI KA KD KT KC KS KJ KG KV S or ODS Oracle Program Interface Compilation Layer - Parse SQL, compile PL/SQL Execution Layer - Bind and execute SQL and PL/SQL Distributed Execution Layer - 2PC handling Network Program Interface Security Layer - Validate privs Query Layer Recursive Program Interface Access Layer Data Layer Transaction Layer Cache Layer Services Layer Lock Manager Layer Generic Layer Kernel Variables (eg. x$KVIS and X$KVII) Operating System Dependencies
Oracle Security
How does one change an Oracle users password?
Issue the following SQL command: ALTER USER <username> IDENTIFIED BY <new_password>; From Oracle8 you can just type password from SQL*Plus, or if you need to change another users password, type password user_name. Look at this example:
SQL> password Changing password for SCOTT Old password: New password: Retype new password:
How does one create and drop database users? Look at these examples:
CREATE USER scott IDENTIFIED BY tiger DEFAULT TABLESACE tools index segments TEMPORARY TABLESPACE temp; DROP USER scott CASCADE; -- Assign password -- Assign space for table and -- Assign sort space -- Remove user
20
CREATE PROFILE my_profile LIMIT PASSWORD_LIFE_TIME 30; ALTER USER scott PROFILE my_profile;
21
Follow this procedure to create a new password file: Log in as the Oracle software owner Runcommand: orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=mypasswd Shutdown the database (SQLPLUS> SHUTDOWN IMMEDIATE) Edit the INIT.ORA file and ensure REMOTE_LOGIN_PASSWORDFILE=exclusive is set. Startup the database (SQLPLUS> STARTUP) NOTE: The orapwd utility presents a security risk in that it receives a password from the command line. This password is visible in the process table of many systems. Administrators needs to be aware of this!
Note: Also see the su.sql script in the Useful Scripts and Sample Programs Page.
Who created all these users in my database?/ Can I drop this user?
Oracle creates a number of default database users or schemas when a new database is created. Below are a few of them: SYS/CHANGE_ON_INSTALL or INTERNAL
Oracle Data Dictionary/ Catalog Created by: ?/rdbms/admin/sql.bsq and various cat*.sql scripts Can password be changed: Yes (Do so right after the database was created) Can user be dropped: NO
SYSTEM/MANAGER The default DBA user name (please do not use SYS) Created by: ?/rdbms/admin/sql.bsq
22
Can password be changed: Yes (Do so right after the database was created) Can user be dropped: NO OUTLN/OUTLN Stored outlines for optimizer plan stability Created by: ?/rdbms/admin/sql.bsq Can password be changed: Yes (Do so right after the database was created) Can user be dropped: NO SCOTT/TIGER, ADAMS/WOOD, JONES/STEEL, CLARK/CLOTH and BLAKE/PAPER. Training/ demonstration users containing the popular EMP and DEPT tables Created by: ?/rdbms/admin/utlsampl.sql Can password be changed: Yes Can user be dropped: YES - Drop users cascade from all production environments HR/HR (Human Resources), OE/OE (Order Entry), SH/SH (Sales History). Training/ demonstration users containing the popular EMPLOYEES and DEPARTMENTS tables Created by: ?/demo/schema/mksample.sql Can password be changed: Yes Can user be dropped: YES - Drop users cascade from all production environments
CTXSYS/CTXSYS
TRACESVR/TRACE
Oracle Trace server Created by: ?/rdbms/admin/otrcsvr.sql
DBSNMP/DBSNMP Oracle Intelligent agent Created by: ?/rdbms/admin/catsnmp.sql, called from catalog.sql Can password be changed: Yes - put the new password in snmp_rw.ora file Can user be dropped: YES - Only if you do not use the Intelligent Agents ORDPLUGINS/ORDPLUGINS
Object Relational Data (ORD) User used by Time Series, etc. Created by: ?/ord/admin/ordinst.sql
ORDSYS/ORDSYS Object Relational Data (ORD) User used by Time Series, etc Created by: ?/ord/admin/ordinst.sql DSSYS/DSSYS Oracle Dynamic Services and Syndication Server Created by: ?/ds/sql/dssys_init.sql MDSYS/MDSYS Oracle Spatial administrator user Created by: ?/ord/admin/ordinst.sql AURORA$ORB$UNAUTHENTICATED/INVALID Used for users who do not authenticate in Aurora/ORB Created by: ?/javavm/install/init_orb.sql called from ?/javavm/install/initjvm.sql PERFSTAT/PERFSTAT Oracle Statistics Package (STATSPACK) that supersedes UTLBSTAT/UTLESTAT Created by: ?/rdbms/admin/statscre.sql Remember to change the passwords for the SYS and SYSTEM users immediately after installation! Except for the user SYS, there should be no problem altering these users to use a different default and temporary tablespace.
23
select * from EMP where c1 = 09; -- No auditing Now we can see the statments that triggered the auditing condition... select sqltext from sys.fga_log$; delete from sys.fga_log$;
RMAN
WHAT IS RMAN ?
Recovery Manager is a tool that: manages the process of creating backups and also manages the process of restoring and recovering from them.
No extra costs Its available free RMAN introduced in Oracle 8 it has become simpler with newer versions and easier than user managed backups Proper security You are 100% sure your database has been backed up. Its contains detail of the backups taken etc in its central repository Facility for testing validity of backups also commands like crosscheck to check the status of backup. Faster backups and restores compared to backups without RMAN RMAN is the only backup tool which supports incremental backups. Oracle 10g has got further optimized incremental backup which has resulted in improvement of performance during backup and recovery time Parallel operations are supported Better querying facility for knowing different details of backup No extra redo generated when backup is taken..compared to online backup without RMAN which results in saving of space in hard disk RMAN an intelligent tool Maintains repository of backup metadata Remembers backup set location Knows what need to backed up Knows what is required for recovery Knows what backups are redundant
An oracle RMAN comprises of RMAN EXECUTABLE This could be present and fired even through client side TARGET DATABASE This is the database which needs to be backed up . RECOVERY CATALOG Recovery catalog is optional otherwise backup details are stored in target
24
database controlfile . It is a repository of information queried and updated by Recovery Manager It is a schema or user stored in Oracle database. One schema can support many databases It contains information about physical schema of target database datafile and archive log ,backup
Backups in RMAN
Oracle backups in RMAN are of the following type RMAN complete backup OR RMAN incremental backup These backups are of RMAN proprietary nature
IMAGE COPY
The advantage of uing Image copy is its not in RMAN proprietary format..
Backup Format
RMAN backup is not in oracle format but in RMAN format. Oracle backup comprises of backup sets and it consists of backup pieces. Backup sets are logical entity In oracle 9i it gets stored in a default location There are two type of backup sets Datafile backup sets, Archivelog backup sets One more important point of data file backup sets is it do not include empty blocks. A backup set would contain many backup pieces. A single backup piece consists of physical files which are in RMAN proprietary format.
Example of taking backup using RMAN Taking RMAN Backup In non archive mode in dos prompt type
RMAN
You get the RMAN prompt RMAN > Connect Target Connect to target database : Magic <Dbid=129283912> using target database controlfile instead of recovery catalog
Restoring database
Restoring database has been made very simple in 9i . It is just Restore database.. RMAN has become intelligent to identify which datafiles has to be restored and the location of backuped up file.
25
A new configure command has been introduced in Oracle 9i , that lets you configure various features including automatic channels, parallelism ,backup options, etc. These automatic allocations and options can be overridden by commands in a RMAN command file.
26
Previous to version Oracle 9i backups were not that easy which means you had to allocate a channel compulsorily to take backup You had to give a run etc . The syntax was a bit complex RMAN has now become very simple and easy to use.. If you changed the location of backup set it is compulsory for you to register it using RMAN or while you are trying to restore backup It resulted in hanging situations There is no method to know whether during recovery database restore is going to fail because of missing archive log file. Compulsory Media Management only if using tape backup Incremental backups though used to consume less space used to be slower since it used to read the entire database to find the changed blocks and also They have difficult time streaming the tape device. . Considerable improvement has been made in 10g to optimize the algorithm to handle changed block.
Observation
Introduced in Oracle 8 it has become more powerful and simpler with newer version of Oracle 9 and 10 g. So if you really dont want to miss something critical please start using RMAN.
What are the components of OEM? Oracle Enterprise Manager (OEM) has the following components:
Management Server (OMS): Middle tier server that handles communication with the intelligent agents. The OEM Console connects to the management server to monitor and configure the Oracle enterprise. Console: This is a graphical interface from where one can schedule jobs, events, and monitor the database. The console can be opened from a Windows workstation, Unix XTerm (oemapp command) or Web browser session (oem_webstage). Intelligent Agent (OIA): The OIA runs on the target database and takes care of the execution of jobs and events scheduled through the Console.
Windows NT/2000 users can just stop and start the required services. The default OEM administrator is sysman with a password of oem_temp. NOTE: Use command oemctrl instead of oemctl for Oracle 8i and below.
27
The following describes means to create a OEM V1.x (very old!!!) repository on WindowsNT:
Create a tablespace that would hold the repository data. A size between 200- 250 MB would be ideal. Let us call it Dummy_Space. Create an Oracle user who would own this repository. Assign DBA, SNMPAgent, Exp_Full_database, Imp_Full_database roles to this user. Lets call this user Dummy_user. Assign Dummy_Space as the default tablespace. Create an operating system user with the same name as the Oracle username. I.e. Dummy_User. Add Log on as a batch job under advanced rights in User manager. Fire up Enterprise manager and log in as Dummy_User and enter the password. This would trigger the creation of the repository. From now on, Enterprise manager is ready to accept jobs.
will guide you through the process of discovering your databases and other services. Should the OEM Console be displayed at all times (when there are scheduled jobs)?
When a job is submitted the agent will confirm the status of the job. When the status shows up as scheduled, you can close down the OEM console. The processing of the job is managed by the OIA (Oracle Intelligent Agent). The OIA maintains a .jou file in the agents subdirectory. When the console is launched communication with the Agent is established and the contents of the .jou file (binary) are reported to the console job subsystem. Note that OEM will not be able to send e-mail and paging notifications when the Console is not started.
How does one backout events and jobs during maintenance slots?
Managemnet and data collection activity can be suspended by imposing a blackout. Look at these examples:
agentctl start blackout agentctl stop blackout agentctl start blackout ORCL agentctl stop blackout ORCL management # Blackout the entrire agent # Resume normal monitoring and management # Blackout database ORCL # Resume normal monitoring and # Blackout jobs for
28
How does one start the Oracle Intelligent Agent? One needs to start an OIA (Oracle Intelligent Agent) process on all machines that will to be managed via OEM.
For OEM 9i and above: agentctl start agent agentctl stop agent
On Windows NT, start the OracleAgent Service. If the agent doesnt want to start, ensure your environment variables are set correctly and delete the following files before trying again: 1) In $ORACLE_HOME/network/admin: snmp_ro.ora and snmp_rw.ora. 2) Also delete ALL files in $ORACLE_HOME/network/agent/.
29
30
31
than one table, this statement will only show information about the current table being imported. Contributed by Osvaldo Ancarola, Bs. As. Argentina. Method 2: Use the FEEDBACK=n import parameter. This command will tell IMP to display a dot for every N rows imported.
Can one import tables to a different tablespace? Oracle offers no parameter to specify a different tablespace to import data into. Objects will be re-created in the tablespace they were originally exported from. One can alter this behaviour by following one of these procedures:
Pre-create the table(s) in the correct tablespace: Import the dump file using the INDEXFILE= option Edit the indexfile. Remove remarks and specify the correct tablespaces. Run this indexfile against your database, this will create the required tables in the appropriate tablespaces Import the table(s) with the IGNORE=Y option. Change the default tablespace for the user: Revoke the UNLIMITED TABLESPACE privilege from the user Revoke the users quota from the tablespace from where the object was exported. This forces the import utility to create tables in the users default tablespace. Make the tablespace to which you want to import the default tablespace for the user Import the table
Can one export to multiple files?/ Can one beat the Unix 2 Gig limit?
From Oracle8i, the export utility supports multiple output files. This feature enables large exports to be divided into files whose sizes will not exceed any operating system limits (FILESIZE= parameter). When importing from multi-file export you must provide the same filenames in the same sequence in the FILE= parameter. Look at this example: exp SCOTT/TIGER FILE=D:\F1.dmp,E:\F2.dmp FILESIZE=10m LOG=scott.log
Use the following technique if you use an Oracle version prior to 8i:
Create a compressed export on the fly. Depending on the type of data, you probably can export up to 10 gigabytes to a single file. This example uses gzip. It offers the best compression I know of, but you can also substitute it with zip, compress or whatever. # create a named pipe mknod exp.pipe p # read the pipe - output to zip file in the background gzip < exp.pipe > scott.exp.gz & # feed the pipe exp userid=scott/tiger file=exp.pipe ...
32
EXPORT:
Set the BUFFER parameter to a high value (e.g. 2M) Set the RECORDLENGTH parameter to a high value (e.g. 64K) Stop unnecessary applications to free-up resources for your job. If you run multiple export sessions, ensure they write to different physical disks. DO NOT export to an NFS mounted filesystem. It will take forever.
IMPORT:
Create an indexfile so that you can create indexes AFTER you have imported data. Do this by setting INDEXFILE to a filename and then import. No data will be imported but a file containing index definitions will be created. You must edit this file afterwards and supply the passwords for the schemas on all CONNECT statements. Place the file to be imported on a separate physical disk from the oracle data files Increase DB_CACHE_SIZE (DB_BLOCK_BUFFERS prior to 9i) considerably in the init$SID.ora file Set the LOG_BUFFER to a big value and restart oracle. Stop redo log archiving if it is running (ALTER DATABASE NOARCHIVELOG;) Create a BIG tablespace with a BIG rollback segment inside. Set all other rollback segments offline (except the SYSTEM rollback segment of course). The rollback segment must be as big as your biggest table (I think?) Use COMMIT=N in the import parameter file if you can afford it Use ANALYZE=N in the import parameter file to avoid time consuming ANALYZE statements Remember to run the indexfile previously created
Oracle SQL*Loader
What is SQL*Loader and what is it used for?
SQL*Loader is a bulk loader utility used for moving data from external files into the Oracle database. Its syntax is similar to that of the DB2 Load utility, but comes with more options. SQL*Loader supports various load formats, selective loading, and multi-table loads.
33
Another Sample control file with in-line data formatted as fix length records. The trick is to specify * as the name of the data file, and use BEGINDATA to start the data section in the control file. load data infile * replace into table departments ( dept position (02:05) char(4), deptname position (08:27) char(20) ) begindata COSC COMPUTER SCIENCE ENGL ENGLISH LITERATURE MATH MATHEMATICS POLY POLITICAL SCIENCE
34
11111AAAAAAAAAA 22222BBBBBBBBBB Can one skip header records load while loading? Use the SKIP n keyword, where n = number of logical rows to skip. Look at this example: LOAD DATA INFILE * INTO TABLE load_positional_data SKIP 5 ( data1 POSITION(1:5), data2 POSITION(6:15) ) BEGINDATA 11111AAAAAAAAAA 22222BBBBBBBBBB
35
WHEN projno != ( projno POSITION(25:27) INTEGER EXTERNAL, empno POSITION(1:4) INTEGER EXTERNAL )
Can one selectively load only the records that one need?
Look at this example, (01) is the first character, (30:37) are characters 30 to 37: LOAD DATA INFILE mydata.dat BADFILE mydata.bad DISCARDFILE mydata.dis APPEND INTO TABLE my_selective_table WHEN (01) <> H and (01) <> T and (30:37) = 19991217 ( region CONSTANT 31, service_key POSITION(01:11) INTEGER EXTERNAL, call_b_no POSITION(12:29) CHAR )
How can get SQL*Loader to COMMIT only at the end of the load file?
One cannot, but by setting the ROWS= parameter to a large value, committing can be reduced. Make sure you have big rollback segments ready when you use a high value for ROWS=.
How does one use SQL*Loader to load images, sound clips and documents?
SQL*Loader can load data from a primary data file, SDF (Secondary Data file - for loading nested tables and VARRAYs) or LOGFILE. The LOBFILE method provides and easy way to load documents, images and audio clips into BLOB and CLOB columns. Look at this example:
36
Given the following table: CREATE TABLE image_table ( image_id NUMBER(5), file_name VARCHAR2(30), image_data BLOB); Control File: LOAD DATA INFILE * INTO TABLE image_table REPLACE FIELDS TERMINATED BY , ( image_id INTEGER(5), file_name CHAR(30), image_data LOBFILE (file_name) TERMINATED BY EOF ) BEGINDATA 001,image1.gif 002,image2.jpg
What is the difference between the conventional and direct path loader?
The conventional path loader essentially loads the data by using standard INSERT statements. The direct path loader (DIRECT=TRUE) bypasses much of the logic involved with that, and loads directly into the Oracle data files. More information about the restrictions of direct path loading can be obtained from the Utilities Users Guide.
What is a DBA?
A DBA is a Database Administrator, and this is the most common job that you find a database specialist doing. There are Development DBAs and Production DBAs. A Development DBA usually works closely with a team of developers and gets more involved in design decisions, giving advice on performance and writing good SQL. That can be satisfying at a human level because you are part of a team and you share the satisfaction of the teams accomplishments. A Production DBA (on the other hand) is responsible for maintaining Databases within an organisation, so it is a very difficult and demanding job. He or she, often gets involved when all the design decisions have been made, and has simply to keep things up and running. Therefore, of course, it is also a rewarding job, both financially and in terms of job satisfaction. But its a more lonely job than being a Development DBA. I have many years experience of working as a Production DBA, maintaining live Databases in Investment Banks, such as J.P.Morgan and Salomon Smith Barney. Those were some of the most demanding and high-pressure years in my professionalcareer. I knew that if the phone rang, nobody was calling to ask about my health, or to say that everything was OK. If they called, it meant they had a problem, and they wanted it fixed immediately, and they did not care what else you were doing. Of course, sometimes the phone would ring at home when I was in bed at 3.00 in the morning, so I would have to get up, switch on my PC, login remotely and fix the problem. This usually meant bringing the Database Servers down and then up again. After I while I got to be able to do this without becoming fully awake so I could to go back to bed and back to sleep again, and get paid for it !!! To enjoy being a DBA, and to do it properly, you need to like technical responsibility. You need to enjoy the feeling that this is my territory and to take sole responsibility for a technically demanding role. Oddly enough, its easy to find out whether you would be a good DBA. These are the Steps you follow :-
37
Buy a book,(see elsewhere on this Site), If you buy a book with an evaluation copy of a DBMS then the next Step is made a whole lot easier. Hint: Look for a book called SQL Reference, by Groff and Weinberg, which have copies of all three Oracle, IBMs DB2 and Microsofts SQL Server on the CD-ROM that comes with the book. Get Oracle, DB2 or SQL Server on a PC using NT. Start doing DBA tasks, going through your chosen Step-by-Step book, (such as SAMS Teach Yourself DB2 in 21 days, or Oracle 8i on NT in 24 hours). If you find it boring then give it up. If you dont like the prospect of always being at the end of a phone Help Line, then give it up. Else, get started as a DBA by doing daily tasks on your Database at home, and prepare for an interview. Surprisingly enough, its easy to find work - either a permanent job or a contract. There is a great demand, which is likely to remain so for the next few years. VENDORS: Microsoft SQL Server is easier to get started with, because everything is Windows-driven. It doesnt pay so well, but you might be able to get an interesting role combining DBA with Development work, because being a DBA doesnt take so much time. Being a DBA in a development environment is much less stressful, and is a natural progression as you begin to experience burn-out in a production environment. Oracle has a steeper learning curve, because it is geared towards the Command Line, (except for TOAD), but it pays better. IBMs DB2 is somewhere in between. Certification will help you get a job, but (like a degree - see below) because of the demand, Certification is not always mandatory if you have experience as a DBA. Can you get a job as an Oracle DBA with Certification but no experience ? If you get certified as an Oracle DBA but dont have any experience, it can be difficult to find a job. I have heard about people who have been able to do it, but Ive also been told that it is very difficult. It obviously helps if you have a background as an Oracle developer, and if you have no other Oracle experience, then its certainly going to be difficult. It is very difficult to get a job as a Production DBA without hands-on experience, and its hard to find openings for Junior DBAs. It is easier to find a job as a Development DBA, then if you really wanted to, you could move into a slot as a Production DBA. To do this, you should offer experience in PL/SQL, advising developers on writing efficient SQL, creating Data Sets and sample data, which is the kind of thing, which developers often ask for. So if you have any experiences that you would like to share and help other people trying to plan what to do, please let us know. Personally, I think Microsoft Certification process is just another example of how Microsoft tries to increase their revenue stream, and Ive heard that many of the questions asked in the Certification exams are not the kind of questions, which come up as part of the job. Ive also met many people who have obtained Microsoft Certification but then never use it. Neither Certification nor Degrees are necessary if you know your stuff, but they will definitely help to prove commitment and competence if you are trying to change careers. Oracle has recently introduced a qualification of Internet Database Operator, which offers the cheapest path to Certification, at a relatively modest (for Oracle Education) cost of one 4-day Course and a Certification Examination. This qualification will look good on your CV but it will not help you get a job because it only teaches you how to install Oracle Products and get them to work,(although thats a valuable skill but it is not enough on its own). It also teaches you some basics about SQL in Oracle. One option is to sign up as an Oracle Partner, which gives you 5 days free training and then use, the training to get Certification as an Internet Database Operator. There is a very useful set of Oracle 8i Documentation available online (Courtesy Ars Digita and Philip Greenspun) which will help you learn a lot about how Oracle works. The announcement of Oracle 9i means that the water has just become muddier because it means that a great deal of the current lengthy training may be unnecessary. 9i is moving much closer to point-and-click and away from command-line administration, although there will be plenty of Oracle 8i installations for a long time to come. Check out the Oracle 9i Partner Accelerator Kit for an overview, and see how Oracle expects you to
38
administer a Database using Oracle Enterprise Manager. Then finally, look at Oracles new Wizard for creating a Database for Data Warehousing. All of these new features mean that Oracle is moving towards to a point-and-click approach for many common DBA tasks. This will make the work of an Oracle DBA work much more like it is for IBMs DB2 and Microsft SQL Server. This means that many Command Line skills being taught will become obsolete in the future. Oracle - another Career Option As well as DBA work,a very attractive Career Option involves PL/SQL, which is Oracles Procedural Language. PL/SQL includes and extends SQL, and is primarily intended for developers who work close to the Database, rather than close to the User. Working with PL/SQL often includes some DBA work, for example, in data extraction and migration from a Database. It is therefore much more of a development job and offers design challenges and is more creative than 100% DBA work. Heres a typical Help Wanted Ad to give you a feeling for the skills required PL/SQL Developer With DBA Skills Multinational Multimedia organisation requires an experienced PL/SQL Developer who also has had DBA exposure, with good Unix Shell Scripting skills. Working on a systems migration project, you will have proven technical ability and excellent interpersonal skills. An ability to be able to write PL/SQL packages & procedures, create database load scripts and set-up development databases is essential. The position will demand some DBA support (approximately 20% of the role) however the support will be of a wholly ad-hoc nature. Working within an Oracle 7, 8 & v8i environment, associated experience is essential,as is solid commercial experience with PL/SQL. As for Qualifications, its always good to have at least a Bachelors degree, but because of the demand, thats not always necessary. Subsequently, you need to keep up-to-date with new versions of your chosen RDBMS(s). Beware, that if you talk a good interview, but dont deliver, you will get found out very quickly, and then youll be on the road again. What are the major Components in an RDBMS ? ANSWER : This describes the three major Components which make up the run-time processes. 1) The Database Server. This takes the SQL, decides how to execute it, with a sub-Component called the Query Optimiser, and produces a Query Execution Plan. It is possible to have many Database Server processes running simultaneously, with each one tailored to a particular kind of SQL Query. I used to work as a DBA for Salomon, Smith Barney supporting databases for Florida,England and Germany running on the same UNIX box. I always had three Servers running, one for each location, so that I could provide high-priority,high-CPU percentage,high-memory allocation for the very demanding real-time applications,and lower-priority for background batch jobs. It also allowed me to handle each database independently, and bring down the server for England without affecting the Servers and the Databases for Florida and Germany. 2) An Archive Process. This writes completed Transactions onto a Journal or History File and deletes them from the Log File. This is done to avoid the Log File getting filled up because then everything fails and the Servers have to be brought down to recover. This is an embarrassing process. The worst part is that as the DBA, you often do not know that the Archive process is not running until the Log File fills up, no more transactions can start, everybodys program hangs and the phone rings off the hook. I also worked as a DBA at J.P.Morgan where the user were just as demanding as Salomon, Smith Barney, so I created some UNIX daemons which ran all the time and would notify me automatically if the Archive process was not running. This was in the situation where the normal messages from starting up the Database Server would not make it clear whether the Archive process had started correctly. 3) A Recovery Process. The Recovery Process handles the situations where is there is a Database crash and it recovers to the last known point at which the Database was running OK and had integrity. In other words, all the data
39
representing a consistent set of related records had been written to the Database at the end of a committed Transaction, with no open Transactions.
40
If the system provides a low-level (record-at-a-time) interface, then that interface cannot be used to subvert the system (e.g.) bypassing a relational security or integrity constraint.
1) Normal
During normal shutdown no new connections are allowed and the server will wait for all users
41
to disconnect before shutting down. The redo buffers and database buffer are written to the datafiles, then the variousbackground processes are terminated and the allocated memory for the SGAare de-allocated. Finally Oracle will close and dismount the database.
2) Transactional
During transactional shutdown no new connections are allowed and the server will disconnect users as soon as they complete their current transaction. After that Oracle will immediately shut down the Instance.
3) Immediate
During immediate shutdown no new connections are allowed. The server will not wait for clients to disconnect nor for transactions to complete and will do a rollback if needed. So after disconnecting the clients and rolling back any active transactions Oracle will shut down the Instance.
4) Abort
During abort shutdown no new connections are allowed. The server will not wait for connected users to disconnect, uncommitted transactions will not be rolled back redo and database buffers are not written to disk and the database is not closed or dismounted. Instance recovery will be needed on the next startup.
Added by Deepak
1. Check patches applied to db There are several ways to identify whether a patch applied to database. Few of them 1)By invoking $ opatch lsinventory. Note that before invoking opatch you have to set or export ORACLE_HOME and then change the directory to opatch. oracle:/home/oracle APPS> $ opatch lsinventory Invoking OPatch 10.2.0.4.3 Oracle Interim Patch Installer version 10.2.0.4.3 Copyright (c) 2007, Oracle Corporation. All rights reserved.
42
Oracle Home : /APPS/app/oracle/product/10.2.0/db Central Inventory : /APPS/app/oracle/oraInventory from : /var/opt/oracle/oraInst.loc OPatch version : 10.2.0.4.3 OUI version : 10.2.0.4.0 OUI location : /APPS/app/oracle/product/10.2.0/db/oui Log file location : /APPS/app/oracle/product/10.2.0/db/cfgtoollogs/opatch/opatch2010-01-07_00-1928AM.log Lsinventory Output file location : /APPS/app/oracle/product/10.2.0/db/cfgtoollogs/opatch/lsinv/lsinventory20100107_00-19-28AM.txt ----------------------------------------------------------------------------Installed Top-level Products (2): Oracle Database 10g 10.2.0.1.0 Oracle Database 10g Release 2 Patch Set 3 10.2.0.4.0 There are 2 products installed in this Oracle Home. There are no Interim patches installed in this Oracle Home. ----------------------------------------------------------------------------OPatch succeeded. 2)By invoking $ opatch lsinventory -details oracle:/APPS/app/oracle/product/10.2.0/db/OPatch AHDP> $ opatch lsinventory -details Invoking OPatch 10.2.0.4.3 Oracle Interim Patch Installer version 10.2.0.4.3 Copyright (c) 2007, Oracle Corporation. All rights reserved. Oracle Home : /APPS/app/oracle/product/10.2.0/db Central Inventory : /APPS/app/oracle/oraInventory from : /var/opt/oracle/oraInst.loc OPatch version : 10.2.0.4.3 OUI version : 10.2.0.4.0 OUI location : /APPS/app/oracle/product/10.2.0/db/oui Log file location : /APPS/app/oracle/product/10.2.0/db/cfgtoollogs/opatch/opatch2010-01-07_00-2617AM.log Lsinventory Output file location : /APPS/app/oracle/product/10.2.0/db/cfgtoollogs/opatch/lsinv/lsinventory201001-07_00-26-17AM.txt Installed Top-level Products (2): Oracle Database 10g 10.2.0.1.0 Oracle Database 10g Release 2 Patch Set 3 10.2.0.4.0 There are 2 products installed in this Oracle Home. Installed Products (160): 10.2.0.1.0 SQLJ Runtime Patch 10.2.0.4.0
43
SSL Required Support Files for InstantClient 10.2.0.1.0 SSL Required Support Files for InstantClient Patch 10.2.0.4.0 Sun JDK 1.4.2.13.0 Sun JDK extensions 9.0.4.0.0 XDK Required Support Files 10.2.0.1.0 XDK Required Support Files Patch 10.2.0.4.0 XML Parser for Java 10.2.0.1.0 XML Parser for Java Patch 10.2.0.4.0 XML Parser for Oracle JVM 10.2.0.1.0 XML Parser for Oracle JVM Patch 10.2.0.4.0 There are 160 products installed in this Oracle Home. There are no Interim patches installed in this Oracle Home. ----------------------------------------------------------------------------OPatch succeeded. 3)Login to oracle as sys user and invoke select * from sys.registry$history; SQL> select * from sys.registry$history; ACTION_TIME ACTION NAMESPACE ------------------------------- -----------------------------VERSION ID COMMENTS BUNDLE_SERIES ------------------------------------ -----------------------------30-JUL-08 05.43.41.290171 PM CPU 6452863 view recompilation 08-SEP-08 08.22.59.110066 PM CPU SERVER 10.2.0.3.0 6864068 CPUApr2008 05-AUG-09 07.08.18.158451 AM UPGRADE SERVER 10.2.0.4.0 Upgraded from 10.2.0.3.0 05-AUG-09 07.42.03.040347 AM CPU 6452863 view recompilation 4)Various OS Commands. $ showrev -p $ owhat bin/oracle
Create Index and Rebuilt Index create index and rebuild index on the original table will be added when the 4 locks on obj$ plus 3 locks to prevent DML operations on the original table create index online and rebuild index online using a temporary table to deal with new or to re-create the original table when the index changes the index column, so that you can not lock the table, ensure that the original form of the dml operations in the process can be run properly. rebuild process can still take the old users to query the index, index, rebuild the index needs twice the space the original index Test 1: create table lock conn scott / tiger select sid, username from v $ session; create index test_index on test (name);
44
SID USERNAME ------- ------------139 143 SCOTT SQL> SELECT OBJECT_NAME, LMODE FROM V $ LOCK L, DBA_OBJECTS O WHERE O. OBJECT_ID = L.ID1 AND L. TYPE = 'TM' AND SID = 143; OBJECT_NAME LMODE ------------------------------ ---------OBJ $ 3 TEST 4 Test 2: rebuild online lock alter index test_index rebuild online; SELECT OBJECT_NAME, LMODE FROM V $ LOCK L, DBA_OBJECTS O WHERE O. OBJECT_ID = L.ID1 AND L. TYPE = 'TM' AND SID = 143; OBJECT_NAME LMODE ------------------------------ ---------SYS_JOURNAL_10499 4 TEST 2 Attached to the lock type 0, 'None', / * Mon Lock equivalent * / 1, 'Null', / * N * / 2, 'Row-S (SS)', / * L * / 3, 'Row-X (SX)', / * R * / 4, 'Share', / * S * / 5, 'S / Row-X (SSX)', / * C * / 6, 'Exclusive', / * X * / Test 3: In the online renewal process, the database is to record. First create a large table, to ensure there is sufficient time to observe the details of the index rebuild process. SQL> create table test_rebuild as select * from dba_objects; Table created. SQL> insert into test_rebuild select * from test_rebuild; 6398 rows created. Insertion of non-stop data SQL> / 409472 rows created. SQL> commit; Commit complete. SQL> desc test_rebuild Name Null? Type
45
----------------------------------------- -------- - -------------------OWNER VARCHAR2 (30) OBJECT_NAME VARCHAR2 (128) SUBOBJECT_NAME VARCHAR2 (30) OBJECT_ID NUMBER DATA_OBJECT_ID NUMBER OBJECT_TYPE VARCHAR2 (18) CREATED DATE LAST_DDL_TIME DATE TIMESTAMP VARCHAR2 (19) STATUS VARCHAR2 (7) TEMPORARY VARCHAR2 (1) GENERATED VARCHAR2 (1) SECONDARY VARCHAR2 (1) SQL> create index idx_rebuild on test_rebuild (object_name); Index created. Then the three began to highlight open session 15:13:09 session1> alter index idx_rebuild rebuild online; 15:13:30 session2> select rowid, object_name from scott.test_rebuild where rownum <2; ROWID OBJECT_NAME ------------------ -------------------------------- ---------------------------AAABoLAAFAAAAI0AAA old 15:13:41 session2> update scott.test_rebuild set object_name = 'new' where rownum <2; 1 row updated. 15:13:54 SQL> commit; Commit complete. 15:13:57 session3> select * from scott.SYS_JOURNAL_6668; C0 OPTODE PARTNO RID -------------------------------------------------- ----old D 0 AAAAABAAFAAAAI0AAA new I 0 AAAAABAAFAAAAI0AAA When session1 Report Index altered. And then query select * from scott.SYS_JOURNAL_6668; will prompt table does not exist Oracle can be seen in the changes to the index out of the process will modify the value to write to create a temporary table SYS_JOURNAL_xxxx, xxxx that index object_id, can query select index_name, object_id from user_objects get such example update operation, the temporary creation table records the two movements, a representative of the old value of D to delete, the representative I insert a new value, while recording changes rowid. Modifications to the non-indexed column SYS_JOURNAL_xxxx no records. Added: If the building is the combination of the index create index idx_rebuild on test_rebuild (object_name, status) online
46
, The query select * from scott.SYS_JOURNAL_6668; C0 C1 O PARTNO RID ------------------------------ ------- - ---------- - ---------------new invalid I 0 BAEAAAAAFAAAAI0AAA old invalid D 0 BAEAAAAAFAAAAI0AAA Combination of the two columns built an index, it will create the temporary table has two columns C at the beginning
RMAN Backup current controlfile creates a BACKUPSET containing controlfile. You don't have to give the FILENAME Backup controlfile copy <filename> creates a BACKUPSET from a copy of controlfile. You have to give the FILENAME.
RMAN architecture as follows: 1, RMAN tool is RMAN commands, originated in the Oracle version 8, generally in the $ORACLE_HOME /bin directory, you can run the rman this command to start the RMAN tool for backup and restore interface. 2, the service process RMAN service process is a background process, with the RMAN tool for communication between the database and also for the RMAN tool and disk / tape, etc. I/O communication between devices, services, backup and recovery process for all the work in the following circumstances will result in a service process when connecting to the target database is assigned a new channel 3, channel-channel is a service process and I / O devices read and write channels, a channel will correspond to a service process, in the distribution channel, the need to consider the I / O device of the type, I / O parallel processing capacity, I / O devices to create the file size, the largest database file read rate, the maximum number of open files and so on. 4, The target database RMAN backup and recovery is a database, RMAN can back up in addition to the online log, pfile, password file other than data files, control files, archived log, spfile. 5, Recovery catalog to store information on backup and restore a database, is not recommended to create the target database, using recovery catalog can also manage multiple target databases, the backup storage for more information, you can store the backup script. If you do not use recovery catalog, you can use control file instead of recovery catalog, oracle 9i as the functions of automatic backup control file, using a large extent can be replaced to restore control file directory. 6, media management Media Management Layer (MML) is a third-party tools or software for the management of the tape read and write and document tracking management. If you want RMAN backups directly to tape, you must configure the media management, media management tools such as backup software can call the RMAN to back up and recovery. 7, Backup, backup sets and backup time when the issue of backup command, RMAN will create a complete backup, including one to the multiple backup sets, backup set is a logical structure, contains a set of physical files. The physical file corresponding to the backup piece. Backup 47
piece is the most basic physical structure, can produce a disk or tape, you can target database that contains the data files, control files, archived log files and spfile. Backup sets and backup the following provisions: A data file can not span a backup set, but can span the backup piece, data files, control files can be saved in the same backup sets, but can not be stored in the same archive log backup set. Second, start and run RMAN 2.1 Operation requirements 1, The process requires more process and memory needs of a large pool allocation 2, the basic needs of the environment variable ORACLE_SID, ORACLE_HOME, PATH, NLS_LANG, if used in a time-based backup and recovery, need another set NLS_DATE_FORMAT 3, The permissions need SYSDBA system privileges required, if local, can use OS authentication, the remote requires authentication using the password file. 4, version requirements RMAN tool version and the target database must be the same version, if you use a recovery catalog, also need attention: * Create a RMAN recovery catalog script version must be equal to or greater than the version to restore directory where the database creates RMAN recovery catalog script version must be equal to or greater than the target database version 2.2 Basic operation method 9i default nocatalog, do not use the recovery catalog, enter the command rman RMAN command line interface, such as [Oracle @ db oracle] $ $ ORACLE_HOME / bin / rman Recovery Manager: Release 9.2.0.4.0 - Production Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved. RMAN> Connect the target database, you can use the following similar command RMAN> Connect target / 2.3 how to run RMAN commands like 1, a single execution RMAN> backup database; 2, run a command block RMAN> run ( copy datafile 10 to '/ oracle/prod/backup/prod_10.dbf'; ) 3, run the script $ Rman TARGET / @ backup_db.rman RMAN> @ backup_db.rman RMAN> RUN (@ backup_db.rman) Run stored in the recovery catalog script RMAN> RUN (EXECUTE SCRIPT backup_whole_db); 4, SHELL script, if executed in cron, pay attention to set the correct environment variables in the script [Oracle @ db worksh] $ more rmanback.sh #! / Bin / ksh # Set env export ORACLE_HOME = / opt/oracle/product/9.2 export ORACLE_SID = test
48
export NLS_LANG = "AMERICAN_AMERICA.zhs16gbk" export PATH = $ PATH: $ ORACLE_HOME / bin echo "----------------------------- start ------------------ -----------"; date # Backup start $ ORACLE_HOME / bin / rman <<EOF connect target delete noprompt obsolete; backup database format '/ netappdata1/rmanback/tbdb2 /% U_% s.bak' filesperset = 2; exit; EOF echo "------------------------------ end ----------------- -------------"; date 3, RMAN's automatic configuration Oracle 9i can configure the number of parameters such as channel, backup strategies, maintain the information, through a set can be repeatedly used, and set the information in the script does not affect the re-set. RMAN default configuration parameters can be seen through the show all come out. RMAN> show all; RMAN configuration parameters are: CONFIGURE RETENTION POLICY TO REDUNDANCY 1; CONFIGURE BACKUP OPTIMIZATION OFF; CONFIGURE DEFAULT DEVICE TYPE TO DISK; CONFIGURE CONTROLFILE AUTOBACKUP OFF; CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR TYPE DISK TO '% F'; CONFIGURE DEVICE TYPE DISK PARALLELISM 1; CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; CONFIGURE MAXSETSIZE TO UNLIMITED; CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/ U01/app/oracle/product/9.0.2/dbs/snapcf_U02.f'; 3.1 maintain a backup strategy to keep two strategies, one strategy is time to decide at least one backup to restore to the specified date, a redundancy strategy, provides at least a few redundant backup. CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 5 DAYS; CONFIGURE RETENTION POLICY TO REDUNDANCY 5; CONFIGURE RETENTION POLICY TO NONE; In the first strategy is to ensure that at least one backup can be restored to Sysdate-5 time point, the backup will be marked prior to Obsolete. The second strategy described at least three redundant backup exist, if the excess over the three backups will be marked as redundant backup. NONE can maintain a strategy of failure to make a backup, Clear will maintain the strategy to restore the default. 3.2-channel configuration and automatic channel allocation configuration through the CONFIGURE automatic distribution channel, but also through a different channel number to specify the distribution. CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/ U01/ORACLE/BACKUP /% U' CONFIGURE CHANNEL n DEVICE TYPE DISK FORMAT '/ U01/ORACLE/BACKUP /% U' Of course, you can run block, manually specify the channel distribution, so, will replace the default channel allocation. Run (
49
allocate channel cq type disk format = '/ u01/backup /% u.bak' ... ... ) Here are some characteristics of read channel rate limiting Allocate channel ... ... rate = integer The maximum size limit backup piece Allocate channel ... ... maxpiecesize = integer The maximum number of concurrent open files (default 16) Allocate channel ... ... maxopenfile = integer 3.3 Automatic backup control file starting from 9i, you can configure the automatic backup control file, but this set is in standby database failure. By the following command, you can set the automatic backup control file CONFIGURE CONTROLFILE AUTOBACKUP ON; Did not resume the directory for the backup strategy is, this feature is particularly effective, automated backup control file backup or copy Zairen He happened the Order of, or after any change in the database's structure. The configuration can be specified as the backup control file path and format CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR TYPE DISK TO '% F'; During the backup, will produce a snapshot control file, used to control the read consistency of the file, the snapshots can be configured as follows CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/ U01/app/oracle/product/9.0.2/dbs/snapcf_U02.f'; 3.4 Parallel backup set RMAN supports parallel backup and restore, you can also specify a default in the configuration of parallel level. As CONFIGURE DEVICE TYPE DISK PARALLELISM 4; Specified in subsequent backup and recovery, the parallel degree of 4, 4 channels simultaneously open the backup and recovery, of course, can also run the operation block in the specified channel to determine the degree of parallel backup and restore. Determine the number of parallel open channel number. If you specify a channel configuration, will use the specified channel, if the channel is not specified, will use the default channel configuration. 3.5 Configure the default IO device type IO device type can be a disk or tape, in case of default is the disk, the following command can be re-configured. CONFIGURE DEFAULT DEVICE TYPE TO DISK; CONFIGURE DEFAULT DEVICE TYPE TO SBT; Note that if for an IO device, the corresponding configuration changes also needs to be done, such as RMAN> CONFIGURE DEVICE TYPE SBT PARALLELISM 2; 3.6 Configuring the number of multiple backup copies of a single backup set, if that does not worry, you can set up multiple copies of backup sets, such as CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 2; CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 2; If you specify more than one copy, you can configure in the channel configuration or the backup location specified in multiple copies CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/ u01/backup /% U', '/ u02/backup /% U'; RMAN> backup datafile n format '/ u01/backup /% U', '/ u02/backup /% U'; 3.7 Optimizing the backup set in the configuration backup can be optimized, such as
50
CONFIGURE BACKUP OPTIMIZATION ON; If the optimal set to open, will back up data files, archive log, or backup sets to run an optimization algorithm. The same DBID, checkpoint SCN, ResetlogSCN and time normal offline, read-only or normal log off filing the same thread, sequence number and time RESETLOG SCN 3.8 backup file format backup file to customize a variety of formats, as follows % C backup copies of films % D database name % D in the first few days of the mid-(DD) % M in the first few months in the (MM) % F DBID a unique name based on this format in the form of c-IIIIIIIIII-YYYYMMDD-QQ, One IIIIIIIIII the database DBID, YYYYMMDD for the date, QQ is the sequence of a 1-256 % N database name, the right to fill to the maximum of eight characters % U the name of a representative of eight characters and create the backup set time % P Backup piece of the backup set number, starting from a number of documents to create % U a unique file name, on behalf of% u_% p_% c % S Backup set number % T Backup set timestamp % T years day format (YYYYMMDD) Fourth, the RMAN backup RMAN can be used to back up the primary or standby database, such as tablespaces, data files, archive logs, control files, server files and backup sets. 4.1 The file copy of the original file copy, a bit like OS hot backup, you can copy the entire data file to another location, but the results can only be written to the hard disk, and separate files are separate. Example of a file copy run ( allocate channel d1 type disk; allocate channel d2 type disk; allocate channel d3 type disk; copy # first datafile 1 to '$ HOME/prd1.dbf', datafile 2 to '$ HOME/prd2.dbf'; copy # second datafile 3 to '$ HOME/prd3.dbf'; sql 'alter system archive log current'; ) 4.2 backup and backup sets RMAN backup is to generate only regular RMAN backup sets can be identified, so, in addition to other than the backup copy command, all RMAN backup sets created and the corresponding backup pieces. Example of a backup database, open the two channels, the database backup to tape run ( allocate channel t1 type 'SBT_TAPE'; allocate channel t2 type 'SBT_TAPE'; backup filesperset 2 format 'df_% t_% s_% p' database; ) RMAN can also be achieved with multiple mirror backup
51
Run ( allocate channel d1 type disk; allocate channel d2 type disk; allocate channel d3 type disk; SET BACKUP COPIES 3; BACKUP DATAFILE 7 FORMAT '/ tmp /% U','?/ oradata /% U','?/% U'; ); The following are common examples of the backup archive RMAN> sql 'alter system archive log current'; RMAN> backup archivelog all delete input; RMAN> backup archivelog from time '01-jan-00 'until time '30-jun-00'; RMAN> backup archivelog like 'oracle / arc / dest / log%'; RMAN> backup archivelog all; RMAN> backup archivelog from logseq 20 until logseq 50 thread 1; RMAN> backup archivelog from scn 1 until scn 9999; In the RAC environment, because the database is shared, so you can connect to an instance you can back up the entire database, however, because archived logs can be backed up locally, so RAC archive log backup to become more complex, we can connect to the Two examples of the channel to back up two instances of the archive log. run ( ALLOCATE CHANNEL node_c1 DEVICE TYPE DISK CONNECT 'sys / pass @ dbin1'; ALLOCATE CHANNEL node_c2 DEVICE TYPE DISK CONNECT 'sys / pass @ dbin2'; sql 'ALTER SYSTEM ARCHIVE LOG CURRENT'; backup archivelog all delete input format '/ u01/dbbak /% U_% s.bak' filesperset = 5; ) 4.3 Common backup parameters 1, Keep the special parameters can be maintained long-term backup or copy them from the default backup strategy of keeping, such as RMAN> BACKUP DATABASE KEEP UNTIL TIME 2> "to_date ('31-MAR-2002 ',' DD_MM_YYYY)" nologs; RMAN> BACKUP TABLESPACE SAMPLE KEEP FOREVER NOLOGS; That can not keep them NOLOGS since the backup archive log, the default is the LOGS, said that since the parameters of the retention of the backup, the backup if you want a permanent and effective, you can use FOREVER parameters. 2, Tag parameters specify the backup set of signs, up to 30 characters in length, such as RMAN> BACKUP DEVICE TYPE DISK DATAFILE 1 TAG 2> "wkly_bkup"; After the Oracle 92 release, RMAN automatically provides a TAG, the format TAGYYYYMMDDTHHMMSS as TAG20020208T133437, through the backup flag TAG, also can easily recover from a backup set, such as Restore database from tag = 'tag name' 4.4 incremental backup before incremental backup in the notes, we must first understand the difference between incremental and cumulative incremental backups, and incremental backups of the backup and recovery principles. Incremental difference, is the default incremental backup. Cumulative incremental backup, you can see, the difference is incremental backup since the changes in higher-level or equivalent backup block, the cumulative incremental backup is a backup since the changes in higher-level block. Cumulative incremental backups increases the time, but because the recovery time, less need to focus on restoring the backup data, so in order to reduce recovery time, the cumulative incremental backups incremental backups more efficient than the differences. Whatever incremental backup, the Oracle version 9, or the need to compare all the data blocks in the database, this process is also a long process, and because the formation of a number of
52
different incremental backup backup set, make recovery becomes more unreliable and slow, so incremental backups in version 9 is still tasteless, unless very large data warehouse system, no need to choose an incremental backup. Oracle version 10 in the incremental backup made a big improvement, you can make incremental backups into a truly incremental, because the special increment by the log, so RMAN does not need to compare the database of each block, of course the price is the log IO and disk space to pay, full or not suitable for OLTP systems. In addition, version 10 through the back of the merger, so that the result of incremental backups can be combined together, and completely reduced recovery time. Incremental backup requires a foundation, such as level 0 incremental backup is the foundation of all backup, level 0 backup and full backup of the difference is level 0 backup can be used as the basis for other incremental backup backup backup and all is not possible, whether Select incremental backup as your backup strategy, ultimately, you need to have a clear understanding of their own. The following are examples of zero-level backup backup incremental level 0 database; An example of the incremental difference backup incremental level 1 database; An example of the cumulative incremental backup incremental level 1 cumulative database; 4.5 Validate backup checks we can check whether the command to back up, such as data file exists, the existence of bad blocks can not be backed up, such as: BACKUP VALIDATE DATABASE; BACKUP VALIDATE DATABASE ARCHIVELOG ALL; 4.6 Restart the backup for the backup abnormal end, many people may not want to start back up it again, especially back up to 90%, and the reasons for abnormal termination of the backup, then how should we do? RMAN provides a way to start back up, through a simple command, you can only back up that less than 10% of the data. RMAN> BACKUP NOT BACKED UP SINCE TIME 'SYSDATE-14' 2> DATABASE PLUS ARCHIVELOG; 4.7 RMAN The following dynamic performance view has a relationship with the RMAN backup some dynamic performance view, information is obtained from the control file. V$ARCHIVED_LOG V$BACKUP_CORRUPTION V$COPY_CORRUPTION V$BACKUP_DATAFILE V$BACKUP_REDOLOG V$BACKUP_SET V$BACKUP_PIECE V$BACKUP_DEVICE V$CONTROLFILE_RECORD_SECTION Here is a view, we can roughly monitor the extent to RMAN backups. Such as through the following SQL script, will be the backup progress. SQL> SELECT SID, SERIAL #, CONTEXT, SOFAR, TOTALWORK, 2 ROUND (SOFAR / TOTALWORK * 100,2) "% _COMPLETE" 3 FROM V $ SESSION_LONGOPS 4 WHERE OPNAME LIKE 'RMAN%' 5 AND OPNAME NOT LIKE '% aggregate%' 6 AND TOTALWORK! = 0 7 AND SOFAR <> TOTALWORK; SID SERIAL # CONTEXT SOFAR TOTAL WORK% _COMPLETE --- ------- ------- ------- --------- ----------
53
13,751,947,015,360 61.65 128,111,587,128,160 56.36 5, restore and recovery 5.1 General Reduction and Recovery RMAN in the recovery process can be divided into restore (restore) and restore (recover), their meaning is very different, one is the physical meaning of the file to restore and copy, a means to restore database consistency, Therefore, the correct understanding of these two concepts will help to restore the correct database. The RMAN backup, restore operations can only be in use RMAN or RMAN packages do, and for the recovery operation is very flexible, and in addition to RMAN, can be completed in SQLPLUS. Restore and restore a database, you can use the following two simple commands to complete RMAN> restore database; RMAN> recover database; To restore a table space, or restore a data file, restore the database can take relatively less time. RMAN> SQL "ALTER TABLESPACE tools OFFLINE IMMEDIATE"; RMAN> RESTORE TABLESPACE tools; RMAN> RECOVER TABLESPACE tools; RMAN> SQL "ALTER TABLESPACE tools ONLINE"; The database and data files, you can restore from the specified tag RMAN> RESTORE DATAFILE 1 FROM TAG = 'tag name' The recovery time is not fully recovered, may only completely restore the database. RMAN> RUN ( 2> ALLOCATE CHANNEL c1 TYPE DISK; 3> ALLOCATE CHANNEL c2 TYPE DISK; 4> SET UNTIL TIME = '2002-12-09: 11:44:00 '; 5> RESTORE DATABASE; 6> RECOVER DATABASE; 7> ALTER DATABASE OPEN RESETLOGS;) Incomplete recovery in RMAN can also log-based recovery RMAN> RUN ( 2> SET UNTIL SEQUENCE 120 THREAD 1; 3> ALTER DATABASE MOUNT; 4> RESTORE DATABASE; 5> RECOVER DATABASE; # recovers through log 119 6> ALTER DATABASE OPEN RESESTLOGS; 7>) If possible, you can restore data files to a new location SET NEWNAME FOR datafile '/ U01/oradata/tools01.dbf' TO '/ tmp/tools01.dbf'; RESTORE datafile '/ u01/oradata/tools01.dbf'; SWITCH DATAFILE ALL; In addition to restoration of database and data files, we can restore control file, need to start to nomount, using the following command can be Restore controlfile from 'file name' Restore controlfile from autobackup Restore controlfile from tag = '... ...' Under normal circumstances, no recovery archive log, the recovery process will automatically search for the required archive logs, of course, we can specify where to restore. SET ARCHIVELOG DESTINATION TO '/ u02/tmp_restore'; RESTORE ARCHIVELOG ALL; If you use the server parameter file (spfile), RMAN can back up the parameter file, in case of file corruption, you can use RMAN to restore spfile parameter file, in case of no parameter file,
54
using Rman temporary parameter file to start the database Nomount under execute the following command can be Restore controlfile from autobackup Restore controlfile from 'file name' 5.2 The special circumstances of the restoration of lost in the assumption that recovery catalog and control file, only the backup sets and backup pieces, this time may only be restored from the file. The following is a call dbms_backup_restore package, from file recovery example. declare devtype varchar2 (100); done boolean; recid number; stamp number; fullname varchar2 (80); begin devtype: = dbms_backup_restore.deviceallocate ('sbt_tape', params => 'ENV = (NSR_SERVER = backup_server) '); dbms_backup_restore.restoresetdata file; dbms_backup_restore.restorecontrolfileto ( 'First_control_file'); dbms_backup_restore.restorebackuppiece ('backup_piece', done); dbms_backup_restore.copycontrolfile ('first_control_file', 'Second_control_file', recid, stamp, fullname); - Repeat the above copycontrolfile for each control file end; / 5.3 Reduction of inspection and test to check the same with the backup, restore operations can also check whether the normal restore or if the backup set is valid. Such as: RMAN> RESTORE DATABASE VALIDATE; RMAN> VALIDATE BACKUPSET 218; Recover can be tested, test recovery error, the error message recorded in the alert file, pass the test, we can know whether the restore operation completed normally. SQL> RECOVER TABLESPACE sales TEST; SQL> RECOVER DATABASE UNTIL CANCEL TEST 5.4-level recovery block restoration Block Media Recovery (BMR), block the restoration of the smallest unit, the block can reduce recovery time, and data files online. Recovery block when the block must specify the specific number, such as: BLOCKRECOVER datafile 6 BLOCK 3; To recover the bad block information from the alarm and tracking files, table and index analysis, DBV tools or third-party media management tools, and get a specific query. Causes of damage produced block generally intermittent or random IO errors or block of memory error. Block error information is stored in V $ DATABASE_BLOCK_CORRUPTION, use the following command to restore the view out the bad block RMAN> BLOCKRECOVER CORRUPTION LIST 2> RESTORE UNTIL TIME 'sysdate - 10'; Backup bad block information stored in V $ BACKUP_CORRUPTION V $ COPY_CORRUPTION Can use the following command to recover bad blocks. BLOCKRECOVER datafile 2 BLOCK 12, 13 datafile 7 BLOCK 5, 98, 99 datafile 9 BLOCK 19; BLOCKRECOVER TABLESPACE SYSTEM DBA 4194404, 4194405 FROM TAG
55
"Weekly_backup"; BLOCKRECOVER TABLESPACE SYSTEM DBA 4194404, 4194405 RESTORE UNTIL TIME 'SYSDATE-2'; 5.5 Database replication can be used RMAN to copy and clone the database, RMAN provides a special command to complete this operation. As CONNECT TARGET CONNECT AUXILIARY SYS / aux_pwd @ newdb DUPLICATE TARGET DATABASE TO ndbnewh LOGFILE '? / Dbs/log_1.f' SIZE 100M, '? / Dbs/log_2.f' SIZE 100M SKIP READONLY NOFILENAMECHECK; In the above command before, note the following points 1, back up all data on the primary database files, control files, and backup and archive logs generated after the backup, and the need to copy the backup copy to the machine the same directory (if not the same directory, in linux / unix environment may be considered to establish a link to complete). 2, copy the primary database initialization parameter file to the copy machine and make the appropriate changes, such as modifying the database name and instance name 3, in the copy machine to create a new password file, and start copying the database to nomount next. 4, configure the primary database to copy the database or copy a database of network connections to the main database. 5 in the main database or copy the database to run RMAN, are connected to the primary database and copy the database instance. 6, run the copy command, the command will restore all data files, re-create the control file, and start using the new parameter file to restore the database to a consistent state, and finally with resetlog open the database, create the specified redolog. Copy command can also backup from the tape copy, and change the database name, you can also change the database file of the new path and return to the previous point in time, skip the copy of the table space does not need, such as a more complex replication command: RUN ( ALLOCATE AUXILIARY CHANNEL newdb1 DEVICE TYPE sbt; DUPLICATE TARGET DATABASE TO newdb DB_FILE_NAME_CONVERT = ('/ h1/oracle/dbs/trgt /','/ h2/oracle/oradata/newdb /') UNTIL TIME 'SYSDATE-1' # specifies incomplete recovery SKIP TABLESPACE cmwlite, drsys, example # skip desired tablespaces PFILE =? / Dbs / initNEWDB.ora lOGFILE GROUP 1 ('? / Oradata/newdb/redo01_1.f', '? / Oradata/newdb/redo01_2.f') SIZE 200K, GROUP 2 ('? / Oradata/newdb/redo02_1.f', '? / Oradata/newdb/redo02_2.f') SIZE 200K GROUP 3 ('? / Oradata/newdb/redo03_1.f', '? / Oradata/newdb/redo03_2.f') SIZE 200K REUSE; ) 5.6 Using RMAN to create standby database using RMAN to create standby database can be used two ways, one is conventional Restore command from the main database using backup control file copy in the past, to start to back-mount standby database, this time to the standby
56
database there is no data file. And then back-end, start the RMAN command, connect to the database (DBID as the main database), the master database from backup to restore RMAN copied out. Finally, like other methods, and access to the management of backup recovery mode. Another way is to copy the commands, such as DUPLICATE TARGET DATABASE FOR STANDBY NOFILENAMECHECK; The following detailed description of this process. 1, create a backup parameter file and password file, start the standby database to the next nomount 2, back up the primary database and standby control file and all archives RMAN> Backup Database; RMAN> Backup current controlfile for standby; RMAN> sql "Alter System Archive Log Current"; RMAN> Backup filesperset 10 ArchiveLog all delete input; 3, copy the backup to the standby database, all the same path 4, configure the primary database to the standby database connection 5, start RMAN rman target / auxiliary sys / change_on_install @ STANDBY 6, start creating standby database RMAN> duplicate target database for standby dorecover nofilenamecheck; The whole process including the creation of the standby control file, start to the Mount, the parameter file path specified in the reduction of conversion and data files, archive log restore so. 7, the final restoration of the log and start to manage recovery mode. SQL> recover standby database; SQL> alter database recover managed standby database disconnect; 6, RMAN management 6.1Report command Report command can detect those files to backup, the backup file can be deleted and those who can not obtain information, such as the reporting database can be backed up data files for all objects Report schema Or RMAN> REPORT SCHEMA AT TIME 'SYSDATE-14'; RMAN> REPORT SCHEMA AT SCN 1000; RMAN> REPORT SCHEMA AT SEQUENCE 100 THREAD 1; Report need backup of data files Report need backup [redundancy | days | incremental n]; Report out of date or unavailable data file backup and copy Report obsolete [orphan] Report not available or inaccessible data file information Report unrecoverable [database] 6.2 List command List command is usually used to view the backup and copy information, such as view the backup information List backup View the backup summary information List backup summary View the file copy of the information List copy See detailed backup information List backup of datafile 'file name' list incarnation of database;
57
6.3 Crosscheck command checks the disk or tape backup or copy is correct, and update the status of backup or copy, if incorrect, will be marked as expired (expired) Crosscheck backup; Crosscheck archivelog all; Delete [noprompt] expired backup command to delete expired backups can also be used to view the report of the List LIST EXPIRED BACKUP; LIST EXPIRED BACKUP SUMMARY; 6.4 Delete command Delete command can be used to delete the backup, or to remove abandoned or expired backup sets, such as delete the specified backup sets and backup pieces RMAN> DELETE BACKUPPIECE 101; RMAN> DELETE CONTROLFILECOPY '/ tmp/control01.ctl'; RMAN> DELETE BACKUP OF TABLESPACE users DEVICE TYPE sbt; Remove outdated or obsolete backup RMAN> DELETE EXPIRED BACKUP; RMAN> DELETE NOPROMPT OBSOLETE; RMAN> DELETE OBSOLETE REDUNDANCY = 3; RMAN> DELETE OBSOLETE RECOVERY WINDOW OF 7 DAYS; Remove the backup archive RMAN> DELETE NOPROMPT ARCHIVELOG UNTIL SEQUENCE = 300; 7, recovery catalog Oracle version 9, because the control files automatically backed up, you can become a great extent do not need to restore catalog, but to restore the directory using the following benefits have only been restored some order catalog support (for 9i, the special operation is to restore directory statements only) * Be able to retain more historical backup information to manage a recovery catalog database, if multiple targets with the backup in 9i ago, lost control of files not restored directory will be hard to recover without recovery catalog, and place the structure on De change, time of recovery requires careful operation can storage backup and recovery of the script can see, is mainly to retain more of Beifenxinxi Yu Fang Bian's Guanli multiple Mubiao database, this target database in the Zhongduo case, is can be considered. 7.1 Creating restore directory attention, recovery catalog and target database do the same machine, but also relatively small size requirements. SQL> create user RMAN identified by RMAN 2 temporary tablespace TEMP 3 default tablespace RCVCAT 4 quota unlimited on RCVCAT; SQL> grant recovery_catalog_owner to RMAN; RMAN> create catalog RMAN> register database; Recovery catalog can be used to upgrade and delete the following command RMAN> UPGRADE CATALOG; RMAN> DROP CATALOG; 7.2 recovery catalog management to support the following command to restore directory (CREATE | UPGRADE | DROP) CATALOG (CREATE | DELETE | REPLACE | PRINT) SCRIPT LIST INCARNATION REGISTER DATABASE REPORT SCHEMA AT TIME
58
RESET DATABASE RESYNC CATALOG 1, Resync command Resync can be synchronized between the database and recovery catalog information, in practice, rman can generally be automatically synchronized. In the following circumstances need to synchronize changes in the physical structure of the database data file is to change the size of the increase or remove the rollback tablespace to create and delete the archive logs to generate 10 per 2, Reset command after the target database resetlogs need to reset the recovery catalog. Reset command to reset the recovery catalog. 7.3 recovery catalog view to restore directory itself has a view of the target database for the storage and backup information, such as the restoration of directory-related view RC_DATABASE RC_DATAFILE RC_STORED_SCRIPT RC_STORED_SCRIPT_LINE RC_TABLESPACE By the following command to view information select * from rc_database; 7.4 Storage store script script RMAN> creata script level0backp ( backup incremental level 0 format '/ u01/db01/backup /% U' filesperset 5 database plus archivelog delete input; sql 'alter database archive log current'; ) Scripting RMAN> run (execute script Level0backup;) Update script RMAN> replace script level0backup ( ... ... ) Remove Script RMAN> delete script Level0backup; View Script RMAN> print script level0backup; Section RMAN architecture and operating method RMAN for common backup methods Reduction and Recovery RMAN Management method and common RMAN recovery catalog and restore order to use the directory command in Appendix abandoned and replaced by a new version of the old command syntax of the command current 9.2 REPLICATE RESTORE CONTROLFILE FROM ... SET AUTOLOCATE Now enabled by default. ALLOCATE CHANNEL FOR DELETE Not available
59
901 ALLOCATE CHANNEL ... TYPE CONFIGURE CHANNEL ... DEVICE TYPE 9.0.1 ALLOCATE CHANNEL ... KBYTES CONFIGURE CHANNEL ... MAXPIECESIZE 901 ALLOCATE CHANNEL ... READRATE CONFIGURE CHANNEL ... RATE 9.0.1 ... ARCHIVELOG ... LOGSEQ ... ARCHIVELOG ... SEQUENCE 9.0.1 BACKUP ... SETSIZE BACKUP ... MAXSETSIZE 9.0.1 CHANGE ... CROSSCHECK CROSSCHECK 9.0.1 CHANGE ... DELETE DELETE 9.0.1 REPORT ... AT LOGSEQ REPORT ... AT SEQUENCE 9.0.1 SET AUXNAME CONFIGURE AUXNAME A practical script, including the RAC database backup and archiving log shell script [Oracle @ db worksh] $ more rmanback.sh #! / Bin / sh # Set env export ORACLE_HOME = / opt/oracle/product/9.2 export ORACLE_SID = db2in1 export NLS_LANG = "AMERICAN_AMERICA.zhs16gbk" export PATH = $ PATH: $ ORACLE_HOME / bin: / sbin: / usr / sbin echo "----------------------------- start ------------------ -----------"; date # Backup start $ ORACLE_HOME / bin / rman <<EOF connect target delete noprompt obsolete; backup database include current controlfile format '/ rmanback/db2 /% U_% s.bak' filesperset = 2; run ( ALLOCATE CHANNEL node_c1 DEVICE TYPE DISK CONNECT 'sys / pass @ db1in1'; ALLOCATE CHANNEL node_c2 DEVICE TYPE DISK CONNECT 'sys / pass @ db2in2'; sql 'ALTER SYSTEM ARCHIVE LOG CURRENT'; backup archivelog all delete input format '/ rmanback/db2 /% U_% s.bak' filesperset = 5; ) list backup; exit; EOF echo "------------------------------ end ----------------- -------------"; date Why RMAN Backup On top of all of the good things you have said there are a couple of other very very good things about RMAN: 1. It is much (MUCH) faster than OS file copies by a long shot. I can fully backup small databases even on Windoze in a few minutes. 2. It deals with the backup process at the block level so it waits for each block to become consistent to back it up, therfore no "cracked blocks" like file copying. 3. You can "easily" parallelize backup and much more importantly it can parallelize recovery.
60
4. Backup retension scheduling is built-in, no more do I delete this backup or not, it's part of your design and deployment process. 5. It can manage the archived redo log automatically for you (getting them off the system to somewhere safe is important) including deleting the old logs. 6. It deals with cold backups (if anybody actually wants to do one anymore). 7. One RMAN catalog database can manage a complete enterprise, Unix, Windoze who cares and it can do it concurrently because the Oracle database Server is doing the real work. 8. Testing backups without restoral is built-in and that's nice as well. 9. No more putting tablespaces in backup mode and hammering the daylights out of the redo log system. 10. Making standby databases and cloning is way simpler under RMAN becuse it is designed to do that for you.
Forcing a checkpoint
To force a checkpoint use
Events
Introduction Enabling Events Listing All Events Listing Enabled Events Event Reference
61
Introduction
There are four types of numeric events
Immediate dumps Conditional dumps Trace dumps Events that change database behaviour
Every event has a number which is in the Oracle error message range e.g. event 10046 is ORA-10046 Each event has one or more levels which can be
range e.g. 1 to 10 bitmask e.g. 0x01 0x02 0x04 0x08 0x10 flag e.g. 0=off; 1=on identifier e.g. object id, memory address etc
Note that events change from one release to another. As existing events become deprecated and then obsolete, the event number is frequently reused for a new event. Note also that the message file sometimes does not reflect the events in the current release. Many events change the behaviour of the database. Some testing events may cause the database to crash. Never set an event on a production database without obtaining permission from Oracle support. In addition, never set an event on a development database without first making a backup.
Enabling Events
Events can be enabled at instance level in the init.ora file using
event = "10248 trace name context forever, level 10:10249 trace name context forever, level 10"
2 - List events on consecutive lines e.g.
event = "10248 trace name context forever, level 10" event = "10249 trace name context forever, level 10"
Note that in some versions of Oracle, the keyword "event" must be in the same case (i.e. always uppercase or always lowercase). Events can also be enabled at instance level using the ALTER SYSTEM command
ALTER SYSTEM SET EVENTS 'event trace name context forever, level level';
Events are disabled at instance level using
ALTER SESSION SET EVENTS 'event trace name context forever, level level';
Events are disabled at session level using
62
ORADEBUG SETORAPID 8 ORADEBUG EVENT 10046 TRACE NAME CONTEXT FOREVER, LEVEL 12
To disable an event in a process use
SET SERVEROUTPUT ON DECLARE err_msg VARCHAR2(120); BEGIN dbms_output.enable (1000000); FOR err_num IN 10000..10999 LOOP err_msg := SQLERRM (-err_num); IF err_msg NOT LIKE '%Message '||err_num||' not found%' THEN dbms_output.put_line (err_msg); END IF; END LOOP; END; /
On Unix systems event messages are in the formatted text file
$ORACLE_HOME/rdbms/mesg/oraus.msg
To print detailed event messages (Unix only) use the following script
event=10000 while [ $event -ne 10999 ] do event=`expr $event + 1` oerr ora $event done
63
FOR l_event IN 10000..10999 LOOP dbms_system.read_ev (l_event,l_level); IF l_level > 0 THEN dbms_output.put_line ('Event '||TO_CHAR (l_event)|| ' is set at level '||TO_CHAR (l_level)); END IF; END LOOP; END; / -----------Check background process using command SELECT ksbdd.ksbddidn, ksmfsv.ksmfsnam, ksbdd.ksbdddsc FROM x$ksbdd ksbdd, x$ksbdp ksbdp, x$ksmfsv ksmfsv WHERE ksbdd.indx = ksbdp.indx AND ksbdp.addr = ksmfsv.ksmfsadr ORDER BY ksbdd.ksbddidn /
Redo
All changes to the database are recorded by redo. Redo includes all changes to datafiles, but does not include changes to control files or the parameter file. Redo is initially written to online redo logs. The contents of a redo log file depend on a combination of Oracle version, operating system and server architecture. In general redo logs written on one architecture cannot be read on another. There are a few exceptions to this rule. For example, in Oracle 10.2 a redo log written in Linux can be read by a Windows database.
Redo Threads
Each online redo log has a thread number and a sequence number. The thread number is mainly relevant in RAC databases where there can be multiple threads; one for each instance. The thread number is not necessarily the same as the instance number. For single instance databases there is only one redo log thread at any time.
Log Switches
Log switches occur when the online redo log becomes full. Alternatively log switches can be triggered externally by commands such as:
64
When a log switch occurs, the sequence number is incremented and redo continues to be written to the next file in the sequence. If archive logging is enabled, then following a low switch the completed online redo log will be copied to the archive log destination(s) either by the ARCH background process or the LNSn background process depending on the configuration.
Other data is stored in the header. Note that the End SCN is actually the Start SCN of the next redo log file.
Redo Blocks
The body of the redo log file is used to store redo blocks. Each redo block has a 16 byte header (Oracle 9.2 and 10.2). The remainder of each redo block is used to store redo records.
Redo Records
Redo records are a logical structure. The upper size limit is probably 65536 bytes. Redo records can therefore span multiple physical redo blocks. A physical redo block can also contain multiple redo records. Each redo record has a header. The VLD field in the redo record header specifies the type of the redo record. The size of the redo record header varies depending on the type. In Oracle 9.2 the redo record header is normally 12 bytes, though they can occasionally increase in size to 28 bytes. In Oracle 10.2 the redo record header is normally 24 bytes, though under some circumstances they can increase to 68 bytes. The following is an example of a redo record header from Oracle 10.2:
REDO RECORD - Thread:1 RBA: 0x000092.00000193.0088 LEN: 0x0050 VLD: 0x01 SCN: 0x0000.00181068 SUBSCN: 1 05/07/2009 21:53:48
The header includes the following fields
Thread - redo log thread number RBA - redo byte address - address of redo record within redo log. Format is <sequence_number>.<block_number>.<offset> LEN - length of redo record in bytes including header VLD - see below SCN - system change number of redo record
65
The VLD field determines the size of the redo record header. Known values are shown in the following table. These values may vary from one release to another.
Value Description 0 The contents are not valid 1 Includes change vectors 2 Includes commit SCN 4 Includes dependent SCN New SCN mark record. SCN allocated exactly at this point in the KCRNMARK 8 redo log by this instance Old SCN mark record. SCN allocated at or before this point in the KCROMARK 16 redo. May be allocated by another instance New SCN was allocated to ensure redo for some block would be KCRORDER 32 ordered by inc/seq# when redo sorted by SCN
Change Vectors
A redo record consists of one or more change records known as change vectors. Each change vector consists of:
The size of the change header is 28 bytes in both Oracle 9.2 and 10.2. The list of element lengths has a two byte header specifying the overall length of the element length list in bytes. The length of each element is stored in a two byte field. Finally if the structure does not align on a four byte boundary, a further two byte field is appended. The list of elements consists of one or more elements aligned on a four byte boundary. Element sizes can range from four bytes to at least 32K. If supplemental logging is enabled then for update operations (11.5), additional elements are appended to the change vector containing the primary key, unique key or column values of the row.
Operation Codes
Each change vector has an operation code. In Oracle 9.2 there were over 150 redo log operations; this number has grown significantly in Oracle 10.2 though the exact figure is not known. The operation code consists of a major number and a minor number. The major number describes the level in the kernel where the redo is generated. The following table shows common levels:
Level 4 5 10 11 13 14
Description Block Cleanout Transaction Layer (Undo) Index Operation Table Operation (DML) Block Allocation Extent Allocation 66
17 18 19 20 22 23 24
Backup Management Online Backup Direct Load Transaction Metadata (LogMiner) Space Management (ASSM) Block Write (DBWR) DDL Statement
For each level there is one or more subcode. Follow the hyperlinks for more details on individual operations:
Level 4 - Block Cleanout Level 5 - Transaction Layer (Undo) Level 10 - Index Operation Level 11 - Table Operation (DML) Level 13 - Block Allocation Level 14 - Extent Allocation Level 17 - Backup Management Level 18 - Online Backup Level 19 - Direct Load Level 20 - Transaction Metadata (LogMiner) Level 22 - Space Management (ASSM) Level 23 - Block Write (DBWR) Level 24 - DDL Statement
Log File Dumps Symbolic dumps can be created for both online redo logs and archived redo logs using the following syntax:
ALTER SYSTEM DUMP LOGFILE '<filename>';
For online redo logs the filename of the current redo log can be obtained using the following SQL:
SELECT member FROM v$logfile WHERE group# = ( SELECT group# FROM v$log WHERE status = 'CURRENT' );
67