Table space in oracle, schema, segment, extent, block)

Source: Internet
Author: User

Data Files and log files are the most important files in the database. They are the place where data is stored. Each database has at least one related data file. Generally, there are more than one file. How is data organized in a data file? To understand this content, we must first understand what is table space, segments, partitions, and blocks ), these are the basic units for oracle databases to organize data in data files. Now let's understand these concepts.
Blocks are physical units of data storage and the most basic units in data files. Data is directly stored in blocks. Is the minimum unit for oracle space allocation. There are three common block sizes in oracle: 2 kb, 4 kb, and 8 KB. The block size is fixed when the database is created. The size of each block in the database is the same, and all the blocks have the same format, it consists of "Block header + Table directory + row directory + free space + Data Space. The block header contains information about the block type (such as the table block or index block) and the location of the block on the disk. The table directory contains information about the tables in each row in this block (if one block contains data from multiple tables ). The row directory contains the description of the data row. It is a pointer array that indicates the physical location of each row in the data block. Block headers, table directories, and row directories are collectively referred to as block overhead, which is the original statistics and Management block of oracle. The remaining two parts are simple. The data that already contains data is the data space, and the free space is not saved for the time being.
A partition, also called a disk partition, is a continuous allocation space in a data file. It is larger than a block and consists of blocks. Some objects may need at least two disk zones when allocating space, such as rollback segments. These two disk zones do not necessarily need to be connected. The partition size ranges from 1 block to 2 GB.
Segments are the allocation units in the oracle database. objects such as tables and indexes are allocated in segments. When a table is created, a table segment is created, and an index segment is created when an index is created. Each object that consumes storage space is stored in a single segment. Rollback segments, temporary segments, clustering segments, and index segments are supported.
A tablespace is a logical container associated with a data file. A tablespace must have at least one data file associated with it. One tablespace can have multiple segments, and one segment can belong to only one tablespace.
Schema, also called schema, is a logical concept that is a level smaller than the tablespace. It is also a logical container. Multiple users may share one tablespace. How can we separate each user? Each user has a corresponding solution in the tablespace to save the information of a single user.
The hierarchical structure of oracle storage is summarized as follows:
1. A database consists of one or more tablespaces.
2. a tablespace consists of one or more data files. A tablespace contains multiple segments.
3. A segment consists of one or more zones.
4. A partition is a continuous space allocated in a data file. It consists of one or more blocks.
5. blocks are the smallest and most basic units in the database and the smallest I/O units used by the database.
6. Each user has a corresponding solution

1. service name: the service name (actually the database name), which must be specified when installing ORACLE
2. tablespace table space: disk storage location of database objects
3. schema scheme, logical classification of database objects
4. user, equivalent to schema
5. service name> tablespace> schema (user)

Detailed description:
Schema is a set of database objects. To distinguish each set, we need to name this set. These names are the nodes with similar user names that we see in the schema of the Enterprise Manager, these username-like nodes are actually a schema. The schema contains various objects such as tables, views, sequences, stored procedures, synonyms, indexes, clusters, and database links.

A user generally corresponds to a schema. The schema name of the user is the same as the username and serves as the default schema of the user. This is why the schema names in the schema of the Enterprise Manager are database usernames. You cannot create a new schema in an Oracle database. To create a schema, you can only create a user, but it is not used to create a schema). When creating a user, create a schem with the same name as the user name and use it as the default shcema for the user. That is to say, the number of schemas is the same as the number of users, and the schema names are one-to-one and the same as the names of users. All aliases that can be called schema as users are inaccurate, but it is easier to understand.

A user has a default schema, and Its schema name is the same as the user name. Of course, a user can also use other schemas. If we access a table without specifying which schema the table belongs to, the system will automatically add the default sheman name to the table. For example, when we access the database, we can access the emp table under the scott user through select * from emp; in fact, the complete Syntax of this SQL statement is select * from scott. emp. The full name of an object in the database is schema. object, not user. object. Similarly, if we do not specify the schema of the object when creating the object, the schema of the object is the default schema of the user. This is like a user has a default tablespace, but the user can also use other tablespaces. If we do not specify tablespace when creating an object, the object is stored in the default tablespace, to store an object in other tablespaces, We need to specify the tablespace of the object when creating the object.

Example:
SQL> Gruant dba to scott
SQL> create table test (name char (10 ));
Table created.

SQL> create table system. test (name char (10 ));
Table created.

SQL> insert into test values ('Scott ');
1 row created.

SQL> insert into system. test values ('system ');
1 row created.

SQL> commit;
Commit complete.

SQL> conn system/manager
Connected.

SQL> select * from test;
NAME
----------
System

SQL> ALTER SESSION SET CURRENT_SCHEMA = scott; -- change the default schema name.
Session altered.

SQL> select * from test;
NAME
----------
Scott

SQL> select owner, table_name from dba_tables where table_name = upper ('test ');
OWNER TABLE_NAME
------------------------------------------------------------
SCOTT TEST
SYSTEM TEST

-- The preceding query uses schema as the alias of the user. In fact, shcema is exactly the same as the user, and there is no difference. The user name can also appear in the place where the schema name appears.

The schema is generally the same as the user. After a user is created, a schema is obtained. For example, after the HR user is created, the HR solution is available. When a table, index, and other database objects are created, to specify the schema to which it belongs, you must also specify the tablespace in which it is stored.
It can also be understood that schema is the logical attribution and classification of database objects, while tablespace is the physical and actual storage location of database objects.

Schema is a collection of objects to which users belong. objects include tables, indexes, views, JAVA, PL/SQL blocks, etc.
The Schema name is the same as the username. When a user is created, the shema corresponding to the user is also created. The username interacts with the schema.
There is no relation between Schema and tablespace. Objects in the same schema can be stored in different tablespaces, and objects in different schemas can be stored in the same tablespace.
Do not create other data objects in SYS and system schema.
Schema is the collection of database objects owned by a database user.
Schema has the same name as the user owns it.
Schema objects include structures such as tables, views, indexes, Java, PL/SQL etc ..
Schema is no relationship with tablespace.
Object in the same schema can be in different tablespaces.
When a database user is created, acorresponding schema with the same name is created for that user.
Username and Schema are offen used interchangeably.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.