MySQL 8.0 Reference Manual Including MySQL NDB Cluster 8.0

28.3.15 The INFORMATION_SCHEMA FILES Table

The FILES table provides information about the files in which MySQL tablespace data is stored.

The FILES table provides information about InnoDB data files. In NDB Cluster, this table also provides information about the files in which NDB Cluster Disk Data tables are stored. For additional information specific to InnoDB, see InnoDB Notes, later in this section; for additional information specific to NDB Cluster, see NDB Notes.

The FILES table has these columns:

Notes

  • FILES is a nonstandard INFORMATION_SCHEMA table.

  • As of MySQL 8.0.21, you must have the PROCESS privilege to query this table.

InnoDB Notes

The following notes apply to InnoDB data files.

  • Information reported by FILES is obtained from the InnoDB in-memory cache for open files, whereas INNODB_DATAFILES gets its data from the InnoDB SYS_DATAFILES internal data dictionary table.

  • The information provided by FILES includes global temporary tablespace information which is not available in the InnoDB SYS_DATAFILES internal data dictionary table, and is therefore not included in INNODB_DATAFILES.

  • Undo tablespace information is shown in FILES when separate undo tablespaces are present, as they are by default in MySQL 8.0.

  • The following query returns all FILES table information relating to InnoDB tablespaces.

    SELECT
      FILE_ID, FILE_NAME, FILE_TYPE, TABLESPACE_NAME, FREE_EXTENTS,
      TOTAL_EXTENTS, EXTENT_SIZE, INITIAL_SIZE, MAXIMUM_SIZE,
      AUTOEXTEND_SIZE, DATA_FREE, STATUS
    FROM INFORMATION_SCHEMA.FILES
    WHERE ENGINE='InnoDB'\G
    

