ORACLE数据库设计与优化

<!-- /* Font Definitions */ @font-face {font-family:Wingdings; panose-1:5 0 0 0 0 0 0 0 0 0; mso-font-charset:2; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:0 268435456 0 0 -2147483648 0;} @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 159 0;} @font-face {font-family:Cambria; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1073741899 0 0 159 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face {font-family:"Trebuchet MS"; panose-1:2 11 6 3 2 2 2 2 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:647 0 0 0 159 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} h1 {mso-style-priority:9; mso-style-unhide:no; mso-style-qformat:yes; mso-style-link:"标题 1 Char"; mso-style-next:正文; margin-top:17.0pt; margin-right:0cm; margin-bottom:16.5pt; margin-left:21.6pt; text-align:justify; text-justify:inter-ideograph; text-indent:-21.6pt; line-height:240%; mso-pagination:lines-together; page-break-after:avoid; mso-outline-level:1; mso-list:l3 level1 lfo1; font-size:22.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-font-kerning:22.0pt;} h2 {mso-style-priority:9; mso-style-qformat:yes; mso-style-link:"标题 2 Char"; mso-style-next:正文; margin-top:13.0pt; margin-right:0cm; margin-bottom:13.0pt; margin-left:28.8pt; text-align:justify; text-justify:inter-ideograph; text-indent:-28.8pt; line-height:173%; mso-pagination:lines-together; page-break-after:avoid; mso-outline-level:2; mso-list:l3 level2 lfo1; font-size:16.0pt; font-family:"Cambria","serif"; mso-ascii-font-family:Cambria; mso-ascii-theme-font:major-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:Cambria; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi; mso-font-kerning:1.0pt;} h3 {mso-style-priority:9; mso-style-qformat:yes; mso-style-link:"标题 3 Char"; mso-style-next:正文; margin-top:13.0pt; margin-right:0cm; margin-bottom:13.0pt; margin-left:36.0pt; text-align:justify; text-justify:inter-ideograph; text-indent:-36.0pt; line-height:173%; mso-pagination:lines-together; page-break-after:avoid; mso-outline-level:3; mso-list:l3 level3 lfo1; font-size:16.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-font-kerning:1.0pt;} h4 {mso-style-noshow:yes; mso-style-priority:9; mso-style-qformat:yes; mso-style-link:"标题 4 Char"; mso-style-next:正文; margin-top:14.0pt; margin-right:0cm; margin-bottom:14.5pt; margin-left:43.2pt; text-align:justify; text-justify:inter-ideograph; text-indent:-43.2pt; line-height:156%; mso-pagination:lines-together; page-break-after:avoid; mso-outline-level:4; mso-list:l3 level4 lfo1; font-size:14.0pt; font-family:"Cambria","serif"; mso-ascii-font-family:Cambria; mso-ascii-theme-font:major-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:Cambria; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi; mso-font-kerning:1.0pt;} h5 {mso-style-noshow:yes; mso-style-priority:9; mso-style-qformat:yes; mso-style-link:"标题 5 Char"; mso-style-next:正文; margin-top:14.0pt; margin-right:0cm; margin-bottom:14.5pt; margin-left:50.4pt; text-align:justify; text-justify:inter-ideograph; text-indent:-50.4pt; line-height:156%; mso-pagination:lines-together; page-break-after:avoid; mso-outline-level:5; mso-list:l3 level5 lfo1; font-size:14.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-font-kerning:1.0pt;} h6 {mso-style-noshow:yes; mso-style-priority:9; mso-style-qformat:yes; mso-style-link:"标题 6 Char"; mso-style-next:正文; margin-top:12.0pt; margin-right:0cm; margin-bottom:3.2pt; margin-left:57.6pt; text-align:justify; text-justify:inter-ideograph; text-indent:-57.6pt; line-height:133%; mso-pagination:lines-together; page-break-after:avoid; mso-outline-level:6; mso-list:l3 level6 lfo1; font-size:12.0pt; font-family:"Cambria","serif"; mso-ascii-font-family:Cambria; mso-ascii-theme-font:major-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:Cambria; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi; mso-font-kerning:1.0pt;} p.MsoHeading7, li.MsoHeading7, div.MsoHeading7 {mso-style-noshow:yes; mso-style-priority:9; mso-style-qformat:yes; mso-style-link:"标题 7 Char"; mso-style-next:正文; margin-top:12.0pt; margin-right:0cm; margin-bottom:3.2pt; margin-left:64.8pt; text-align:justify; text-justify:inter-ideograph; text-indent:-64.8pt; line-height:133%; mso-pagination:lines-together; page-break-after:avoid; mso-outline-level:7; mso-list:l3 level7 lfo1; font-size:12.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt; font-weight:bold;} p.MsoHeading8, li.MsoHeading8, div.MsoHeading8 {mso-style-noshow:yes; mso-style-priority:9; mso-style-qformat:yes; mso-style-link:"标题 8 Char"; mso-style-next:正文; margin-top:12.0pt; margin-right:0cm; margin-bottom:3.2pt; margin-left:72.0pt; text-align:justify; text-justify:inter-ideograph; text-indent:-72.0pt; line-height:133%; mso-pagination:lines-together; page-break-after:avoid; mso-outline-level:8; mso-list:l3 level8 lfo1; font-size:12.0pt; font-family:"Cambria","serif"; mso-ascii-font-family:Cambria; mso-ascii-theme-font:major-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:Cambria; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi; mso-font-kerning:1.0pt;} p.MsoHeading9, li.MsoHeading9, div.MsoHeading9 {mso-style-noshow:yes; mso-style-priority:9; mso-style-qformat:yes; mso-style-link:"标题 9 Char"; mso-style-next:正文; margin-top:12.0pt; margin-right:0cm; margin-bottom:3.2pt; margin-left:79.2pt; text-align:justify; text-justify:inter-ideograph; text-indent:-79.2pt; line-height:133%; mso-pagination:lines-together; page-break-after:avoid; mso-outline-level:9; mso-list:l3 level9 lfo1; font-size:10.5pt; font-family:"Cambria","serif"; mso-ascii-font-family:Cambria; mso-ascii-theme-font:major-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:Cambria; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi; mso-font-kerning:1.0pt;} p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph {mso-style-priority:34; mso-style-unhide:no; mso-style-qformat:yes; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; text-indent:21.0pt; mso-char-indent-count:2.0; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} span.1Char {mso-style-name:"标题 1 Char"; mso-style-priority:9; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"标题 1"; mso-ansi-font-size:22.0pt; mso-bidi-font-size:22.0pt; mso-font-kerning:22.0pt; font-weight:bold;} span.2Char {mso-style-name:"标题 2 Char"; mso-style-priority:9; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"标题 2"; mso-ansi-font-size:16.0pt; mso-bidi-font-size:16.0pt; font-family:"Cambria","serif"; mso-ascii-font-family:Cambria; mso-ascii-theme-font:major-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:Cambria; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi; font-weight:bold;} span.3Char {mso-style-name:"标题 3 Char"; mso-style-priority:9; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"标题 3"; mso-ansi-font-size:16.0pt; mso-bidi-font-size:16.0pt; font-weight:bold;} span.4Char {mso-style-name:"标题 4 Char"; mso-style-noshow:yes; mso-style-priority:9; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"标题 4"; mso-ansi-font-size:14.0pt; mso-bidi-font-size:14.0pt; font-family:"Cambria","serif"; mso-ascii-font-family:Cambria; mso-ascii-theme-font:major-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:Cambria; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi; font-weight:bold;} span.5Char {mso-style-name:"标题 5 Char"; mso-style-noshow:yes; mso-style-priority:9; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"标题 5"; mso-ansi-font-size:14.0pt; mso-bidi-font-size:14.0pt; font-weight:bold;} span.6Char {mso-style-name:"标题 6 Char"; mso-style-noshow:yes; mso-style-priority:9; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"标题 6"; mso-ansi-font-size:12.0pt; mso-bidi-font-size:12.0pt; font-family:"Cambria","serif"; mso-ascii-font-family:Cambria; mso-ascii-theme-font:major-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:Cambria; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi; font-weight:bold;} span.7Char {mso-style-name:"标题 7 Char"; mso-style-noshow:yes; mso-style-priority:9; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"标题 7"; mso-ansi-font-size:12.0pt; mso-bidi-font-size:12.0pt; font-weight:bold;} span.8Char {mso-style-name:"标题 8 Char"; mso-style-noshow:yes; mso-style-priority:9; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"标题 8"; mso-ansi-font-size:12.0pt; mso-bidi-font-size:12.0pt; font-family:"Cambria","serif"; mso-ascii-font-family:Cambria; mso-ascii-theme-font:major-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:Cambria; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi;} span.9Char {mso-style-name:"标题 9 Char"; mso-style-noshow:yes; mso-style-priority:9; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"标题 9"; mso-bidi-font-size:10.5pt; font-family:"Cambria","serif"; mso-ascii-font-family:Cambria; mso-ascii-theme-font:major-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:Cambria; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:15.6pt;} div.Section1 {page:Section1;} /* List Definitions */ @list l0 {mso-list-id:62609625; mso-list-type:hybrid; mso-list-template-ids:-1443748050 67698693 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;} @list l0:level1 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:42.6pt; text-indent:-21.0pt; font-family:Wingdings;} @list l1 {mso-list-id:169681521; mso-list-type:hybrid; mso-list-template-ids:1333804264 67698693 590896308 67698693 67698689 67698691 67698693 67698689 67698691 67698693;} @list l1:level1 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:42.0pt; text-indent:-21.0pt; font-family:Wingdings;} @list l1:level2 {mso-level-start-at:3; mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:62.25pt; text-indent:-20.25pt; mso-ansi-font-size:10.5pt; font-family:Wingdings; mso-fareast-font-family:宋体; mso-bidi-font-family:宋体;} @list l2 {mso-list-id:385489189; mso-list-type:hybrid; mso-list-template-ids:2132054586 67698693 -1245944160 67698693 67698689 67698691 67698693 67698689 67698691 67698693;} @list l2:level1 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:42.0pt; text-indent:-21.0pt; font-family:Wingdings;} @list l2:level2 {mso-level-start-at:3; mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:60.0pt; text-indent:-18.0pt; mso-ansi-font-size:10.5pt; font-family:Wingdings; mso-fareast-font-family:宋体; mso-bidi-font-family:宋体;} @list l3 {mso-list-id:437220440; mso-list-template-ids:-806997388;} @list l3:level1 {mso-level-style-link:"标题 1"; mso-level-text:%1; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:21.6pt; text-indent:-21.6pt;} @list l3:level2 {mso-level-style-link:"标题 2"; mso-level-text:"%1/.%2"; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:28.8pt; text-indent:-28.8pt; mso-ansi-font-weight:bold;} @list l3:level3 {mso-level-style-link:"标题 3"; mso-level-text:"%1/.%2/.%3"; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:36.0pt; text-indent:-36.0pt;} @list l3:level4 {mso-level-style-link:"标题 4"; mso-level-text:"%1/.%2/.%3/.%4"; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:43.2pt; text-indent:-43.2pt;} @list l3:level5 {mso-level-style-link:"标题 5"; mso-level-text:"%1/.%2/.%3/.%4/.%5"; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:50.4pt; text-indent:-50.4pt;} @list l3:level6 {mso-level-style-link:"标题 6"; mso-level-text:"%1/.%2/.%3/.%4/.%5/.%6"; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:57.6pt; text-indent:-57.6pt;} @list l3:level7 {mso-level-style-link:"标题 7"; mso-level-text:"%1/.%2/.%3/.%4/.%5/.%6/.%7"; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:64.8pt; text-indent:-64.8pt;} @list l3:level8 {mso-level-style-link:"标题 8"; mso-level-text:"%1/.%2/.%3/.%4/.%5/.%6/.%7/.%8"; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:72.0pt; text-indent:-72.0pt;} @list l3:level9 {mso-level-style-link:"标题 9"; mso-level-text:"%1/.%2/.%3/.%4/.%5/.%6/.%7/.%8/.%9"; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:79.2pt; text-indent:-79.2pt;} @list l4 {mso-list-id:507670091; mso-list-type:hybrid; mso-list-template-ids:-93542940 67698693 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;} @list l4:level1 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:42.0pt; text-indent:-21.0pt; font-family:Wingdings;} @list l5 {mso-list-id:2049337260; mso-list-type:hybrid; mso-list-template-ids:1230816024 67698693 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;} @list l5:level1 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:42.0pt; text-indent:-21.0pt; font-family:Wingdings;} @list l5:level3 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:84.0pt; text-indent:-21.0pt; font-family:Wingdings;} ol {margin-bottom:0cm;} ul {margin-bottom:0cm;} -->

