Use ORWID to simulate Bad blocks and fix them

Source: Internet
Author: User
Use rowid to simulate the restoration of bad database blocks: 1. Rowid definition (Official Website) Agloballyuniqueaddressforarowinadatabase. OracleDatabase

Use rowid to simulate the restoration of bad database blocks: 1. Rowid definition (Official Website) A globally unique address for a row in a Database. Oracle database

Use rowid to simulate the restoration process of Bad blocks in the database:

1. Rowid definition (official website)
A globally unique address for a row in a database.
Oracle Database uses a rowid to uniquely identify a row. internally, the rowid is a structure that holds information that the database needs to access a row. A rowid is not physically stored in the database, but is inferred from the file and block on which the data is stored.
An extended rowid between des a data object number. this rowid type uses a base 64 encoding of the physical address for each row. the encoding characters are A-Z, a-z, 0-9, +, and /.
Example 12-1 queries the ROWID pseudo docolumn to show the extended rowid of the row in the employees table for employee 100.
Example 12-1 ROWID pseudo Column
SQL> SELECT ROWID FROM employees WHERE employee_id = 100;

ROWID
------------------
AAAPecAAFAAAABSAAA
Figure 12-8 specify strates the format of an extended rowid.
Figure 12-8 ROWID Format

Description of "Figure 12-8 ROWID Format"
An extended rowid is displayed in a four-piece format, OOOOOOFFFBBBBBBRRR, with the format pided into the following components:
• OOOOOO
The data object number identifies the segment (data object AAAPec in Example 12-1 ). A data object number is assigned to every database segment. schema objects in the same segment, such as a table cluster, have the same data object number.
• FFF
The tablespace-relative data file number identifies the data file that contains the row (file AAF in Example 12-1 ).
• BBBBBB
The data block number identifies the block that contains the row (block AAAABS in Example 12-1 ). block numbers are relative to their data file, not their tablespace. thus, two rows with identical block numbers cocould reside in different data files of the same tablespace.
• RRR
The row number identifies the row in the block (row AAA in Example 12-1 ).
After a rowid is assigned to a row piece, the rowid can change in special circumstances. for example, if row movement is enabled, then the rowid can change because of partition key updates, Flashback Table operations, shrink table operations, and so on. if row movement is disabled, then a rowid can change if the row is exported and imported using Oracle Database utilities.
Note:
Internally, the database performs row movement as if the row were physically deleted and reinserted. However, row movement is considered an update, which has implications for triggers.
Ii. Some instructions
Rowid is a pseudo column, which means that the column itself does not exist in the data dictionary and is constructed when the query result is output.
Rowid does not actually exist in the data block of the table, but it exists in the index to find row data in the table through rowid.

ROWID format:
The extended ROWID requires 10 bytes of storage space on the disk and is displayed with 18 characters.

It contains the following components:
1. Data Object number: each data object (such as a table or index) is assigned with this number when it is created, and this number is unique in the database.
2. Related File number: This number is unique for each data file in the tablespace.
3. block number: indicates the position of the block containing this row in the data file.
4. row number: identify the location of the row directory in the block Header

Internally, the 10 bytes (bytes) stored, that is, 80 bits, are divided according to the following rules:
(1) The data object number must be 32 bit.
(2) The number of related files must be 10 bits.
(3) The block number must be 22 Bits.
(4) The row number must be 16 bits.
View the specified rowid
SQL> select file_id, relative_fno, block_id from dba_extents where owner = 'center' and segment_name = 'test ';

FILE_ID RELATIVE_FNO BLOCK_ID
--------------------------------
6 136

SQL> select rowid, file_id, relative_fno, block_id from dba_extents where owner = 'center' and segment_name = 'test ';

Select rowid, file_id, relative_fno, block_id from dba_extents where owner = 'center' and segment_name = 'test'
--- Rowed is not saved in the data dictionary
ORA-01446: the DISTINCT, group by, and other clauses cannot be used to select ROWID or sample from the View
SQL> set serveroutput on
SQL>
SQL> DECLARE
2 v_rowid_type NUMBER;
3 v_OBJECT_NUMBER NUMBER;
4 v_RELATIVE_FNO NUMBER;
5 v_BLOCK_NUMBERE_FNO NUMBER;
6 v_ROW_NUMBER NUMBER;
7 BEGIN
8 DBMS_ROWID.rowid_info (
9 rowid_in => 'aaasusaagaaaacnaa ',
10 rowid_type => v_rowid_type,
11 object_number => v_OBJECT_NUMBER,
12 relative_fno => v_RELATIVE_FNO,
13 block_number => v_BLOCK_NUMBERE_FNO,
14 ROW_NUMBER => v_ROW_NUMBER );
15 DBMS_OUTPUT.put_line ('rowid _ TYPE: '| TO_CHAR (v_rowid_type ));
16 DBMS_OUTPUT.put_line ('object _ NUMBER: '| TO_CHAR (v_OBJECT_NUMBER ));
17 DBMS_OUTPUT.put_line ('relative _ FNO: '| TO_CHAR (v_RELATIVE_FNO ));
18 DBMS_OUTPUT.put_line ('block _ NUMBER: '| TO_CHAR (v_BLOCK_NUMBERE_FNO ));
19 DBMS_OUTPUT.put_line ('row _ NUMBER: '| TO_CHAR (v_ROW_NUMBER ));
20 END;
21/

ROWID_TYPE: 1
OBJECT_NUMBER: 75026
RELATIVE_FNO: 6
BLOCK_NUMBER: 141
ROW_NUMBER: 0
1. Create Bad blocks
1) create a tablespace, user center, specify the tablespace tps, create a table test, create a tablespace, insert data to the tablespace
2) various methods to modify files and create bad blocks, such as editing data files and deleting and modifying one character are supported by the ultraedit tool.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.