unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Efraim Flashner <efraim@flashner.co.il>
To: 58624@debbugs.gnu.org
Cc: Efraim Flashner <efraim@flashner.co.il>
Subject: [bug#58624] [PATCH v2] guix gc: Add '--vacuum-database'.
Date: Thu, 20 Oct 2022 22:27:53 +0300	[thread overview]
Message-ID: <a68398d3bb3f09e15c1a716d0f4ae822273f87c5.1666294004.git.efraim@flashner.co.il> (raw)
In-Reply-To: <56516d4a8143b96ef80d6dfd18f147568f23b73e.1666171506.git.efraim@flashner.co.il>

* guix/scripts/gc.scm (show-help, %options): Add '--vacuum-database'.
* guix/store/database.scm (vacuum-database): New procedure.
* doc/guix.texi (Invoking guix gc): Document the option.
---
 doc/guix.texi           | 12 ++++++++++++
 guix/scripts/gc.scm     | 11 +++++++++++
 guix/store/database.scm |  9 ++++++++-
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index fd8b19fe46..1c13480cbc 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -4531,6 +4531,18 @@ Invoking guix gc
 this option is primarily useful when the daemon was running with
 @option{--disable-deduplication}.
 
+@item --vacuum-database
+@cindex vacuum the store database
+@comment Avoid words like 'repair,' 'compress,' and 'optimize.'
+Guix uses an sqlite database to keep track of the items in (@pxref{The Store}).
+Overtime it is possible that the database may grow to a large size and become
+fragmented.  As a result, one may wish to clear the freed space and join the
+partially used pages in the database left behind from removed packages or after
+running the garbage collector.  Running @command{sudo guix gc
+--vacuum-database} will lock the database and @code{VACUUM} the store,
+defragmenting the database and purging freed pages, unlocking the database when
+it finishes..
+
 @end table
 
 @node Invoking guix pull
diff --git a/guix/scripts/gc.scm b/guix/scripts/gc.scm
index 65cd4bdf8b..5e775c5cdb 100644
--- a/guix/scripts/gc.scm
+++ b/guix/scripts/gc.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2012-2013, 2015-2020, 2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2022 Efraim Flashner <efraim@flashner.co.il>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -27,6 +28,7 @@ (define-module (guix scripts gc)
                                 generation-number)
   #:autoload   (guix scripts package) (delete-generations)
   #:autoload   (gnu home) (home-generation-base)
+  #:autoload   (guix store database) (vacuum-database)
   #:use-module (ice-9 match)
   #:use-module (ice-9 regex)
   #:use-module (srfi srfi-1)
@@ -86,6 +88,10 @@ (define (show-help)
   (display (G_ "
       --clear-failures   remove PATHS from the set of cached failures"))
   (newline)
+  (display (G_ "
+      --vacuum-database  repack the sqlite database tracking the store
+                         using less space"))
+  (newline)
   (display (G_ "
   -h, --help             display this help and exit"))
   (display (G_ "
@@ -131,6 +137,11 @@ (define %options
                 (lambda args
                   (show-version-and-exit "guix gc")))
 
+        (option '("vacuum-database") #f #f
+                (lambda args
+                  (vacuum-database)
+                  (exit 0)))
+
         (option '(#\C "collect-garbage") #f #t
                 (lambda (opt name arg result)
                   (let ((result (alist-cons 'action 'collect-garbage
diff --git a/guix/store/database.scm b/guix/store/database.scm
index 8d08def833..e664015673 100644
--- a/guix/store/database.scm
+++ b/guix/store/database.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2017, 2019 Caleb Ristvedt <caleb.ristvedt@cune.org>
 ;;; Copyright © 2018, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+;;; Copyright © 2022 Efraim Flashner <efraim@flashner.co.il>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -45,7 +46,8 @@ (define-module (guix store database)
             sqlite-register
             register-items
             %epoch
-            reset-timestamps))
+            reset-timestamps
+            vacuum-database))
 
 ;;; Code for working with the store database directly.
 
@@ -438,3 +440,8 @@ (define* (register-items db items
                     (register db item)
                     (report))
                   items)))))
+
+(define (vacuum-database)
+  (let ((db (sqlite-open (store-database-file))))
+    (sqlite-exec db "VACUUM;")
+    (sqlite-close db)))

base-commit: 00ff6f7c399670a76efffb91276dea2633cc130c
-- 
2.38.0





  parent reply	other threads:[~2022-10-20 19:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-19  9:26 [bug#58624] [PATCH] guix gc: Add '--vacuum-store' Efraim Flashner
2022-10-20 18:51 ` Liliana Marie Prikler
2022-10-20 19:22   ` Efraim Flashner
2022-10-20 19:27 ` Efraim Flashner [this message]
2022-11-03 16:20   ` [bug#58624] [PATCH v2] guix gc: Add '--vacuum-database' Christopher Baines
2022-11-06 12:04     ` bug#58624: " Efraim Flashner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a68398d3bb3f09e15c1a716d0f4ae822273f87c5.1666294004.git.efraim@flashner.co.il \
    --to=efraim@flashner.co.il \
    --cc=58624@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).