Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a tablespace and why is it used?

While investigating an issue, I came across this error:

30503 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous tablespace mysql/innodb_index_stats uses space ID: 2 at filepath: ./mysql/innodb_index_stats.ibd. Cannot open tablespace Mydb/be_command_log which uses space ID: 2 at filepath: ./Mydb/be_command_log.ibd

After reading a bit about this issue, I came to know that this is a known issue of MySQL.

But my problem is that I don't know much about how tablespaces really work. How are they useful? I read this definition, but it does not give all the information.

Can someone share some detailed information about what are tablespaces and how do they work?

like image 390
Bhupesh Pant Avatar asked Jun 14 '16 07:06

Bhupesh Pant


People also ask

What is the purpose of tablespace in Oracle?

Each tablespace in an Oracle database is comprised of one or more operating system files called datafiles. A tablespace's datafiles physically store the associated database data on disk. A database's data is collectively stored in the datafiles that constitute each tablespace of the database.

What is tablespace in Oracle with example?

What is an Oracle Tablespace. Oracle divides a database into one or more logical storage units called tablespaces. Each tablespace consists of one or more files called datafiles. A datafile physically stores the data objects of the database such as tables and indexes on disk.

What is the difference between table and tablespace?

The tablespace is where tables gets stored. It links the physical storage layer (files on disks) and the logical storage layer (tables, indexes).

What is table space and its types?

There are three types of tablespaces: Permanent. You use permanent tablespaces to store your user and application data. Oracle Database uses permanent tablespaces to store permanent data, such as system data. Each user is assigned a default permanent tablespace.


1 Answers

A data file that can hold data for one or more InnoDB tables and associated indexes.

There are many types of tablespaces based on the configuration w.r.t the information clubbing per table. These are,

a. System tablespace b. File per tablespace c. General tablespace

System tablespace contains,

  1. InnoDB data dictionary.
  2. DoubleWrite Buffer.
  3. Change buffer
  4. Undo Logs.

Apart from this it also contains,

  1. Tables &
  2. Index data

Associated file is .idbdata1

The innodb_file_per_table option, which is enabled by default in MySQL 5.6 and higher, allows tables to be created in file-per-table tablespaces, with a separate data file for each table. Enabling the innodb_file_per_table option makes available other MySQL features such as table compression and transportable tablespaces.

Associated file is .idbd

InnoDB introduced general tablespaces in MySQL 5.7.6. General tablespaces are shared tablespaces created using CREATE TABLESPACE syntax. They can be created outside of the MySQL data directory, are capable of holding multiple tables, and support tables of all row formats.

like image 98
Bhupesh Pant Avatar answered Oct 13 '22 23:10

Bhupesh Pant