MySQL table auto-increment id overflow fault review solution

MySQL table auto-increment id overflow fault review solution

Problem: The overflow of the auto-increment ID in a MySQL table caused a business block

background:

A large table tb1 of the tokudb engine stores business machine audit logs. A large number of data are written every day. Due to historical reasons, this table is of int signed type and can store a maximum of 2147483647 rows.

Processing process:

Add a DBLE middleware agent, perform range partitioning, and write new data to a newly added shard. At the same time, the business modified the connection and changed the connection mode of this table tb1 to DBLE. However, after the business code was modified, it was found that some remaining insert into tb1 write requests were forwarded to the old table, and some tables were incorrectly routed to DBLE. This complicates things further. Finally, the entire business returned to normal after the code that wrote tb1 was taken offline.

After reviewing the situation, I thought that in this case, for problems with log tables, the DBA should take quick and decisive measures to restore business as soon as possible, and then consider other issues. If we think in this way, the above problem can be easily solved. Just a few steps:

use logdb;

select max(id) from tb1; -- Record the current maximum id as xxxx
create table tb2 LIKE tb1; -- Create a shadow table alter table tb2 modify column id bigint unsigned not null auto_increment; -- Modify the new table to bigint unsigned type, which can store 18446744073709551615 rows of data.
alter table tb2 auto_increment=xxxx+1; -- Change the starting value of the auto-increment primary key of the new table rename table tb1 to tb_archive , tb2 to tb1; -- Switch the table name

After this operation, data can be written to tb1 and the business can be temporarily restored. The remaining work is to migrate the data in the tb_archive table to tb1 (you can use the pt-archiver tool to migrate data and run it slowly in the background).

After some calculations, it takes only about 5 minutes at most to cut the table and resume the business write operation, and the impact on the remaining migrated data will be relatively small.

Subsequent optimization measures:

Add monitoring of auto-increment id, see here https://www.jb51.net/article/184935.htm

Sort out some unexpected problems that may be encountered in production, and formulate relevant emergency plans accordingly

This is the end of this article about the troubleshooting and solution of MySQL table auto-increment id overflow. For more related MySQL auto-increment id overflow content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Solution to running out of MySQL's auto-increment ID (primary key)
  • What you need to know about MySQL auto-increment ID
  • Summary of some small issues about MySQL auto-increment ID
  • You may not know these things about Mysql auto-increment id
  • Troubleshooting and solutions for MySQL auto-increment ID oversize problem
  • Solution to the problem of self-increment ID in MySQL table
  • What to do if the online MySQL auto-increment ID is exhausted

<<:  Detailed explanation of the implementation process of Nginx log timing splitting in CentOS 7

>>:  JavaScript Basics Series: Functions and Methods

Recommend

The 6 Most Effective Ways to Write HTML and CSS

This article shares the 6 most effective methods,...

Pure CSS to achieve the water drop animation button in Material Design

Preface You should often see this kind of special...

Limit input type (multiple methods)

1. Only Chinese characters can be input and pasted...

DOCTYPE Document Type Declaration (Must-Read for Web Page Lovers)

DOCTYPE DECLARATION At the top of every page you w...

Linux kernel device driver virtual file system notes

/******************** * Virtual File System VFS *...

How does Vue track data changes?

Table of contents background example Misconceptio...

Summary of MySQL usage specifications

1. InnoDB storage engine must be used It has bett...

Simple implementation method of vue3 source code analysis

Table of contents Preface 🍹Preparation 🍲vue3 usag...

How to implement second-level scheduled tasks with Linux Crontab Shell script

1. Write Shell script crontab.sh #!/bin/bash step...

HTML Tutorial: title attribute and alt attribute

XHTML is the basis of CSS layout. jb51.net has al...

Detailed explanation of MySQL and Spring's autocommit

1 MySQL autocommit settings MySQL automatically c...

css3 animation ball rolling js control animation pause

CSS3 can create animations, which can replace man...

Summary of Vue component basics

Component Basics 1 Component Reuse Components are...

JavaScript code to implement Weibo batch unfollow function

A cool JavaScript code to unfollow Weibo users in...