Data files and log files are the most important files in the database. They are where the data is stored. Each database has at least one data file associated with it, usually more than one and many. How the data is organized in the data file. To understand these things, we first have to understand what is tablespace (tablespace), segments (segment), extents (extent), blocks (block), which are the basic units in which Oracle databases organize data in data files. Now we have to understand these concepts.
Block is the physical unit of data storage, and it is the most basic unit in the data file, and the data is stored directly on the block. is the smallest unit of Oracle space allocation. The size of the blocks in Oracle is typically three, 2KB, 4KB, 8KB. The size of the block is fixed when the database is created, the size of each block in the database is the same, and all blocks have the same format, composed of "Block size + Table Directory + row directory + Free Space + data space". The size contains information such as the block type (for example, the table block, or the index block), the location of the block on the disk, and so on. Tables directory (table directory), if any, contains information about the tables in this block that store each row, if there is data in more than one table in a block. Row directory contains descriptive information about the rows of data, which is an array of pointers indicating the physical location of each row in the data block. The block size, table directory, and row directory are collectively called blocks overhead, which is Oracle's original statistics and management block itself. The rest of the two parts is very simple, already have data is the data space, temporarily did not save is the free space.
Area is called the disk area, is a continuous allocation space in the data file, it is larger than the block, composed of blocks. Some objects may require at least two disks when allocating space, such as rolling back segments, and these two areas are not necessarily connected. The size of the zone ranges from one block to 2GB
A segment is an allocation unit in an Oracle database, and objects such as tables, indexes, and so on are allocated in segments. When you create a table, a table segment is created, and an index segment is created when an index is created. Each object that consumes storage space is eventually stored in a single segment. There are rollback segment, temporary segment, cluster segment, index segment, etc.
A tablespace is a logical container that is associated with a data file and a table space that has at least one data file associated with it. A table space can have multiple segments, and a segment can only belong to one table space.
Schema, also called pattern, is a logical concept that is smaller than table space, and it is also a logical container. Multiple users may share a table space, and that's how to partition each user. Then there is a scenario for each user in the tablespace to hold the individual user's information.
The hierarchical structure of storage in Oracle is summarized as follows:
A database consists of one or more table spaces
The table space consists of one or more data files, and a table space contains multiple segments
A section is made up of one or more areas.
The region is a continuous allocation space in a data file, consisting of one or more blocks
Block is the smallest and most basic unit in the database, and is the smallest I/O unit used by the database.
Six, each user has a corresponding solution
1. Service name (in fact, database name), a name that must be specified when ORACLE is installed
2. Tablespace table space, the 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 collection of database objects, in order to distinguish the collections, we need to give this collection a name, which we see in the Enterprise Manager schema of many similar user-name nodes, these similar user name node is actually a Schema,schema It contains a variety of objects such as: tables,views,sequences,stored Procedures,synonyms,indexes,clusters,and database links.
A user typically corresponds to a schema, the user's schema name equals the user name, and is the default schema for that user. This is why we see schema names as database user names under the schema of Enterprise Manager. A schema cannot be created in an Oracle database, and to create a schema can only be resolved by creating a user (although Oracle has a CREATE SCHEMA statement, but it is not used to create a schema), creating a user To create a schem with the same name as the user name for this user, and as the default shcema for that person. That is, the number of schemas is the same as the number of user, and the schema name corresponds to the user name one by one, and all of the aliases we can call schema the user, although this is not accurate, is easier to understand.
A user has a default schema whose schema name equals the username, and of course a user can use a different schema. If we visit a table without specifying which schema the table belongs to, the system automatically adds the default Sheman name to the table. For example, when we visit the database, we visit the EMP table under Scott's user, through the select * from EMP; In fact, this SQL statement is fully written as 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 a schema for the object when we create the object, the schema of the object is the default schema of user. It's like a user has a default tablespace, but the user can also use other tablespace, and if we don't specify tablespace when we create an object, the object is stored in the default tablespace, and you want the object to be stored in the other In tablespace, we need to specify the object's tablespace when we create the object.
Examples are as follows:
Sql> Gruant DBA to Scott
Sql> CREATE TABLE 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; --Changing the user 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 query above is the basis for the alias of the schema as user. In fact, in use, Shcema is exactly the same as user, and the user name can appear where the schema name appears.
Schema and user are generally consistent, the establishment of a user can be a schema, such as: HR users after the establishment of the HR program, then set up tables, indexes and other database objects, to specify which schema it belongs to, also to specify its storage in which tablespace.
It can also be understood that schema is the logical attribution and classification of database objects, and tablespace is the physical and actual storage location of database objects.
A Schema is a collection of objects that the user belongs to, including tables, indexes, views, java,pl/sql blocks, and so on.
Schema has the same name as the user name, and when a user is created, the corresponding Shema of that user is also created, and the user name interacts with the schema.
There is no connection between schema and Tablespace, objects of the same schema can be stored in different table spaces, and objects of different schemas can be stored in the same tablespace.
Do not create additional data objects under the SYS and system schemas.
Schema is the collection's 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 is in different tablespaces.
When a database user are created,acorresponding schema with the same name is created to that user.
Username and Schema are offen used interchangeably.
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.