How To Clean Up and Reduce the Size of Your KeePass Database

Introduction

The file size of a KeePass database is an often overlooked aspect impacting the way that you manage your passwords. A smaller database file translates to faster syncing and improved overall performance, saving you time and ensuring a seamless user experience. We’ve found that databases that are smaller than 4 MB perform the best.

Below are some tips for how to reduce the size of your KeePass database as much as possible, including:

Going From 20 MB to 68 KB

Recently I was experiencing some issues syncing my KeePass database between my Mac and iPhone. After saving a change on my Mac, sometimes that change would not be there when I unlocked the same database on my iPhone.

Data loss is extremely worrying, particularly when it concerns something as important as passwords and personal information.

Like many people, I was syncing my database between devices using a cloud storage provider. I noticed that the sync itself was taking a long time because my KeePass database file size had ballooned to over 20 MB. Every time I changed my database, the entire 20 MB file was uploaded to the cloud. This could sometimes take a minute or more when I was in an area with a poor internet connection.

So, in fact, no data was being lost (and I was confident that I could use Strongbox’s advanced Compare and Merge function to easily address any sync conflicts). But it was inconvenient.

This lead me to experiment with ways to reduce the size of my database. Now my database, containing over 600 entries, is only 68 KB. Syncing is lightning-fast and my experience of using KeePass is vastly improved.

You can do the same to your database by following the steps below.

Why Size Matters

If you’re interested in understanding why reducing the file size of your database can have such a big impact, read on. Or, you can skip straight to the step-by-step instructions below.

A KeePass database is a “flat” file. Every time that you make a change on one device, the entire database file needs to be transferred to your other devices. This is called a “cumulative update”.

Many other online services work differently, allowing individual changes to be pushed and pulled between different databases. So if you make a change on one device, only that specific change needs to be transferred to your other devices. This is known as a “delta update”.

Imagine a large document with many pages. Each page represents an entry in your database. When you change a page in the document, the whole document has to be recreated. If you want to share this updated version of the document with your friend, you have to give them a whole new copy of the document that contains all of the pages, both new and old. This is a cumulative update.

If you instead take a copy of the single page that you changed, give that to your friend and they replace only that one page in their copy of the document, this is the equivalent of a delta update.

Since KeePass is based on a cumulative update model, the overall size of the database file is relevant to its performance and portability.

Smaller Means Faster

Every time that you update your database, the entire file has to be uploaded to the cloud and then downloaded on your other devices. The smaller your database file, the faster this will happen.

And the faster this happens, the less likely you are to inadvertently make a change to an older version of the database on another device and thereby create a sync conflict.

In addition, every time you unlock your database, the entire volume must be decrypted. The smaller your database file, the faster this will also happen.

On many modern devices, the difference in unlock time is relatively marginal, but for older devices, a smaller database can result in meaningful speed improvements. This is particularly true when you consider that you might be unlocking your database multiple times a day over the course of years of usage. Those small time savings can add up.

More interestingly perhaps, reducing the file size could also create more headroom that you could take advantage of to increase the amount of encryption used to protect your database.

With a smaller file to decrypt, it will be possible to increase the number of iterations without creating an inconvenient time delay.

How To Reduce the Size of Your KeePass Database

PSA: Remember to always create a backup of your KeePass database before making any changes, and ensure you have a secure and reliable backup strategy in place!

Remove Attachments (20 MB down to 7.5 MB)

The first step is somewhat obvious but still worth mentioning. File attachments, even small ones, are many times larger than any text-only entry you have in your database.

Some of these you can probably delete. (Remember that any attachments that you delete will go to the Recycle Bin and that, until you empty the Recycle Bin, the size of your database file won’t actually decrease.)

Some of these you could archive in another storage location, such as a separate KeePass database or an encrypted disk image (using a tool such as VeraCrypt).

Strongbox has a dedicated Attachments view which you can select from the left-hand sidebar.

For instance, I was storing some ID documents in Strongbox, like a JPG of my driver’s license, that I didn’t need to have there. What I did instead was to use an app called TextSniper to copy and paste the important data from the JPG into custom fields within a Strongbox entry. I then exported the file to an iCloud Drive folder and deleted it from Strongbox.

In my case, I was able to remove around 14 MB of attachments. Most of these were PDFs and JPGs that didn’t need to be encrypted in my KeePass database. I moved them into folders in iCloud Drive and deleted them from Strongbox.

Remove Custom Icons and Favicons (6 MB down to 1.5 MB)

