From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id UIkII1yiUWPzAgEAbAwnHQ (envelope-from ) for ; Thu, 20 Oct 2022 21:32:44 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id sD0SI1yiUWN9FwAAauVa8A (envelope-from ) for ; Thu, 20 Oct 2022 21:32:44 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 432B96226 for ; Thu, 20 Oct 2022 21:32:44 +0200 (CEST) Received: from localhost ([::1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olbHX-0008Pe-Go for larch@yhetil.org; Thu, 20 Oct 2022 15:32:43 -0400 Received: from [::1] (helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olbE0-0006MV-H1 for larch@yhetil.org; 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1666294364; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=NCbfO/K5YXeC5RZDyBVQxY2KX4byDDDxn65FDGQbIZg=; b=sfvMRq7zziVuAuVBKt/GQh/0nIIwIzWUNBihvLXZueGTI4i7ZmuI6g1a17FefsXTZJ41lg hgIw4Mgr0kjsRpMAUTc8OOqJtxft/oDOG6ZqB30D/3duFNOq8RZqeSF1reaQTzn3v7Ee4V E3SDn6BNHZ9GdmOHnWZAGNa3k33DATwlyap1aIcu4n/OsTGWqUH8qY7WKT7mByF+ydNUJF dx0JTpl7Zb0IXbYtjLr8Xv2hC5x/FFgCRF2xFuNv0WnbZDsKbyi9BaUEtbETqisZvbly1v wU4rwhnfBE/ZhsNwpOxZQwpFlEQbGNhRSgjrziS5gU2r0sJPIwUxDrB4pPR9gg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1666294364; a=rsa-sha256; cv=none; b=g6Ne3/tbq3kkHr/M7y01saB040hPH/xCzLuCPMg3nNK8E1L7vSgrSxT8NUazSTwdjG7qFL ETDLpvKoTW0IsIbwA4oT2dR+WGQAeTFGm8Kg0MTKqNPziUtHTKry6zCKHR5RohbR+ihQiR 5w/Wse9MG6ehXas12u1KsKn6KHcq/T817ErOTcS5QF15z5SpQtjZV4E9EK8vJqT/7Ip1dw 7ZjB2x+8KJaro0pbaK4bP9ej4uZaBaQT1v4eFeYKpQhLS6NARnbWM8LnNWwIv6fIUdjvnr 8Le4FPpaoCq2xWHeZoZ7u6UR8IVDDBWWmrnxc6FxH7BNykvm2725grM3JlvNCQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=HVEKx88T; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 1.57 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=HVEKx88T; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 432B96226 X-Spam-Score: 1.57 X-Migadu-Scanner: scn0.migadu.com X-TUID: gXbNrvwvlirc * 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 +;;; 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))) base-commit: 00ff6f7c399670a76efffb91276dea2633cc130c -- 2.38.0