ORACLE 数据库设计与优化

1       Oracle 数据库设计策略及规范

1.1     基本策略

u  分类拆分数据量大的表。

对于经常使用的表(如某些参数表或代码对照表),由于其使用频率很高,要尽量减少表中的记录数量。

u  分区策略

在拥有数500 行以上的表时,采用分区策略。

u  索引设计。

在索引设计中,索引字段应挑选重复值较少的字段;在对建有复合索引的字段进行检索时,应注意按照复合索引字段建立的顺序进行。

u  减少表的关联,恰当的数据冗余是允许的。

u  为表和索引建立不同的表空间,禁止在系统表空间中放入非核心oracle 系统成分的对象, 确保数据表空间和索引表空间位于不同的磁盘磁盘驱动器上。

u  对于经常发生同时查询或频繁查询的表,最好把他放到不同的磁盘空间上。

1.2     逻辑设计规范

1.2.1  表设计

u  对于数据量比较大的表,根据表数据的属性进行分区。如果表按某些字段进行增长,则采用按字段值范围进行范围分区;如果表按某个字段的几个关键值进行分布,则采用列表分区;对于静态表,则采用Hash 分区或列表分区;在范围分区中,如果数据按某关键字段均衡分布,则采用子分区的复合分区方法。

u  每个表均创建类型为Sequence 的主键字段。

