Oracle DBA, How To, Error, Cause and Action

Showing posts with label Datafiles. Show all posts
Showing posts with label Datafiles. Show all posts

Rename Datafile (2/2)

Rename Datafile (1/2)
Rename Datafile (2/2) [You are here]

2. Rename datafile with database mounted

Procedure renaming datafile with mounted Database:
- Shutdown
- Startup mount
- Alter database or alter tablespace to the rename file command
- Alter database open

In this example my objective is to change the my_tbs_01.dbf to my_tbs_1000.dbf

1. Shutdown database gracefully

Shutdown database gracefully means that you are shutdown database with either with SHUTDOWN NORMAL, SHUTDOWN IMMEDIATE, or SHUTDOWN TRANSACTIONAL.
With above method of shutdown, Oracle will conclude all active transaction, and you will have good copy of database.

SHUTDOWN IMMEDIATE



2. Startup mount



3. Alter database or alter tablespace to the rename file command

There are two methods of renaming datafile, you may can choose one from here.

ALTER DATABASE RENAME FILE '/datafiles/edba01/edba01/my_tbs_01.dbf' TO '/datafiles/edba01/edba01/my_tbs_1000.dbf';


or

ALTER TABLESPACE my_tbs RENAME DATAFILE '/datafiles/edba01/edba01/my_tbs_01.dbf' TO '/datafiles/edba01/edba01/my_tbs_1000.dbf';


4. Alter database open


Check the status of the new file

Rename Datafile (1/2)
Rename Datafile (2/2) [You are here]

Rename Datafile (1/2)

Rename Datafile (1/2) [You are here]
Rename Datafile (2/2)

There are 2 ways of renaming datafile (relocating file to another directory also consider as renaming datafile, because the name of the file is including the full path of the file)

1. Rename datafile while database is OPEN

To rename datafile while database is open first you must bring the tablespace that related to the datafile OFFLINE. There are two ways to do that

1.1 Procedure renaming datafile while database is OPEN:

- Alter the tablespace to READ ONLY mode
- Alter the tablespace to OFFLINE
- Rename the datafile from OS
- Alter database or alter tablespace to the rename file command
- Alter the tablespace to ONLINE
- Alter the tablespace to READ WRITE mode

In this example my objective is to change the my_tbs_02.dbf to my_tbs_2000.dbf

Now I show you step by step, first bring the tablespace to read only mode.

1. Alter the tablespace to READ ONLY mode

ALTER TABLESPACE my_tbs READ ONLY;



the STATUS now are READ ONLY

2. Alter the tablespace to OFFLINE

ALTER TABLESPACE my_tbs OFFLINE;

The reason you are not see the STATUS OFFLINE is because the tablespace was in READ ONLY mode, however you can see the change that once it OFFLINE the BYTES column are nil.


3. Rename the datafile from OS

mv /datafiles/edba01/edba01/my_tbs_02.dbf /datafiles/edba01/edba01/my_tbs_2000.dbf

If you want to execute OS command without exit from SQL prompt you can include ! infront of your command, for windows user you can use HOST, for example SQL> host dir /w


4. Alter database or alter tablespace to the rename file command

There are two methods of renaming datafile, you may can choose one from here.

ALTER DATABASE RENAME FILE '/datafiles/edba01/edba01/my_tbs_02.dbf' TO '/datafiles/edba01/edba01/my_tbs_2000.dbf';


or

ALTER TABLESPACE my_tbs RENAME DATAFILE '/datafiles/edba01/edba01/my_tbs_02.dbf' TO '/datafiles/edba01/edba01/my_tbs_2000.dbf';


I am using the first one
If you do not change the OS filename as step 3 Oracle will give you error, because Oracle will search for the new filename, and Oracle required the file to be exists.


5. Alter the tablespace to ONLINE

ALTER TABLESPACE my_tbs ONLINE;

6. Alter the tablespace to READ WRITE mode

ALTER TABLESPACE my_tbs READ WRITE;


Now I have the filename changed.

Rename Datafile (1/2) [You are here]
Rename Datafile (2/2)

Oracle Database Physcial Structures

There are 7 types of files for each created Database.

