OCA/OCP Oracle Database 11g All-in-One Exam Guide 536 B. It will be executed after the outer query. C. It will be executed concurrently with the outer query. D. It will be executed once for every row in the EMPLOYEES table. 5. Consider the following statement: select last_name from employees join departments on employees.department_id = departments.department_id where department_name='Executive'; and this statement: select last_name from employees where department_id in (select department_id from departments where department_name='Executive'); What can be said about the two statements? (Choose two correct answers.) A. The two statements should generate the same result. B. The two statements could generate different results. C. The first statement will always run successfully; the second statement will fail if there are two departments with DEPARTMENT_NAME ‘Executive’. D. Both statements will always run successfully, even if there are two departments with DEPARTMENT_NAME ‘Executive’. 6. What are the distinguishing characteristics of a scalar subquery? (Choose two correct answers.) A. A scalar subquery returns one row. B. A scalar subquery returns one column. C. A scalar subquery cannot be used in the SELECT list of the parent query. D. A scalar subquery cannot be used as a correlated subquery. 7. Which comparison operator cannot be used with multiple-row subqueries? (Choose the best answer.) A. ALL B. ANY C. IN D. NOT IN E. All of the above can be used 8. Consider this statement: select last_name, (select count(*) from departments) from employees where salary = (select salary from employees); What is wrong with it? (Choose the best answer.) A. Nothing is wrong—the statement should run without error. B. The statement will fail because the subquery in the SELECT list references a table that is not listed in the FROM clause. Chapter 13: Subqueries and Set Operators 537 PART II C. The statement will fail if the conditional subquery returns more than one row. D. The statement will run but is extremely inefficient because of the need to run the second subquery once for every row in EMPLOYEES. 9. Which of the following statements are equivalent? (Choose two answers.) A. select employee_id from employees where salary < all (select salary from employees where department_id=10); B. select employee_id from employees where salary < (select min(salary) from employees where department_ id=10); C. select employee_id from employees where salary not >= any (select salary from employees where department_id=10); D. select employee_id from employees e join departments d on e.department_id=d.department_id where e.salary < (select min(salary) from employees) and d.department_ id=10; 10. Consider this statement, which is intended to prompt for an employee’s name and then find all employees who have the same job as the first employee: select last_name,employee_id from employees where job_id = (select job_id from employees where last_name = '&Name'); What would happen if a value were given for &Name that did not match with any row in EMPLOYEES? (Choose the best answer.) A. The statement would fail with an error. B. The statement would return every row in the table. C. The statement would return no rows. D. The statement would return all rows where JOB_ID is NULL. 11. Which of these set operators will not sort the rows? (Choose the best answer.) A. INTERSECT B. MINUS C. UNION D. UNION ALL 12. Which of these operators will remove duplicate rows from the final result? (Choose all that apply.) A. INTERSECT B. MINUS C. UNION D. UNION ALL OCA/OCP Oracle Database 11g All-in-One Exam Guide 538 13. If a compound query contains both a MINUS and an INTERSECT operator, which will be applied first? (Choose the best answer.) A. The INTERSECT, because INTERSECT has a higher precedence than MINUS. B. The MINUS, because MINUS has a higher precedence than INTERSECT. C. The precedence is determined by the order in which they are specified. D. It is not possible for a compound query to include both MINUS and INTERSECT. 14. There are four rows in the REGIONS table. Consider the following statements and choose how many rows will be returned for each: 0, 4, 8, or 16. A. select * from regions union select * from regions B. select * from regions union all select * from regions C. select * from regions minus select * from regions D. select * from regions intersect select * from regions 15. Consider this compound query: select empno, hired from emp union all select emp_id,hired,fired from ex_emp; The columns EMP.EMPNO and EX_EMP.EMP_ID are integer; the column EMP.HIRED is timestamp; the columns EX_EMP.HIRED and EX_EMP.FIRED are date. Why will the statement fail? (Choose the best answer.) A. Because the columns EMPNO and EMP_ID have different names B. Because the columns EMP.HIRED and EX_EMP.HIRED are different data types C. Because there are two columns in the first query and three columns in the second query D. For all of the reasons above E. The query will succeed 16. Which line of this statement will cause it to fail? (Choose the best answer.) A. select ename, hired from current_staff B. order by ename C. minus D. select ename, hired from current staff E. where deptno=10 F. order by ename; 17. Study this statement: select ename from emp union all select ename from ex_emp; In what order will the rows be returned? (Choose the best answer.) A. The rows from each table will be grouped and within each group will be sorted on ENAME. Chapter 13: Subqueries and Set Operators 539 PART II B. The rows from each table will be grouped but not sorted. C. The rows will not be grouped, but will all be sorted on ENAME. D. The rows will be neither grouped nor sorted. Self Test Answers 1. þ A, B, C, and E. Subqueries can be used at all these points. ý D and F. A subquery cannot be used in the GROUP BY and ORDER BY clauses of a query. 2. þ D. Subquery nesting can be done to many levels. ý A, B, and C. A and C are incorrect because subqueries can be nested. B is incorrect because the number of rows returned is not relevant to nesting subqueries, only to the operators being used. 3. þ A. The result set of the inner query is needed before the outer query can run. ý B, C, and D. B and C are not possible because the result of the subquery is needed before the parent query can start. D is incorrect because the subquery is only run once. 4. þ D. This is a correlated subquery, which must be run for every row in the table. ý A, B, and C. The result of the inner query is dependent on a value from the outer query; it must therefore be run once for every row. 5. þ A and D. The two statements will deliver the same result, and neither will fail if the name is duplicated. ý B and C. B is incorrect because the statements are functionally identical, though syntactically different. C is incorrect because the comparison operator used, IN, can handle a multiple-row subquery. 6. þ A and B. A scalar subquery can be defined as a query that returns a single value. ý C and D. C is incorrect because a scalar subquery is the only subquery that can be used in the SELECT list. D is incorrect because scalar subqueries can be correlated. 7. þ E. ALL, ANY, IN, and NOT IN are the multiple-row comparison operators. ý A, B, C, and D. All of these can be used. 8. þ C. The equality operator requires a single-row subquery, and the conditional subquery could return several rows. ý A, B, and D. A is incorrect because the statement will fail in all circumstances except the unlikely case where there is zero or one employee. B is incorrect because this is not a problem; there need be no relationship between the source of data for the inner and outer queries. D is incorrect because the subquery will only run once; it is not a correlated subquery. OCA/OCP Oracle Database 11g All-in-One Exam Guide 540 9. þ A and B are identical. ý C is logically the same as A and B but syntactically is not possible; it will give an error. D will always return no rows, because it asks for all employees who have a salary lower than all employees. This is not an error but can never return any rows. The filter on DEPARTMENTS is not relevant. 10. þ C. If a subquery returns NULL, then the comparison will also return NULL, meaning that no rows will be retrieved. ý A, B, and D. A is incorrect because this would not cause an error. B is incorrect because a comparison with NULL will return nothing, not everything. D is incorrect because a comparison with NULL can never return anything, not even other NULLs. 11. þ D. UNION ALL returns rows in the order that they are delivered by the queries that make up the compound query. ý A, B, and C. INTERSECT, MINUS, and UNION all use sorting as part of their execution. 12. þ A, B, and C. INTERSECT, MINUS, and UNION all remove duplicate rows. ý D. UNION ALL returns all rows, duplicates included. 13. þ C. All set operators have equal precedence, so the precedence is determined by the sequence in which they occur. ý A, B, and D. A and B are incorrect because set operators have equal precedence—though this may change in future releases. D is incorrect because many set operators can be used in one compound query. 14. þ A = 4; B = 8; C = 0; D = 4. ý Note that 16 is not used; that would be the result of a Cartesian product query. 15. þ C. Every query in a compound query must return the same number of columns. ý A, B, D, and E. A is incorrect because the columns can have different names. B is incorrect because the two columns are of the same data type group, which is all that is required. It therefore follows that D and E are also incorrect. 16. þ B. You cannot use ORDER BY for one query of a compound query; you may only place a single ORDER BY clause at the end. ý A, C, D, E, and F. All these lines are legal. 17. þ B. The rows from each query will be grouped together, but there will be no sorting. ý A, C, and D. A is not possible with any syntax. C is incorrect because that would be the result of a UNION, not a UNION ALL. D is incorrect because UNION ALL will return the rows from each query grouped together. PART III Advanced Database Administration ■ Chapter 14 Configuring the Database for Backup and Recovery ■ Chapter 15 Back Up with RMAN ■ Chapter 16 Restore and Recover with RMAN ■ Chapter 17 Advanced RMAN Facilities ■ Chapter 18 User-Managed Backup, Restore, and Recovery ■ Chapter 19 Flashback ■ Chapter 20 Automatic Storage Management ■ Chapter 21 The Resource Manager ■ Chapter 22 The Scheduler ■ Chapter 23 Moving and Reorganizing Data ■ Chapter 24 The AWR and the Alert System ■ Chapter 25 Performance Tuning ■ Chapter 26 Globalization ■ Chapter 27 The Intelligent Infrastructure This page intentionally left blank CHAPTER 14 Configuring the Database for Backup and Recovery Exam Objectives In this chapter you will learn to • 052.14.1 Identify the Types of Failure That Can Occur in an Oracle Database • 052.14.2 Describe Ways to Tune Instance Recovery • 052.14.3 Identify the Importance of Checkpoints, Redo Log Files, and Archived Log files • 052.14.5 Configure ARCHIVELOG Mode • 053.2.1 Configure Multiple Archive Log File Destinations to Increase Availability • 052.14.4 Understand the Flash Recovery Area • 053.2.3 Configure the Flash Recovery Area • 053.2.4 Use the Flash Recovery Area 543 OCA/OCP Oracle Database 11g All-in-One Exam Guide 544 Perhaps the most important aspect of a database administrator’s job is to ensure that the database does not lose data. The mechanisms of redo and undo ensure that it is absolutely impossible to corrupt the database no matter what the DBA does or does not do. After working through the section of this chapter titled “Instance Recovery,” you will be able to prove this. However, it is possible for an Oracle database to lose data because of physical damage if the DBA does not take appropriate precautions. From release 9i onward, an Oracle database can be configured so that no matter what happens the database will never lose a single row of committed data. It is also possible to configure an environment for 100 percent availability. This chapter will go through the concepts behind Oracle’s backup and recovery mechanisms: the enabling structure within which you will configure whatever level of data security and availability is demanded by your organization. Backup and Recovery Issues This is an area where the DBA cannot work in isolation. The amount of downtime and data loss that an organization can stand is a matter for the business analysts, not the DBA. The business analysts in conjunction with the end users will determine the requirement, and the DBA will then configure the database appropriately. To do this, you will require the cooperation of the system administrators and other support staff. Sometimes there will be budget constraints to consider: a zero data loss and 100 per- cent uptime environment will be far more expensive to configure than an environment that does not have such guarantees. Performance may also tend to degrade as the uptime and data loss requirements become more demanding. The end result of considering the business requirements, performance, and financial considerations is often a compromise. It is vitally important that this be documented, usually in the form of a service level agreement that details exactly what is being done, and what the effects will be of various types of failure. For you as the DBA, there is no such thing as “good” or “bad” database administration in this environment; there is only whether the procedures you are following confirm to the service level agreement, or not. This protects the DBA from criticism (you can’t be fired for doing what it has been agreed that you will do) and guarantees the end users the level of service that they have agreed they require. The three areas of a service level agreement relevant to backup and recovery are the mean time between failures (the MTBF), the mean time to recover (the MTTR), and loss of data. Your objective as DBA is to increase the MTBF while reducing the MTTR and data loss. MTBF refers to how frequently the database becomes unavailable. For some organizations, the database must be available all the time. Real-time systems, such as satellite flight control or process control in an oil refinery, must run all the time; even a few minutes’ failure can be catastrophic. Oracle provides two advanced options that can contribute to 100 percent availability: RAC and Streams. A RAC, or clustered, database consists of one physical database opened by multiple instances on multiple computers. If any one computer or instance fails, the database remains open for use through a surviving instance. RAC protects against hardware, operating system, and Chapter 14: Configuring the Database for Backup and Recovery 545 PART III software failure. The Streams environment consists of two or more databases on separate computers, which may be geographically widely separated. The Streams mechanism takes care of keeping the two databases synchronized, in real time if necessary. Users can connect to either, and changes made on each database are published to the other database. If one database becomes unavailable for any reason, work can continue on the other. Streams goes further than RAC for fault tolerance, because it protects against disk and network failure as well as hardware, operating system, and software failure. MTTR refers to the length of downtime following a failure. For many organizations, this is actually more significant than losing data. For example, every minute that the billing system for a telco is unavailable could mean subscribers are getting free cell phone calls, and extended downtime could cost a lot more money than losing a few minutes of data. Clearly the ideal is to have the system available all the time, but when it does fail, it is your duty to bring it back up with minimal delay. A critical part of reducing MTTR is practice. When a database crashes, you will be under enormous pressure to open it as soon as possible. It is vital to be prepared. You do not want to be looking up things in manuals before taking appropriate action. Practice, practice, practice—if you can’t test recovery on a live system, test on a backup system. Run simulations of all possible types of failure, and prepare for all eventualities. The third objective is to minimize data loss. Some organizations cannot stand any data loss whatsoever. For example, a stock trading system must not lose a trade. It might be preferable to have no trades taking place—temporarily close the exchange—than to take the risk of losing a transaction. In other environments it may be acceptable to lose a few hours of data, but make sure that this is documented. From release 9i onward, an Oracle database can be configured for zero data loss, under any circumstances whatsoever. This is done through Data Guard. In a Data Guard system the live database, known as the primary, is protected by one or more standby databases. The standby is continually updated with all the changes applied to the primary. These changes can be propagated in real time if necessary. These three advanced options—RAC, Streams, and Data Guard—all have performance implications (which may be for better or for worse, depending on how things are set up and what the objective is) and should not be embarked upon lightly. They are beyond the scope of the OCP examinations, but knowledge of them is required for Oracle University’s more advanced qualifications. Any fault-tolerant environment will rely heavily on hardware redundancy. This is where you cannot work independently of the system administrators. If a datafile becomes unavailable because of a disk failure, your database will also (at least partially) become unavailable. Your objective of increasing the MTBF must be aligned with your system administrators’ targets for disk redundancy and replacement. Similarly, you are totally dependent on the network. If your users cannot connect, they will not care whether the reason is that a router has failed or the database has crashed. Your targets for the database must be set with the whole IT environment in mind, and the service level agreements must make this clear. Your role as DBA is to ensure that you can meet the agreed standards for uptime and data loss, no matter what the nature of the failure. . Oracle database to lose data because of physical damage if the DBA does not take appropriate precautions. From release 9i onward, an Oracle database can be configured so that no matter what happens. correlated subquery. OCA/ OCP Oracle Database 11g All-in-One Exam Guide 540 9. þ A and B are identical. ý C is logically the same as A and B but syntactically is not possible; it will give an error two databases synchronized, in real time if necessary. Users can connect to either, and changes made on each database are published to the other database. If one database becomes unavailable