每个表中需含有如下几个基本字段:一个表的SEQ 号,4 个创建信息字段,5-8 个备用字段,一个删除标记字段,最好还有一个行版本字段

字段名

类型

备注

业务SEQ

整数型

作为表主键

OBLIGATE1

字符型

备用字段

OBLIGATE2

OBLIGATE3

OBLIGATE4

OBLIGATE5

CREATE_USER_ID

VARCHAR

创建用户ID

CREATE_DATETIME

DATE

创建时间

LAST_UPDATE_USER_ID

VARCHAR

更新用户ID

LAST_UPDATE_DATETIME

TIMESTAMP

更新时间

u  不要用Identify 字段作为表的主键与其它表关联。

u  把允许 NULL 的列放在表的后面

1.2.2  索引设计

 

u  常规OLTP 应用,创建B-TREE 索引, 不创建位图索引

u  不需要为记录数小于5000 的表,创建索引。

u  给单个表创建的索引不超过5 个,特别是海量交易类表。

u  索引条件查询结果记录,不超总记录的20%

u  不要给固定选项的字段创建独立索引。

u  对于复合索引,把查询频率比较高的字段排在索引组合的最前面。

u  索引放到独立的表空间,该表空间不需要REDO LOG

u  含有外键约束的表的字段,必须 有单独索引。如订单明细的表头外键。

