From patchwork Thu Oct 20 19:27:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Efraim Flashner X-Patchwork-Id: 6807 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 3B98827BBE9; Thu, 20 Oct 2022 20:32:22 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id A238327BBE9 for ; Thu, 20 Oct 2022 20:32:21 +0100 (BST) Received: from localhost ([::1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olbHA-0008J8-Nf for patchwork@mira.cbaines.net; Thu, 20 Oct 2022 15:32:20 -0400 Received: from [::1] (helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olbE0-0006MV-Nc for patchwork@mira.cbaines.net; Thu, 20 Oct 2022 15:29:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olbDy-0006Ls-HI for guix-patches@gnu.org; Thu, 20 Oct 2022 15:29:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1olbDy-0003LS-5w for guix-patches@gnu.org; Thu, 20 Oct 2022 15:29:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1olbDy-0003Y7-0z for guix-patches@gnu.org; Thu, 20 Oct 2022 15:29:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#58624] [PATCH v2] guix gc: Add '--vacuum-database'. References: <56516d4a8143b96ef80d6dfd18f147568f23b73e.1666171506.git.efraim@flashner.co.il> In-Reply-To: <56516d4a8143b96ef80d6dfd18f147568f23b73e.1666171506.git.efraim@flashner.co.il> Resent-From: Efraim Flashner Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 20 Oct 2022 19:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58624 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 58624@debbugs.gnu.org Cc: Efraim Flashner Received: via spool by 58624-submit@debbugs.gnu.org id=B58624.166629409013586 (code B ref 58624); Thu, 20 Oct 2022 19:29:01 +0000 Received: (at 58624) by debbugs.gnu.org; 20 Oct 2022 19:28:10 +0000 Received: from localhost ([127.0.0.1]:36165 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1olbD8-0003X4-2v for submit@debbugs.gnu.org; Thu, 20 Oct 2022 15:28:10 -0400 Received: from mail-ej1-f49.google.com ([209.85.218.49]:41551) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1olbD5-0003Ws-Gx for 58624@debbugs.gnu.org; Thu, 20 Oct 2022 15:28:08 -0400 Received: by mail-ej1-f49.google.com with SMTP id d26so1914862ejc.8 for <58624@debbugs.gnu.org>; Thu, 20 Oct 2022 12:28:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=NCbfO/K5YXeC5RZDyBVQxY2KX4byDDDxn65FDGQbIZg=; b=HVEKx88TYwSkpZqypXFvtvZK5fUi1bgDjVyN9wHg36VwLdtHXB52f+GAyi9Wgp/aRQ RiV4yH3i4Op42V4+8CG4Oi2Q1Tx6h+XvyoghOvFCKLZTR2VAtgXZHALhlGiUewQa6Rvm OW3yg8UiOzFbhX1rveFNm6AIN3nt6g/QFwNBj0hYRWJFYIkDZuZC2BMOJK3/F1NkRKwT HlQ8I8PcEB2I1GpCzM4gZxgOX1rkCuVz0QYiBg+OobhreKJEbSLeh7E0W2VLcCdQRHox C4HWC1MMrms69WIJ7C7HU661ZAhOHZngklsyNXbGScgyxkl3dtPI+glYPycbLPwHOvZf pTfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=NCbfO/K5YXeC5RZDyBVQxY2KX4byDDDxn65FDGQbIZg=; b=te73SSAngHkduF1mbQkCJ9qftape7LT27UL3Ij9/9FjLmtPxt53EiPBFIUzDRMpf/H elOeHtGJLrgQnC4s2MG/3aGGPOvkGZctwzRuRZ9rAxaYrY2lhoUXsvvkW0nNmqkvhS9/ 4varTwFkTgeA4SIa/aNSfCq723Ft9GSnRMfD28Hdkrn1ta+pSmCMU4YQLgiyr6pyNJcc jytWvTRR8eul2bpFleCSsOzATLbT+/6f4b9+tzDI2Lcy/SckMzgjvPv9N9gZrdixWeVP TCWzdLUPW/mzq6j51QZjGK6fxfj6FQnwiDkuZky2VlTJJ9OCNLp0uXy7yL4d63X8F3LF 7cnw== X-Gm-Message-State: ACrzQf0T/87l/xFWQbrVWTdzxcA7OPki5jXv5rYvbkXQI7iVxcKBO+DA er1KNoDWbZHIc5YBoetbolIWyuROWZEmLKTY2uE= X-Google-Smtp-Source: AMsMyM5l0AQGe8gmnJsmNsN5ElTgmQrmAxpfuSvBFlSF0kHN6KTfMqsqJzSJloBmlFfLS1uaNmSHQA== X-Received: by 2002:a17:906:cc0b:b0:78e:1d51:36ea with SMTP id ml11-20020a170906cc0b00b0078e1d5136eamr12486758ejb.408.1666294081585; Thu, 20 Oct 2022 12:28:01 -0700 (PDT) Received: from localhost ([141.226.13.62]) by smtp.gmail.com with ESMTPSA id r11-20020a170906704b00b0073d9630cbafsm10694050ejj.126.2022.10.20.12.28.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 12:28:01 -0700 (PDT) From: Efraim Flashner Date: Thu, 20 Oct 2022 22:27:53 +0300 Message-Id: X-Mailer: git-send-email 2.38.0 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * 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(-) base-commit: 00ff6f7c399670a76efffb91276dea2633cc130c 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 +;;; Copyright © 2022 Efraim Flashner ;;; ;;; 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 ;;; Copyright © 2018, 2020, 2021 Ludovic Courtès ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen +;;; Copyright © 2022 Efraim Flashner ;;; ;;; 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)))