They are:
1. Datafiles
2. Control Files
3. Online Redo Log Files
4. Archived Redo Log Files
5. Parameter Files
6. Backup Files

Datafiles

Every Oracle database has one or more physical datafiles, which contain all the database data. The data of logical database structures, such as tables and indexes, is physically stored in the datafiles allocated for a database.

Datafiles have the following characteristics:

- One or more datafiles form a logical unit of database storage called a tablespace.
- A datafile can be associated with only one tablespace.
- Datafiles can be defined to extend automatically when they are full.

Data in a datafile is read, as needed, during normal database operation and stored in the memory cache of Oracle Database. For example, if a user wants to access some data in a table of a database, and if the requested information is not already in the memory cache for the database, then it is read from the appropriate datafiles and stored in memory.

Modified or new data is not necessarily written to a datafile immediately. To reduce the amount of disk access and to increase performance, data is pooled in memory and written to the appropriate datafiles all at once, as determined by the background process database writer process (DBWn). Please note that following process is only can be seen if you are using Unix or Linux System.

Datafiles that are stored in temporary tablespaces are called tempfiles.

Control Files

Every Oracle database has a control file.

A control file contains entries that specify the physical structure of the database, including the following information:

- Database name
- Names and locations of datafiles and redo log files
- Timestamp of database creation

Oracle Database can multiplex the control file, that is, simultaneously maintain a number of identical control file copies, to protect against a failure involving the control file.

Every time an instance of an Oracle database is started, its control file identifies the datafiles, tempfiles, and redo log files that must be opened for database operation to proceed. If the physical makeup of the database is altered (for example, if a new datafile or redo log file is created), then the control file is automatically modified by Oracle Database to reflect the change. A control file is also used in database recovery.


Online Redo Log Files

Every Oracle Database has a set of two or more online redo log files. These online redo log files, together with archived copies of redo log files, are collectively known as the redo log for the database. A redo log is made up of redo entries (also called redo records), which record all changes made to data. If a failure prevents modified data from being permanently written to the datafiles, then the changes can be obtained from the redo log, so work is never lost.

To protect against a failure involving the redo log itself, Oracle Database lets you create a multiplexed redo log so that two or more copies of the redo log can be maintained on different disks.


Archived Redo Log Files

Archived redo log files are database-generated offline copies of online redo log files. Oracle Database automatically archives redo log files when the database is in ARCHIVELOG mode. Oracle recommends that you enable automatic archiving of the online redo log.


Parameter Files

Parameter files contain a list of configuration parameters for that instance and database. Both parameter files (pfiles) and server parameter files (spfiles) let you store and manage your initialization parameters persistently in a server-side disk file.

A server parameter file has these additional advantages:
- The file is concurrently updated when some parameter values are changed in the active instance.
- The file is centrally located for access by all instance in a Real Application Services database.

Oracle recommends that you create a server parameter file as a dynamic means of maintaining initialization parameters.


Alert and Trace Log Files

Each server and background process can write to an associated trace file. When an internal error is detected by a process, the process dumps information about the error to its trace file. Some of the information written to a trace file is intended for the database administrator, while other information is for Oracle Support Services. Trace file information is also used to tune applications and instances. The alert file, or alert log, is a special trace file. The alert log of a database is a chronological log of messages and errors.

The following features provide automation and assistance in the collection and interpretation of trace and alert file information:

The Automatic Dianostic Respository (ADR) is a system-managed repository for storing and organizing trace files and other error diagnostic data. ADR provides a comprehensive view of all the critical errors encountered by the database and maintains all relevant data needed for problem diagnosis and eventual resolution. When the same type of incident occurs too frequently, ADR performs flood control to avoid excessive dumping of diagnostic information.

The Incident Packaging Service (IPS) extracts diagnostic and test case data associated with critical errors from the ADR and packages the data for transport to Oracle.


Backup Files

To restore a file is to replace it with a backup file. Typically, you restore a file when a media failure or user error has damaged or deleted the original file.

User-managed backup and recovery requires you to actually restore backup files before you can perform a trial recovery of the backups.

Server-managed backup and recovery manages the backup process, such as scheduling of backups, as well as the recovery process, such as applying the correct backup file when recovery is needed.