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
What are stored procedures in MySQL?What are stored procedures in MySQL?May 01, 2025 am 12:27 AM

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

How does query caching work in MySQL?How does query caching work in MySQL?May 01, 2025 am 12:26 AM

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

What are the advantages of using MySQL over other relational databases?What are the advantages of using MySQL over other relational databases?May 01, 2025 am 12:18 AM

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

How do you handle database upgrades in MySQL?How do you handle database upgrades in MySQL?Apr 30, 2025 am 12:28 AM

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

What are the different backup strategies you can use for MySQL?What are the different backup strategies you can use for MySQL?Apr 30, 2025 am 12:28 AM

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

What is MySQL clustering?What is MySQL clustering?Apr 30, 2025 am 12:28 AM

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

How do you optimize database schema design for performance in MySQL?How do you optimize database schema design for performance in MySQL?Apr 30, 2025 am 12:27 AM

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

How can you optimize MySQL performance?How can you optimize MySQL performance?Apr 30, 2025 am 12:26 AM

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi

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

Video Face Swap

Video Face Swap

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

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use