RDS Mysql information_schema not updating

0

Hello, I have an Amazon RDS instance with multiple databases.

Yesterday, I enabled the log, and I can see that the queries are now being saved in mysql.general_log.

Today, the table has 800k records, and I want to see how much space it occupies.

To do this, I run the following query:

SELECT 
    table_schema "Database",
    SUM(data_length + index_length) / 1024 / 1024 "Total Size (MB)"
FROM information_schema.tables 
GROUP BY table_schema;

The problem is that it returns the same result as yesterday, meaning it doesn't increase.

I'm also trying the following query, but it doesn't increase either:

SELECT 
    ROUND(SUM(data_length + index_length) / 1024 / 1024 / 1024, 2) AS "Total Size (GB)"
FROM information_schema.tables;

It's as if the information in the information_schema is not updating.

sunco
asked 8 months ago475 views
2 Answers
0

Hi there.

I'm a little confused because you mentioned a table with 800K rows but your query is getting the size of your entire database. If you want to know the size of a particular table, use the column TABLE_NAME. Try the query with this little modification:

SELECT 
    table_name "Table",
    SUM(data_length + index_length) / 1024 / 1024 "Total Size (MB)"
WHERE table_schema = [NAME OF YOUR DATABASE]
FROM information_schema.tables 
GROUP BY table_name;

I hope this helps.

profile pictureAWS
EXPERT
answered 8 months ago
  • Thanks for your reply, but is the same. The entire mysql data base size is the same as before the 800k records

    In fact, the general_log size according to information.schema es 0.00000000

    Now is 965k records

    As stated in the question, is like if information_schema never updates the information

    The RDS instance is a 100 GiB of storage, I only want to see how much of that storage I've used.

0

Hi,

In order for information_schema to not be painfully slow when retrieving this for large tables, it uses estimates, based on the cardinality of the primary key, for InnoDB tables. Otherwise it would end up having to do SELECT COUNT(*) FROM table_name, which for a table with billions of rows could take hours.

Look at SHOW INDEX FROM table_name and you will see that the number reported in information_schema is the same as the cardinality of the PK.

Running ANALYZE TABLE table_name will update the statistics which may make them more accurate, but it will still be an estimate rather than just-in-time checked row-count.

Best,

Didier

profile pictureAWS
EXPERT
answered 8 months ago
  • It says The storage engine for the table doesn't support analyze

    The engine says CSV. It's a systema created table, not by me

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions