# Error: SQLITE\_READONLY: attempt to write a readonly database

**URL:** <https://discourse.nodered.org/t/error-sqlite-readonly-attempt-to-write-a-readonly-database/97707>\
**Category:** General\
**Tags:** docker, home-assistant, sqlite\
**Created:** [19 June 2025 18:47 UTC](https://discourse.nodered.org/t/error-sqlite-readonly-attempt-to-write-a-readonly-database/97707 "2025-06-19T18:47:15Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![CoderN](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/codern/32/101562_2.png) [@CoderN](https://discourse.nodered.org/u/CoderN)\
**Post date:** [19 June 2025 18:47 UTC](https://discourse.nodered.org/t/error-sqlite-readonly-attempt-to-write-a-readonly-database/97707/1 "2025-06-19T18:47:15Z")

</div>

I have a simple flow like this

 ![Screenshot 2025-06-19 at 19.37.57](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/0/208328189eed0a5d5b735429a9fbd369a927ee0a.png)

where the properties of HAS2 SQLite is:

 ![Screenshot 2025-06-19 at 19.39.28](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/1/4182d5041cfe8cb64422a381f34c3d6bfd0bf740.png)

```auto
SQLStatement:
	SELECT
		metadata_id
	FROM
		states_meta
	WHERE
		entity_id = 'sensor.octopus_energy_electricity_[meter#]_[mpan#]_current_accumulative_cost'
;

```

The database was opened as `Read=Only` mode. It generated the following error:

```auto
Error: SQLITE_READONLY: attempt to write a readonly database

```

However, the same SQL statement works fine with readonly mode on CLI:

```auto
sqlite> .header on
sqlite> .open --readonly home-assistant_v2.db
sqlite>SELECT
    metadata_id
FROM
    states_meta
WHERE
    entity_id = 'sensor.octopus_energy_electricity_[meter#]_[mpan#]_current_accumulative_cost'
;
metadata_id
7361

```

How do I fix it?

Many Thanks!

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [19 June 2025 19:33 UTC](https://discourse.nodered.org/t/error-sqlite-readonly-attempt-to-write-a-readonly-database/97707/2 "2025-06-19T19:33:49Z")

</div>

Welcome to the forums @CoderN

You will need to check access on the Node RED process user to that file path, even `select` statements, might do some background (non destructive) writes - like a temp table for instance (the mode you mentioned will stop altering data, not necessarily system based tables it might need to do stuff with) and file permissions will play a part here

Given this is HA - it might be beneficial to refer to the HA forums, as if using the Node RED plugin - they will have the answers, in how Access is granted to plugins at certain file paths

I could be wrong here of course, but it's my best guess.

Others may have more info (and may correct me)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [19 June 2025 19:41 UTC](https://discourse.nodered.org/t/error-sqlite-readonly-attempt-to-write-a-readonly-database/97707/3 "2025-06-19T19:41:16Z")

</div>

At a guess, the DB is in a directory that the account running the node-red process (inside the HA docker instance), does not have write access to?

If you raise this on the HA forum - they will probably understand how these things fit together and be able to offer advice.

---

<div class="post-metadata">

**Author:** ![CoderN](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/codern/32/101562_2.png) [@CoderN](https://discourse.nodered.org/u/CoderN)\
**Post date:** [20 June 2025 15:02 UTC](https://discourse.nodered.org/t/error-sqlite-readonly-attempt-to-write-a-readonly-database/97707/4 "2025-06-20T15:02:18Z")

</div>

@marcus-j-davies

Thanks for your help. I have installed Home Assistant and Node-RED as 2 separated docker containers sharing a single user. I have verified the read permission inside the Node-RED container with docker exec. Here are the 2 `compose.yaml` files.

```auto
$ cat node-red/compose.yaml
---
services:
  node-red:
    container_name: node-red
    image: nodered/node-red:latest
    deploy:
      resources:
        limits:
          memory: 256M
    restart: unless-stopped
    user: "3005:3005"
    environment:
      - TZ=Europe/London
    ports:
      - "1880:1880"
    volumes:
      - ./data:/data:rw
      - ../homeassistant/config/home-assistant_v2.db:/mnt/ha2/config/home-assistant_v2.db:ro

```

```auto
$ cat homeassistant/compose.yaml
---
include:
  - ./volumes.yaml

services:
  homeassistant:
    image: linuxserver/homeassistant:latest
    container_name: homeassistant
    deploy:
      resources:
        limits:
          memory: 1G
    environment:
      - PUID=3005
      - PGID=3005
      - TZ=Europe/London
      - REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "./custom-cont-init.d:/custom-cont-init.d:ro"
      - "./config:/config"
      - type: volume
        source: cctv
        target: /cctv
        volume:
          subpath: ha2/hass_events
      - type: volume
        source: cctv
        target: /config/nest
        volume:
          subpath: ha2/nest

    ports:
      - 8123:8123
    restart: unless-stopped

    depends_on:
      mosquitto:
        condition: service_started
        restart: false

```

I set the permission of the home-assistant\_v2.db in node-red container as read only on purpose. Node-RED should not modify it.

And the SQL Node-RED it run was a simple SELECT statement. It should not require write access regardless what the sqlite file was generated by.

I have posted on the forums of Home Assistant for help as well.

---

<div class="post-metadata">

**Author:** ![CoderN](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/codern/32/101562_2.png) [@CoderN](https://discourse.nodered.org/u/CoderN)\
**Post date:** [20 June 2025 15:06 UTC](https://discourse.nodered.org/t/error-sqlite-readonly-attempt-to-write-a-readonly-database/97707/5 "2025-06-20T15:06:13Z")

</div>

@Steve-Mcl

Thanks for your suggestion. Yeah. I have posted on Home Assistant forums as well.

Having said that, the node reporting error is a [node-red-node-sqlite](https://flows.nodered.org/node/node-red-node-sqlite) node. It seems to me that Node-Red SQLITE should be more relevant.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 June 2025 15:15 UTC](https://discourse.nodered.org/t/error-sqlite-readonly-attempt-to-write-a-readonly-database/97707/6 "2025-06-20T15:15:49Z")

</div>

The SQLite node is reporting it cannot write to the DB. This looks like permissions.

If you know how docker works (it is like a virtual machine running inside a host) - that is where HA runs Node-RED (and so that is where the SQLite node is running also). Therefore, the account that runs the Node-RED process is an account inside the VM (aka docker container) and so, by the looks of the DB file path (/mnt/xxx/yyy) the DB is NOT inside the container but actually inside the host (the computer running HA / Docker host). Thats why I said:

> [@Steve-Mcl](#):
>
> If you raise this on the HA forum - they will probably understand how these things fit together and be able to offer advice.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [20 June 2025 15:26 UTC](https://discourse.nodered.org/t/error-sqlite-readonly-attempt-to-write-a-readonly-database/97707/7 "2025-06-20T15:26:18Z")

</div>

I think there is confusion about exactly what you are complaining of. Is it that, when accessing a read only database, it is not possible to read from the DB?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 June 2025 15:54 UTC](https://discourse.nodered.org/t/error-sqlite-readonly-attempt-to-write-a-readonly-database/97707/8 "2025-06-20T15:54:50Z")

</div>

> [@Colin](#):
>
> I think there is confusion about exactly what you are complaining of.

oh, I see. I speed read the write error:

> [@CoderN](#):
>
> `Error: SQLITE_READONLY: attempt to write a readonly database`

This might then be a quirk of sqlite. For example, I am not certain if select queries that cause a lock should have write access.

failing that, perhaps the OP has INSERT/UPDATE quersies in the flows?

failing that, the node-red-node-sqlite is always asking for open "with write" (if that is such a thing?)

Lets see what the OP says.

---

<div class="post-metadata">

**Author:** ![CoderN](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/codern/32/101562_2.png) [@CoderN](https://discourse.nodered.org/u/CoderN)\
**Post date:** [20 June 2025 17:11 UTC](https://discourse.nodered.org/t/error-sqlite-readonly-attempt-to-write-a-readonly-database/97707/9 "2025-06-20T17:11:37Z")

</div>

@Steve-Mcl

Sorry for the confusion I have created.

I am not complaining. I know it must be my configuration errors. Let me provide more information about it.

For another basic test, I changed the file `compose.yaml` for node-red to

```auto
$ cat node-red/compose.yaml
---
services:
  node-red:
    container_name: node-red
    image: nodered/node-red:latest
    deploy:
      resources:
        limits:
          memory: 256M
    restart: unless-stopped
    environment:
      - TZ=Europe/London
    ports:
      - "1880:1880"
    volumes:
      - ./data:/data:rw
      - ../homeassistant/config/home-assistant_v2.db:/mnt/ha2/config/home-assistant_v2.db:rw

```

Now node-red is run as the default user (1000) and the `home-assistant_v2.db` is mounted as read-write.

Then I have changed the ownership of `home-assistant_v2.db` to user 1000. And it is writeable by the user node-red inside the container as shown below:

```auto
$ sudo docker exec -it -u 1000 node-red bash
e607b472495d:~$ id
uid=1000(node-red) gid=1000(node-red) groups=1000(node-red)
e607b472495d:~$ ls -lh /mnt/ha2/config/
total 4G     
-rw-rw-rw- 1 1000 1000 6.6G Jun 20 17:40 home-assistant_v2.db
e607b472495d:~$ touch /mnt/ha2/config/home-assistant_v2.db
e607b472495d:~$ ls -lh /mnt/ha2/config/
-rw-rw-rw- 1 1000 1000 6.6G Jun 20 18:23 home-assistant_v2.db
e607b472495d:~$ ps aux | grep "node-red"
    1 node-red 0:00 {entrypoint.sh} /bin/bash ./entrypoint.sh
    7 node-red 0:12 node-red
  778 node-red 0:00 bash
  846 node-red 0:00 ps aux
  847 node-red 0:00 grep node-red

```

And I have changed the database mode of the sqlite node to Read-Write-Create as shown below:

 ![Screenshot 2025-06-20 at 16.31.09](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/7/072a3a8335da2b662cda4c258412985cdaacd9b2.png)

The SQL statement executed was `SELECT * FROM states_meta ORDER BY entity_id DESC LIMIT 1`

It still reported the same error `Error: SQLITE_READONLY: attempt to write a readonly database` when the testing inject was pressed.

What have I missed?

---

<div class="post-metadata">

**Author:** ![CoderN](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/codern/32/101562_2.png) [@CoderN](https://discourse.nodered.org/u/CoderN)\
**Post date:** [20 June 2025 17:21 UTC](https://discourse.nodered.org/t/error-sqlite-readonly-attempt-to-write-a-readonly-database/97707/10 "2025-06-20T17:21:47Z")

</div>

The docker log might be helpful:

```auto
20 Jun 17:21:27 - [info] [sqlitedb:137383098fbd7a8e] opened /mnt/ha2/config/home-assistant_v2.db ok
20 Jun 17:21:29 - [error] [sqlite:HA2] Error: SQLITE_READONLY: attempt to write a readonly database
20 Jun 17:25:25 - [error] [sqlite:HA2] Error: SQLITE_READONLY: attempt to write a readonly database
20 Jun 17:25:27 - [error] [sqlite:HA2] Error: SQLITE_READONLY: attempt to write a readonly database

```

---

<div class="post-metadata">

**Author:** ![CoderN](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/codern/32/101562_2.png) [@CoderN](https://discourse.nodered.org/u/CoderN)\
**Post date:** [20 June 2025 17:24 UTC](https://discourse.nodered.org/t/error-sqlite-readonly-attempt-to-write-a-readonly-database/97707/11 "2025-06-20T17:24:23Z")

</div>

Sorry for the confusion. I am not complaining. I know it must be my configuration errors.

I have stated the situation again with more information above. This time with the database access set to RWC mode and the read-write permissions of the database file of the node-red user inside the container verified. It still gave me the same error.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 June 2025 18:00 UTC](https://discourse.nodered.org/t/error-sqlite-readonly-attempt-to-write-a-readonly-database/97707/12 "2025-06-20T18:00:26Z")

</div>

> [@CoderN](#):
>
> `/mnt/ha2/config/home-assistant_v2.db`

My guess is the db has permissions issue OR it is being locked by HA.

Potential Clue: [Upgrading to 0.24 resulted in read-only database - Configuration - Home Assistant Community](https://community.home-assistant.io/t/upgrading-to-0-24-resulted-in-read-only-database/2431)

Have you tried restarting HA?

My next step would likely be to mount `../homeassistant/config` with `rw` and do some simple file read/write tests (using the `file` nodes in node-red) to see if the node-red process has necessary permissions to the mounted fs. Next I would closely inspect the permissions of the db (though what these all are/should be is not something I am familiar with - HA folk will likely know how this is _supposed_ to work off the top of their heads)

Best I can do i'm afraid (not a HA user)

---

<div class="post-metadata">

**Author:** ![CoderN](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/codern/32/101562_2.png) [@CoderN](https://discourse.nodered.org/u/CoderN)\
**Post date:** [20 June 2025 23:42 UTC](https://discourse.nodered.org/t/error-sqlite-readonly-attempt-to-write-a-readonly-database/97707/13 "2025-06-20T23:42:53Z")

</div>

@Steve-Mcl

Thanks for your help.

I am happy to report that I have found the culprit. There are two more files accompany the sqlite database file. The error is gone once I have mounted the extra files inside the node-red container. In my case, they are `home-assistant_v2.db-wal` and `home-assistant_v2.db-shm`.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [4 July 2025 23:43 UTC](https://discourse.nodered.org/t/error-sqlite-readonly-attempt-to-write-a-readonly-database/97707/14 "2025-07-04T23:43:17Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
