ORACLE空间管理实验1:探索LMT表空间管理下数据文件头的结构及位
ORACLE空间管理实验1:探索LMT表空间管理下数据文件头的结构及位图中区的记录方式 目录(?) [] 实验分两步: 1.LMT本地管理的表空间,ASSM 自动段管理时数据文件的结构分析 ORACLE 11G:0号操作系统块,1-2是文件头,3-127是位图信息。128号开始及之后存放的是
ORACLE空间管理实验1:探索LMT表空间管理下数据文件头的结构及位图中区的记录方式
目录(?)[+]
实验分两步:1.LMT本地管理的表空间,ASSM 自动段管理时数据文件的结构分析
ORACLE 11G:0号操作系统块,1-2是文件头,3-127是位图信息。128号开始及之后存放的是数据了—可能是段头或段的数据。ORACLE 10G时数据文件头只有8个块存放位图信息。--本文未实验。
2.位图块中对于区的使用情况的记录--第一个记录区使用情况的是3号块,本文查看的就是3号块。
在位图块中用二进制数值1来表示区的起始个数--或者叫第一个可以分配的区的位置。 这个记录上的区个数和自动或固定区大小是没有关系的,可以通过建两个不同分配方式表空间来验证,下面贴有。结合实验,我理解的是位图中的表示的是区的位置,不是DBA这种绝对位置,而是相对的第几个第几个这种,ORACEL在分配时根据位图块中的信息,找到第一个可以供分配的区。--不知道这样说准确不,弄不清的就看后面实验吧。
3.哪些操作会释放空间?空间释放会做什么操作?
删除段时的位图变化:如果段被删除(DROP)或TRUNCATE,相应的区将被回收。如果只是DELETE数据,是不会回收区空间的--数据块中的空间也不会回收-高水位。
比如1、2、3、4、5个区,TRUNCATE 2号区所在的表A,
truncate table a;DDL操作,做一次完全检查点,再DUMP位图中记录区的数据文件3号块,发现FIRST已经变化,释放区空间。
就是DUMP的数据文件3号块这一行信息中变化:RelFno: 14, BeginBlock: 128, Flag: 0, First: 1, Free: 63487
4.是否开启闪回DROP回收站功能时验证Oracle找寻可用区的不同方式:
打开闪回DROP回收站功能-11G默认打开,比如一个数据文件中有多个段(表),表的建立先后顺序不同,分配到的区在数据文件中的先后也会不同。这时,如果把数据文件上建的第一个表drop,DUMP位图块会发现,First: 4,这个值会变为First: 1, ,后面可能在很远后会有 0000FFFFFFFF0F00。
但是据说,开启闪回时查找可用区是扫描整个位图,First: 4,这个值是没用的。 在drop后,事实上是将表系统命令rename,区及数据还存在数据文件上。如果查找整个位图区,都没有可用区,则会按 drop的时间,将最早drop的区释放。如果释放了所有回收站中的表的空间,还是不够用,就会扩展数据文件。
如未打开闪回DROP的回收站功能,如果把数据文件上建的第一个表删除或TRUNCATE,,位图中First: 4, 这个值是不会变的,会一直接从First: 4,往下分配,直到数据文件中区分配完,才会再回到最前面查找空闲。
DUMP此块,可以看到比如以下:
RelFno: 7, BeginBlock: 128, Flag: 0, First: 4, Free: 63451
0F00000000000000
这是因为,块中用16进制来表示2进制,应该将16进制转化为2进制,查看二进制1的个数来计算起始区的个数。
更简单的计算方法是:每个16进制最多表示4个1,分别是十六进制1--二进制1,十六进制3--二进制11,十六进制7--二进制11,十六进制F--二进制1111
在我这里0F就是四个二进制1了,表示分配了四个区。
实验第一步:LMT本地管理的表空间,ASSM 自动段管理时数据文件的结构分析
新建一个表空间test4,在test4表空间上新建一个数据文件,插入一行数据,做一个完全检查点。可以从dba_segments.header_block查出段头的位置,DUMP test4表空间的1-4及127-131号块。
BYS@ bys3>create table test4(aa int) tablespace test4;Table created.
BYS@ bys3>insert into test4 values(99889);
1 row created.
BYS@ bys3>commit;
Commit complete.
BYS@ bys3>select segment_name,header_block,header_file,blocks from dba_segments where segment_name='TEST4';
SEGMENT_NAME HEADER_BLOCK HEADER_FILE BLOCKS
--------------- ------------ ----------- ----------
TEST4 130 14 8
BYS@ bys3>alter system checkpoint; ---要做一个完全检查点,不然新插入的数据未写入数据文件。
System altered.
#############
BYS@ bys3>alter system dump datafile 14 block min 1 block max 4;
System altered.
BYS@ bys3>select value from v$diag_info where name like 'De%';
VALUE
----------------------------------------------------------------------------------------------------
/u01/diag/rdbms/bys3/bys3/trace/bys3_ora_12335.trc
BYS@ bys3>alter system dump datafile 14 block min 127 block max 131;
System altered.
BYS@ bys3>select value from v$diag_info where name like 'De%';
VALUE
----------------------------------------------------------------------------------------------------
/u01/diag/rdbms/bys3/bys3/trace/bys3_ora_12377.trc
################
DUMP数据块的内容分析
2号块内容:--位图块头
Start dump data blocks tsn: 9 file#:14 minblk 1 maxblk 4
Block 1 (file header) not dumped:use dump file header command --DUMP数据文件第1个块--块头,要用alter system set events 'immediate trace name file_hdrs level 3';Block dump from cache: --这一点从buffer cache中来的
Dump of buffer cache at level 4 for tsn=9 rdba=58720258
BH (0x217f7538) file#: 14 rdba: 0x03800002 (14/2) class: 13 ba: 0x2171c000 --BH信息详解见:详解Buffer Header--DUMP buffer结合X$BH视图各字段
set: 3 pool: 3 bsz: 8192 bsi: 0 sflg: 1 pwc: 0,0
dbwrid: 0 obj: -1 objn: 1 tsn: 9 afn: 14 hint: f
hash: [0x2a39741c,0x2a39741c] lru: [0x22fed538,0x22fe44d8]
ckptq: [NULL] fileq: [NULL] objq: [0x24444154,0x22fe44f0] objaq: [0x2444414c,0x22fe44f8]
st: XCURRENT md: NULL fpin: 'ktfbwh0d: ktfbsearch' tch: 2
flags: block_written_once redo_since_read
LRBA: [0x0.0.0] LSCN: [0x0.0] HSCN: [0xffff.ffffffff] HSUB: [1]
Block dump from disk:
buffer tsn: 9 rdba: 0x03800002 (14/2) ------tsn: 9表空间号,rdba: 0x03800002 (14/2) 14号文件2号块
scn: 0x0000.0077dfdb seq: 0x02 flg: 0x04 tail: 0xdfdb1d02
frmt: 0x02 chkval: 0xb96b type: 0x1d=KTFB Bitmapped File Space Header --这里可以看到这个块是位图块的信息
Hex dump of block: st=0, typ_found=1
Dump of memory from 0xB6C22600 to 0xB6C24600
B6C22600 0000A21D 03800002 0077DFDB 04020000 [..........w.....]
B6C22610 0000B96B 0000000E 00000008 00000500 [k...............]
B6C22620 00000001 00000000 00000000 0000007E [............~...]
B6C22630 000004FF 00000001 0000008F 00000003 [................]
B6C22640 00000000 00000000 00000000 00000000 [................]
B6C22650 00000080 00000008 00000000 00000000 [................]
B6C22660 00000000 00000000 00000000 00000000 [................]
Repeat 504 times
B6C245F0 00000000 00000000 00000000 DFDB1D02 [................]
File Space Header Block:
Header Control:
RelFno: 14, Unit: 8, Size: 1280, Flag: 1 ---相对文件号14,Unit: 8--分配单元,每个块的大小为8192,。 Size: 1280--此数据文件包含的块数-1280*8K=10M
AutoExtend: NO, Increment: 0, MaxSize: 0 ---
Initial Area: 126, Tail: 1279, First: 1, Free: 143 ---Initial Area: 126,这是指出了有126个块用于记录位图信息-,从3-127-11G前是6个
Deallocation scn: 3.0
Header Opcode:
Save: No Pending Op
Block dump from cache:
Dump of buffer cache at level 4 for tsn=9 rdba=58720259 --TNS9是表空间号,rdba=58720259是FILE和BLOCK,RDBA计算方法如下:
BYS@ bys3>select dbms_utility.make_data_block_address(14,2) from dual;
DBMS_UTILITY.MAKE_DATA_BLOCK_ADDRESS(14,2)
------------------------------------------
58720258
3号块内容--第一个位图块--区的分配在此可以观察--详见实验第二步
############Block dump from cache:
Dump of buffer cache at level 4 for tsn=9 rdba=58720260
Block dump from disk:
buffer tsn: 9 rdba: 0x03800004 (14/4) --4号位图块,未使用。
scn: 0x0000.0077dc17 seq: 0x01 flg: 0x04 tail: 0xdc171e01
frmt: 0x02 chkval: 0x8364 type: 0x1e=KTFB Bitmapped File Space Bitmap
Hex dump of block: st=0, typ_found=1
Dump of memory from 0xB6C22600 to 0xB6C24600
B6C22600 0000A21E 03800004 0077DC17 04010000 [..........w.....]
B6C245F0 00000000 00000000 00000000 DC171E01 [................]
File Space Bitmap Block:
BitMap Control:
RelFno: 14, BeginBlock: 508032, Flag: 0, First: 0, Free: 63488 --这个位图块中没有记录有区的信息。。数据文件刚开始用,才分了一个区,用不到这个位图块来记录。
###################################################################################################
Start dump data blocks tsn: 9 file#:14 minblk 127 maxblk 131
Block dump from cache:
Dump of buffer cache at level 4 for tsn=9 rdba=58720383
Block dump from disk:
buffer tsn: 9 rdba: 0x0380007f (14/127)
scn: 0x0000.0077dd0d seq: 0x01 flg: 0x04 tail: 0xdd0d1e01
frmt: 0x02 chkval: 0x40d9 type: 0x1e=KTFB Bitmapped File Space Bitmap --这个块还是关于区的位图块
Hex dump of block: st=0, typ_found=1
Dump of memory from 0xB6BE1600 to 0xB6BE3600
Repeat 507 times
B6BE35F0 00000000 00000000 00000000 DD0D1E01 [................]
File Space Bitmap Block:
BitMap Control:
RelFno: 14, BeginBlock: 62980224, Flag: 0, First: 0, Free: 63488 --这个位图块中没有记录有区的信息。。数据文件刚开始用,才分了一个区,用不到这个位图块来记录。
################################################################################
Block dump from cache:
Dump of buffer cache at level 4 for tsn=9 rdba=58720384
BH (0x21be7f70) file#: 14 rdba: 0x03800080 (14/128) class: 8 ba: 0x218e0000
set: 3 pool: 3 bsz: 8192 bsi: 0 sflg: 1 pwc: 0,0
dbwrid: 0 obj: 22963 objn: 22963 tsn: 9 afn: 14 hint: f
hash: [0x2b3fd83c,0x2b3fd83c] lru: [0x21fe8ec0,0x227f1d68]
ckptq: [NULL] fileq: [NULL] objq: [0x24440ce4,0x21fe8ed8] objaq: [0x21fe8ee0,0x21ff6f2c]
st: XCURRENT md: NULL fpin: 'ktspfwh6: ktspffbmb' tch: 1
flags: block_written_once redo_since_read
LRBA: [0x0.0.0] LSCN: [0x0.0] HSCN: [0xffff.ffffffff] HSUB: [1]
Block dump from disk:
buffer tsn: 9 rdba: 0x03800080 (14/128)
scn: 0x0000.0077dfe3 seq: 0x02 flg: 0x04 tail: 0xdfe32002
frmt: 0x02 chkval: 0x9faf type: 0x20=FIRST LEVEL BITMAP BLOCK ---可以看到,第128个块是新创建表的L1块了,后面还有L2,段头-L3,不是本篇主题,我没贴出来了。
Hex dump of block: st=0, typ_found=1
实验第二步:位图块中对于区的使用情况的记录
1.正常情况下的分析:
BH (0x22fe4424) file#: 14 rdba: 0x03800003 (14/3) class: 12 ba: 0x22c56000set: 3 pool: 3 bsz: 8192 bsi: 0 sflg: 1 pwc: 0,0
dbwrid: 0 obj: -1 objn: 1 tsn: 9 afn: 14 hint: f
hash: [0x2a7fb618,0x2a7fb618] lru: [0x217f75ec,0x20bfca24]
ckptq: [NULL] fileq: [NULL] objq: [0x217f7604,0x24444154] objaq: [0x217f760c,0x2444414c]
st: XCURRENT md: NULL fpin: 'ktfbwh36: ktfbbsearch' tch: 2
flags: block_written_once redo_since_read
LRBA: [0x0.0.0] LSCN: [0x0.0] HSCN: [0xffff.ffffffff] HSUB: [1]
Block dump from disk:
buffer tsn: 9 rdba: 0x03800003 (14/3)
scn: 0x0000.0077dfdb seq: 0x01 flg: 0x04 tail: 0xdfdb1e01
frmt: 0x02 chkval: 0x4c9b type: 0x1e=KTFB Bitmapped File Space Bitmap --第3个块,开始使用位图记录此数据文件中区的使用情况
Hex dump of block: st=0, typ_found=1
Dump of memory from 0xB6C22600 to 0xB6C24600
B6C22600 0000A21E 03800003 0077DFDB 04010000 [..........w.....]
B6C22610 00004C9B 0000000E 00000080 00000000 [.L..............]
B6C22620 00000001 0000F7FF 00000000 00000000 [................]
B6C22630 00000000 00000000 00000001 00000000 [................]
B6C22640 00000000 00000000 00000000 00000000 [................]
Repeat 506 times
B6C245F0 00000000 00000000 00000000 DFDB1E01 [................]
File Space Bitmap Block:
BitMap Control:
RelFno: 14, BeginBlock: 128, Flag: 0, First: 1, Free: 63487 --因为是新建的表空间,并在此表空间新建表,暂时只分配了一个区。
0100000000000000 0000000000000000 0000000000000000 0000000000000000
这里的01就是表示的区的块数,十六进制01表示二进制是一个1,二进制的一个1就是表示分配了一个区了,因为新表插入一行数据,所以只分配了一个区。。可以使用手动分配区命令后再DUMP ,alter table test2 allocate extent ;
如果是 First: 3,表示当前已经分配了3个区,那么对应的十六进制是0700,二进制为111。。见图:

2.在数据文件中有两个表,删除靠前的一个---位图中变为 First: 1,
BYS@ bys3>create table test4 (aa int) tablespace test2;Table created.
BYS@ bys3>insert into test4 select object_id from dba_objects;
17556 rows created.
BYS@ bys3>commit;
Commit complete.
BYS@ bys3>alter system checkpoint;
System altered.
BYS@ bys3>alter system dump datafile 7 block 3;
System altered.
BYS@ bys3>select value from v$diag_info where name like 'De%';
VALUE
----------------------------------------------------------------------------------------------------
/u01/diag/rdbms/bys3/bys3/trace/bys3_ora_22652.trc
此时DUMP文件中3号块的位图记录:
File Space Bitmap Block:
BitMap Control:
RelFno: 7, BeginBlock: 128, Flag: 0, First: 1204, Free: 62284
FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFF0F00 0000000000000000
删除第一个表:
BYS@ bys3>truncate table test2;
Table truncated.
BYS@ bys3>alter system checkpoint;
System altered.
BYS@ bys3>exit
新会话:
BYS@ bys3>alter system dump datafile 7 block 3;
System altered.
BYS@ bys3>select value from v$diag_info where name like 'De%';
VALUE
----------------------------------------------------------------------------------------------------
/u01/diag/rdbms/bys3/bys3/trace/bys3_ora_22707.trc
此时DUMP文件中3号块的位图记录:
RelFno: 7, BeginBlock: 128, Flag: 0, First: 1, Free: 63451
0100000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000FFFFFFFF0F00 0000000000000000
3.不同大小的区分配方式,对位图中区的记录没有影响。
BYS@ bys3>create tablespace test3 datafile '/u01/oradata/bys3/test3.dbf' size 100m uniform size 8m;Tablespace created.
BYS@ bys3>create table test33(aa int) tablespace test3;
Table created.
BYS@ bys3>insert into test33 values(11);
1 row created.
BYS@ bys3>commit;
Commit complete.
BYS@ bys3>alter system checkpoint;
System altered.
BYS@ bys3>alter system dump datafile 8 block 3;
System altered.
BYS@ bys3>select * from v$DIAG_INFO;
/u01/diag/rdbms/bys3/bys3/trace/bys3_ora_23058.trc
###########
RelFno: 8, BeginBlock: 128, Flag: 0, First: 1, Free: 63487
0100000000000000 0000000000000000 0000000000000000 0000000000000000
########33
BYS@ bys3>alter table test33 allocate extent;
Table altered.
BYS@ bys3>alter system checkpoint;
System altered.
BYS@ bys3>alter system dump datafile 8 block 3;
#############3
RelFno: 8, BeginBlock: 128, Flag: 0, First: 2, Free: 63486
0300000000000000 --这里的十六进制3,转换为二进制就是11,表示分配了两个区。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The retention period of Oracle database logs depends on the log type and configuration, including: Redo logs: determined by the maximum size configured with the "LOG_ARCHIVE_DEST" parameter. Archived redo logs: Determined by the maximum size configured by the "DB_RECOVERY_FILE_DEST_SIZE" parameter. Online redo logs: not archived, lost when the database is restarted, and the retention period is consistent with the instance running time. Audit log: Configured by the "AUDIT_TRAIL" parameter, retained for 30 days by default.