u  表的字段很少,不适合建索引

 

2       SQL 语句优化

u  尽量使 SQL 语句能够使用索引

u  SQL 语句中包含 not in,<>,is null,is not null,like ‘%%’ 的时候不会用索引。

解决方法:

         IN in 会拆成一堆 or 的,可以使用表的索引

         NOT IN :强列推荐不使用。可以用 NOT EXISTS 或(外连接 + 判断为空)代替

         <> :永远不会用到索引的,用其它相同功能的操作运算代替。例如 a<>0 改为 a>0 or a<0 a<>’’ 改为 a>’’

         IS NULL IS NOT NULL :用其它相同功能的操作运算代替。如 a is not null 改为 a>0  a>’’ 等。

         LIKE :如 LIKE ‘%001%’ LIKE ‘001%’

u  多表查询时,一般一个大表关联几个小表。不要几个大表关联

u  经常查询的 SQL 可以写成存储过程

 

 

3       超大型数据库应用系统的设计方法

3.1     概论

超大型系统的特点为:

1. 处理的用户数一般都超过百万,有的还超过千万,数据库的数据量一般超过1TB

2. 系统必须提供实时响应功能,系统需不停机运行,要求系统有很高的可用性及可扩展性。

为了能达到以上要求,除了需要性能优越的计算机和海量存储设备外,还需要先进的数据库结构设计和优化的应用系统。

一般的超大型系统采用双机或多机集群系统。

3.2     Oracle 并行服务器应用划分策略

