[Oracle] The relationship among database instances, table spaces, users, and tables

A complete Oracle database usually consists of two parts: Oracle database and database instance.
1) A database is a collection of a series of physical files (data files, control files, online logs, parameter files, etc.);
2) An Oracle database instance is a set of Oracle background processes/threads and shared memory areas allocated on the server.

When the Oracle database server is started, an Oracle instance is actually created in the server's memory (that is, shared memory is allocated in the server memory and related background memory is created), and then the Oracle database instance is used to access and control the data in the disk file. Oracle has a large memory block and becomes the global area (SGA).

One, database, table space, data file

1. Database

A database is a collection of data. Oracle is a database management system and a relational database management system.
Usually, what we call "database" does not only refer to physical data collections, it includes physical data and database management systems. That is, a combination of physical data, memory, and operating system processes.

When we install the Oracle database, we will let us choose to install and start the database (that is, the default global database) as shown below:



Global database name: It is the identification of a database. It should be thought about during installation. Generally, it will not be modified in the future. It is troublesome to modify, because once the database is installed, the database name is written into the control file, database table, and it will be used in many places. The name of this database.

Start the database: also called the global database, it is the entrance of the database system, it will have some built-in users with advanced authority such as SYS, SYSTEM, etc. We can create tablespaces, users, and tables in the database instance by logging in with these high-level privilege accounts.

Query the current database name:

select name from v$database;

2. Database instance

Using Oracle's official description: an instance is a part of the computer memory and auxiliary processing background processes required to access the Oracle database. It is a collection of processes and the memory (SGA) used by these processes.
In fact, it is a process used to access and use the database. It only exists in memory. Just like the new instance object in Java.

When we visit Oracle, we are accessing an instance, but if this instance is associated with a database file, it can be accessed. If not, we will get an instance unavailable error.

The instance name refers to the name of the database management system used to respond to a certain database operation, and is also called SID. The instance name is determined by the parameter instance_name.

Query the name of the current database instance:

select instance_name from v$instance;

The database instance name (instance_name) is used to connect to the outside world. To get the connection with the database in the operating system, the database instance name must be used. For example, if we want to connect to the database for development, we have to connect to the database instance name:

jdbc:oracle:thin:@localhost:1521:orcl (orcl is the database instance name)

A database can have multiple instances, which can be used when making a database service cluster.

3. Table space

The Oracle database stores physical tables through table spaces. A database instance can have N table spaces, and a table space can have N tables .

With a database, you can create a table space.

Tablespace (tablespace) is a logical division of the database, each database has at least one tablespace (called SYSTEM tablespace). In order to facilitate management and improve operational efficiency, some additional table spaces can be used to divide users and applications. For example: the USER table space is for general users, and the RBS table space is for the rollback segment. A table space can only belong to one database.

Create table space syntax:

Create TableSpace 表空间名称  
DataFile          表空间数据文件路径  
Size              表空间初始大小  
Autoextend on

Such as:

create tablespace db_test  
datafile 'D:\oracle\product\10.2.0\userdata\db_test.dbf'  
size 50m  
autoextend on;

View the table space that has been created:

select default_tablespace, temporary_tablespace, d.username  
from dba_users d

4. User

After the Oracle database is built, if you want to create a table in the database, you must first create a user for the database and specify a table space for the user .

We have built the database and tablespace above, and then create users:

Create a new user:

CREATE USER          用户名  
IDENTIFIED BY        密码  
DEFAULT TABLESPACE   表空间(默认USERS)  
TEMPORARY TABLESPACE 临时表空间(默认TEMP) 

Such as:

CREATE USER utest  
IDENTIFIED BY utestpwd  
DEFAULT TABLESPACE db_test  
TEMPORARY TABLESPACE temp;(这里临时表空间不能使用我们创建的db_test,不知为何?) 

With a user, if you want to use a user account to manage your tablespace, you have to give it permissions:

GRANT CONNECT TO utest;  
GRANT RESOURCE TO utest;  
GRANT dba TO utest;--dba为最高级权限,可以创建数据库,表等。

View database users:

select  * from dba_users;

5. Table

With the database, table space, and user, you can create a table in your own table space with a custom user. With the table, we can develop.

Reference article

https://www.cnblogs.com/adforce/p/3312252.html

Guess you like

Origin blog.csdn.net/xiaoxiao_su123/article/details/114265414