[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Re: direct MDB access for counting entries from Python
- To: Michael Ströder <michael@stroeder.com>, openldap-technical <openldap-technical@openldap.org>
- Subject: Re: direct MDB access for counting entries from Python
- From: Howard Chu <hyc@symas.com>
- Date: Fri, 17 Jan 2020 02:09:49 +0000
- Dkim-filter: OpenDKIM Filter v2.10.3 zmcc-2-mta-1.zmailcloud.com 115CFCF645
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=symas.com; s=37C7994C-28CA-11EA-A30F-68F90BB9D764; t=1579226992; bh=F9Y5/OH9wbzhEFFbx/WFhoT7aiIG+JuZjE96Vks41vg=; h=To:From:Message-ID:Date:MIME-Version; b=oDqIsp3uigEGAH7NkWlBmD79srji+U5TzPvYUiXkAG1lgy2TUzwZY7bfP7ND2hP7Q dvuho3rYsV9JjOYmzry3nxO1EQL5e6ilAm/9pX5D3GCWBjsUjK1qp6G45r/36H/DfU wuLaDTZMBeYdho9ToonbJ3Ji87cTAwflmra33Fu3Hz91L0lJZLN515lhhVHML36y73 Rm/rAlxf7L8p55cfm/0pSflKWdEf8eUYL8h4uvmMBYLZ/ZORSd6yKhLL6meKsKrdAP iQj2soF+dsQuN8UfGbQWGcyySH1mNW8K7pvoN2S52+kK0GtnAMm3rmsSQWRu1BUah7 oDsSQttQJ+EUA==
- In-reply-to: <df86e66c-c6f5-e16a-2c20-012d652fdff6@stroeder.com>
- References: <df86e66c-c6f5-e16a-2c20-012d652fdff6@stroeder.com>
- User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0 SeaMonkey/2.53
Michael Ströder wrote:
> HI!
>
> In my monitoring check I'd like to indicate how many entries are in a
> database.
>
> Currently I'm using the no-op search control without any filtering to
> count the entries which is obviously a huge waste of CPU and I/O
> ressources for just retrieving the raw number of DB entries.
>
> 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. (Yes, I know
> subprocess module but I really hate invoking command-line tools from
> Python.)
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)
####
--
-- Howard Chu
CTO, Symas Corp. http://www.symas.com
Director, Highland Sun http://highlandsun.com/hyc/
Chief Architect, OpenLDAP http://www.openldap.org/project/