Oracle 并行服务器允许不同节点上的多个INSTANCE 实例同时访问一个数据库,以提高系统的可用性、可扩展性及性能。Oracle 并行服务器中的每个INSTANCE 实例都可将共享数据库中的表或索引的数据块读入本地的缓冲区中,这就意味着一个数据块可存在于多个INSTANCE 实例的SGA 区中。那么保持这些缓冲区的数据的一致性就很重要。Oracle 使用 PCM Parallel Cache Management ) 锁维护缓冲区的一致性,Oracle 同时通过I DLM ( 集成的分布式锁管理器)实现PCM , 并通过专门的LCK 进程实现INSTANCE 实例间的数据一致。

考虑这种情况:INSTANCE1BLOCK X 块修改,这时INSTANCE2BLOCK X 块也需要修改。Oracle 并行服务器利用PCM 锁机制,使BLOCK XINSTANCE 1SGA 区写入数据库数据文件中,又从数据文件中把BLOCK X 块读入INSTANCE2SGA 区中。发生这种情况即为一个PINGPING 使原来1MEMORY IO 可以完成的工作, 变成2DISK IO1 MEMORY IO 才能够完成, 如果系统中有过多的PING ,将大大降低系统的性能。

Oracle 并行服务器中的每个PCM 锁可管理多个数据块。PCM 锁管理的数据块的个数与分配给一个数据文件的PCM 锁的个数及该数据文件的大小有关。当INSTANCE 1INSTANCE 2 要操作不同的BLOCK ,如果这些BLOCK 是由同一个PCM 锁管理的, 仍然会发生PING 。这些PING 称为FALSE PING 。当多个INSTANCE 访问相同的BLOCK 而产生的PINGTRUE PING

合理的应用划分使不同的应用访问不同的数据,可避免或减少TRUE PING ;通过给FALSE PING 较多的数据文件分配更多的PCM 锁可减少 FALSE PING 的次数,增加PCM 锁不能减少TRUE PING

所以, Oracle 并行服务器设计的目的是使系统交易处理合理的分布在INSTANCE 实例间,以最小化PING ,同时合理的分配PCM 锁,减少FALSE PING 。设计的关键是找出可能产生的冲突,从而决定应用划分的策略。应用划分有如下四种方法:

1. 根据功能模块划分,不同的节点运行不同的应用

2. 根据用户划分,不同类型的用户运行在不同的节点上

3. 根据数据划分,不同的节点访问不同的数据或索引

4. 根据时间划分,不同的应用在不同的时间段运行

应用划分的两个重要原则是使PING 最小化及使各节点的负载大致均衡。

3.3     数据库物理结构的设计

数据库物理结构设计包括确定表及索引的物理存储参数,确定及分配数据库表空间,确定初始的回滚段,临时表空间,redo log files 等,并确定主要的初始化参数。物理设计的目的是提高系统的性能。整个物理设计的参数可以根据实际运行情况作调整。

表及索引数据量估算及物理存储参数的设置

表及索引的存储容量估算是根据其记录长度及估算的最大记录数确定的。在容量计算中考虑了数据块的头开销及记录和字段的头开销等等。表及索引的initialnext 存储参数一般设为相等,pctincrease 设为0

表空间的设计

Oracle 数据库的表和索引是透过表空间tablespace 存储在数据库中的。在tablespace 设计时一般作以下考虑:

1 、一般较大的表或索引单独分配一个tablespace

2 Read only 对象或Read mostly 对象分成一组,存在对应的tablespace 中。

3 、若tablespace 中的对象皆是read only 对象,可将tablespace 设置成read only 模式,在备份时,read only tablespace 只需备份一次。

4 、高频率insert 的对象分成一组,存在对应的tablespace 中。

5 、增、删、改的对象分成一组,存在对应的tablespace 中。

6 、表和索引分别存于不同的tablespace

7 、存于同一个 tablespace 中的表(或索引)的extent 大小最好成倍数关系,有利于空间的重利用和减少碎片。

● DB BLOCK SIZE

超大型数据库DB BLOCK SIZE 一般在4KB 64KB ,而最常用的是8KB 16KB32KB 。选用较大的DB BLOCK SIZE 可使INDEX 的高度降低,也会提高IO 效率。

● Redo Log Files

Oracle 进程redo log writer (LGWR) 将日志写入日志文件。一般日志文件最好建在专用的镜像盘上。日志文件组的个数及文件的大小的设定与系统交易量的大小有关。ORACLE 并行服务器中每个INSTANCE 使用各自的一组rego log files 。一般的每组日志文件的个数为3-7 个,每个的大小为200MB500MB

数据文件大小

