Skip to the content
pacman-master.com

unable to lock database

The error means the lock file /var/lib/pacman/db.lck is present. pacman creates it at the start of a transaction and removes it at the end, so either another pacman is running right now, or one stopped without cleaning up.

/var/lib/pacman/db.lck

What it does. pacman creates this file when a transaction starts and removes it when the transaction ends.

Watch out. The error means the file exists. Find out whether a pacman is running before deleting it.

What the lock is for

Why a stale db.lck is left behind, and when it is safe to removeA run of pacman from top to bottom: pacman starts, db.lck is created, the work happens, db.lck is removed. A branch marked interrupted here leaves the run part way through, so db.lck stays on disk and the next run is refused. Underneath, the command pgrep -a pacman is given as the check to run before deleting the lock file, marked as not being a pacman command.pacman startsdb.lck is createdthe work happensdb.lck is removeddb.lck is left behindand the next run is refusedinterrupted hereA lock is how pacman keeps twotransactions from writing the samedatabase at the same moment.Check before deleting it:pgrep -a pacmannot pacman
The lock file itself is not damage. It is a note saying a transaction was in progress.

The database lock is the file /var/lib/pacman/db.lck, which exists only while a pacman transaction is in progress, so that two pacman processes cannot write the local database at the same time.

Two processes installing at once would each be rewriting the record of which files belong to which package. Refusing to start is pacman protecting the database, not a bug to work around.

Work through it in this order

  1. Check whether pacman is actually running. If it is, the answer is to wait: a large upgrade can spend a long time downloading before it prints anything new.
    not pacmanpgrep -a pacman

    pgrep comes from procps-ng, not from pacman. Output means a pacman process exists; no output means none does.

  2. Look for something else that runs pacman. A graphical package manager, an update applet or a scheduled job holds the same lock while it works, and it may not be visible on screen.
  3. Only when nothing is running, remove the file. At that point the lock is left over from a process that no longer exists, and deleting it is the documented way forward.
    not pacmansudo rm /var/lib/pacman/db.lck

    rm is not pacman, so the explainer has no level for it. Deleting the file while a transaction is genuinely in progress lets a second pacman write the database at the same time as the first. Read the callout below before running it.

Do not start with the deletion. The order above exists because the two causes look identical from the error message, and only one of them is safe to clear.

If it keeps coming back

A lock that reappears every time means something is starting pacman that you are not. The database consistency check is the place to start, since it reads the local database and reports rather than changing anything:

routinepacman -Dk

Checks the local database for consistency. Read-only.

If the interrupted transaction was an upgrade, re-running the upgrade is the normal next step: pacman works out what was already done. See updating Arch Linux.

Common questions

What does unable to lock database mean?

It means /var/lib/pacman/db.lck exists. pacman creates that file while a transaction runs and removes it at the end, so either a pacman is running now or a previous one did not exit cleanly.

Is it safe to delete db.lck?

Only once you have checked that no pacman process is running. If one is, deleting the lock lets a second pacman write the same database at the same time, which is exactly what the lock exists to prevent.

Why does the lock file keep coming back?

Because something is starting pacman that you did not start by hand, such as a graphical package manager or a scheduled update job. Those hold the same lock while they work.

How to check this page

Two commands on your own machine: pacman -<operation> --help lists the modifiers that operation accepts, and man pacman opens the pacman(8) manual page these descriptions are written from. Where the descriptions come from, and what this site is not, is set out on the about page.

This page was last edited on .