{"id":1134,"date":"2022-09-30T19:20:43","date_gmt":"2022-09-30T17:20:43","guid":{"rendered":"https:\/\/alessandromasciadri.com\/?p=1134"},"modified":"2022-09-30T19:43:09","modified_gmt":"2022-09-30T17:43:09","slug":"come-ridurre-la-dimensione-di-un-boltdb","status":"publish","type":"post","link":"https:\/\/alessandromasciadri.com\/come-ridurre-la-dimensione-di-un-boltdb\/","title":{"rendered":"Come ridurre la dimensione di un boltdb"},"content":{"rendered":"\t\t<div data-akihiro-type=\"ama-post\" data-akihiro-id=\"1134\" class=\"akihiro akihiro-1134\" data-akihiro-post-type=\"post\">\n\t\t\t\t<div class=\"akihiro-element akihiro-element-0fc5639 e-flex e-con-boxed e-con e-parent\" data-id=\"0fc5639\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"akihiro-element akihiro-element-dc1cc4e akihiro-widget akihiro-widget-text-editor\" data-id=\"dc1cc4e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"akihiro-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Questo post parte da <a href=\"https:\/\/github.com\/boltdb\/bolt\/issues\/423#issuecomment-141827222\">questa risposta<\/a>\u00a0ad una domanda posta sul <a href=\"https:\/\/github.com\/boltdb\/bolt\">repository ufficiale di boltdb<\/a>.<\/p><p>Nella domanda si chiede come ridurre la dimensione di un database bolt dopo aver cancellato un certo numero di buckets al suo interno.<\/p><p>La risposta ci conduce alla riflessione che per ridurre la dimensione di un database bolt non \u00e8 sufficiente cancellarne i buckets, bens\u00ec \u00e8 necessario eseguire una copia uno a uno dei buckets rimasti nel db in un altro bolt file.<\/p><p>Nella risposta si suggerisce di scrivere un programma che iteri per ogni buckets copiandolo in un nuovo db file. Questa opzione la lascer\u00f2 per un articolo successivo dove scriver\u00f2 uno script che esegua una copia di tutti i buckets presenti in un boltdb in un altro.<\/p><p>Per ora utilizzeremo <a href=\"https:\/\/github.com\/jessepeterson\/boltcopy\">boltcopy<\/a>, uno script in Go che permette di copiare i buckets da un boltdb file ad uno nuovo, ma che ha come limitazione quello di non supportare buckets annidati.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"akihiro-element akihiro-element-35f3c80 akihiro-widget akihiro-widget-heading\" data-id=\"35f3c80\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"akihiro-widget-container\">\n\t\t\t\t\t<h3 class=\"akihiro-heading-title akihiro-size-default\">Come ridurre la dimensione di un boltdb file con boltcopy<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"akihiro-element akihiro-element-1ff02da akihiro-widget akihiro-widget-text-editor\" data-id=\"1ff02da\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"akihiro-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Anzitutto \u00e8 necessario installare lo script Go e per farlo usiamo il seguente comando<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"akihiro-element akihiro-element-c270444 akihiro-widget akihiro-widget-code-highlight\" data-id=\"c270444\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"akihiro-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-okaidia copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash \">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>go install https:\/\/github.com\/jessepeterson\/boltcopy@latest<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"akihiro-element akihiro-element-350c6bc akihiro-widget akihiro-widget-text-editor\" data-id=\"350c6bc\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"akihiro-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Rechiamoci ora nella cartella \/home\/go\/bin dove troveremo un binary file chiamato boltcopy pronto per essere invocato con questo comando<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"akihiro-element akihiro-element-8b8794e akihiro-widget akihiro-widget-code-highlight\" data-id=\"8b8794e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"akihiro-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-okaidia copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash \">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>.\/boltcopy my-database.boltdb my-new-database.boltdb<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"akihiro-element akihiro-element-907fdaf akihiro-widget akihiro-widget-text-editor\" data-id=\"907fdaf\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"akihiro-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Attendiamo che il programma effettui la copia. Il tempo dipende in base alla dimensione del database di partenza.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"akihiro-element akihiro-element-59dc627 akihiro-widget akihiro-widget-text-editor\" data-id=\"59dc627\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"akihiro-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Ricordiamo che questa operazione \u00e8 da eseguire successivamente all&#8217;eliminazione di buckets dal nostro boltdb. Per gestire con semplicit\u00e0 questa operazione possiamo utilizzare <a href=\"https:\/\/github.com\/br0xen\/boltbrowser\">boltbrowser<\/a>, un altro programma scritto in Go che permette di visualizzare ed editare i buckets contenuti nel nostro database.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Questo post parte da questa risposta\u00a0ad una domanda posta sul repository ufficiale di boltdb. Nella domanda si chiede come ridurre la dimensione di un database bolt dopo aver cancellato un certo numero di buckets al suo interno. La risposta ci conduce alla riflessione che per ridurre la dimensione di un database bolt non \u00e8 sufficiente [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[41,40],"class_list":["post-1134","post","type-post","status-publish","format-standard","hentry","category-sistemistica","tag-boltdb","tag-go"],"_links":{"self":[{"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/posts\/1134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/comments?post=1134"}],"version-history":[{"count":4,"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/posts\/1134\/revisions"}],"predecessor-version":[{"id":1138,"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/posts\/1134\/revisions\/1138"}],"wp:attachment":[{"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/media?parent=1134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/categories?post=1134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/tags?post=1134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}