A tablespace is a logical division of a database, and a tablespace can only belong to one database. All
database
objects are stored in the specified tablespace. But the main storage is the table, so called the table space.
There is at least one tablespace in the Oracle database
, that is, the tablespace of SYSTEM.
The biggest difference between a SQL Server database and an Oracle database is the tablespace design. Oracle database pioneered the design concept of table space, which made an indelible contribution to the high performance of Oracle database. It can be said that many optimizations in Oracle are based on the design concept of table space.
Typical applications of tablespaces
edit
Typical application 1: Control the table space quota occupied by users.
In some large database applications, we need to control the disk space occupied by a user or a group of users. It's like in a file
server
,
disk
to prevent running out of hard disk space. Therefore, in the database, we also need to limit the amount of disk space that users can use. In order to achieve this goal, we can achieve through the table space.
We can create different table spaces in the Oracle database, set the maximum storage capacity for them, and then assign users to this table space. In this case, the storage capacity of the user is limited by the size of the table space.
Typical application 2: Control the disk space occupied by the database.
Sometimes, more than one service may be running while the Oracle database
server is running.
In addition to the
database
server , there may be application system servers such as
mail
servers. To this end, it is necessary to make a plan for the disk space of the Oracle database. Otherwise,
when
the disk space occupied by multiple application services increases infinitely, each service may stop due to the exhaustion of hard disk space. Therefore, when using multiple application services on the same server, we need to plan and allocate disk space for each application service first. The disk space of each service cannot exceed the maximum limit we allocate, or remind us in time after it exceeds. Only in this way can various application services crash due to the exhaustion of disk space.
Typical application 3: Place table spaces flexibly to improve the input and output performance of the database.
The database administrator
can also place different types of data in different tablespaces, which can significantly improve the database input and output performance, and is conducive
to
management work such as data backup and recovery. Because our database administrators can back up data by tablespace when backing up or restoring data. For example, when designing a large-scale
distribution system
background database
, we can create tablespaces by province. Data files related to Zhejiang Province are placed in the tablespace of Zhejiang Province, and business records in Beijing are recorded in the tablespace of Beijing. In this way, when there is an error in the business data of Zhejiang Province, the table space of Zhejiang Province can be directly restored. Obviously, this design can avoid the impact on other tablespaces when the data in a certain tablespace needs to be recovered.
In addition, tablespaces can be backed up independently. When the database capacity is relatively
large
, it will obviously take more time to back up the entire database at once. Although the Oracle database supports
hot
backup , it will occupy more system resources during the backup period, resulting in the decline of database performance. For this reason, when the database capacity is relatively large, we need to set up multiple table spaces, and then plan the backup time of each table space, so as to improve the backup efficiency of the entire database and reduce the impact of backup on the normal operation of the database.
Typical application four: sorting operation of large tables.
We all know that when there are many records in the table, querying them will be slower. After the first query is successful, if it is reordered a second time, it still takes so much time. For this reason, when we design the
database
often put it in a separate table space for this kind of large-capacity table object to improve the performance of the database.
Typical application five: log files and data files are separated to improve database security.
By default, log files and data files are stored in the same tablespace. However, this is not very good for
database
security . Therefore, in the process of database design, we often like to put log files, especially important log files, in a separate table space, and then store it on another hard disk. In this case, when the hard disk that stores the data files fails, the database can be repaired immediately through the redo log files stored in another table space, so as to reduce the losses caused by data loss.
Of course, the advantages of table space are not only these, the higher the performance requirements of the enterprise for the database, or the larger the database capacity, the greater the advantage of the table space will be.
Table space establishes the order relationship between table space and user establishment
edit
During
database
design , we recommend that
database
administrators set up tablespaces in the following order.
Step 1: Create a tablespace.
When designing a database, you first need to design a tablespace. We need to consider whether to create only one tablespace, or to create multiple tablespaces, as well as the storage location of each tablespace,
disk quota
, and so on.
There is no unified statement on how many table spaces to design are reasonable, which is mainly judged according to the actual needs of the enterprise. If the enterprise needs to control the disk quota for users, it needs to set the table space according to the number of users. When the data capacity of the enterprise is relatively large, and it has relatively high requirements on the performance of the database, it is necessary to set up different table spaces according to different types of data to improve its input and output performance.
Step 2: Create a user and develop a default tablespace for the user.
When creating a user, we recommend that the
database
administrator specify the user's default tablespace. Because when we use the CREATE statement to create
database
objects , such as database tables, they are stored in the current default space of the database by default. If the user default tablespace is not specified, the user must specify the tablespace every time a database object is created. Obviously, this is not very reasonable.
Also note that different tablespaces have different permission controls. The user has full control authority over tablespace A, and may only have query authority over tablespace B, and may not even have the authority to connect. Therefore, it is also a way to improve the security of the database to reasonably configure the access rights of the tablespace for the user.