search
HomeDatabaseMysql Tutorial初识Oracle表空间与数据文件

初识Oracle表空间与数据文件,描述oracle数据库的逻辑结构,创建表空间,改变表空间大小,为临时段分配空间,改变表空间状态,改

学习目标

1.描述Oracle数据库的逻辑结构
2.创建表空间
3.改变表空间大小
4.为临时段分配空间
5.改变表空间状态
6.改变表空间的存储设置

首先看一下oracle存储结构:

1.oracle数据库逻辑结构包含哪些东西?

1)表空间
    a.一个Oracle数据库逻辑上分为更小的逻辑区域叫做表空间
    b.一个表空间同时只属于一个数据库
    c.每个表空间由一个或多个系统文件组成,叫做数据文件datafile
    d.一个表空间可以有1个或多个段组成
    e.当数据库运行时表空间可以是online状态
    f.除了SYSTEM表空间或者带有活动回滚段的表空间,其他表空间可以设置为offline状态
    g.表空间可以再读写(read-write)和只读(read-only)状态间切换

2)段
    a.一个段是在一个表空间中为指定的逻辑存数结构分配的空间。例如,分配给一个表的所有存储就是一个段。
    b.一个段只能属于一个表空间,可以跨越多个数据文件
    c.一个段由一个或多个区组成

3)区
    a.随着段的增长,额外的区将分配给段
    b.DBA可以为段手动增加区
    c.一个区是连续的oracle块集合
    d.一个区只能在一个数据文件中存在

4)块
    a.块作为oracle数据库最小的存储单位,数据全部存储在数据块中。
    b.一个oracle数据块相当于一个或多个从已存在的数据文件中分配的操作系统块
    c.一个标准数据块的大小由数据库创建时的初始化参数DB_BLOCK_SIZE指定
    d.为避免不必要的I/O,数据块的大小应该是操作系统块大小的几倍
    e.最大的数据块大小取决于操作系统

2.系统表空间与非系统表空间的区别?

1)系统表空间 system tablespaces:
    a.随着数据库的创建而创建
    b.在所有数据库中必须存在
    c.系统表空间包含数据字典,存储程序单元
    e.包含系统回滚段
    f.最好不要包含用户数据

2)非系统表空间 non-system tablespaces:
    a.分离回滚段、临时段、应用数据段和应用索引段
    b.通过备份需求分离数据
    c.分离动态和静态数据
    e.控制用户对象空间分配的数量
    f.方便数据库管理

3.如何创建表空间?
使用create tablespace语句,一下是官方示例:

CREATE TABLESPACE userdata
    DATAFILE '/u01/oradata/userdata01.dbf' SIZE 100M
   AUTOEXTEND ON NEXT 5M MAXSIZE 200M;

CREATE TABLESPACE tablespace
 [DATAFILE clause]
 [MINIMUM EXTENT integer[K|M]]
 [BLOCKSIZE integer [K]]
 [LOGGING|NOLOGGING]
 [DEFAULT storage_clause ]
 [ONLINE|OFFLINE]
 [PERMANENT|TEMPORARY]

MINIMUM EXTENT 指定最小区大小,,使用K(千兆)或M(兆)
LOGGING  默认值,指定表空间中对所有表,索引和分区修改写入到redo中
NOLOGGING 与LOGGING相反
ONLINE与OFFLINE 创建完表空间后是否立即可用
PERMANENT 指定表空间可用来保留永久对象
TEMPORARY 指定表空间只能来保留临时对象
AUTOEXTEND 启用数据文件自动扩展

4.管理表空间的方式?
1)本地管理表空间
    a.用位图bitmap(在每个数据文件中维护)记录空闲区
    b.每个bit对应一个数据块
    c.bit值指示空闲和已使用
好处:减少数据字典表的争用;空间分配和回收不发生undo;没有合并需求(减少碎片);

用法举例:
CREATE TABLESPACE userdata
  DATAFILE '/u01/oradata/userdata01.dbf' SIZE 500M
  EXTENT MANAGEMENT LOCAL UNIFORM SIZE 256K;

[ EXTENT MANAGEMENT
    [ DICTIONARY | LOCAL
  [ AUTOALLOCATE | UNIFORM [SIZE integer[K|M]] ] ] ]

LOCAL和DICTIONARY 就不解释了。
AUTOALLOCATE 指定表空间由系统管理,用户不能指定区大小
UNIFORM 指定表空间由同一的区大小管理。使用K或M指定大小。

2)数据字典管理表空间
    a.默认管理方法
    b.空闲区被记录在数据字典表中