建议用标准的文件大小,如200M 、1GB 、2GB4GB8GB 等,可简化空间的维护工作。

回滚段

回滚段一般建在专用的表空间中。每一个INSTANCE 实例拥有各自的回滚段。设置回滚段的一般原则是: initial next 存储参数的值是相等的,同时还是DB BLOCK SIZE 的倍数。每个回滚段的minextents 设为20optimal 参数的值保证回滚段缩小时不低于20extents

临时表空间

临时表空间一般建在专用的表空间中。每一个INSTANCE 实例拥有各自的临时表空间。这样使用临时表空间时不会有PING 。设置临时表空间的initial=next

3.4     系统硬盘的划分及分

在多机集群环境下,Oracle 并行服务器通过操作系统提供的DRD 服务来共享同一个数据库。每一个INSTANCE 对数据库的数据文件的访问都是通过该数据文件所在的DRD 服务进行的。

考虑以下情况:主机1 上有DRD 服务1 ,该服务对应的数据文件有12133567 等,这时如果主机2 上的INSTANCE2 需要读取数据文件13 ,通过DRD 服务调度,主机1 通过DRD 服务访问磁盘阵列上的数据文件13 ,把INSTANCE2 需要的数据读到内存,然后通过MEMORY IO 把数据传到主机2INSTANCE2 。写操作是读操作的逆过程。

通过以上分析可知,系统硬盘的划分及分配的原则是尽量减少MEMORY IO

3.5     备份及恢复策略的考虑

数据库的备份与恢复在系统设计中占很重要的地位。好的备份及恢复策略可以降低系统的运行风险,减少因硬件故障而造成的损失。

Oracle 备份方法:

1. 物理备份

将数据库的物理文件通过操作系统的命令或工具备份到备份介质上。物理备份往往用于存储介质故障时恢复数据库系统的数据。

根据数据库运行方式的不同,可进行不同的物理备份:

a) 物理冷备份(offline backup

物理冷备份要求数据库在关闭( 所有INSTANCEs 停止) 的情况下进行。这种备份必须是完全备份,即需备份所有的数据文件、控制文件(control file) 、日志文件(redo log file) 、初始参数文件等等。

物理冷备份的步骤简单,但要求系统能够停止。

b) 物理热备份(online backup

物理热备份是在数据库系统正常运行的情况下进行的数据库备份。这种备份可以是数据库的部分备份,既备份数据库的某个表空间(tablespace) 或某个数据文件(datafile) ,也可备份控制文件(control file)

物理热备份要求数据库在ARCHIVELOG 模式下运行。这种备份一般用于应用系统不能停机的情况。

c) 归档日志文件备份(archived log file backup)

要使数据库系统能够恢复到故障点前一时刻状态,或恢复到某指定时刻状态,数据库必须采用ARCHIVELOG 模式。在ARCHIVELOG 模式下,数据库系统会产生归档日志文件(archive log files) 。归档日志文件也需备份到备份介质上。在恢复时,这些文件可使数据库恢复到最近状态。

归档日志文件产生在指定目录下,这些文件一生成就可以备份到备份介质上,DBA 可根据磁盘空间情况,定时将它们备份出去。

2. 逻辑备份

逻辑备份是通过Oracle 提供的Export 工具,将数据库的结构定义及其数据卸出到特定格式的文件中,并备份该文件。

在实际应用中,逻辑备份与物理备份并用。一般来说,物理备份用于磁盘介质损坏或数据文件损坏;逻辑备份用于数据库中的某些对象被破坏或用户误操作。

备份策略的考虑主要在以下三个方面:

存储空间

对现行运行的系统的性能影响

恢复时间的影响

如果需要节省空间和恢复时间就需要增加备份的频率,但是备份操作会明显增加现行运行的系统的负载。、

Oracle 的恢复方法

根据不同的备份方法采用不同的恢复方法。

使用物理备份恢复

Oracle 提供了三种恢复手段:

1 、数据库级的恢复

2 、表空间(Tablespace) 的恢复

3 、数据文件的恢复

数据库级的恢复要求数据库在关闭但Mount 的状态下进行。表空间及数据文件的恢复可在数据库运行的状态下进行。

使用逻辑备份恢复

当数据库中的某一对象被损坏,或用户的误操作使数据破坏(如误删表) 时可用逻辑备份恢复。用逻辑备份只能恢复到备份时刻的状态。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值