Ошибка attempt to write a readonly database

I have a SQLite database that I am using for a website. The problem is that when I try to INSERT INTO it, I get a PDOException

SQLSTATE[HY000]: General error: 8 attempt to write a readonly database

I SSH’d into the server and checked permissions, and the database has the permissions

-rw-rw-r--

I’m not that familiar with *nix permissions, but I’m pretty sure this means

  • Not a directory
  • Owner has read/write permissions (that’s me, according to ls -l)
  • Group has read/write permissions
  • Everyone else only has read permissions

I also looked everywhere I knew to using the sqlite3 program, and found nothing relevant.

Because I didn’t know with what permissions PDO is trying to open the database, I did

chmod o+w supplies.db

Now, I get another PDOException:

SQLSTATE[HY000]: General error: 14 unable to open database file

But it ONLY occurs when I try to execute an INSERT query after the database is open.

Any ideas on what is going on?

Hi all, apologies I’ve been uber busy so only getting round to testing the latest image (2022.02.01).
Thankfully the permissions issue with adding/removing DNS and CNAME records has been resolved. Much appreciated.

However I now get the same/similar issue when trying to add/remove adlists, blacklist/whitelist updates, or any of the other actions that try to edit gravity.db (although I’m not familiar enough with the inner workings so it could be an issue with another file(s) e.,g. pihole-FTL.db).
For example., trying to add a new adlist gives this error:
image

The original problematic files seem fine now, they are now owned by root:root and the GUI (I assume that’s being run under the www-data user) has no problem updating these. The problem seems to be when the GUI tries to update some of the files owned by pihole:pihole although not certain why since the www-datauser is in the pihole group so should be able to edit those files.

The new error only occurs when the volume is mounted. I currently have the following mounts defined in docker-compose.yml:
- $DOCKER_DIR/pihole/data/etc/dnsmasq.d/:/etc/dnsmasq.d/
- $DOCKER_DIR/pihole/data/etc/pihole/:/etc/pihole/

But gravity.db (and some other files) look like they are owned by pihole:pihole and the GUI is having issues updating these. From my local (ubuntu) system the /etc/pihole directory looks like:

ls -al /storage/Docker/pihole/data/etc/pihole/
total 12M
drwxrwxr-x+ 3  999 docker 4.0K Mar  7 00:19 .
drwxrwxr-x+ 4 ryan ryan   4.0K Mar  7 00:17 ..
-rw-r--r--  1 root root      0 Mar  7 00:17 custom.list
-rw-r--r--+ 1  999 docker    0 Mar  7 00:19 dhcp.leases
-rw-r--r--+ 1 root root    651 Mar  7 00:17 dns-servers.conf
-rw-r--r--+ 1 root root     16 Mar  7 00:18 GitHubVersions
-rw-rw-r--+ 1  999 docker 8.7M Mar  7 00:17 gravity.db
-rw-rw-r--+ 1  999 docker  92K Mar  7 00:17 gravity_old.db
-rw-r--r--+ 1 root root   3.0M Mar  7 00:17 list.1.raw.githubusercontent.com.domains
-rw-rw-r--+ 1 root root     95 Mar  7 00:17 list.1.raw.githubusercontent.com.domains.sha1
-rw-r--r--+ 1 root root    17K Mar  7 00:17 list.2.urlhaus.abuse.ch.domains
-rw-rw-r--+ 1 root root     86 Mar  7 00:17 list.2.urlhaus.abuse.ch.domains.sha1
-rw-r--r--+ 1 root root    67K Mar  7 00:17 list.3.zerodot1.gitlab.io.domains
-rw-rw-r--+ 1 root root     88 Mar  7 00:17 list.3.zerodot1.gitlab.io.domains.sha1
-rw-r--r--+ 1 root root     13 Mar  7 00:17 localbranches
-rw-r--r--+ 1 root root     65 Mar  7 00:17 local.list
-rw-r--r--+ 1 root root     21 Mar  7 00:17 localversions
drwxrwxr-x+ 2 root root   4.0K Mar  7 00:17 migration_backup
-rw-rw-r--  1  999 root    138 Mar  7 00:17 pihole-FTL.conf
-rw-rw-r--+ 1  999 docker  92K Mar  7 00:19 pihole-FTL.db
-rw-rw-r--+ 1 root root    191 Mar  7 00:17 setupVars.conf
-rw-rw-r--+ 1 root root      0 Mar  7 00:17 setupVars.conf.update.bak

And when I log into the container the files look like:

