From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id WIygOePDT2O5aQEAbAwnHQ (envelope-from ) for ; Wed, 19 Oct 2022 11:31:16 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id 8AGyOOPDT2NgZAAAG6o9tA (envelope-from ) for ; Wed, 19 Oct 2022 11:31:15 +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 4011FE036 for ; Wed, 19 Oct 2022 11:31:15 +0200 (CEST) Received: from localhost ([::1]:46034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ol5Pu-0003wd-CC for larch@yhetil.org; Wed, 19 Oct 2022 05:31:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42958) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ol5Pj-0003uF-3i for guix-patches@gnu.org; Wed, 19 Oct 2022 05:31:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:56755) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ol5Pi-0002gm-Md for guix-patches@gnu.org; Wed, 19 Oct 2022 05:31:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ol5Pi-0002GP-FV for guix-patches@gnu.org; Wed, 19 Oct 2022 05:31:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#58624] [PATCH] guix gc: Add '--vacuum-store'. Resent-From: Efraim Flashner Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 19 Oct 2022 09:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 58624 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 58624@debbugs.gnu.org Cc: Efraim Flashner X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16661718078606 (code B ref -1); Wed, 19 Oct 2022 09:31:02 +0000 Received: (at submit) by debbugs.gnu.org; 19 Oct 2022 09:30:07 +0000 Received: from localhost ([127.0.0.1]:55833 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ol5Op-0002Dr-A6 for submit@debbugs.gnu.org; Wed, 19 Oct 2022 05:30:07 -0400 Received: from lists.gnu.org ([209.51.188.17]:41290) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ol5Ok-0002D8-Sk for submit@debbugs.gnu.org; Wed, 19 Oct 2022 05:30:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ol5Oi-0003FJ-49 for guix-patches@gnu.org; Wed, 19 Oct 2022 05:30:01 -0400 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]:44943) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ol5Oc-0002PJ-9E for guix-patches@gnu.org; Wed, 19 Oct 2022 05:29:59 -0400 Received: by mail-ej1-x62c.google.com with SMTP id w18so38479181ejq.11 for ; Wed, 19 Oct 2022 02:29:53 -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=oc8+dRDaejSL9wqWEc8iHkvF0ehETg8nygZPqkS8UOs=; b=TsSv8Y/KkHKZG80pIVAu1ED9eE/nbHYyUagmC8hgbqtRy6/sr/as+ODNWoB/+uxiKd aeNYPu4N4jITnLEorQqQDNh2JAkACw3gWFUSMxILuwx9ug0FyZizLLE+KwbH/CkcHxR1 k1zt65T7S4V3Q4jacbBoC3NgLbYPnqUVDiZWjntALJwlqoPF/ynncsIC4LUezQllvtxv OIL4R7cRwtIJmSWKXkX3R5ryKNgu/uNBbh7xKLzH01HI6ymPHsrHN/79NKEgoH/rI9oZ F3fznANcNTWPVjBYKcf6unZvKwvm9L1LFQsuNbZGjYtTEp/wotGxLwux9SYjzcE7Zi6P zAKg== 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=oc8+dRDaejSL9wqWEc8iHkvF0ehETg8nygZPqkS8UOs=; b=Ay+iiRFwjrf8AWh/o5trPacD8I/OukrTMfu0lCOqpwaehQYj5VT5+4+FhyXxJnUNuK lNwyyqOpT8Z0iF4VhlPCWNHeR0DiTMGKzilm9Vb9YSah9n4XBGT/J3doPiIk+Esqs6Ye BfLWZvuwTBha1H16pjoQqJQCr8DIl0eYz4U6Idoa34gKzuhJRT+0rQkCnd+IboG48wlL ID0JYmwXkpftzuZNseemUI8umsr7WnFDQpBFpFnJTeY++XL5VlxRO3PNomcxgSBP24YA cEdKllmUqNFHsSVOCqcs3371HFTfcoNz1ClV6GALnVQMbUpe73hVpFzHI/ZOYboR2afn xCwg== X-Gm-Message-State: ACrzQf1sOznAf7yCYh4tBQjWOeXgIQfdr6/4taAESiwaTDMYPnZrTtZ8 TCmTkFiOm0Otr4CPyk/DvMNov6Kxx38yWn5iKtA= X-Google-Smtp-Source: AMsMyM4UIqKYeo8ldjvQjumZQscQDrQHAqbTlDhrQ5OhVXnNI/M3Y34nU8xZ8Kqc8Q6iPazIvLD4bA== X-Received: by 2002:a17:907:2cd9:b0:78d:9e76:be26 with SMTP id hg25-20020a1709072cd900b0078d9e76be26mr5800632ejc.315.1666171792196; Wed, 19 Oct 2022 02:29:52 -0700 (PDT) Received: from localhost ([141.226.13.62]) by smtp.gmail.com with ESMTPSA id 16-20020a170906309000b0078d22b0bcf2sm8769944ejv.168.2022.10.19.02.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 02:29:51 -0700 (PDT) From: Efraim Flashner Date: Wed, 19 Oct 2022 12:26:20 +0300 Message-Id: <56516d4a8143b96ef80d6dfd18f147568f23b73e.1666171506.git.efraim@flashner.co.il> X-Mailer: git-send-email 2.38.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=efraim.flashner@gmail.com; helo=mail-ej1-x62c.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action 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=1666171875; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=oc8+dRDaejSL9wqWEc8iHkvF0ehETg8nygZPqkS8UOs=; b=rTmIcAX4KweJqIPY5ejM+gPxJ7LaF1M6/FmhgRnHuaKlXT77s2WPcXxjZ91vHjcjMGYPcx KhyWlZ/iedQHf3ABXLx0ew4WuCikdfiYXaCISiKU1Kd4CgeuMdPlsy9T6BzPLMxGZK1T/J bCvCGQt3mm1Og6i7XqocybfwrFJRk8xVUrDsDFLMPMBwAvE4IfkjGMl4i2uFXttCPlu/Nq xl8SOKxSRGn3wtSAjwvN2zZycgr7LUL/mQVKb0kGgUI/2MlQbYRil3VImfMM2rMS6k30mD avQIG+WDceImNS6pgAR1F8uc72uYjWcCIuAFAkLbfbh3hPDKMX97eVRuX+nb+Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1666171875; a=rsa-sha256; cv=none; b=c/mt5hxOixKi4uApkMq+PQKGZWAjdCoRXEjVIMiZoZAxI3GddPnHncp8hU7YZsh1HcFXfK MnfvlS9IQNHEAtC3a1WZaEASsN3mCrWQZ0ZhO6zNutTKgbdDJbpqfiQtheCJTJ8IyI8Gmv 2G00lSKsiq4fbOwOl2i1OeKqk+4VOAxvljSlX7XfLdfV05iy3g6766ELDGUoOEWyDj9L0E AShrYE9HBDk8qLPz/oD5EOfyOHLxODM6ssahOVBvWXwle+lOE7zCDsU6HwChcgv3IZYTch qOhENHvTZ5xaEG14hZH65bJkDzieEITCRfCfV9ZrJybEd69DTXc8KkzmcOWFoA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b="TsSv8Y/K"; 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: 2.38 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b="TsSv8Y/K"; 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: 4011FE036 X-Spam-Score: 2.38 X-Migadu-Scanner: scn0.migadu.com X-TUID: wVv/8jd6UvEJ * guix/scripts/gc.scm (show-help, %options): Add '--vacuum-store'. * guix/store/database.scm (vacuum-database): New procedure. * doc/guix.texi (Invoking guix gc): Document the option. --- doc/guix.texi | 11 +++++++++++ guix/scripts/gc.scm | 11 +++++++++++ guix/store/database.scm | 9 ++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index 3bf2dee752..89fd04415a 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -4531,6 +4531,17 @@ Invoking guix gc this option is primarily useful when the daemon was running with @option{--disable-deduplication}. +@item --vacuum-store +@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-store} +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: 3bb145b6e2a8c84e7739ead9ae76dc4d42bb9850 -- 2.38.0