DB connection is not getting closed. I can see many connection in sleep mode. I directly running metabase on the server using jar file. So how can i resolve

DB connection is not getting closed. I can see many connection in sleep mode. I'm directly running metabase on the server using jar file. So how can i close this connections

Hi @mitesh.b
Please post "Diagnostic Info" from Admin > Troubleshooting.
And can you post the status from your database, so I can see how many connections it is and for how long they have been idle?

I can see almost there are 7-8 connection in idle state

here is the diagnostic info

{
"browser-info": {
"language": "en-US",
"platform": "Win32",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36",
"vendor": "Google Inc."
},
"system-info": {
"file.encoding": "UTF-8",
"java.runtime.name": "OpenJDK Runtime Environment",
"java.runtime.version": "11.0.7+10-LTS",
"java.vendor": "Oracle Corporation",
"java.vendor.url": "http://java.oracle.com/",
"java.version": "11.0.7",
"java.vm.name": "OpenJDK 64-Bit Server VM",
"java.vm.version": "11.0.7+10-LTS",
"os.name": "Linux",
"os.version": "4.14.209-160.339.amzn2.x86_64",
"user.language": "en",
"user.timezone": "UTC"
},
"metabase-info": {
"databases": [
"mysql",
"h2"
],
"hosting-env": "unknown",
"application-database": "h2",
"application-database-details": {
"database": {
"name": "H2",
"version": "1.4.197 (2018-03-18)"
},
"jdbc-driver": {
"name": "H2 JDBC Driver",
"version": "1.4.197 (2018-03-18)"
}
},
"run-mode": "prod",
"version": {
"date": "2021-02-19",
"tag": "v0.38.0.1",
"branch": "release-x.38.x",
"hash": "0635914"
},
"settings": {
"report-timezone": null
}
}
}

@mitesh.b Okay, they should timeout after 15 minutes and 3 hours - depending on which type of connection it is. But it would be helpful if you provided SHOW FULL PROCESSLIST from MySQL.

Latest release is 0.38.2

You should migrate away from H2 if you are using Metabase in production:
https://www.metabase.com/docs/latest/operations-guide/migrating-from-h2.html

I am using 0.38.1 version. Below i have provided an image of open connection

image

@mitesh.b You are using version 0.38.0.1 - not 0.38.1.

From your screenshot there's only 2 idle connections, which has been idled for about 33 minutes.
Metabase tries to keep some connections alive, so those can be reused, when someone makes a query in Metabase, since it takes a lot of time to open a new connection, which would mean that the user experience would be slower.

I don't see the problem, so it would be helpful if you could explain that in more details.

Thank you fort such a great help.

Currently there were 2 connections but i have seen 7-8 connections earlier.

Can you help me with the exact count like how many connection it keep alive and for how much time?

@mitesh.b Metabase will use anywhere from 1 to 15 connections per configured database - sometimes even more.
Like I wrote earlier, they should timeout after 15 minutes and 3 hours - depending on which type of connection it is.

Have a look at this article, which explains what happens, when there aren't enough available connections:
https://www.metabase.com/learn/data-diet/analytics/metabase-at-scale.html