mysqlmariadbmariadb-connect-engine

How does MariaDB work with maintaining db connection?


I am using Peewee ORM to update and modify database table from my python project. I have set max connection limit to 15 using:

set global max_connections = 15

to get total connection I run the command,

> select count(*) from  information_schema.processlist;

> 12

now that connection limit is 15 and even if I run a my code to do some work on db by opening a connection the number of connection goes up by 2

> select count(*) from  information_schema.processlist;

> 14

now even if am done doing the task, I close python terminal I still see total number of connection from process list count to be 14, it seems like old connections get reused or what, if I run the same command to update db table, from different terminal I add 2 more connection but it gives error saying too many connections. but the first terminal I had opened still work.

I can post peewee code if required.


Solution

  • If you are using the regular MySQLDatabase class, then calling .close() on the connection will close it.

    On the other hand if you are using PooledMySQLDatabase, .close() will recycle the connection to the pool of available connections. You can manage the connections in the pool using the following APIs: http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#PooledDatabase