# Pt-online-schema-change Running simultaneously for multiple databases

**URL:** <https://forums.percona.com/t/pt-online-schema-change-running-simultaneously-for-multiple-databases/30589>\
**Category:** Percona Toolkit\
**Tags:** mysql, percona\
**Created:** [May 27, 2024, 9:09am UTC](https://forums.percona.com/t/pt-online-schema-change-running-simultaneously-for-multiple-databases/30589 "2024-05-27T09:09:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Federico\_Bau](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/federico_bau/32/16575_2.png) [@Federico\_Bau](https://forums.percona.com/u/Federico_Bau)\
**Post date:** [May 27, 2024, 9:09am UTC](https://forums.percona.com/t/pt-online-schema-change-running-simultaneously-for-multiple-databases/30589/1 "2024-05-27T09:09:28Z")

</div>

Imagine this scenario:

- Need to do an ALTER to add in index i.e: `ADD INDEX index_name (`column\_name`)`
- Within a host, there are 30 databases with same schema
- Need to run `pt-online-schema-change` for **each database**
- I created a Python script that using threading, run 30, same command in same time but pointing to a different database.

### Question

Can `pt-online-schema-change` run with no problem under such scenario?

### More info

I did test it but for now on my local setup. Most of queries **will work** however, for some sporadic databases I get the following error:

```auto
Cannot connect to MySQL: DBI connect('database_name;host=localhost;mysql_read_default_group=client','root',...)
 failed: Too many connections at /usr/bin/pt-online-schema-change line 2345.
18 at /usr/bin/pt-online-schema-change line 8758.

```

While this is a **strong indication** that `pt-online-schema-change` is not designed to be used this way, could also be that is due to my local setup.  
So I’d like to check opinions on this.  
Maybe there is a command that _‘enables’ this?_

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [May 27, 2024, 11:53am UTC](https://forums.percona.com/t/pt-online-schema-change-running-simultaneously-for-multiple-databases/30589/2 "2024-05-27T11:53:37Z")

</div>

> [@Federico\_Bau](#):
>
> could also be that is due to my local setup

You don’t have enough `max-connections` allowed. Increase this variable in your config.

More importantly, you don’t need pt-osc for simply adding an index. Adding indexes is an online operation. When you `ALTER TABLE .. ADD INDEX(col1)`, writes and reads are still allowed in other connections. Adding indexes does not block/lock anything other than your session which executed the SQL.

---

<div class="post-metadata">

**Author:** ![Federico\_Bau](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/federico_bau/32/16575_2.png) [@Federico\_Bau](https://forums.percona.com/u/Federico_Bau)\
**Post date:** [May 27, 2024, 12:09pm UTC](https://forums.percona.com/t/pt-online-schema-change-running-simultaneously-for-multiple-databases/30589/3 "2024-05-27T12:09:33Z")

</div>

Hi, ok so is the max-connections of MySQL?  
Anyways, really?

I think is something from latest MySQL correct?[indexing - Create an index on a huge MySQL production table without table locking - Stack Overflow](https://stackoverflow.com/a/14248906/13903942)  
Meaning from MySQL 5.6 adding an index wont lock read and write and therefore, we don’t need this percona tool?

Did I understand this correctly?

Also, Do i need to add something specific to an alter statement ? (I know this is related to MySQL but if happen that you know I’d be glad otherwise I ll look it up!)

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [May 28, 2024, 12:12am UTC](https://forums.percona.com/t/pt-online-schema-change-running-simultaneously-for-multiple-databases/30589/4 "2024-05-28T00:12:16Z")

</div>

> [@Federico\_Bau](#):
>
> I think is something from latest MySQL correct

MySQL 5.6 is not “latest” in any way; it’s from 2013. This functionality has been around 10+ years. MySQL 8 expanded this more with INSTANT ALTER TABLE.

> [@Federico\_Bau](#):
>
> Do i need to add something specific to an alter statement ?

No. Just ALTER TABLE foo ADD INDEX (col1, col2) and it will process online. Just a reminder, your session executing the ALTER will be blocked, but other sessions will still be able to read/write to the table.

---

<div class="post-metadata">

**Author:** ![Federico\_Bau](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/federico_bau/32/16575_2.png) [@Federico\_Bau](https://forums.percona.com/u/Federico_Bau)\
**Post date:** [May 28, 2024, 8:59am UTC](https://forums.percona.com/t/pt-online-schema-change-running-simultaneously-for-multiple-databases/30589/5 "2024-05-28T08:59:04Z")

</div>

Ok thanks for the information, very helpful!.  
For clarification I know latest version is not 5.6 😃