root@1ac381f4f224:/etc/pihole# ls -al /etc/pihole/
total 12220
drwxrwxr-x+ 3 pihole pihole    4096 Mar  7 00:22 .
drwxr-xr-x  1 root   root      4096 Mar  7 00:17 ..
-rw-r--r--+ 1 root   root        16 Mar  7 00:18 GitHubVersions
-rw-r--r--  1 root   root         0 Mar  7 00:17 custom.list
-rw-r--r--+ 1 pihole pihole       0 Mar  7 00:19 dhcp.leases
-rw-r--r--+ 1 root   root       651 Mar  7 00:17 dns-servers.conf
-rw-rw-r--+ 1 pihole pihole 9052160 Mar  7 00:17 gravity.db
-rw-rw-r--+ 1 pihole pihole   94208 Mar  7 00:17 gravity_old.db
-rw-r--r--+ 1 root   root   3092387 Mar  7 00:17 list.1.raw.githubusercontent.com.domains
-rw-rw-r--+ 1 root   root        95 Mar  7 00:17 list.1.raw.githubusercontent.com.domains.sha1
-rw-r--r--+ 1 root   root     17031 Mar  7 00:17 list.2.urlhaus.abuse.ch.domains
-rw-rw-r--+ 1 root   root        86 Mar  7 00:17 list.2.urlhaus.abuse.ch.domains.sha1
-rw-r--r--+ 1 root   root     67622 Mar  7 00:17 list.3.zerodot1.gitlab.io.domains
-rw-rw-r--+ 1 root   root        88 Mar  7 00:17 list.3.zerodot1.gitlab.io.domains.sha1
-rw-r--r--+ 1 root   root        65 Mar  7 00:17 local.list
-rw-r--r--+ 1 root   root        20 Mar  7 00:20 localbranches
-rw-r--r--+ 1 root   root        38 Mar  7 00:20 localversions
drwxrwxr-x+ 2 root   root      4096 Mar  7 00:17 migration_backup
-rw-rw-r--  1 pihole root       138 Mar  7 00:17 pihole-FTL.conf
-rw-rw-r--+ 1 pihole pihole  118784 Mar  7 00:22 pihole-FTL.db
-rw-rw-r--+ 1 root   root       191 Mar  7 00:17 setupVars.conf
-rw-rw-r--+ 1 root   root         0 Mar  7 00:17 setupVars.conf.update.bak

I have a solution/workaround by using the experimental pihole/web-data ID environment variables:

1. Set all 4 variables
Set pihole and web-data to match each other:

environment:
  - PIHOLE_UID=1000
  - PIHOLE_GID=999
  - WEB_UID=1000
  - WEB_GID=999

In this case, 1000 is the user ID of my main ubuntu system user, and 999 is the ‘docker’ group on my system. But that’s just coincidence as it also works with some random values which didn’t match any host or container user/group IDs.
I’m effectively trying to turn the two users into the same single user by setting them equal to each other. I would assume that if pihole and www-data match then the permission issue will be resolved. Although probably not the best practice as we’re eliminating any role separation.

2. Set web-user GID only
The above solution with the 4 environment variables works but so does just using WEB_GID=999 (999 is the pihole group inside the container).
My thoughts here were to just try explicitly setting www-data to be part of the group with permission to edit these files — seems to have worked but don’t know why it does unless there is a part of the pihole script which also does this but is not being run for some reason.

I haven’t had time to try any other combination of the UID/GID variables yet.

Also, the two ‘solutions’ from before continue to be a workaround for this new permission problem. i.e.

  • Using command line from host or from inside container e.g.
    pihole -w test123.org
    docker exec pihole pihole -b testABC.org
  • Running the chmod -R workaround that everyone seemed to do in order to get around the old issue. I really don’t like this as a solution.

Happy to help with more testing/troubleshooting if that’s useful.

Здравствуйте.

Столкнулся с ошибкой 8 - attempt to write a readonly database [Sqlite]. В интернете особо информации о ней нет (многие советуют поставить права 777 файлу sqlite, но это только ухудшает ситуацию).

Собственно обстановка:

Имеются два файла test.php и test_web.php, они подключены к data.sqlite. К test_web.php обращаюсь get-запросами, использую INSERT, чтобы записать в таблицу, и вывожу ошибку через $db->lastErrorMsg() — получаю attempt to write a readonly database.

Далее решил проверить, как это все пройдет в ssh, переделал файл под $argv, написал в ssh и все отлично работает. Внимательно посмотрел файлы, заметил, что они все пренадлежат root (apache2 работает через www-root), решил через chown -R www-root:www-root сделать владельца и группу www-root (для базы Sqlite + test_web.php) и в результате получилось:

14 - unable to open database file

То есть доступ вообще исчез ?.
Мучаюсь уже два дня, пожалуйста, подскажите как решить проблему.

У меня есть база данных SQLite, которую я использую для веб-сайта. Проблема в том, что когда я пытаюсь INSERT INTO, я получаю PDOException

SQLSTATE[HY000]: General error: 8 attempt to write a readonly database

I SSH’d на сервер и проверял разрешения, а база данных имеет разрешения

-rw-rw-r--

Я не знаком с разрешениями * nix, но я уверен, что это означает

  • Не каталог
  • У владельца есть права на чтение/запись (что я, согласно ls -l)
  • У группы есть права на чтение/запись.
  • У всех остальных есть разрешения на чтение

Я также искал всюду, что знал, используя программу sqlite3, и не нашел ничего полезного.

Поскольку я не знал, с какими разрешениями PDO пытается открыть базу данных, я сделал

chmod o+w supplies.db

Теперь я получаю еще один PDOException:

SQLSTATE[HY000]: General error: 14 unable to open database file

Но он ТОЛЬКО возникает, когда я пытаюсь выполнить запрос INSERT после открытия базы данных.

Любые идеи о том, что происходит?

Делаю сайт на джанго. После очередного обновления исходников на серваке возникла ошибка «attempt to write a readonly database». Обновления касалис работой с базой sqlite3. До этого на хостинге сайт не взаимодействовал с базой. Команда «python manage.py migrate» проходит замечательно(без ошибок). Но при входе на сайт появляется эта ошибка. Я так понимаю, проблема с правами доступа? Решить задачу при помощи гула не получается. Прошу помощи)


  • Вопрос задан

    более трёх лет назад

  • 10420 просмотров

Понравилась статья? Поделить с друзьями:
  • Ошибка attempt to index global
  • Ошибка asr мерседес что это
  • Ошибка asr камаз как отключить
  • Ошибка asr гольф 6 bse
  • Ошибка asr volkswagen jetta 6