# "database is locked" - unable to use grafana anymore :(

**URL:** <https://community.grafana.com/t/database-is-locked-unable-to-use-grafana-anymore/16557>\
**Category:** General\
**Created:** [April 21, 2019, 4:30pm UTC](https://community.grafana.com/t/database-is-locked-unable-to-use-grafana-anymore/16557 "2019-04-21T16:30:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chbla](https://avatars.discourse-cdn.com/v4/letter/c/bbce88/32.png) [@chbla](https://community.grafana.com/u/chbla)\
**Post date:** [April 21, 2019, 4:30pm UTC](https://community.grafana.com/t/database-is-locked-unable-to-use-grafana-anymore/16557/1 "2019-04-21T16:30:30Z")

</div>

Hi there,

I had a power outage and my docker containers got killed. After restarting them, Grafana is very  
slow and I get a lot of these messages in the logs:

`t=2019-04-21T16:28:24+0000 lvl=eror msg="Failed to update last_seen_at" logger=context userId=1 orgId=1 uname=admin error="database is locked"`

I also cannot save the dashboard. I suspect there are some stale locks in place?

Can anyone tell me how I can fix this?  
Thank you very much!

---

<div class="post-metadata">

**Author:** ![dcech](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/dcech/32/49_2.png) [@dcech](https://community.grafana.com/u/dcech)\
**Post date:** [April 21, 2019, 11:31pm UTC](https://community.grafana.com/t/database-is-locked-unable-to-use-grafana-anymore/16557/2 "2019-04-21T23:31:19Z")

</div>

The “database is locked” error indicates a problem with your sqlite database. This can happen if the database is left in an inconsistent state after a crash, or if there are problems with the disk.

One thing you can try is to dump the data from your existing db file into a new one, then swap it out. From inside your Grafana data directory (after shutting down Grafana):

```
sqlite3 grafana.db '.clone grafana-new.db'
mv grafana.db grafana-old.db
mv grafana-new.db grafana.db
```

---

<div class="post-metadata">

**Author:** ![chbla](https://avatars.discourse-cdn.com/v4/letter/c/bbce88/32.png) [@chbla](https://community.grafana.com/u/chbla)\
**Post date:** [April 22, 2019, 5:51pm UTC](https://community.grafana.com/t/database-is-locked-unable-to-use-grafana-anymore/16557/3 "2019-04-22T17:51:32Z")

</div>

Thanks a lot! This worked!

---

<div class="post-metadata">

**Author:** ![iraklic](https://avatars.discourse-cdn.com/v4/letter/i/f19dbf/32.png) [@iraklic](https://community.grafana.com/u/iraklic)\
**Post date:** [April 22, 2022, 8:15pm UTC](https://community.grafana.com/t/database-is-locked-unable-to-use-grafana-anymore/16557/4 "2022-04-22T20:15:52Z")

</div>

I have this exact issue, but I am running grafana from the container. How can I apply this solution?

---

<div class="post-metadata">

**Author:** ![schneefisch](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@schneefisch](https://community.grafana.com/u/schneefisch)\
**Post date:** [March 22, 2023, 10:34am UTC](https://community.grafana.com/t/database-is-locked-unable-to-use-grafana-anymore/16557/5 "2023-03-22T10:34:21Z")

</div>

Hi @iraklic ,

if you are using the grafana/grafana docker image then the sqlite is located at `/var/lib/grafana/grafana.db`  
Again, if you are using grafana/grafana image inside kubernetes then the sqlite is stored on a persistent-volume. Inside the container, there is no sqlite3 available.

Therefore you must copy the database out of the container or PVC on your machine, clone it there and copy it back.

```auto
kubectl cp <grafana_pod_name>:/var/lib/grafana/grafana.db -c grafana ./grafana.db

```

then do the cloning as described above and copy it back.

---

<div class="post-metadata">

**Author:** ![vyshaksekhar](https://avatars.discourse-cdn.com/v4/letter/v/7cd45c/32.png) [@vyshaksekhar](https://community.grafana.com/u/vyshaksekhar)\
**Post date:** [June 6, 2023, 7:59am UTC](https://community.grafana.com/t/database-is-locked-unable-to-use-grafana-anymore/16557/6 "2023-06-06T07:59:42Z")

</div>

Hey, I got the same issue “database is locked” 2 weeks back, and used the steps for cloning that u mentioned and it solved the error, but now it again came and I had to again implement the cloning to make it right. There was no Grafana crash or anything issue recent, so how to solve this permanently?
