Hi, I am pretty confused by the rpm database in openSUSE. In Fedora, the rpm database file is /var/lib/rpm/rpmdb.sqlite, I can read this database file by sqlite module in python.
Using rpm python module can read database file in openSUSE. But I wonder that any other ways of read the specific rpm database file in openSUSE?
Fedora:
[ruby@fedora ~]$ file /var/lib/rpm/rpmdb.sqlite
/var/lib/rpm/rpmdb.sqlite: SQLite 3.x database, last written using SQLite version 3040000, writer version 2, read version 2, file counter 109, database pages 24635, 1st free page 436, free pages 27, cookie 0x31, schema 4, UTF-8, version-valid-for 109
openSUSE:
ruby@localhost:/var/lib/rpm> file /var/lib/rpm/Packages.db
/var/lib/rpm/Packages.db: data
simple Python example of using rpm module to read rpm database
import rpm
ts = rpm.TransactionSet()
rpmdb = ts.dbMatch()
for pkg in rpmdb:
print(f"name: {pkg['name']}")
Here on Leap 15.4, the RPM database is a Berkeley DB –
> file /var/lib/rpm/Packages
/var/lib/rpm/Packages: Berkeley DB (Hash, version 9, native byte-order)
> rpm --version
RPM version 4.14.3
>
Possibly, between the RPM version being used by Leap and, the newest RPM version being used by Tumbleweed, they changed the Database Engine – you’ll have to check the RPM Release Notes: <https://rpm.org/index.html>
BTW, > apropos RPM
will show you which RPM tools are available on your system.
“rpmqpack” is an interesting method of checking which RPM packages have been installed on your system …
But, in general, on openSUSE systems, most of the RPM Package Management is performed by the ZYpp System Management Library → the “zypper” CLI tool → or, the “YaST” graphical System Management interface …
thanks for your answer. In my openSUSE and Fedora machine, their rpm version both are 4.18.0, but they choose different database backend, sqlite for Fedora and ndb for openSUSE, which cheked by
rpm -E "%{_db_backend}"
openSUSE Tumbleweed:
ruby@localhost:~> rpm -E "%{_db_backend}"
ndb
ruby@localhost:/var/lib/rpm> cd /var/lib/rpm
ruby@localhost:/var/lib/rpm> file *
Index.db: data
Packages.db: data
ruby@localhost:/var/lib/rpm> rpm --version
RPM version 4.18.0
Fedora:
[ruby@fedora rpm]$ rpm -E "%{_db_backend}"
sqlite
[ruby@fedora ~]$ cd /var/lib/rpm
[ruby@fedora rpm]$ file *
rpmdb.sqlite: SQLite 3.x database, last written using SQLite version 3040000, writer version 2, read version 2, file counter 109, database pages 24635, 1st free page 436, free pages 27, cookie 0x31, schema 4, UTF-8, version-valid-for 109
rpmdb.sqlite-shm: data
rpmdb.sqlite-wal: empty
[ruby@fedora rpm]$ rpm --version
RPM version 4.18.0
I just want to do some simple programming with rpm in C/C++, but I find there are little tutorials about this. And the documentation on https://rpm.org and reading the source code may be not suitable for me, which I find it a little difficult now.
Then use librpm which provides also high-level access to RPM database, hiding the backend implementation. If you are going to read RPM database using low level format, you will effectively re-implement librpm.