The Oracle database startup sequence is: 1. Check the preconditions; 2. Start the listener; 3. Start the database instance; 4. Wait for the database to open; 5. Connect to the database; 6. Verify the database status; 7. Enable the service (if necessary ); 8. Test the connection.

To find the number of occurrences of a character in Oracle, perform the following steps: Get the total length of a string; Get the length of the substring in which a character occurs; Count the number of occurrences of a character by subtracting the substring length from the total length.

Oracle database server hardware configuration requirements: Processor: multi-core, with a main frequency of at least 2.5 GHz. For large databases, 32 cores or more are recommended. Memory: At least 8GB for small databases, 16-64GB for medium sizes, up to 512GB or more for large databases or heavy workloads. Storage: SSD or NVMe disks, RAID arrays for redundancy and performance. Network: High-speed network (10GbE or higher), dedicated network card, low-latency network. Others: Stable power supply, redundant components, compatible operating system and software, heat dissipation and cooling system.

The amount of memory required by Oracle depends on database size, activity level, and required performance level: for storing data buffers, index buffers, executing SQL statements, and managing the data dictionary cache. The exact amount is affected by database size, activity level, and required performance level. Best practices include setting the appropriate SGA size, sizing SGA components, using AMM, and monitoring memory usage.

To create a scheduled task in Oracle that executes once a day, you need to perform the following three steps: Create a job. Add a subjob to the job and set its schedule expression to "INTERVAL 1 DAY". Enable the job.

The amount of memory required for an Oracle database depends on the database size, workload type, and number of concurrent users. General recommendations: Small databases: 16-32 GB, Medium databases: 32-64 GB, Large databases: 64 GB or more. Other factors to consider include database version, memory optimization options, virtualization, and best practices (monitor memory usage, adjust allocations).

70B model, 1000 tokens can be generated in seconds, which translates into nearly 4000 characters! The researchers fine-tuned Llama3 and introduced an acceleration algorithm. Compared with the native version, the speed is 13 times faster! Not only is it fast, its performance on code rewriting tasks even surpasses GPT-4o. This achievement comes from anysphere, the team behind the popular AI programming artifact Cursor, and OpenAI also participated in the investment. You must know that on Groq, a well-known fast inference acceleration framework, the inference speed of 70BLlama3 is only more than 300 tokens per second. With the speed of Cursor, it can be said that it achieves near-instant complete code file editing. Some people call it a good guy, if you put Curs
