Skip to content

Commit d4e2016

Browse files
joe-alewinedenyeart
authored andcommitted
[FAB-13161] Tips and tricks for couchdb
Change-Id: I16a1cbff60637f1f610463a84f04514f614ac94c Signed-off-by: joe-alewine <Joe.Alewine@ibm.com>
1 parent 76b7d9c commit d4e2016

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

docs/source/couchdb_as_state_database.rst

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ index is getting initialized. During transaction processing, the indexes will au
137137
as blocks are committed to the ledger.
138138

139139
CouchDB Configuration
140-
----------------------
140+
---------------------
141141

142142
CouchDB is enabled as the state database by changing the ``stateDatabase`` configuration option from
143143
goleveldb to CouchDB. Additionally, the ``couchDBAddress`` needs to configured to point to the
@@ -212,5 +212,35 @@ is to be changed after creation of the container.
212212

213213
.. note:: CouchDB peer options are read on each peer startup.
214214

215+
Good practices for queries
216+
--------------------------
217+
218+
Avoid using chaincode for queries that will result in a scan of the entire
219+
CouchDB database. Full length database scans will result in long response
220+
times and will degrade the performance of your network. You can take some of
221+
the following steps to avoid long queries:
222+
223+
- When using JSON queries:
224+
225+
* Be sure to create indexes in the chaincode package.
226+
* Avoid query operators such as ``$or``, ``$in`` and ``$regex``, which lead
227+
to full database scans.
228+
229+
- For range queries, composite key queries, and JSON queries:
230+
231+
* Utilize paging support (as of v1.3) instead of one large result set.
232+
233+
- If you want to build a dashboard or collect aggregate data as part of your
234+
application, you can query an off-chain database that replicates the data
235+
from your blockchain network. This will allow you to query and analyze the
236+
blockchain data in a data store optimized for your needs, without degrading
237+
the performance of your network or disrupting transactions. To achieve this,
238+
applications may use block or chaincode events to write transaction data
239+
to an off-chain database or analytics engine. For each block received, the block
240+
listener application would iterate through the block transactions and build a
241+
data store using the key/value writes from each valid transaction's ``rwset``.
242+
The :doc:`peer_event_services` provide replayable events to ensure the
243+
integrity of downstream data stores.
244+
215245
.. Licensed under Creative Commons Attribution 4.0 International License
216-
https://creativecommons.org/licenses/by/4.0/
246+
https://creativecommons.org/licenses/by/4.0/

0 commit comments

Comments
 (0)