Managing Tablespaces   «Prev  Next»
Lesson 8Read-only tablespaces
ObjectiveMake a tablespace read-only.

Read-only tablespaces in Oracle

To make a tablespace in Oracle read-only, you can use the following SQL statement:
ALTER TABLESPACE  READ ONLY;

This will prevent any data modifications, such as inserts, updates, or deletes, from being performed on the tablespace. However, users will still be able to read data from the tablespace. Here is an example of how to use the statement:
ALTER TABLESPACE users READ ONLY;

This will make the `users` tablespace read-only. To make a tablespace read-write again, you can use the following SQL statement:
ALTER TABLESPACE  READ WRITE;

This will allow data modifications to be performed on the tablespace again. Here is an example of how to use the statement:
ALTER TABLESPACE users READ WRITE;

This will make the `users` tablespace read-write again. It is important to note that making a tablespace read-only will not have any effect on transactions that are already in progress. Transactions that are in progress will still be able to modify data in the tablespace.
Here are some reasons why you might want to make a tablespace read-only:
  • To protect data from accidental modification
  • To perform maintenance on the tablespace
  • To improve performance by reducing the amount of write I/O to the tablespace

SEMrush Sports Car
If you have large amounts of static data, which is data that doesn't change, then you should consider storing it in a read-only tablespace. A read-only tablespace is one that has been flagged as read-only using the ALTER TABLESPACE statement. Oracle doesn't allow writes to a read-only tablespace, ensuring that the data remains unchanged. An advantage of read-only tablespaces is that these tablespaces need to be backed up only once--immediately after they have been marked read-only. To flag a tablespace as read-only, or to make it read-write again, use the ALTER TABLESPACE statement:

ALTER TABLESPACE tablespace_name READ ONLY;

ALTER TABLESPACE tablespace_name READ WRITE;
The first command, with the READ ONLY keywords, sets the tablespace so that it is read-only. The second command, with the READ WRITE keywords, resets the tablespace so that the tablespace is writeable again.
Because you need to back up read-only tablespaces only once, you can potentially shorten the amount of time needed to back up your database. The gain depends on the size of the tablespace. The larger the tablespace, the more time you will save by not backing it nightly. Flagging a tablespace read-only also ensures that critical reference data is not changed by mistake. In the next lesson, you will learn how to create and make the most of temporary tablespaces.