Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005
CHAPTER 6 ■ LOCKING AND LATCHING 219 The last type of DDL lock is a breakable parse lock. When your session parses a statement, a parse lock is taken against every object referenced by that statement. These locks are taken in order to allow the parsed, cached statement to be invalidated (flushed) in the Shared pool if a referenced object is dropped or altered in some way. A view that is invaluable for looking at this information is DBA_DDL_LOCKS. There is no V$ view for you to look at. The DBA_DDL_LOCKS view is built on the more mysterious X$ tables and, by default, it will not be installed in your database. You can install this and other locking views by running the catblock.sql script found in the directory [ORACLE_HOME]/rdbms/admin. This script must be executed as the user SYS in order to succeed. Once you have executed this script, you can run a query against the view. For example, in a single-user database I see the following: ops$tkyte@ORA10G> select session_id sid, owner, name, type, 2 mode_held held, mode_requested request 3 from dba_ddl_locks; SID OWNER NAME TYPE HELD REQUEST ---- --------- --------------------- -------------------- ---- --------- 161 SYS DBMS_UTILITY Body Null None 161 SYS DBMS_UTILITY Body Null None 161 SYS DBMS_APPLICATION_INFO Table/Procedure/Type Null None 161 OPS$TKYTE OPS$TKYTE 18 Null None 161 SYS DBMS_OUTPUT Body Null None 161 SYS DATABASE 18 Null None 161 SYS DBMS_UTILITY Table/Procedure/Type Null None 161 SYS DBMS_UTILITY Table/Procedure/Type Null None 161 SYS PLITBLM Table/Procedure/Type Null None 161 SYS DBMS_APPLICATION_INFO Body Null None 161 SYS DBMS_OUTPUT Table/Procedure/Type Null None 11 rows selected. These are all the objects that my session is “locking.” I have breakable parse locks on a couple of the DBMS_* packages. These are a side effect of using SQL*Plus; it calls DBMS_ APPLICATION_INFO, for example. I may see more than one copy of various objects here—this is normal, and it just means I have more than one thing I’m using in the Shared pool that references these objects. It is interesting to note that in the view, the OWNER column is not the owner of the lock; rather, it is the owner of the object being locked. This is why you see many SYS rows. SYS owns these packages, but they all belong to my session. To see a breakable parse lock in action, let’s first create and run a stored procedure, P: ops$tkyte@ORA10G> create or replace procedure p as begin null; end; 2 / Procedure created. ops$tkyte@ORA10G> exec p PL/SQL procedure successfully completed.
220 CHAPTER 6 ■ LOCKING AND LATCHING The procedure, P, will now show up in the DBA_DDL_LOCKS view. We have a parse lock on it: ops$tkyte@ORA10G> select session_id sid, owner, name, type, 2 mode_held held, mode_requested request 3 from dba_ddl_locks 4 / SID OWNER NAME TYPE HELD REQUEST ---- --------- --------------------- -------------------- ---- --------- 161 OPS$TKYTE P Table/Procedure/Type Null None 161 SYS DBMS_UTILITY Body Null None 161 SYS DBMS_UTILITY Body Null None ... 161 SYS DBMS_OUTPUT Table/Procedure/Type Null None 12 rows selected. We then recompile our procedure and query the view again: ops$tkyte@ORA10G> alter procedure p compile; Procedure altered. ops$tkyte@ORA10G> select session_id sid, owner, name, type, 2 mode_held held, mode_requested request 3 from dba_ddl_locks 4 / SID OWNER NAME TYPE HELD REQUEST ---- --------- --------------------- -------------------- ---- --------- 161 SYS DBMS_UTILITY Body Null None 161 SYS DBMS_UTILITY Body Null None ... 161 SYS DBMS_OUTPUT Table/Procedure/Type Null None 11 rows selected. We find that P is now missing from the view. Our parse lock has been broken. This view is useful to you, as a developer, when it is found that some piece of code won’t compile in the test or development system—it hangs and eventually times out. This indicates that someone else is using it (actually running it), and you can use this view to see who that might be. The same will happen with GRANTS and other types of DDL against the object. You cannot grant EXECUTE on a procedure that is running, for example. You can use the same method to discover the potential blockers and waiters. Latches Latches are lightweight serialization devices used to coordinate multiuser access to shared data structures, objects, and files.
- Page 214 and 215: CHAPTER 5 ■ ORACLE PROCESSES 169
- Page 216 and 217: CHAPTER 5 ■ ORACLE PROCESSES 171
- Page 218 and 219: CHAPTER 5 ■ ORACLE PROCESSES 173
- Page 220 and 221: CHAPTER 5 ■ ORACLE PROCESSES 175
- Page 222 and 223: CHAPTER 5 ■ ORACLE PROCESSES 177
- Page 224 and 225: CHAPTER 5 ■ ORACLE PROCESSES 179
- Page 226 and 227: CHAPTER 5 ■ ORACLE PROCESSES 181
- Page 228 and 229: CHAPTER 6 ■ ■ ■ Locking and L
- Page 230 and 231: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 232 and 233: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 234 and 235: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 236 and 237: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 238 and 239: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 240 and 241: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 242 and 243: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 244 and 245: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 246 and 247: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 248 and 249: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 250 and 251: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 252 and 253: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 254 and 255: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 256 and 257: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 258 and 259: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 260 and 261: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 262 and 263: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 266 and 267: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 268 and 269: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 270 and 271: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 272 and 273: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 274 and 275: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 276 and 277: CHAPTER 7 ■ ■ ■ Concurrency a
- Page 278 and 279: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 280 and 281: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 282 and 283: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 284 and 285: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 286 and 287: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 288 and 289: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 290 and 291: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 292 and 293: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 294 and 295: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 296 and 297: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 298 and 299: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 300 and 301: CHAPTER 8 ■ ■ ■ Transactions
- Page 302 and 303: CHAPTER 8 ■ TRANSACTIONS 257 •
- Page 304 and 305: CHAPTER 8 ■ TRANSACTIONS 259 So,
- Page 306 and 307: CHAPTER 8 ■ TRANSACTIONS 261 X --
- Page 308 and 309: CHAPTER 8 ■ TRANSACTIONS 263 “s
- Page 310 and 311: CHAPTER 8 ■ TRANSACTIONS 265 busi
- Page 312 and 313: CHAPTER 8 ■ TRANSACTIONS 267 Many
220<br />
CHAPTER 6 ■ LOCKING AND LATCHING<br />
The procedure, P, will now show up in the DBA_DDL_LOCKS view. We have a parse lock on it:<br />
ops$tkyte@ORA10G> select session_id sid, owner, name, type,<br />
2 mode_held held, mode_requested request<br />
3 from dba_ddl_locks<br />
4 /<br />
SID OWNER NAME TYPE HELD REQUEST<br />
---- --------- --------------------- -------------------- ---- ---------<br />
161 OPS$TKYTE P Table/Procedure/Type Null None<br />
161 SYS DBMS_UTILITY Body Null None<br />
161 SYS DBMS_UTILITY Body Null None<br />
...<br />
161 SYS DBMS_OUTPUT Table/Procedure/Type Null None<br />
12 rows selected.<br />
We then recompile our procedure <strong>and</strong> query the view again:<br />
ops$tkyte@ORA10G> alter procedure p compile;<br />
Procedure altered.<br />
ops$tkyte@ORA10G> select session_id sid, owner, name, type,<br />
2 mode_held held, mode_requested request<br />
3 from dba_ddl_locks<br />
4 /<br />
SID OWNER NAME TYPE HELD REQUEST<br />
---- --------- --------------------- -------------------- ---- ---------<br />
161 SYS DBMS_UTILITY Body Null None<br />
161 SYS DBMS_UTILITY Body Null None<br />
...<br />
161 SYS DBMS_OUTPUT Table/Procedure/Type Null None<br />
11 rows selected.<br />
We find that P is now missing from the view. Our parse lock has been broken.<br />
This view is useful to you, as a developer, when it is found that some piece of code won’t<br />
compile in the test or development system—it hangs <strong>and</strong> eventually times out. This indicates<br />
that someone else is using it (actually running it), <strong>and</strong> you can use this view to see who that<br />
might be. The same will happen with GRANTS <strong>and</strong> other types of DDL against the object. You<br />
cannot grant EXECUTE on a procedure that is running, for example. You can use the same<br />
method to discover the potential blockers <strong>and</strong> waiters.<br />
Latches<br />
Latches are lightweight serialization devices used to coordinate multiuser access to shared<br />
data structures, objects, <strong>and</strong> files.