edit gravity.db directly without web interface

Problem with Beta 5.0:
I am trying to edit the gravity.db using the linux command line. It states that the database is readonly. Is there a way to change the database to where it can be written to?

I am trying to modify the "client_by_group" table.

There does not seem to be a way to change the above table by API unless I am mistaken? API would be another way to achieve what I want to do.

Debug Token:
When I ran pihole -d there was a bunch of output but I could not find a token.

Tell us what you intend to do and we can try to help.

here (can't edit post - closed)

version is now (change in script)
also requires mbstring (sudo apt-get -y install php-mbstring)

OR get the script from draft pihole v5 manual (chapter 25 / section 3)

Note: Any advice on editing internal files and databases that is not directly from a Pi-hole Developer is unsupported.

1 Like

At the end of the debug log, you should see this (see below). If you answer "Y", then the debug log is uploaded and you will receive a token in return. The token allows us to find your debug log on the server.


    * The debug log can be uploaded to tricorder.pi-hole.net for sharing with developers only.
    * For more information, see: https://pi-hole.net/2016/11/07/crack-our-medical-tricorder-win-a-raspberry-pi-3/
    * If available, we'll use openssl to upload the log, otherwise it will fall back to netcat.

[?] Would you like to upload the log? [y/N] y
    * Using curl for transmission.
[✓] Your debug token is: https://tricorder.pi-hole.net/sx1yoyvczi

Thank you for the quick replies.

What I am trying to do is to be able to either change the groups that I client belongs to or to enable and disable ad blocking on specific groups. Both of these goals are to be achieved without using the web interface's new "group management" section but rather using the command line by directly changing the database or using API.

Is this a personal preference, or is there a problem in how the web GUI handles these functions?

I was going to setup a raspberry pi for my mother to be able to enable and disable the adblocking on either her phone and/or computer with two physical switches.

I was going to setup the raspberry pi to convert the physical switch choices to talk with the pi-hole.

1 Like

If it's not currently something we can do then I would put it high on the list of things that we should be doing.

Thank you,

Please let me know if there is anything I can do to help.

I am not very good at programming but please let me know if there is anything I can test.

You can modify the database from the CLI, there are two things to consider here:

  1. The standard user pi is not allowed to write to the database. Use something like
    sudo -u pihole sqlite3 ...
    to be allowed to write to the database
  2. Remember to call
    pihole restartdns reload-lists
    after modifying the database to inform FTL about possible changes. We do not monitor the database continuously as this would consume quite some resources, otherwise.

You can find some examples for how to modify the fields in the database in the preview of the Pi-hole v5.0 documentation here:

1 Like

Does applying the changes to the database including the "pihole restartdns reload-lists" cause the pi-hole to stop forwarding DNS traffic for other devices?

Thank you.

I will try this.

For the very brief period of time while FTL is restarting, yes. This is less than a second. The clients will likely not have problems, and if they do, a re-request will be answered.

you don't really need physical switches,
on your pi, you can start a script in a screen
make a script loop, first command in the loop:

while :
	nc -l 5000
	if [ "$enable" = false ]; then
		some sql commands …
		some other sql commands …
	pihole restartdns reload-lists

this will let nc listen on port 5000

on you windows pc, use telnet (in a script, with desktop shortcut), to signal the NC (on the pi) it needs to continue

echo "exit" | telnet <IP_of_ pihole> 5000

As soon as nc receives the command from the windows pc, it will exit, the script can now continue (the proper (enable/disable) sqlite3 commands and pihole restartdns reload-lists), after this, the loop returns to the first command (nc), pi again listening on port 5000

Sure, (a lot) of additional scripting is required to achieve the result you want, but, you don't need physical switches, you only need an icon on the desktop.

Fixed, thanks!