一.表空间的创建 创建表空间: Create tablespace felix Datafile/u01/app/oracle/oradata/felix/felixtbs.dbf Size100m autoextendonnext10m maxsize1024m Extentmanagementlocaluniformsize128k Segmentspacemanagementauto; 这个很重要,如何查看创建的
一.表空间的创建
创建表空间:
Create tablespace felix
Datafile'/u01/app/oracle/oradata/felix/felixtbs.dbf'
Size100m autoextendonnext10m maxsize1024m
Extentmanagementlocaluniformsize128k
Segmentspacemanagementauto;
这个很重要,如何查看创建的表空间属性,就用如下的语句:
selecttablespace_name,block_size,contents,extent_management,allocation_type,segment_space_management
from dba_tablespaces
where tablespace_name='FELIX';
如果需要查看表空间的扩展属性,需要通过dba_data_files进行查看:
selecttablespace_name,autoextensible,increment_by,maxbytes
fromdba_data_files
where tablespace_name='FELIX';
--为应用创建用户
createuser felix identifiedby felix
defaulttablespace felix
temporarytablespace temp;
#创建用户的相关信息则可以通过DBA_USERS 视图查询得到:
selectusername,user_id,password,default_tablespace,temporary_tablespace
fromdba_users
whereusername='FELIX'
#进行相应的权限的授予:
grantconnect,resourceto felix;
revokeunnlimited tablesapce from felix;
alteruser felix quotaunlimitedon felix;
二.表空间管理技术
(1)数据字典表空间管理技术(DMT):所谓的数据字典管理表空间是指,当创建或者删除对象时,oracle的表空间分配或回收是通过数据库中的数据字典来记录和管理的,用于管理的两个数据字典分别是:UET$ (used extents,已使用的空间)和FET$ (free extents,空闲表空间)。
SQL> DESC UET$;
Name Type Nullable Default Comments
--------- ------ -------- ------- --------
SEGFILE# NUMBER
SEGBLOCK# NUMBER
EXT# NUMBER
TS# NUMBER
FILE# NUMBER
BLOCK# NUMBER
LENGTH NUMBER
SQL> DESC FET$;
Name Type Nullable Default Comments
------ ------ -------- ------- --------
TS# NUMBER
FILE# NUMBER
BLOCK# NUMBER
LENGTH NUMBER
可以清晰的看到文件号(FILE#),数据块号(BLOCK#)等信息来管理空间的分配和回收;
数据字典管理表空间的工作方式;当一个新的段或者段在表空间中请求新的空间时,oracle通过执行一系列的sql语句来完成这个工作,这些工作包括从FET$找到可用的自由空间移动或增减相应的行到UET$中,并在FET$中删除相应的记录;当删除一个段的时候,oracle则移动UET$中相应的行到FET$;这个过程是连续的、串行的,在繁忙的数据库中,这类操作极可能导致竞争和等待,产生数据字典的争用;另一方面,当数据字典的表的信息被修改时,系统同样要记录undo和redo信息,频繁的修改又不可避免的对整个数据库的性能产生影响;
然而,数据字典管理表空间面临的另外一个问题就是:空间碎片
(2)本地管理表空间技术(LMT):oracle不再使用数据字典管理而是在每个表空间的数据文件头加了一个位图区域,在其中记录每个extent的使用情况,每当一个extent被使用,或者被释放以供重新使用时oracle都会跟新数据文件头的这个记录,反应这个变化;
创建语法如下:
CREATE TABLESPACEtablespace_name
DATAFILE ‘datafile_path_name’
[EXTENT MANASGEMENT { LOCAL| AUTOALLOCATION | UNIFORM [SIZEINTER [K|M]]}];
由于区间(extent)是oracle创建对象时的最小分配单元,所以表空间的管理实际上就是针对区间的管理;
--通过DBA_TABLESPACES视图查询表空间的类型:
select tablespace_name,extent_management,allocation_type
from dba_tablespaces;
DBA_EXTENTS记录了每个对象分配的区间(EXTENT),哪些对象分配了多少空间以及区间具体位于的文件等信息:
SQL> SELECTEXTENT_ID,BLOCK_ID,BLOCKS FROM DBA_EXTENTS WHERE SEGMENT_NAME='TS_TEST';
EXTENT_ID BLOCK_ID BLOCKS
---------- ---------- ----------
0 536 8
1 544 8
2 552 8
3 560 8
4 568 8
5 576 8
6 584 8
7 592 8
8 600 8
9 608 8
... …
11 624 8
12 632 8
13 640 8
14 1800 8
15 1808 8
16 768 128
17 896 128
18 1024 128
19 1152 128
20 1280 128
21 1408 128
56 7040 128
57 7168 128
58 rowsselected
转储数据块信息:
select object_id,
dbms_rowid.rowid_relative_fno(rowid) file#,
dbms_rowid.rowid_block_number(rowid) block#
from ts_test
where rownum
进行dump查看:
#alter systemdumpdatafile3blockmax 1blockmin 6;
selectvaluefrom v$diag_info;
[oracle@felix ~]$ vi /u01/app/oracle/diag/rdbms/felix/felix/trace/felix_ora_3219.trc
*** 2014-03-25 00:53:38.498
Block 1 (file header) not dumped:use dump file header command
Block dump from cache:
Dump of buffer cache at level 4 for tsn=2rdba=12582914
BH (0x6dbf97a8) file#: 3 rdba: 0x00c00002(3/2) class: 13 ba: 0x6db88000
set: 3 pool: 3 bsz: 8192 bsi: 0 sflg: 1 pwc: 0,25
dbwrid: 0 obj: -1 objn: -1 tsn: 2 afn: 3 hint: f
hash: [0x77fb7be0,0x77fb7be0] lru: [0x6dbf9e80,0x6dbf9760]
lru-flags: hot_buffer
obj-flags: object_ckpt_list
ckptq: [0x6a3ed9a8,0x6a3e4eb8] fileq: [0x6c7e74c8,0x6bfe75f8] objq:[0x6d3e5e08,0x6dbf9788] objaq: [0x6dbf9eb8,0x6dbf9798]
st:XCURRENT md: NULL tch: 13
flags: buffer_dirty block_written_once redo_since_read
LRBA: [0x14.4b5f.0] LSCN: [0x0.14de1c] HSCN: [0x0.14de27] HSUB: [1]
Block dump from disk:
buffer tsn: 2 rdba: 0x00c00002 (3/2)
scn: 0x0000.00145380 seq: 0x02 flg: 0x04tail: 0x53801d02
frmt: 0x02 chkval: 0x1352 type: 0x1d=KTFB Bitmapped FileSpace Header
Hex dump of block: st=0, typ_found=1
Dump of memory from 0x00007FAD09B98200 to0x00007FAD09B9A200
7FAD09B98200 0000A21D 00C00002 0014538004020000 [.........S......]
7FAD09B98210 00001352 00000003 0000000800003700 [R............7..]
7FAD09B98220 00000009 00000280 003FFFFE0000007E [..........?.~...]
7FAD09B98230 000036FF 00000060 000004DA00145375 [.6..`.......uS..]
7FAD09B98240 00000000 00000000 0000000000000000 [................]
alter session set events 'immediate trace name file_hdrs level 10';
1 select file_id,extent_id,block_id,blocks
2 from dba_extents
3*where segment_name='TS_TEST'
FILE_ID EXTENT_ID BLOCK_ID BLOCKS
---------- ---------- ---------- ----------
4 0 536 8
4 1 544 8
4 2 552 8
4 13 640 8
4 14 1800 8
4 15 1808 8
4 16 768 128
4 17 896 128
4 18 1024 128
4 19 1152 128
4 20 1280 128
4 21 1408 128
4 22 1536 128
4 23 1664 128
4 24 2944 128
4 25 3072 128
4 26 3200 128
4 56 7040 128
4 57 7168 128
4 58 7296 128
59 rows selected.
SQL> select block_size,tablespace_name,min_extents,max_extents fromdba_tablespaces;
BLOCK_SIZE TABLESPACE_NAME MIN_EXTENTS MAX_EXTENTS
---------- ------------------------------ ----------- -----------
8192 SYSTEM 1 2147483645
8192 SYSAUX 1 2147483645
8192 UNDOTBS1 1 2147483645
8192 TEMP 1
8192 USERS 1 2147483645
8192 EXAMPLE 1 2147483645
8192 STATSPACK 1 2147483645
8192 STATSPACKTEMP 1
8192 FELIX 1 2147483645
9 rows selected
段空间管理技术:
段内则是以block为单位进行空间使用和管理的;
主要段的类型有:
SQL>select distinct(segment_type) fromdba_segments;
SEGMENT_TYPE
------------------------------------
LOBINDEX
INDEX PARTITION
TABLE SUBPARTITION
TABLE PARTITION
NESTED TABLE
ROLLBACK
LOB PARTITION
LOBSEGMENT
INDEX
TABLE
CLUSTER
TYPE2 UNDO
12 rows selected.
(1) 手工段空间管理(manual Segment space management):这种技术(9i之前的做法)是室通过段头分配的自由列表(pctlist)来管理block的使用,简单一点就是把自由列表想象成一个数据表,oracle依赖一系列的算法通过自由列表中加入或移出block来管理段空间;
(2) 自动断管理方式(autosegment space management):通过位图实现管理
ASSM的巨大优势是位图组能够减轻缓冲区忙等待(Bufferbusy wait)的负担,在9i以前的版本里曾是一个严重的问题;并且显著提高了并发性,因为位图数组的不同部分可以被同时使用,这样就消除了寻找剩余空间的串行化。
ASSM的管理机制,首先前2个数据块为数据文件头,3~8个数据块为位图区,接下来的第9个块和第10个块就是ASSM位图块;
进行dump第9个块:
Alter database dump datafile 3 block 9;
SQL>alter systemdump datafile 3 block 9;
System altered.
SQL>select value from v$diag_info;
VALUE
------------------------------------------------------------------------------------
TRUE
/u01/app/oracle
/u01/app/oracle/diag/rdbms/felix/felix
/u01/app/oracle/diag/rdbms/felix/felix/trace
/u01/app/oracle/diag/rdbms/felix/felix/alert
/u01/app/oracle/diag/rdbms/felix/felix/incident
/u01/app/oracle/diag/rdbms/felix/felix/cdump
/u01/app/oracle/diag/rdbms/felix/felix/hm
/u01/app/oracle/diag/rdbms/felix/felix/trace/felix_ora_3050.trc
0
0
11 rows selected.
tail -300 /u01/app/oracle/diag/rdbms/felix/felix/trace/felix_ora_3050.trc
*** 2014-03-25 02:07:30.355
Block dump from cache:
Dump of buffer cache at level 4 for tsn=2rdba=12582921
Block dump from disk:
buffer tsn: 2 rdba: 0x00c00009 (3/9)
scn: 0x0000.000f2557 seq: 0x01 flg: 0x04tail: 0x25571e01
frmt: 0x02 chkval: 0xc075 type: 0x1e=KTFBBitmapped File Space Bitmap
Hex dump of block: st=0, typ_found=1
Dump of memory from 0x00007FAD0893C600 to0x00007FAD0893E600
7FAD0893C600 0000A21E 00C00009 000F255704010000 [........W%......]
7FAD0893C610 0000C075 00000003 002E808000000000 [u...............]
7FAD0893C620 00000000 0000F800 0000000000000000 [................]
7FAD0893C630 00000000 00000000 0000000000000000 [................]
Repeat 507 times
7FAD0893E5F0 00000000 00000000 0000000025571E01 [..............W%]
File Space Bitmap Block:
BitMap Control:
RelFno: 3, BeginBlock: 3047552, Flag: 0,First: 0, Free: 63488
0000000000000000 0000000000000000 00000000000000000000000000000000
0000000000000000 00000000000000000000000000000000 0000000000000000
0000000000000000 00000000000000000000000000000000 0000000000000000
查询segment header,可以使用dba_segment视图:
SQL> selectsegment_name,header_file,header_file,header_block from dba_segments
2 where segment_NAME='TS_TEST';
SEGMENT_NAME HEADER_FILE HEADER_FILE HEADER_BLOCK
------------------- ----------- -----------------------
TS_TEST 4 4 538

MySQLhandlesconcurrencyusingamixofrow-levelandtable-levellocking,primarilythroughInnoDB'srow-levellocking.ComparedtootherRDBMS,MySQL'sapproachisefficientformanyusecasesbutmayfacechallengeswithdeadlocksandlacksadvancedfeatureslikePostgreSQL'sSerializa

MySQLhandlestransactionseffectivelyusingtheInnoDBengine,supportingACIDpropertiessimilartoPostgreSQLandOracle.1)MySQLusesREPEATABLEREADasthedefaultisolationlevel,whichcanbeadjustedtoREADCOMMITTEDforhigh-trafficscenarios.2)Itoptimizesperformancewithabu

Best practices include: 1) Understanding the data structure and MySQL processing methods, 2) Appropriate indexing, 3) Avoid SELECT*, 4) Using appropriate JOIN types, 5) Use subqueries with caution, 6) Analyzing queries with EXPLAIN, 7) Consider the impact of queries on server resources, 8) Maintain the database regularly. These practices can make MySQL queries not only fast, but also maintainability, scalability and resource efficiency.

MySQLisbetterforspeedandsimplicity,suitableforwebapplications;PostgreSQLexcelsincomplexdatascenarioswithrobustfeatures.MySQLisidealforquickprojectsandread-heavytasks,whilePostgreSQLispreferredforapplicationsrequiringstrictdataintegrityandadvancedSQLf

MySQL processes data replication through three modes: asynchronous, semi-synchronous and group replication. 1) Asynchronous replication performance is high but data may be lost. 2) Semi-synchronous replication improves data security but increases latency. 3) Group replication supports multi-master replication and failover, suitable for high availability requirements.

The EXPLAIN statement can be used to analyze and improve SQL query performance. 1. Execute the EXPLAIN statement to view the query plan. 2. Analyze the output results, pay attention to access type, index usage and JOIN order. 3. Create or adjust indexes based on the analysis results, optimize JOIN operations, and avoid full table scanning to improve query efficiency.

Using mysqldump for logical backup and MySQLEnterpriseBackup for hot backup are effective ways to back up MySQL databases. 1. Use mysqldump to back up the database: mysqldump-uroot-pmydatabase>mydatabase_backup.sql. 2. Use MySQLEnterpriseBackup for hot backup: mysqlbackup--user=root-password=password--backup-dir=/path/to/backupbackup. When recovering, use the corresponding life

The main reasons for slow MySQL query include missing or improper use of indexes, query complexity, excessive data volume and insufficient hardware resources. Optimization suggestions include: 1. Create appropriate indexes; 2. Optimize query statements; 3. Use table partitioning technology; 4. Appropriately upgrade hardware.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
