Previous Table of Contents Next


Listing 7.2 locks.sql shows all locks in the database.

SET LINESIZE 132
SET PAGESIZE 60
COLUMN OBJECT HEADING 'Database|Object'        FORMAT a15 TRUNCATE
COLUMN lock_type HEADING 'Lock|Type'           FORMAT a4 TRUNCATE
COLUMN mode_held HEADING 'Mode|Held'           FORMAT a15 TRUNCATE
COLUMN mode_requested HEADING 'Mode|Requested' FORMAT a15 TRUNCATE
COLUMN sid heading 'Session|ID'
COLUMN username HEADING 'Username'             FORMAT a20 TRUNCATE
COLUMN IMAGE HEADING 'active image'            FORMAT a20 TRUNCATE

SPOOL /tmp/locks
SELECT
        c.sid,
        substr(object_name,1,20) OBJECT,
        c.username,
        substr(c.program,length(c.program)-20,length(c.program)) image,
        DECODE(b.type,
                'MR', 'Media Recovery',
                'RT', 'Redo Thread',
                'UN', 'User Name',
                'TX', 'Transaction',
                'TM', 'DML',
                'UL', 'PL/SQL User Lock',
                'DX', 'Distributed Xaction',
                'CF', 'Control File',
                'IS', 'Instance State',
                'FS', 'File Set',
                'IR', 'Instance Recovery',
                'ST', 'Disk Space Transaction',
                'TS', 'Temp Segment',
                'IV', 'Library Cache Invalidation',
                'LS', 'Log Start or Switch',
                'RW', 'Row Wait',
                'SQ', 'Sequence Number',
                'TE', 'Extend Table',
                'TT', 'Temp Table',
                b.type) lock_type,
        DECODE(b.lmode,
                0, 'None',                /* Mon Lock equivalent */
                1, 'Null',                /* NOT */
                2, 'Row-SELECT (SS)',     /* LIKE */
                3, 'Row-X (SX)',          /* R */
                4, 'Share',               /* SELECT */
                5, 'SELECT/Row-X (SSX)',  /* C */
                6, 'Exclusive',           /* X */
                to_char(b.lmode)) mode_held,
         DECODE(b.request,
                0, 'None',                /* Mon Lock equivalent */
                1, 'Null',                /* NOT */
                2, 'Row-SELECT (SS)',     /* LIKE */
                3, 'Row-X (SX)',          /* R */
                4, 'Share',               /* SELECT */
                5, 'SELECT/Row-X (SSX)',  /* C */
                6, 'Exclusive',           /* X */
                to_char(b.request)) mode_requested
FROM sys.dba_objects a, sys.v_$lock b, sys.v_$session c WHERE
a.object_id = b.id1 AND b.sid = c.sid AND OWNER NOT IN ('SYS','SYSTEM');

Listing 7.3 shows the output of locks.sql.

Listing 7.3 The results from locks.sql.

SQL> @locks

   Session Database                            Lock     Mode   Mode
        ID Object        Username  Active Ima  Type     Held   Requested
---------- ------------  --------  ----------  -------  -----  --------
         2 DUAL                    Media       Reco     Share  None
         2 SYSTEM_PRIVI            Media       Reco     Share  None
         2 TABLE_PRIVIL            Media       Reco     Share  None
         2 STMT_AUDIT_O            Media       Reco     Share  None
         2 V$CONTROLFIL            Media       Reco     Share  None
         2 V$DATAFILE              Media       Reco     Share  None
         2 V$LOG                   Media       Reco     Share  None
         2 V$THREAD                Media       Reco     Share  None
         2 V$PROCESS               Media       Reco     Share  None
         2 V$BGPROCESS             Media       Reco     Share  None
         2 V$SESSION               Media       Reco     Share  None
         2 V$LICENSE               Media       Reco     Share  None
         2 V$TRANSACTIO            Media       Reco     Share  None
         2 V$LATCH                 Media       Reco     Share  None
         2 V$LATCHNAME             Media       Reco     Share  None
         2 V$LATCHHOLDE            Media       Reco     Share  None
         2 V$RESOURCE              Media       Reco     Share  None
         2 V$_LOCK                 Media       Reco     Share  None
         2 V$LOCK                  Media       Reco     Share  None
         2 V$SESSTAT               Media       Reco     Share  None

20 rows selected.

Tablespace Considerations

Choosing how to pair tables and indexes into tablespaces has a great impact on the performance of distributed databases. Since the designer has many choices, it is a good idea to explore the available options. In general, the following characteristics apply:

  Group tables with similar characteristics in a tablespace. For example, all tables that are read-only could be grouped into a single, read-only tablespace. Tables with random I/O patterns could also be grouped together, all small tables should be grouped together, and so on.
  Create at least two tablespaces for use by the TEMP tablespaces. This approach has the advantage of allowing the designer to dedicate numerous TEMP tablespaces to specific classes of users. As we know, the TEMP tablespace is used for large sorting operations, and assigning appropriately sized TEMP tablespaces to users depending upon their sorting requirements can enhance performance. Remember, in a distributed SQL query, the rows are fetched from the remote database and sorted on the Oracle that initiated the request. The use of multiple TEMP tablespaces has the added advantage of allowing the developer to switch TEMP tablespaces in case of disk failure.
  Use many small, manageable tablespaces. This approach makes it easier to take a single tablespace offline for maintenance without affecting the entire system. Oracle highly recommends that no tablespace should ever become greater than 10 GB, and placing all tables into a single tablespace also reduces recoverability in case of media failure. However, this approach does not advocate creating a single tablespace for each table in a system. For example, Oracle recommends that the system tablespace contain only systems tables, and that a separate tablespace be created for the exclusive use of the rollback segments.
  Place the rollback segments in a separate tablespace. This isolates the activity of the rollback segments (which tend to have a high I/O rate) from the data files belonging to the application.


Previous Table of Contents Next