CREATE TABLESPACE userdata
  DATAFILE '/u01/oradata/userdata01.dbf' SIZE 500M
  EXTENT MANAGEMENT DICTIONARY
   DEFAULT STORAGE ( initial 1M NEXT 1M );

5.undo表空间
1)undo表空间只能用来存储回滚段
2)创建undo表空间只能使用DATAFILE和EXTENT MANAGEMENT语句
CREATE UNDO TABLESPACE undo1
  DATAFILE '/u01/oradata/undo101.dbf' SIZE 40M;

6.temporary表空间
1)用来进行排序操作 SORT_AREA_SIZE(用来设置排序区的大小)
2)不能包含任何永久对象
3)推荐使用本地管理
CREATE TEMPORARY TABLESPACE temp
  TEMPFILE '/u01/oradata/temp01.dbf' SIZE 500M
  EXTENT MANAGEMENT LOCAL UNIFORM SIZE 10M;

4)本地管理临时表空间有临时数据文件tempfiles:
    a.临时文件一直是NOLOGGING模式
    b.不能设置临时文件为只读read-only
    c.不能重命名一个临时文件
    d.不能使用ALTER DATABASE命令增加临时文件
    e.临时文件对于只读数据库是需要的
    f.介质恢复不恢复临时文件
    g.备份控制文件时不生成任何临时文件的信息
    h.创建控制文件时不能指定任何关于临时文件的信息

7.默认default临时表空间
1)避免使用SYSTEM表空间存储临时数据
2)可以使用CREATE DATABASE和ALTER DATABASE语句创建
3)当使用CREATE DATABSE命令创建,默认临时表空间为本地管理

默认临时表空间的限制:
    a.没有指定新的默认临时表空间之前不能删除现有默认临时表空间
    b.不能更改默认临时表空间为永久类型
    c.不能修改默认临时表空间为offline状态
注:SYSTEM表空间、带有活动回滚段和默认临时表空间不能设置为离线状态

linux

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
When should you use a composite index versus multiple single-column indexes?When should you use a composite index versus multiple single-column indexes?Apr 11, 2025 am 12:06 AM

In database optimization, indexing strategies should be selected according to query requirements: 1. When the query involves multiple columns and the order of conditions is fixed, use composite indexes; 2. When the query involves multiple columns but the order of conditions is not fixed, use multiple single-column indexes. Composite indexes are suitable for optimizing multi-column queries, while single-column indexes are suitable for single-column queries.

How to identify and optimize slow queries in MySQL? (slow query log, performance_schema)How to identify and optimize slow queries in MySQL? (slow query log, performance_schema)Apr 10, 2025 am 09:36 AM

To optimize MySQL slow query, slowquerylog and performance_schema need to be used: 1. Enable slowquerylog and set thresholds to record slow query; 2. Use performance_schema to analyze query execution details, find out performance bottlenecks and optimize.

MySQL and SQL: Essential Skills for DevelopersMySQL and SQL: Essential Skills for DevelopersApr 10, 2025 am 09:30 AM

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

Describe MySQL asynchronous master-slave replication process.Describe MySQL asynchronous master-slave replication process.Apr 10, 2025 am 09:30 AM

MySQL asynchronous master-slave replication enables data synchronization through binlog, improving read performance and high availability. 1) The master server record changes to binlog; 2) The slave server reads binlog through I/O threads; 3) The server SQL thread applies binlog to synchronize data.

MySQL: Simple Concepts for Easy LearningMySQL: Simple Concepts for Easy LearningApr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL: A User-Friendly Introduction to DatabasesMySQL: A User-Friendly Introduction to DatabasesApr 10, 2025 am 09:27 AM

The installation and basic operations of MySQL include: 1. Download and install MySQL, set the root user password; 2. Use SQL commands to create databases and tables, such as CREATEDATABASE and CREATETABLE; 3. Execute CRUD operations, use INSERT, SELECT, UPDATE, DELETE commands; 4. Create indexes and stored procedures to optimize performance and implement complex logic. With these steps, you can build and manage MySQL databases from scratch.

How does the InnoDB Buffer Pool work and why is it crucial for performance?How does the InnoDB Buffer Pool work and why is it crucial for performance?Apr 09, 2025 am 12:12 AM

InnoDBBufferPool improves the performance of MySQL databases by loading data and index pages into memory. 1) The data page is loaded into the BufferPool to reduce disk I/O. 2) Dirty pages are marked and refreshed to disk regularly. 3) LRU algorithm management data page elimination. 4) The read-out mechanism loads the possible data pages in advance.

MySQL: The Ease of Data Management for BeginnersMySQL: The Ease of Data Management for BeginnersApr 09, 2025 am 12:07 AM

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor