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

Detailed explanation of docker command to backup linux system

tar backup system sudo tar cvpzf backup.tgz --exc...

MySQL optimization: how to write high-quality SQL statements

Preface There are a lot of information and method...

Detailed explanation of this pointing problem in JavaScript

Preface The this pointer in JS has always been a ...

Search optimization knowledge to pay attention to in web design

1. Link layout of the new site homepage 1. The loc...

MySQL variable declaration and stored procedure analysis

Declaring variables Setting Global Variables set ...

Vue uses the video tag to implement video playback

This article shares the specific code of Vue usin...

IE9beta version browser supports HTML5/CSS3

Some people say that IE9 is Microsoft's secon...

MySQL 8.0.13 download and installation tutorial with pictures and text

MySQL is the most commonly used database. You mus...

How to implement n-grid layout in CSS

Common application scenarios The interfaces of cu...

Detailed explanation of docker compose usage

Table of contents Docker Compose usage scenarios ...

How to use webSocket to update real-time weather in Vue

Table of contents Preface About webSocket operati...

Detailed example of how to implement transaction commit and rollback in mysql

Recently, we need to perform a scheduled migratio...

Eight common SQL usage examples in MySQL

Preface MySQL continued to maintain its strong gr...

How to print highlighted code in nodejs console

Preface When the code runs and an error occurs, w...