All of the icons and favicons that you’re using are stored within your database file itself. This means they are encrypted and decrypted regularly and they have to be synced every time you make a change to your database.

I had over 600 entries in my database and most of which had favicons attached, which I had downloaded using Strongbox’s Favicon Downloader.

Personally, I decided that the advantages of a smaller database outweighed the advantages of having attractive, easy-to-recognise icons. By setting all entries to use a single icon, I was able to reduce my database size by a further 4.5 MB.

Setting all entries to use the same icon is less colourful, but more efficient.

To strip out all of the icons from your database, follow these steps:

  1. Open the Strongbox app preferences
  2. Go to the Advanced tab
  3. Make sure that ‘Strip Unused Icons on Save is enabled
  4. Unlock your database
  5. Select All Entries in the left sidebar
  6. Select all the entries in the list (CMD + A)
  7. Right-click them and choose Set Icon
  8. Choose one of the icons from the options provided
  9. Save your database (CMD + S)

Of course, you don’t have to strip the icons from every entry. You could instead choose to only do this for a selection of the entries in your database.

(N.B. you may find that your database doesn’t actually reduce in size until you do the step below. This is because the old icons could still be stored as part of your password history.)

And if you later decide to add favicons back, you can select the entries, right click and choose Find Favicon(s).

If you decide to start using favicons again, it’s easy to add them back using Strongbox’s Favicon Downloader.

Remove Password History and Unnecessary Metadata (1.5 MB down to 68 KB)

Strongbox (and other KeePass apps) will store password history and other metadata in your database file. You can remove all of this by creating a new database file and then copying all of your entries across. This is a “fresh start” for your database.

(This metadata is used to do things like manage sync conflicts and database merges, but it’s not necessary to keep it forever.)

To do this we recommend using Strongbox on your Mac. The steps are:

  1. Create a new database
  2. Unlock your current database in another window or tab
  3. Copy and paste or drag and drop all of your entries from the current database to the new database
  4. Use the new database as your current database, and delete (or backup) the old one

It’s also possible to do this on iOS. The steps are:

  1. Create a new database
  2. Go back to the list of databases and unlock your current database
  3. Select the entries to move (tap the three-dot menu in the top right of the screen and then tap Select)
  4. Select the entries to move (note that it’s easier to move large numbers of entries if they’re inside a group)
  5. Tap Export Item(s)
  6. Choose your new database
  7. Unlock the new database and confirm

This should reduce the size of your database significantly. In my case, I was able to clear out a further 1.5 MB.

Taking It Further

At this point, we’re at the point of diminishing returns. The steps below are mostly focused on removing unnecessary entries from your database, but the entries themselves are tiny in comparison to the attachments and icons that are mentioned above. That said, here are some extra steps that you can take to optimise your database to be as small as possible.

Empty the Recycle Bin

Attachments and entries that you delete go to the Recycle Bin. Until you empty the Recycle Bin, they won’t actually contribute to reducing the size of your database.

You can empty it by right clicking it on Mac or long pressing it on iOS and selecting Empty Recycle Bin.

Delete Duplicate Entries

You can view all duplicated entries in Strongbox on Mac by selecting Duplicated under the Audit Issues heading in the left sidebar. On iOS, tap the search bar and then Audit Issues.

As well as saving a bit of space, deleting duplicates is going to make AutoFill suggestions easier for you to parse.

Spread Entries Across Different Database Files

If you’re currently storing all of your entries in a single database, you might want to consider splitting them across multiple databases instead.

For instance, if you have a group of entries that you rarely use, you could “archive” these by moving them to a different database. This means that your primary database is going to unlock and sync faster because it’s not weighed down by entries that are rarely needed.

This would be particularly effective if you have a lot of attachments. In this case, you could even create a separate database just to store your attachments.

This is less convenient of course, potentially requiring multiple database unlocks to access data when before only one would have been necessary. It can also make configuring AutoFill more complicated.

Make Sure That Compression Is Enabled

Strongbox uses gzip compression by default. It’s worth checking that this is enabled in the Encryption Settings for your database, particularly if you have a lot of attachments.

Gzip is enabled by default when you create a new database in Strongbox, but it might be turned off if you’ve imported your database from another KeePass app.

Conclusion

Hopefully, you can apply some or all of the steps above to reduce the size of your database, making your experience of using Strongbox even faster.

If you have any other tips or tricks to reduce database size, let us know in our subreddit or on Twitter.

Recommended Posts