Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

Free Oracle Tips

HTML Text

 Home
 E-mail Us
 Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB   


 

 

 


 

 

 
 


Oracle read only table tips

Oracle Tips by Burleson Consulting

May 20, 2010

11g Enhanced Read-only tables

Oracle 11g has introduced a much simpler method for enabling read-only tables that even protect the table from unintentional DML by the table’s owner.  Prior to 11g, a read-only table was achieved by creating a table under a restricted account and granting select privileges to the appropriate users.  However, using this method, it is possible for the owner of the table to unintentionally modify the table. 

Also see my related notes on locking and read only tablespaces.
 
Oracle Database 11g introduces new ALTER TABLE syntax. For example, a table can be set to read-only by issuing the following command:
 
ALTER TABLE READ ONLY;
 
A table can be returned to read and write using the following command:
 
ALTER TABLE READ WRITE;
 
In read-only mode, the following operations are permitted on the table:

  •  Select
  •  Management indexes, constraints, supplemental log
  •  Dropping and deallocation of unused columns
  •  Renaming and moving of the table
  •  Altering the table for physical property changes, row movement, and shrinking the segment
  •  Drop table

The following operations are disabled on a table in read-only mode:

  •  DML on table or any table partitions
  •  Truncation of table
  •  Select for update
  •  Adding, removing, renaming, dropping, or setting a column to unused
  •  Dropping a partition or sub partition belonging to the table
  •  Online redefinition
  •  Flashback on the table

For example, consider a transactional table that stores a customer’s account, sales amount, and transaction date:
 
SQL> desc account_sales
 


 Name                                      Null?    Type
 ----------------------------------------- -------- ------
 
 ACCOUNT_ID                                         NUMBER
 SALES_AMOUNT                                       NUMBER
 TRX_DATE                                           DATE

 
The business might request that this table be used to keep a historical record of accounts that were active during each month.  If it is November 1st, 2007, the DBA might run the following command to meet this requirement and then make the table read-only since the table is only for a historical record:
 
SQL> create table
  2     account_sales_october2007
  3  as
  4  select
  5    *
  6  from
  7     account_sales
  8  where
  9     trx_date between ('01-OCT-07') and ('31-OCT-07');
 
Table created.
 
SQL> alter table account_sales_october2007 read only;
 
Table altered.

 
A table’s read-only status is available from the read_only column of the dictionary views for [user|all|dba]_tables.  For example:
 
SQL> select
  2     table_name,
  3     read_only
  4  from
  5     user_tables
  6  where
  7     table_name = 'ACCOUNT_SALES_OCTOBER2007';
 
TABLE_NAME                     READ_ONLY
------------------------------ ----------
ACCOUNT_SALES_OCTOBER2007      YES

 
Any attempts to insert, delete, or update the data from this table while it is in read-only status results in the following error:
 
SQL> insert into
  2     account_sales_october2007
  3  values (3, 100, '31-OCT-2007');
   account_sales_october2007
   *
ERROR at line 2:
ORA-12081: update operation not allowed on table
"VJ"."ACCOUNT_SALES_OCTOBER2007"
 
 
SQL> delete from
  2     account_sales_october2007
  3  where
  4     account_id = 3;
   account_sales_october2007
   *
ERROR at line 2:
ORA-12081: update operation not allowed on table
"VJ"."ACCOUNT_SALES_OCTOBER2007"
 
 
SQL> update
  2     account_sales_october2007
  3  set
  4     sales_amount = 2*sales_amount
  5  where
  6     customer_id = 3;
   account_sales_october2007
   *
ERROR at line 2:
ORA-12081: update operation not allowed on table
"VJ"."ACCOUNT_SALES_OCTOBER2007"

 
While the example above has been simplified to focus on the new feature, there are many business cases where a read-only table is appropriate.  Most of these business cases share the fact that the data is being stored for historical record or reference, and there is no reason that the table should need to be updated.  In many cases, protecting the integrity of the data is a main priority. 

An example is an OLTP table with transactional data and sales compensation based on the table’s monthly activity.  It would be desirable to have each month’s data stored in a read-only table that is protected from modification.
 
The need for read-only data has existed long before the new release of Oracle.  However, this new feature greatly simplifies the process of enabling and disabling read-only status from a table with its simple syntax. 

Oracle read-only table performance

Because Oracle does not have the additional overhead of maintaining internal consistency, there may be a small, but measurable reduction in resource consumption. 

The Oracle 10g Database Administrator's Guide also suggests that read-only transactions will have faster performance:  

For better performance while accessing data in a read-only tablespace, you might want to issue a query that accesses all of the blocks of the tables in the tablespace just before making it read-only.

A simple query, such as SELECT COUNT (*), executed against each table will ensure that the data blocks in the tablespace can be subsequently accessed most efficiently. This eliminates the need for Oracle to check the status of the transactions that most recently modified the blocks.

These notes on Oracle read-only tablespaces and Performance suggest that super high-activity system may see gains.

 
 
  Guarantee your Success!

Oracle is the world's most complex, robust and flexible database, considered impossible to master without a mentor.

That's why all BC Oracle trainers are working professionals, experts in Oracle who share their tips and secrets.


 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright ? 1996 -  2012 

All rights reserved.

Oracle ? is the registered trademark of Oracle Corporation.


 

  
 

 
 
 
 
Oracle performance tuning software
 
 

 

 
 
 
Oracle performance Tuning 10g reference poster
 
 
 
Oracle training in Linux commands
 
Oracle training Excel
 
Oracle training & performance tuning books