✦ For everyone, free.

Practical knowledge for real and everyday life

Home

Local and Sync Databases

Local and sync databases manage system packages efficiently, ensuring consistency across devices while maintaining local control and real-time updates.

Local and Sync Databases are integral components of the Pacman package management system used in Arch Linux and its derivatives. They serve as structured repositories of metadata that track the state of installed packages locally and synchronize with remote repositories to maintain up-to-date package information. These databases enable Pacman to efficiently manage package installations, upgrades, removals, and dependency resolutions.


Definition and Purpose

Local and Sync Databases store essential information about packages, their versions, dependencies, file lists, and other metadata. The Local Database contains details about all packages currently installed on the system, whereas the Sync Database (or remote database) holds information about packages available in configured remote repositories. By comparing these databases, Pacman determines which packages need to be installed, updated, or removed to ensure system consistency.


Local Database

Structure and Storage

The Local Database is a binary database file located in /var/lib/pacman/local/. Each installed package has a dedicated directory named after its package name and version, containing files that describe the package’s metadata such as:

  • desc — textual description, version, architecture, packager, dependencies, and installation date.
  • files — a list of all files installed by the package, including their paths.
  • mtree — filesystem metadata for the package files (used for integrity checks).
  • scripts — optional installation, upgrade, or removal scripts.

This organization allows Pacman to quickly query package information without scanning the entire filesystem.

Role in Package Management

The Local Database tracks the precise state of all installed packages, including their version numbers and file contents. It enables Pacman to:

  • Verify if a package is installed and which version.
  • Detect conflicts or missing dependencies.
  • Perform upgrades by comparing local versions to those in sync databases.
  • Safely remove packages while tracking owned files.

The database is updated automatically during package installation, removal, or upgrade operations.


Sync Database

Structure and Storage

Sync Databases are copies of remote repository metadata downloaded and stored locally, typically in /var/lib/pacman/sync/. Each configured repository has its own database file named after the repository (e.g., core.db, extra.db). These files contain compressed and indexed metadata about all packages available in that repository:

  • Package names and versions.
  • Descriptions and dependencies.
  • Checksums and file size information.
  • Repository signatures for verification.

Synchronization and Updates

Pacman updates Sync Databases by fetching these metadata files from remote servers using the pacman -Sy command or during full system upgrades with pacman -Syu. This synchronization ensures that the package manager has the latest information on available packages and versions.

The Sync Database allows Pacman to:

  • Compare available package versions with those installed locally.
  • Resolve dependencies based on the latest repository data.
  • Download and install the correct package files from repository mirrors.
  • Verify package integrity and authenticity using cryptographic signatures.

Interaction Between Local and Sync Databases

Pacman relies on the comparison between the Local and Sync Databases to determine necessary actions:

  • Upgrade: When the Sync Database contains a newer version of a package than the Local Database, Pacman marks it for upgrade.
  • Installation: If a package is listed in the Sync Database but absent locally, it can be installed.
  • Removal: Packages present locally but no longer needed can be safely removed.
  • Dependency Resolution: Pacman uses repository metadata to ensure all dependencies for a package are satisfied before installation or upgrade.

This interaction ensures consistency, security, and reliability in package management.


Integrity and Security

Both databases incorporate integrity checks and security mechanisms:

  • Sync Databases are signed with PGP keys to prevent tampering during transmission.
  • Pacman verifies signatures before accepting updates to Sync Databases.
  • Package files listed in the databases include checksums for verification after download.
  • The Local Database tracks installed file hashes and permissions to detect file corruption or unauthorized modifications.

These features protect the system against corrupted or malicious packages.


Maintenance and Troubleshooting

Occasionally, the Local or Sync Databases may become corrupted or desynchronized due to interrupted operations or manual file changes. Pacman provides commands to:

  • Refresh Sync Databases (pacman -Sy).
  • Force database refresh and reinstallation of packages to fix inconsistencies.
  • Remove stale or orphaned entries from the Local Database using tools like pacman -Qdt or external utilities.

Proper maintenance of these databases ensures smooth and predictable package management operations.


Summary of Key Locations and Files

DatabaseLocationDescription
Local Database/var/lib/pacman/local/Metadata about installed packages
Sync Database/var/lib/pacman/sync/Remote repository metadata for available packages

By managing the Local and Sync Databases effectively, Pacman achieves precise control over package states, dependencies, and system integrity, ensuring reliable software management on Arch Linux systems.