pt-online-schema-change无锁变更及腾讯云的dmc数据库操作,字段加索引查询 500kb限制

pt-online-schema-change无锁变更及腾讯云的dmc数据库操作,字段加索引查询 500kb限制

1.需求背景
根据会员号统计收益,订单数等,sql复杂,查询比较慢。
在执行查询之前,未对explain分析索引,先提了一个腾讯云的导出工单,埋下的隐患。
工单一直卡住,查询不出来,因为有大表的会员号字段未加索引导致。
同时发现在sql窗口,连基本的count查询表的数量,都查询不出来。
更加不用说提了sql alter变更 会员号的字段加索引了。

在尝试变更查询条件方向上,总不能遇到了问题,绕道而行,那么问题依然还是存在。
咨询了腾讯云的值班客服,通过以下的2个,分析进行中的sql是不是卡住了,然后提工单(数据库可以选当前查询的数据库),kill掉这个进程。【关键】
然后问题解决了。 因为这个没有解决,使用pt-online-schema-change 在执行创建触发器的过程中(Creating triggers...),也是卡死的状态。

##这两个查询结果不同

##不要使用这个
SHOW PROCESSLIST;

##正解的使用这个,这个查询的结果更加全面,可以看到一个大的导出的sql卡死了,就是最上面提的导出工单而未加字段索引的sql  
SELECT * FROM information_schema.PROCESSLIST;


SELECT * FROM information_schema.PROCESSLIST;

##提工单来杀掉进程。
kill 13389147

腾讯云查询sql的工单限制:500kb

sql太多的话,首先无法提交。
如果提交了,但是超出了数量,也是查询不出来结果,卡死状态。
比如根据会员号查询会员信息,会员号1万个可以提交,但是无法查询,
如果是6千个,可以提交可以查询。
所以就会发生一个sql的查询需要根据会员号来拆分,比如:2万4个,则需要拆分出来按4次来查询。

另外避免大量的查询,则简化查询的需求,比如是统计优质车主,那么可以先过滤掉接单数小于100的车主,
这样数量直接从2万4,下降到660个。

最后按会员号作为唯一关联字段,按字段需求的需要单独来查询,然后根据会员号在excel表格中vlookup来匹配关联上。

 

pt-online-schema-change的无锁变更的命令使用:
首先需要在服务器上面安装,pt-online-schema-change 在此跳过,认为已经安装过了。

1.通过工具来解决:
pt-online-schema-change --host=172.XX.23.XX --port=3306 --user=账号 --password=密码 D=mydb,t=my_test_table --alter "ADD INDEX idx_memNo(mem_no)" --dry-run --recursion-method=none 
pt-online-schema-change --host=172.XX.23.XX --port=3306 --user=账号 --password=密码 D=mydb,t=my_test_table --alter "ADD INDEX idx_memNo(mem_no)" --execute --recursion-method=none 

--dry-run 是测试命令
--execute 是执行命令
--set-vars="character_set_client=utf8mb4,character_set_connection=utf8mb4,character_set_results=utf8mb4"      # 表的注释就不会乱码了

注意点:用户名和密码要用高权限的账号
--alter  可以多个  比如一个表你要加多个字段或者多个变更 可以写多次
--alter "ADD COLUMN platform_type varchar(50) DEFAULT NULL COMMENT '类型app或h5', ADD COLUMN os varchar(255) DEFAULT NULL COMMENT 'os类型ANDROID,IOS,miniprogram-alipay等'"


2.测试的执行过程:
pt-online-schema-change --host=172.XX.23.XX --port=3306 --user=账号 --password=密码 D=mydb,t=my_test_table --alter "ADD INDEX idx_memNo(mem_no)" --dry-run --recursion-method=none 
Operation, tries, wait:
  analyze_table, 10, 1
  copy_rows, 10, 0.25
  create_triggers, 10, 1
  drop_triggers, 10, 1
  swap_tables, 10, 1
  update_foreign_keys, 10, 1
Starting a dry run.  `mydb`.`my_test_table` will not be altered.  Specify --execute instead of --dry-run to alter the table.
Creating new table...
Created new table mydb._my_test_table_new OK.
Altering new table...
Altered `mydb`.`_my_test_table_new` OK.
Not creating triggers because this is a dry run.
Not copying rows because this is a dry run.
Not swapping tables because this is a dry run.
Not dropping old table because this is a dry run.
Not dropping triggers because this is a dry run.
2025-10-24T14:01:44 Dropping new table...
2025-10-24T14:01:44 Dropped new table OK.
Dry run complete.  `mydb`.`my_test_table` was not altered.


3.正式的执行过程:
pt-online-schema-change --host=172.XX.23.XX --port=3306 --user=账号 --password=密码 D=mydb,t=my_test_table --alter "ADD INDEX idx_memNo(mem_no)" --execute --recursion-method=none 
No slaves found.  See --recursion-method if host TENCENT64.site has slaves.
Not checking slave lag because no slaves were found and --check-slave-lag was not specified.
Operation, tries, wait:
  analyze_table, 10, 1
  copy_rows, 10, 0.25
  create_triggers, 10, 1
  drop_triggers, 10, 1
  swap_tables, 10, 1
  update_foreign_keys, 10, 1
Altering `mydb`.`my_test_table`...
Creating new table...
Created new table mydb._my_test_table_new OK.
Altering new table...
Altered `mydb`.`_my_test_table_new` OK.
2025-10-24T14:01:57 Creating triggers...
2025-10-24T14:01:57 Created triggers OK.
2025-10-24T14:01:57 Copying approximately 80563 rows...
2025-10-24T14:01:58 Copied rows OK.
2025-10-24T14:01:58 Analyzing new table...
2025-10-24T14:01:58 Swapping tables...
2025-10-24T14:01:58 Swapped original and new tables OK.
2025-10-24T14:01:58 Dropping old table...
2025-10-24T14:01:58 Dropped old table `mydb`.`_my_test_table_old` OK.
2025-10-24T14:01:58 Dropping triggers...
2025-10-24T14:01:58 Dropped triggers OK.
Successfully altered `mydb`.`my_test_table`.

 

posted on 2025-10-30 15:24  oktokeep  阅读(3)  评论(0)    收藏  举报