# Max Open Connections settings

**URL:** <https://forum.mattermost.com/t/max-open-connections-settings/14994>\
**Category:** Troubleshooting\
**Created:** [February 3, 2023, 4:08pm UTC](https://forum.mattermost.com/t/max-open-connections-settings/14994 "2023-02-03T16:08:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![amir.jawaid](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@amir.jawaid](https://forum.mattermost.com/u/amir.jawaid)\
**Post date:** [February 3, 2023, 4:08pm UTC](https://forum.mattermost.com/t/max-open-connections-settings/14994/1 "2023-02-03T16:08:50Z")

</div>

hi, can anyone tell me the difference between the Max Open connections value (default is 300) that we can set from the system console and the value we get via the “show variables like “max\_connections”;” command from within the mysql console (default is 150)?. We have a self-hosted setup

---

<div class="post-metadata">

**Author:** ![agriesser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/agriesser/32/5644_2.png) [@agriesser](https://forum.mattermost.com/u/agriesser)\
**Post date:** [February 5, 2023, 1:12pm UTC](https://forum.mattermost.com/t/max-open-connections-settings/14994/2 "2023-02-05T13:12:29Z")

</div>

Hi @amir.jawaid and welcome to the Mattermost forums!

The `SqlSettings.MaxOpenConns` variable in your Mattermost server’s `config.json` file is telling the server how many connections it should be able to open to the database at maximum. The value you can see when running the query on your database server is the maximum possible connections your database server is configured to accept, so if the connections in the Mattermost server are higher than the ones from your database server, you might run into a situation where the Mattermost server tries to open a connection to the database and fails, because the MySQL server refuses the connection with an error message about having reached the maximum possible connections.  
You should either lower the `SqlSettings.MaxOpenConns` setting in your Mattermost server to a value below the MySQL servers setting, or you should increase the possible connections on your MySQL server. For the latter, please be aware that allowing more connections will also increase memory usage and other system resources on your MySQL server, so I’d suggest to check how many connections have been made at maximum during the last server restart, which should give you an idea of what to set this value to.  
You can use the following query to see the maximum used connection count since the last server startup (15 on my demo system):

```sql
mysql> show status like "Max_used_connections";
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| Max_used_connections | 15 |
+----------------------+-------+
1 row in set (0.00 sec)

```

---

<div class="post-metadata">

**Author:** ![amir.jawaid](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@amir.jawaid](https://forum.mattermost.com/u/amir.jawaid)\
**Post date:** [February 5, 2023, 5:12pm UTC](https://forum.mattermost.com/t/max-open-connections-settings/14994/3 "2023-02-05T17:12:08Z")

</div>

hi,

thank you for the superb detailed reply. I truly appreciate this. The too many open connections problem started when we recently upgraded to Mattermost Version: 7.7.1 / Database Schema Version: 100

Upon checking the values once we started to see “too many connections” error, the SqlSettings.MaxOpenConns was set to 300 while the value with mysql was 150. We made both values to be same at 600, is having the same value OK?, perhaps we set it too high but since we did that, we did not face any issue  
Btw the current max\_used\_connections value i see in our mysql is 140

---

<div class="post-metadata">

**Author:** ![agriesser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/agriesser/32/5644_2.png) [@agriesser](https://forum.mattermost.com/u/agriesser)\
**Post date:** [February 5, 2023, 6:06pm UTC](https://forum.mattermost.com/t/max-open-connections-settings/14994/4 "2023-02-05T18:06:45Z")

</div>

Hi again,

the same value is OK as long as you‘re not reaching it. In theory, there are connection pool recreations on the client side which might cause short overusage and there are superuser reserved connections on the MySQL server which limit the number of available connections. Check the historically max used connections again in a week or two and if it‘s still around 150, you should be good to go with the values you had (and probably could even lower them both to 300).

---

<div class="post-metadata">

**Author:** ![amir.jawaid](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@amir.jawaid](https://forum.mattermost.com/u/amir.jawaid)\
**Post date:** [February 5, 2023, 6:39pm UTC](https://forum.mattermost.com/t/max-open-connections-settings/14994/5 "2023-02-05T18:39:09Z")

</div>

thanks again for the detailed response

---

<div class="post-metadata">

**Author:** ![agriesser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/agriesser/32/5644_2.png) [@agriesser](https://forum.mattermost.com/u/agriesser)\
**Post date:** [February 5, 2023, 11:21pm UTC](https://forum.mattermost.com/t/max-open-connections-settings/14994/6 "2023-02-05T23:21:54Z")

</div>

You’re welcome - I’m marking this topic as resolved now!
