How to solve the "unable to lock database" or "failed to synchronize any databases" errors

The "unable to lock database" or "failed to synchronize any databases" errors occur when your package manager thinks that there's already another instance of your package manager running on your computer.

Quite often this is actually not the case and the error is in fact just an error. And it can be fixed quite easily by deleting the database lock file.

To do this, open a terminal and execcute the following command:

sudo rm /var/lib/pacman/db.lck

That's it.

27 Likes

The best solve to prevent that this warning appears is not to use pamac-daemon. Existing of lock file may inform other instance of pacman / yaourt that package database is in use. Modyfing it by 2 or more instances of package manager at the time may corrupt it ...

@Heart-Of-A-Lion, these tutorials you have been writing are just fantastic and I appreciate them so much, being new to Linux and Manjaro as I am. I really hope that these find their way into the new wiki when that is set up.

Anyway, I just wanted to thank you sincerely for your generosity in sharing your knowledge and the time it takes to write all these. So, Thanks. :green_heart:

1 Like

Thank you Persephone. :slight_smile:

1 Like

This command turns permission error and dont remove target file. In this situation open file manager with root permission.You can this via terminal
sudo thunar -->Go to file system/var/lib/pacman
if there is a file db.lck remove this
or right click desktop choose 'thunar root' then go to .....

here is a list of other common errors and their fixes, which might occur (taken from pacli-simple ):

  •        "sudo rm -f /var/lib/pacman/db.lck" 
          This command removes Pacman's database lock. The database lock prevents multiple Pacman instances from running at the same time and interfering with each other.
          ATTENTION: Only run this command when no other Pacman instance (e.g. Pacman, Yaourt, Pamac, Octopi, PacmanXG4, ...) is running.
    
  •        "sudo pacman-mirrors -g && sudo pacman -Syy"
          This command searches for working and good Manjaro repository mirrors/servers. It will automatically choose the closest server for you. The second command forces a redownload of the latest package database from the best Manjaro repository mirror. 
    
  •        "sudo dirmngr </dev/null"
          Sometimes during key management the package "dirmngr" outputs error messages, which interrupt key management processes (such as the following commands). This command prevents any output from "dirmngr".
    
  •        "sudo rm -r /etc/pacman.d/gnupg &>/dev/null"
          This command deletes your Pacman, Manjaro, and Arch key database. It does not output an error in case the package "gnupg" is not installed on your system.
          ATTENTION: This command will remove all keys from your system, including manually installed keys (with "sudo pacman-key --lsign-key <KEY>"). Please remember to reinstall those keys again after FIX ERRORS has completed!
    
  •        "sudo pacman -Sy gnupg archlinux-keyring manjaro-keyring"
          This command (re-)installs the "gnupg" package and keyrings for Arch Linux and Manjaro. Pacli actually does not use this command but instead downloads and installs these packages manually. This makes it possible to install these packages even if no other packages can be installed on your system due to key database errors.
          ATTENTION: If you want to execute this command on a system with key database problems, it will not work for you! In this case, connect manually (via your browser) to your Manjaro repository server, download these packages, and install these packages manually. Pacli will do all of this automatically for you. If this part of Pacli fails, please wait a couple of hours until your Manjaro mirror has synchronized with the main Manjaro repository and offers the latest version of these 3 packages: gnupg, archlinux-keyring, manjaro-keyring.
    
  •        "sudo pacman-key --init && sudo pacman-key --populate archlinux manjaro"
          These two commands create a fresh key for you and (re-)install all keys from Arch Linux and Manjaro. This will solve problems with your local key database and Manjaro's and Arch's key database. Such problems can occur when new new Arch Linux or Manjaro packagers get added, for example.
          ATTENTION: This command only works, when your system time is set correctly, becasue checking and importing keys or fingerprints is time sensitive! Please make sure of that before you run FIX ERRORS. If you have not set your timezone and/or summer saving time, you should still be able to import keys, though.
          ATTENTION: This command might take a long time to complete. If your system appears to stop or hang, it searches for entropy in order to generate a new key for you. In this case, it might help to do file operations with a lot of reads and/or writes per minute (such as searching for files, copying large directories, etc.). Alternatively, you can open a browser and do some heavy surfing (with a lot of mouse movements, mouse klicks, and keyboard key presses): This can help to generate entropy much faster.
    
  •        "sudo pacman -Sc"
          After an unseccessful attempt to update your system (which quit with a key error), you might have already downloaded unsigned packages to your pacman cache. These packages cannot be installed anymore.
          This command removes all packages from your pacman cache, which are not installed on your system. Afterwards, you need to download all previously downloaded but unsuccessfully installed packages again.
          ATTENTION: This command makes it impossible to DOWNGRADE PACKAGES on systems without an active internet connection.
    
  •        "sudo pacman -Syyuu"
          This last command forces a redownload of the latest package database from the best Manjaro repository mirror. Then, all your installed packages are checked against this latest package database. If an updated package is available from the Manjaro repositories, it will get downloaded and installed on your system. If an installed package is newer than the same package in the Manjaro repositories, the installed package will get downgraded. This behavior ensures your packages are always in sync with the Manajro repositories, even if you have just switched the Manjaro mirror or switched from unstable to stable branch.
5 Likes

Forum kindly sponsored by