NDB Notes

  • The FILES table provides information about Disk Data files only; you cannot use it for determining disk space allocation or availability for individual NDB tables. However, it is possible to see how much space is allocated for each NDB table having data stored on disk—as well as how much remains available for storage of data on disk for that table—using ndb_desc.

  • Beginning with NDB 8.0.29 much of the information in the FILES table can also be found in the ndbinfo.files table.

  • The CREATION_TIME, LAST_UPDATE_TIME, and LAST_ACCESSED values are as reported by the operating system, and are not supplied by the NDB storage engine. Where no value is provided by the operating system, these columns display NULL.

  • The difference between the TOTAL EXTENTS and FREE_EXTENTS columns is the number of extents currently in use by the file:

    SELECT TOTAL_EXTENTS - FREE_EXTENTS AS extents_used
        FROM INFORMATION_SCHEMA.FILES
        WHERE FILE_NAME = './myfile.dat';
    

    To approximate the amount of disk space in use by the file, multiply that difference by the value of the EXTENT_SIZE column, which gives the size of an extent for the file in bytes:

    SELECT (TOTAL_EXTENTS - FREE_EXTENTS) * EXTENT_SIZE AS bytes_used
        FROM INFORMATION_SCHEMA.FILES
        WHERE FILE_NAME = './myfile.dat';
    

    Similarly, you can estimate the amount of space that remains available in a given file by multiplying FREE_EXTENTS by EXTENT_SIZE:

    SELECT FREE_EXTENTS * EXTENT_SIZE AS bytes_free
        FROM INFORMATION_SCHEMA.FILES
        WHERE FILE_NAME = './myfile.dat';
    
    Important

    The byte values produced by the preceding queries are approximations only, and their precision is inversely proportional to the value of EXTENT_SIZE. That is, the larger EXTENT_SIZE becomes, the less accurate the approximations are.

    It is also important to remember that once an extent is used, it cannot be freed again without dropping the data file of which it is a part. This means that deletes from a Disk Data table do not release disk space.

    The extent size can be set in a CREATE TABLESPACE statement. For more information, see Section 15.1.21, “CREATE TABLESPACE Statement”.

  • Prior to NDB 8.0.13, an additional row was present in the FILES table following the creation of a logfile group, having NULL in the FILE_NAME column. In NDB 8.0.13 and later, this row— which did not correspond to any file—is no longer shown, and it is necessary to query the ndbinfo.logspaces table to obtain undo log file usage information. See the description of this table as well as Section 25.6.11.1, “NDB Cluster Disk Data Objects”, for more information.

    The remainder of the discussion in this item applies only to NDB 8.0.12 and earlier. For the row having NULL in the FILE_NAME column, the value of the FILE_ID column is always 0, that of the FILE_TYPE column is always UNDO LOG, and that of the STATUS column is always NORMAL. The value of the ENGINE column is always ndbcluster.

    The FREE_EXTENTS column in this row shows the total number of free extents available to all undo files belonging to a given log file group whose name and number are shown in the LOGFILE_GROUP_NAME and LOGFILE_GROUP_NUMBER columns, respectively.

    Suppose there are no existing log file groups on your NDB Cluster, and you create one using the following statement:

    mysql> CREATE LOGFILE GROUP lg1
             ADD UNDOFILE 'undofile.dat'
             INITIAL_SIZE = 16M
             UNDO_BUFFER_SIZE = 1M
             ENGINE = NDB;
    

    You can now see this NULL row when you query the FILES table:

    mysql> SELECT DISTINCT
             FILE_NAME AS File,
             FREE_EXTENTS AS Free,
             TOTAL_EXTENTS AS Total,
             EXTENT_SIZE AS Size,
             INITIAL_SIZE AS Initial
             FROM INFORMATION_SCHEMA.FILES;
    +--------------+---------+---------+------+----------+
    | File         | Free    | Total   | Size | Initial  |
    +--------------+---------+---------+------+----------+
    | undofile.dat |    NULL | 4194304 |    4 | 16777216 |
    | NULL         | 4184068 |    NULL |    4 |     NULL |
    +--------------+---------+---------+------+----------+
    

    The total number of free extents available for undo logging is always somewhat less than the sum of the TOTAL_EXTENTS column values for all undo files in the log file group due to overhead required for maintaining the undo files. This can be seen by adding a second undo file to the log file group, then repeating the previous query against the FILES table:

    mysql> ALTER LOGFILE GROUP lg1
             ADD UNDOFILE 'undofile02.dat'
             INITIAL_SIZE = 4M
             ENGINE = NDB;
    
    mysql> SELECT DISTINCT
             FILE_NAME AS File,
             FREE_EXTENTS AS Free,
             TOTAL_EXTENTS AS Total,
             EXTENT_SIZE AS Size,
             INITIAL_SIZE AS Initial
             FROM INFORMATION_SCHEMA.FILES;
    +----------------+---------+---------+------+----------+
    | File           | Free    | Total   | Size | Initial  |
    +----------------+---------+---------+------+----------+
    | undofile.dat   |    NULL | 4194304 |    4 | 16777216 |
    | undofile02.dat |    NULL | 1048576 |    4 |  4194304 |
    | NULL           | 5223944 |    NULL |    4 |     NULL |
    +----------------+---------+---------+------+----------+
    

    The amount of free space in bytes which is available for undo logging by Disk Data tables using this log file group can be approximated by multiplying the number of free extents by the initial size:

    mysql> SELECT
             FREE_EXTENTS AS 'Free Extents',
             FREE_EXTENTS * EXTENT_SIZE AS 'Free Bytes'
             FROM INFORMATION_SCHEMA.FILES
             WHERE LOGFILE_GROUP_NAME = 'lg1'
             AND FILE_NAME IS NULL;
    +--------------+------------+
    | Free Extents | Free Bytes |
    +--------------+------------+
    |      5223944 |   20895776 |
    +--------------+------------+
    

    If you create an NDB Cluster Disk Data table and then insert some rows into it, you can see approximately how much space remains for undo logging afterward, for example:

    mysql> CREATE TABLESPACE ts1
             ADD DATAFILE 'data1.dat'
             USE LOGFILE GROUP lg1
             INITIAL_SIZE 512M
             ENGINE = NDB;
    
    mysql> CREATE TABLE dd (
             c1 INT NOT NULL PRIMARY KEY,
             c2 INT,
             c3 DATE
             )
             TABLESPACE ts1 STORAGE DISK
             ENGINE = NDB;
    
    mysql> INSERT INTO dd VALUES
             (NULL, 1234567890, '2007-02-02'),
             (NULL, 1126789005, '2007-02-03'),
             (NULL, 1357924680, '2007-02-04'),
             (NULL, 1642097531, '2007-02-05');
    
    mysql> SELECT
             FREE_EXTENTS AS 'Free Extents',
             FREE_EXTENTS * EXTENT_SIZE AS 'Free Bytes'
             FROM INFORMATION_SCHEMA.FILES
             WHERE LOGFILE_GROUP_NAME = 'lg1'
             AND FILE_NAME IS NULL;
    +--------------+------------+
    | Free Extents | Free Bytes |
    +--------------+------------+
    |      5207565 |   20830260 |
    +--------------+------------+
    
  • Prior to NDB 8.0.13, an additional row was present in the FILES table for each NDB Cluster Disk Data tablespace. Because it did not correspond to an actual file, it was removed in NDB 8.0.13. This row had NULL for the value of the FILE_NAME column, the value of the FILE_ID column was always 0, that of the FILE_TYPE column was always TABLESPACE, that of the STATUS column was always NORMAL, and the value of the ENGINE column is always NDBCLUSTER.

    In NDB 8.0.13 and later, you can obtain information about Disk Data tablespaces using the ndb_desc utility. For more information, see Section 25.6.11.1, “NDB Cluster Disk Data Objects”, as well as the description of ndb_desc.

  • For additional information, and examples of creating, dropping, and obtaining information about NDB Cluster Disk Data objects, see Section 25.6.11, “NDB Cluster Disk Data Tables”.