Database is locked after renew de database sqlite

Hi,

We have a grafana v6.6.2 in a linux SO (Debian 3.16.43). I was having errors of this type:

t=2020-04-28T13:17:30+0200 lvl=eror msg=“Failed to get system stats” logger=metrics error=“database is locked”
t=2020-04-28T13:17:30+0200 lvl=eror msg=“failed to run garbage collect” logger=remotecache.database error=“database is locked”
t=2020-04-28T13:17:30+0200 lvl=eror msg=“Could not load alerts” logger=alerting.ruleReader error=“database is locked”

And after reviewieng some topics about it we do the export to a new database file and stop and start the grafana server but we still have sometimes this errors.

Our files looks like this:

drwxrwxrwx 18 grafana grafana 4096 Oct 10 2018 sessions
drwxrwxrwx 4 grafana grafana 4096 Oct 10 2018 plugins
drwxrwxrwx 2 grafana grafana 4096 Apr 28 10:03 png
-rwxrwxrwx 1 grafana grafana 6721536 Apr 28 13:46 grafana.db
drwxr-xr-x 2 root root 4096 Apr 28 13:47 old
root@ViewnextMonitor:/var/lib/grafana#

And the errors appears:

root@ViewnextMonitor:/var/log/grafana# tail -f grafana.log | grep error
t=2020-04-28T13:17:30+0200 lvl=eror msg=“Failed to get system stats” logger=metrics error=“database is locked”
t=2020-04-28T13:17:30+0200 lvl=eror msg=“failed to run garbage collect” logger=remotecache.database error=“database is locked”
t=2020-04-28T13:17:30+0200 lvl=eror msg=“Could not load alerts” logger=alerting.ruleReader error=“database is locked”

There are any more thing that we can do to avoid it?

Kind regards.

I have put the debug level and I see:

t=2020-04-30T11:34:37+0200 lvl=info msg="[SQL] SELECT (SELECT COUNT() FROM user) AS users,(SELECT COUNT() FROM org) AS
orgs,(SELECT COUNT() FROM dashboard) AS dashboards,(SELECT COUNT() FROM data_source) AS datasources,(SELECT COUNT() FR
OM star) AS stars,(SELECT COUNT(
) FROM playlist) AS playlists,(SELECT COUNT() FROM alert) AS alerts,(SELECT COUNT()
FROM user where last_seen_at > ?) AS active_users,(SELECT COUNT(id) FROM dashboard where is_folder = ?) AS folders,(\n\t
tSELECT COUNT(acl.id)\n\t\tFROM dashboard_acl as acl\n\t\t\tinner join dashboard as d\n\t\t\ton d.id = acl.dashboard_id\n
\t\tWHERE d.is_folder = ?\n\t) AS dashboard_permissions,(\n\t\tSELECT COUNT(acl.id)\n\t\tFROM dashboard_acl as acl\n\t\t\ti
nner join dashboard as d\n\t\t\ton d.id = acl.dashboard_id\n\t\tWHERE d.is_folder = ?\n\t) AS folder_permissions,(SELECT CO
UNT(id) FROM dashboard_provisioning) AS provisioned_dashboards,(SELECT COUNT(id) FROM dashboard_snapshot) AS snapshots,(S
ELECT COUNT(id) FROM team) AS teams,(SELECT COUNT(id) FROM user_auth_token) AS auth_tokens,\n\t\t(\n\t\t\tSELECT COUNT(DI
STINCT u.id)\n\t\t\tFROM user as u, org_user\n\t\t\tWHERE ( org_user.user_id=u.id AND org_user.role=‘Viewer’ )\n\t\t) as vi
ewers,\n\t\t(\n\t\t\tSELECT COUNT(DISTINCT u.id)\n\t\t\tFROM user as u, org_user\n\t\t\tWHERE u.last_seen_at>? AND ( org_us
er.user_id=u.id AND org_user.role=‘Viewer’ )\n\t\t) as active_viewers,\n\t\t(\n\t\t\tSELECT COUNT(DISTINCT u.id)\n\t\t\tFROM
user as u, org_user\n\t\t\tWHERE ( org_user.user_id=u.id AND org_user.role=‘Editor’ )\n\t\t) as editors,\n\t\t(\n\t\t\tSELE
CT COUNT(DISTINCT u.id)\n\t\t\tFROM user as u, org_user\n\t\t\tWHERE u.last_seen_at>? AND ( org_user.user_id=u.id AND org_u
ser.role=‘Editor’ )\n\t\t) as active_editors,\n\t\t(\n\t\t\tSELECT COUNT(DISTINCT u.id)\n\t\t\tFROM user as u, org_user\n\t
\t\tWHERE ( org_user.user_id=u.id AND org_user.role=‘Admin’ )\n\t\t) as admins,\n\t\t(\n\t\t\tSELECT COUNT(DISTINCT u.id)\n\t
\t\tFROM user as u, org_user\n\t\t\tWHERE u.last_seen_at>? AND ( org_user.user_id=u.id AND org_user.role=‘Admin’ )\n\t\t) a
s active_admins []interface {}{time.Time{wall:0xbf98e18b49583dd0, ext:-2523837437667539, loc:(*time.Location)(0x2cbac00)}, "
1", “0”, “1”, time.Time{wall:0xbf98e18b49583dd0, ext:-2523837437667539, loc:(*time.Location)(0x2cbac00)}, time.Time{wall
:0xbf98e18b49583dd0, ext:-2523837437667539, loc:(*time.Location)(0x2cbac00)}, time.Time{wall:0xbf98e18b49583dd0, ext:-2523837
437667539, loc:(*time.Location)(0x2cbac00)}} - took: 491.1µs" logger=sqlstore.xorm
t=2020-04-30T11:34:42+0200 lvl=eror msg=“Failed to get system stats” logger=metrics error="database is locked"
t=2020-04-30T11:34:42+0200 lvl=info msg="[SQL] INSERT INTO user_auth_token (user_id,auth_token,prev_auth_token,user_ agent,client_ip,auth_token_seen,seen_at,rotated_at,created_at,updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
[]interface {}{1, “?”, “?”, “Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0”, “172.18.10.17”, false, 0, 1588239272, 1588239272, 1588239272} - took: 10.624529253s" logger=sqlstore.xorm

Locked but the querys works fine, maybe very slow 10 seconds for a simple query. Any idea?