01.09.2016 Views

Beginning Oracle Database 11g Administration From Novice to Professional

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 11 FIXING PROBLEMS 243<br />

Consider a query that begins at 9 a.m. and completes at 10 a.m. Suppose that the<br />

query is counting the number of records in a very large table and suppose that the table<br />

is very active—that is, records are constantly being inserted in<strong>to</strong> the table. Suppose that<br />

<strong>Oracle</strong>’s answer <strong>to</strong> the query is ten billion records. Does the answer indicate the number<br />

of records at 9 a.m., at 10 a.m., or at some intermediate time in between those times?<br />

If we were working with other database technologies such as IBM’s DB2 or Informix,<br />

Microsoft’s SQL Server, or Sybase, the answer would be 10 a.m. because the query<br />

would not complete until it had locked all the records in the table; it would wait for all<br />

insert, update, and delete operations <strong>to</strong> complete and it would block others from starting.<br />

In other words, readers block writers, and writers block readers. With <strong>Oracle</strong>, on<br />

the other hand, readers do not block writers, and writers do not block readers. Instead,<br />

<strong>Oracle</strong> determines what the answer <strong>to</strong> the query would have been at the instant the<br />

query started, that is, at 9 a.m.; this manner of operation is called read consistency. 3 Read<br />

consistency extends <strong>to</strong> a single query by default or can extend <strong>to</strong> an entire transaction.<br />

For example, the entire contents of a database can be exported by using read- consistent<br />

mode <strong>to</strong> ensure that there are no conflicts or inconsistencies in the data.<br />

To ensure read consistency, <strong>Oracle</strong> must construct a snapshot of the database at the<br />

time the query or transaction started. If the required data has changed since the query<br />

started, <strong>Oracle</strong> must obtain a prior version of the data from the rollback segments. However,<br />

the rollback segments are a shared resource, and the information they contain may<br />

be overwritten if other transactions need the space. Therefore, <strong>Oracle</strong> may not be able <strong>to</strong><br />

construct the snapshot—that is, the snapshot may be <strong>to</strong>o old <strong>to</strong> be reconstructed.<br />

Prior <strong>to</strong> <strong>Oracle</strong> 9i, the number and size of rollback segments was left <strong>to</strong> the database<br />

administra<strong>to</strong>r. <strong>Beginning</strong> with <strong>Oracle</strong> 9i, this task should be entrusted <strong>to</strong> <strong>Oracle</strong> by changing<br />

the value of the setting <strong>to</strong> . If the error occurs,<br />

increase the value of the setting and ensure, through trial and error, that<br />

the tablespace specified by the setting is big enough, adding data files or<br />

increasing the size of data files as necessary. The default value of the setting<br />

is 900 seconds (15 minutes); a large value such as 14,400 (4 hours) may be more appropriate,<br />

depending on the circumstances, but must be supported by an undo tablespace that<br />

is large enough. Note that the error can never be completely avoided<br />

because it is always possible for queries <strong>to</strong> take so long that the available resources are<br />

exhausted. Also, transactions that modify the data typically take precedence over transactions<br />

that read the data—that is, the modified transactions will overwrite the information<br />

in the rollback segments if space is short, irrespective of the value of the <br />

setting. This can be prevented by imposing a retention guarantee on the undo tablespace<br />

by using the command. More care than usual must be taken <strong>to</strong> ensure<br />

that the undo tablespace is adequately sized if a retention guarantee is in effect.<br />

3. SQL Server offers read consistency beginning with SQL Server 2005. However, it is not the default<br />

manner of operation.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!