# Attempt to write to readonly database

**URL:** <https://discourse.pi-hole.net/t/attempt-to-write-to-readonly-database/48499>\
**Category:** Community Help\
**Created:** [July 26, 2021, 8:49pm UTC](https://discourse.pi-hole.net/t/attempt-to-write-to-readonly-database/48499 "2021-07-26T20:49:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kinsham](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/k/7cd45c/32.png) [@kinsham](https://discourse.pi-hole.net/u/kinsham)\
**Post date:** [July 26, 2021, 8:49pm UTC](https://discourse.pi-hole.net/t/attempt-to-write-to-readonly-database/48499/1 "2021-07-26T20:49:21Z")

</div>

I am getting the error "cannot write to read only database" when saving to thw whitelist. This topic was previously reported on in this thread

> [@\[Solved\] While executing: attempt to write a readonly database error](https://discourse.pi-hole.net/t/solved-while-executing-attempt-to-write-a-readonly-database-error/33003/3):
>
> make sure the ownerhips are correct in directory /etc/pihole. (you can find right ownership list @deHakkelaar post below.) usermod -aG pihole www-data reboot this solved my problem. some of the files owned by root and that's why readonly error occured.

I have checked that www-data is a member of the pihole group. This should be OK since the gravity database is pihole:pihole 664 and is as should be as reported in the above post

pi@raspberrypi-b:~ $ grep pihole /etc/group  
pihole:x:995:www-data

pi@raspberrypi-b:~ $ stat -c "%U:%G %a %n" /etc/pihole/\* | column -t  
root:root 644 /etc/pihole/adlists.list  
root:root 644 /etc/pihole/adlists.list.old  
root:root 644 /etc/pihole/custom.list  
pihole:pihole 644 /etc/pihole/dhcp.leases  
root:root 644 /etc/pihole/dns-servers.conf  
root:root 644 /etc/pihole/GitHubVersions  
pihole:pihole 664 /etc/pihole/gravity.db  
root:root 644 /etc/pihole/install.log  
root:root 644 /etc/pihole/list.1.raw.githubusercontent.com.domains  
root:root 644 /etc/pihole/list.1.raw.githubusercontent.com.domains.sha1  
root:root 644 /etc/pihole/localbranches  
root:root 644 /etc/pihole/local.list  
root:root 644 /etc/pihole/localversions  
root:root 644 /etc/pihole/logrotate  
pihole:pihole 644 /etc/pihole/macvendor.db  
root:root 755 /etc/pihole/migration\_backup  
pihole:root 664 /etc/pihole/pihole-FTL.conf  
pihole:pihole 644 /etc/pihole/pihole-FTL.db  
root:root 644 /etc/pihole/setupVars.conf

System - Raspberry PI-B 8GB, pihole, lighttpd  
Lighttpd is installed to /var/www/pihole rather than the default /var/www/html since I already run an Apache2 instance at that location.  
pi@raspberrypi-b:~ $ cat /etc/lighttpd/external.conf  
server.document-root := "/var/www/pihole"  
server.port := 8080

There haven't been any changes since the original install (~3mo) though this issue could have been there all along. I just never had cause to write the whitelist till today.

---

<div class="post-metadata">

**Author:** ![Coro](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/coro/32/15424_2.png) [@Coro](https://discourse.pi-hole.net/u/Coro)\
**Post date:** [July 27, 2021, 9:14am UTC](https://discourse.pi-hole.net/t/attempt-to-write-to-readonly-database/48499/2 "2021-07-27T09:14:10Z")

</div>

> [@kinsham](#):
>
> This should be OK since the gravity database is pihole:pihole 664 and is as should be as reported in the above post

Mint that all folders beneath the database need to be _accessible_ for `www-data` (so it can get there) **and** the directory containing the database itself needs to be _writable_ for the group. Because `sqlite3` has to create a journal file next to the database as safeguard in case a powercut happens in the middle of writing to the database.

---

<div class="post-metadata">

**Author:** ![kinsham](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/k/7cd45c/32.png) [@kinsham](https://discourse.pi-hole.net/u/kinsham)\
**Post date:** [July 27, 2021, 4:33pm UTC](https://discourse.pi-hole.net/t/attempt-to-write-to-readonly-database/48499/3 "2021-07-27T16:33:52Z")

</div>

The database is a file at /etc/pihole/gravity.db, so there aren't folders below it?

/etc/pihole/ is pihole:pihole 755. Should this be set to 775?

---

<div class="post-metadata">

**Author:** ![kinsham](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/k/7cd45c/32.png) [@kinsham](https://discourse.pi-hole.net/u/kinsham)\
**Post date:** [July 27, 2021, 4:36pm UTC](https://discourse.pi-hole.net/t/attempt-to-write-to-readonly-database/48499/4 "2021-07-27T16:36:49Z")

</div>

I did try this and it now allows the whitelist to be written so I guess I answered my own question 👍

---

<div class="post-metadata">

**Author:** ![system](https://discourse.pi-hole.net/uploads/default/original/3X/7/c/7c8792f649eeb921c5d2b4c41564ffa873d9a2b8.png) [@system](https://discourse.pi-hole.net/u/system)\
**Post date:** [August 17, 2021, 4:37pm UTC](https://discourse.pi-hole.net/t/attempt-to-write-to-readonly-database/48499/5 "2021-08-17T16:37:13Z")

</div>

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