[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: direct MDB access for counting entries from Python



On 1/17/20 3:09 AM, Howard Chu wrote:
> Michael Ströder wrote:
>> Is it easily possible to access the id2e sub-DB and query number of entries?
>>
>> Something like
>>
>> mdb_stat -s id2e -e <db-path> | grep Entries
>>
>> but from Python with python-lmdb or a similar module.
> 
> It's pretty trivial in py-lmdb.
> 
> ####
> import lmdb
> 
> env = lmdb.open('/tmp/test', max_dbs=2)
> with env.begin() as txn:
>   subdb = env.open_db('id2e', txn=txn, create=False)
>   print txn.stat(subdb)
> ####

Thanks Howard!

Just for the records: With Python3 one has to pass the name of the
sub-DB as byte-string.

subdb = env.open_db(b'id2e', txn=txn, create=False)

Changed slapdcheck:

https://gitlab.com/ae-dir/slapdcheck/commit/3c4757cbf8546c15ae33dd8de46c6e9b1b7978ff

Ciao, Michael.