首页 > 代码库 > 定位表中的行数据存放于哪一个具体的datafile上
定位表中的行数据存放于哪一个具体的datafile上
副标题:用一个PL/SQL查出表中的行数据存放在哪个具体的datafile中
经常有遇到做DBA的朋友问,该如何知道自己插入的某一行数据,是存在了数据库中的哪一个数据文件(datafile)上了,回答是肯定可以的。在此,就将该方法写出来供更多的朋友使用。
1、正常查询步骤
1.1、先查到表上行数据的ROWID
select rowid from tivoli.test_db_avg1 where rownum =1 |
输出值:
AAAQ0mAAEAAAAhLAAA
1、2、根据ROWID定位到file id
select dbms_rowid.rowid_relative_fno(row_id=>‘AAAQ0mAAEAAAAhLAAA‘)from dual |
输出值:
4
1.3、根据file id定位到具体的文件路径和名称
select file_name from dba_data_fileswhere file_id=4 |
输出值:
/dba/oracle/oradata/single/users01.dbf
2、以上三个步骤,简化成一个PL/SQL块来实现
set serveroutput on DECLARE file_number INTEGER; rowid_val ROWID; file_name_val varchar2(100); BEGIN SELECT ROWID INTO rowid_val FROM tivoli.test_db_avg1 where rownum =1; file_number:= dbms_rowid.rowid_relative_fno(rowid_val); select file_name into file_name_val from dba_data_files where file_id = file_number; dbms_output.put_line(file_name_val); end; / |
输出结果:
/dba/oracle/oradata/single/users01.dbf
3、验证得出的结果是否正确
3.1 将datafile 4(/dba/oracle/oradata/single/users01.dbf)脱机
alter databasedatafile 4 offline; |
3.2 再来查询tivoli.test_db_avg1表是否能正常查询
SQL> SELECT ROWID FROM tivoli.test_db_avg1 where rownum =1; SELECT ROWID FROM tivoli.test_db_avg1 where rownum =1 * ERROR at line 1: ORA-00376: file 4 cannot be read at this time ORA-01110: data file 4: ‘/dba/oracle/oradata/single/users01.dbf‘ |
已不能正常查询,说明文件定位准确。
3.3 恢复datafile 4到联机状态
SQL> alter database recover datafile 4; Database altered.
SQL> alter database datafile 4 online; Database altered.
SQL> SELECT ROWID FROM tivoli.test_db_avg1 where rownum =1; ROWID ------------------ AAAQ0mAAEAAAAhLAAA |
又可以正常查询到tivoli.test_db_avg1表的数据,说明按照此文的方法,完全正确的找到了具体行数据存放在哪个具体的文件上了。
- http://www.youyuanapp.com/thread-11419-1-1.html
http://www.youyuanapp.com/thread-11418-1-1.html
http://www.youyuanapp.com/thread-11417-1-1.html
http://www.youyuanapp.com/thread-11412-1-1.html
http://www.youyuanapp.com/thread-11409-1-1.html
http://www.youyuanapp.com/thread-11404-1-1.html
http://www.youyuanapp.com/thread-11403-1-1.html
http://www.youyuanapp.com/thread-11398-1-1.html
http://www.youyuanapp.com/thread-11397-1-1.html
http://www.youyuanapp.com/thread-11395-1-1.html
http://yishujiayuanq.blog.163.com/blog/static/2447250612015025101147963/
http://yishujiayuanq.blog.163.com/blog/static/2447250612015025101251829/
http://yishujiayuanq.blog.163.com/blog/static/244725061201502510133740/
http://yishujiayuanq.blog.163.com/blog/static/2447250612015025101653328/
http://yishujiayuanq.blog.163.com/blog/static/2447250612015025101718995/
http://yishujiayuanq.blog.163.com/blog/static/2447250612015025101738627/
http://yishujiayuanq.blog.163.com/blog/static/2447250612015025101822599/
http://yishujiayuanq.blog.163.com/blog/static/2447250612015025101841318/
http://yishujiayuanq.blog.163.com/blog/static/2447250612015025101927982/
http://yishujiayuanq.blog.163.com/blog/static/244725061201502510197287/
定位表中的行数据存放于哪一个具体的datafile上