Home Database Mysql Tutorial Oracle表空间管理

Oracle表空间管理

Jun 07, 2016 pm 04:21 PM
oracle space manage

2 表空间 Oracle磁盘管理中的最高逻辑层是表空间,Oracle11g中必须创建的4个表空间是SYSTEM, SYSAUX,TEMP, UNDOTBS1。 2 SYSTEM:存储数据字典等,pl/sql代码等。 2 SYSAUX:存储与数据库选项相关的数据 2 TEMP:用于大的排序操作 2 UNDUTBS1:为读一致性和

   2 表空间

  Oracle磁盘管理中的最高逻辑层是表空间,Oracle11g中必须创建的4个表空间是SYSTEM, SYSAUX,TEMP, UNDOTBS1。

  2 SYSTEM:存储数据字典等,pl/sql代码等。

  2 SYSAUX:存储与数据库选项相关的数据

  2 TEMP:用于大的排序操作

  2 UNDUTBS1:为读一致性和恢复的目的,存储事务信息。

  表空间的下一层是段,一个段只能驻留在一个表空间中;一个或多个区可以组成一个段,每个区只能驻留在一个数据文件中;一组连续的数据块可以组成一个区。如果要查询表空间与对应的数据文件的相关信息,可以从dba_data_files数据字典中查询表空间及其包含的数据文件,举例如下:

  SQL> col tablespace_name for a10;

  SQL> col file_name for a50;

  SQL> col bytes for 999,999,999;

  SQL>Select tablespace_name,file_name, bytes fromdba_data_files order by tablespace_name;

  1、 SYSTEM表空间

  SYSTEM表空间存放内部数据和数据字典,主要存放SYS用户的各个对象和其他用户的少量对象。例如:查询USERS表空间中存放的数据对象及其类型和拥有者。

  SQL>col owner for a10;

  SQL>col segment_name for a30;

  SQL>col segment_type for a20;

  SQL>select segment_type,segment_name,owner fromdba_segments where tablespace_name='USERS';

  2、 SYSAUX表空间

  SYSAUX表空间充当SYSTEM表空间的辅助表空间,,主要用于存储除数据字典以外的其他数据对象。例如,查询SYSAUX表空间所存放的用户及其所拥有的对象数量:

  Select owner as 用户, count(segment_name) as 对象数量 fromdba_segments where tablespace_name='SYSAUX' group by owner;

  3、 创建表空间

  创建表空间的语法如下:

  Create [smallfile | bigfile] tablespace tablespace_name

  Datafile '/path/filename' size num[k|m] reuse

  ['/path/filename' size num[k|m]reuse]

  [, …]

  [autoextend [on|off] next ] num[k|m]

  [maxsize [unlimited | num[k|m]]]

  [mininum extent num[k|m]]

  [default storage storage]

  [online | offline]

  [logging | nologging]

  [permanent | temporary]

  [extent management dictionary | local [autoallocate |uniform size num[k|m]]];

  说明:

  ? smallfile | bigfile:表示创建的是小文件表空间还是大文件表空间

  ? autoextend [on|off] next:表示数据文件为自动扩展或非自动扩展,如为自动扩展则需要设置next的值。

  ? maxsize:表示数据文件自动扩展时,允许数据文件扩展的最大长度字节数,如果指定unlimited关键字,则不需要指定字节长度。

  ? minimum extent:指出在表空间的extent的最小值,这个参数可以减少空间碎片,保证在表空间的extent是这个数值的整数倍。

  ? online | offline:创建表空间时可以指定为在线或离线。

  ? permanent | temporary:指定创建表空间是永久表空间或临时表空间。默认为永久表空间。

  ? logging | nologging:指定该表空间内的表在加载数据时是否产生日志,默认为产生日志,即使设定为nologging,但在进行insert,update,delete操作时,oracle仍会将信息记录到redo log buffer中。

  ? extent management dictionary | local:指定表空间的扩展方式是使用数据字典管理还是本地化管理。默认为本地化管理。

  ? autoallocate | uniform size:如果采用本地化管理,在表空间扩展时,指定每次区的扩展大小是系统自动指定还是按照同等大小进行。如果设定uniform关键字,默认扩展大小为1MB。

  ? reuse:表示如果该文件存在,则清除该文件再重建该文件;若文件不存在,则创建该文件。

  ? default storage:设定以后要创建的表、索引、簇的存储参数值。

  4、 删除表空间

  ? 删除空的表空间,但是不包含物理文件

  drop tablespacetablespace_name;

  ? 删除非空表空间,但是不包含物理文件

  drop tablespacetablespace_name including contents;

  ? 删除空表空间,包含物理文件

  drop tablespace tablespace_nameincluding datafiles;

  ? 删除非空表空间,包含物理文件

  drop tablespacetablespace_name including contents and datafiles;

  ? 如果其他表空间中的表有外键等约束关联到了本表空间中的表的字段,就要加上CASCADECONSTRAINTS

  drop tablespacetablespace_name including contents and datafiles CASCADE CONSTRAINTS;

  5、 案例

  ? 创建表空间,然后删除该表空间。

  Createtablespace exampletb

  Datafile 'E: examp01.dbf' size 5M autoextend on next 128k maxsize 1000m,

  'E: examp02.dbf' size 5Mautoextend on next 128k maxsize 1000m;

  说明:以上例子创建的表空间由examp01.dbf和examp02.dbf两个文件组成。创建完成后,可以发现在相应路径下增加了2个文件。

  drop tablespaceexampletb;

  ? 创建表空间和表,然后删除该表空间。

  Createtablespace exampletb Datafile 'E: examp01.dbf'size 5M autoextendon next 128k maxsize 1000m reuse,

  'E:examp02.dbf' size 5Mautoextend on next 128k maxsize 1000m reuse;

  create tablescott.student

  (

  id number,

  name VARCHAR2(10)

  )tablespaceexampletb;

  说明:向student表插入数据时,数据将存储在表空间exampletb中,而exampletb表空间拥有一个或多个数据文件,所以student数据最终存储到examp01和examp02的数据文件中。

  drop tablespaceexampletb including contents;

  ? 创建表空间,然后删除该表空间及数据文件。

  Create tablespaceexampletb

  Datafile 'E: examp01.dbf' size 5M autoextend on next 128k maxsize 1000mreuse,

  'E:examp02.dbf' size 5Mautoextend on next 128k maxsize 1000m reuse;

  drop tablespaceexampletb including datafiles;

  ? 创建表空间和表,然后删除该表空间及数据文件。

  Createtablespace exampletb

  Datafile 'E: examp01.dbf' size 5M autoextend on next 128k maxsize 1000m,

  'E:examp02.dbf' size 5Mautoextend on next 128k maxsize 1000m;

  create tablescott.student

  (

  id number,

  name VARCHAR2(10)

  )tablespaceexampletb;

  drop tablespaceexampletb including contents and datafiles;

  说明:如果drop tablespace语句中含有datafiles,那datafiles之前必须有contents关键字,不然会提示错误。

  ? 创建两个表空间,分别在其中创建主码表和外码表,然后删除包含主码表的表空间及数据文件。

  Createtablespace exampletb1

  Datafile 'E: examp03.dbf' size 5M autoextend on next 128k maxsize 1000m;

  Createtablespace exampletb2

  Datafile 'E: examp02.dbf' size 5M autoextend on next 128k maxsize 1000m;

  create tabletest1(mobile number(13) primary key)tablespace exampletb1;

  create table test2(mobile number(13) references test1(mobile)) tablespace exampletb2;

  drop tablespace exampletb1 including contents and datafiles cascade constraints;

Statement of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

What to do if the oracle log is full What to do if the oracle log is full Apr 12, 2025 am 06:09 AM

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

See all articles