Adding Index Keeps Stalling

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 添加索引一直卡住

| username: zzps

[TiDB Usage Environment] Production Environment
[TiDB Version] 7.1.1
[Reproduction Path] Using Navicat to add an index, whether it is a unique index or a regular index, it gets stuck and remains stuck.
[Encountered Problem: Problem Phenomenon and Impact] Adding an index, whether it is a unique index or a regular index, it gets stuck and remains stuck.
[Resource Configuration]
[Attachments: Screenshots/Logs/Monitoring]


| username: WalterWj | Original post link

admin show ddl jobs; Let’s see if it’s queued or doing something.

Is the table relatively large? With TiDB’s default parameters, it can add an index to approximately 6 million rows per minute.

| username: zzps | Original post link

When I execute “admi show ddl jobs”, it reports an error. Could you please write it out completely? This is an empty table with no data.

| username: 啦啦啦啦啦 | Original post link

admin show ddl jobs

| username: Billmay表妹 | Original post link

You can refer to a similar issue like this one.

| username: zzps | Original post link

It’s still stuck now.

| username: zzps | Original post link

I have a primary key, and it’s an empty table. When I add an index, it gets stuck, whether it’s a regular index or a unique index.

| username: WalterWj | Original post link

Try restarting the tidb-server.

| username: 啦啦啦啦啦 | Original post link

Does the /tmp/tidb/ directory exist under the tidb server?

| username: zzps | Original post link

After being stuck for almost 10 minutes, this thing popped up.

| username: 啦啦啦啦啦 | Original post link

That means there are missing directories. Execute the following commands on each TiDB server:

mkdir /tmp/tidb/tmp_ddl-4000 -p
chown tidb:tidb -R /tmp/tidb
| username: zzps | Original post link

Does each machine node need to execute it?

| username: 啦啦啦啦啦 | Original post link

Execute on the machine with the TiDB server, not needed for PD and TiKV only.

| username: zzps | Original post link

Do I need to restart the TiDB server? I tried adding it again but it still doesn’t work.

| username: 啦啦啦啦啦 | Original post link

No need to restart, I see the topology above is mixed, so all three machines need to be executed.

| username: zzps | Original post link


I followed this and it’s still stuck.

| username: 啦啦啦啦啦 | Original post link

Just follow the commands I sent, there should be no problem. I’m not sure if there’s an error in the document or if the document version doesn’t match~
mkdir /tmp/tidb/tmp_ddl-4000 -p
chown tidb:tidb -R /tmp/tidb

| username: zzps | Original post link

According to your command, it should work, but I’m puzzled. The command in the official documentation has already granted the permissions, or maybe the tmp_ddl-4000 folder hasn’t been created.

| username: 路在何chu | Original post link

Your tmp directory probably cleared the tidb level directory.

| username: zzps | Original post link

Originally, there was no /tmp/tidb directory. Later, I added it according to the official documentation and granted permissions, but it still didn’t work. I guess I also need to add the tmp_ddl-4000 directory, as it won’t be created automatically.