<p>You may mix up block data with the UTXO set (unspent transaction outputs).
Bitcoin Core uses LevelDB for the later (the UTXO set).</p>

<p>Quick lookups for unspent transaction is important for performance.</p>

<p>The block data is a different things. If you have a non-pruned peer (normal full node mode), Core stores all block files so it can serve those blocks to other peers bootstrapping (and for chain reorganisations).</p>

<p>Those block files are not an API, use it with care. If you interested in parsing blocks, consider using the RPC or REST API.</p>

<p>The .blk files contain a bunch of blocks (raw network serialisation format). There is also a block index (a levelDB database) that contains the file offsets and the headers.</p>

<p>Learn more about the blocks format <a href="https://bitcoin.stackexchange.com/questions/48736/reading-transactions-from-blk-dat-files/48738">here</a> (or google).</p>

CC BY-SA 4.0
2018-12-01T23:10:53.537Z
So If I wanted to try implement storing blockchain on filesystem, how would you suggest doing it?

having file with indexes and each index would represent block location inside another file?
dtechlearn
CC BY-SA 4.0
2018-12-01T01:13:46.610Z
2018-12-01T01:13:46.610Z
Jonas Schnelli
<p>Libbitcoin db uses memory mapped files(mmap). No data is deleted, only appended, as all public data is validated first before transferred to the store. All valid tx are permanently stored (no tx are removed from unconfirmed set). Each db (tx, block, history etc) includes a hashtable which maps the key to the respective file offset in the db file.</p>

<p>As a memory mapped file is just a pointer from the application point of view, the actual IO is hidden and optimized by the OS. This is one reason for the high query performance of Libbitcoin Server. The specific application of storing/indexing Bitcoin public data allows for a high performance specialized store vs a generalized one optimized for journaling/recoverability and other guarantees not needed for public Bitcoin data.</p>

CC BY-SA 4.0
2018-12-01T07:24:24.580Z
2018-12-01T07:24:24.580Z
James C.
<p>Hi how is blockchain actually stored on disk? </p>

<p>I noticed bitcoin uses key store database level DB but what is the structure? </p>

<p><a href="https://github.com/bitcoin-core/leveldb-old/blob/bitcoin-fork/doc/table_format.txt" rel="nofollow noreferrer">https://github.com/bitcoin-core/leveldb-old/blob/bitcoin-fork/doc/table_format.txt</a></p>

<p>Here I don't get it... Does anyone has simple overview how it is stored? </p>

<p>I have also read this... but don't get it.
<a href="https://bitcoin.stackexchange.com/questions/28168/what-are-the-keys-used-in-the-blockchain-leveldb-ie-what-are-the-keyvalue-pair">What are the keys used in the blockchain levelDB (ie what are the key:value pairs)?</a></p>

<bitcoin-core><blockchain>
How is blockchain stored on disk?
dtechlearn
# How is blockchain stored on disk?

(Asked by: username_0 on 2018-12-01)

Hi how is blockchain actually stored on disk?

I noticed bitcoin uses key store database level DB but what is the structure?

<https://github.com/bitcoin-core/leveldb-old/blob/bitcoin-fork/doc/table_format.txt>

Here I don't get it... Does anyone has simple overview how it is stored?

I have also read this... but don't get it.
[What are the keys used in the blockchain levelDB (ie what are the key:value pairs)?](https://bitcoin.stackexchange.com/questions/28168/what-are-the-keys-used-in-the-blockchain-leveldb-ie-what-are-the-keyvalue-pair)

**Tags:** bitcoin-core, blockchain


---

## 2 answers

### Answer by username_1 on 2018-12-01. Score: 3

You may mix up block data with the UTXO set (unspent transaction outputs).
Bitcoin Core uses LevelDB for the later (the UTXO set).

Quick lookups for unspent transaction is important for performance.

The block data is a different things. If you have a non-pruned peer (normal full node mode), Core stores all block files so it can serve those blocks to other peers bootstrapping (and for chain reorganisations).

Those block files are not an API, use it with care. If you interested in parsing blocks, consider using the RPC or REST API.

The .blk files contain a bunch of blocks (raw network serialisation format). There is also a block index (a levelDB database) that contains the file offsets and the headers.

Learn more about the blocks format [here](https://bitcoin.stackexchange.com/questions/48736/reading-transactions-from-blk-dat-files/48738) (or google).

> **Comments:**
> **username_0**: So If I wanted to try implement storing blockchain on filesystem, how would you suggest doing it?  having file with indexes and each index would represent block location inside another file?  

---

### Answer by username_2 on 2018-12-01. Score: 0

Libbitcoin db uses memory mapped files(mmap). No data is deleted, only appended, as all public data is validated first before transferred to the store. All valid tx are permanently stored (no tx are removed from unconfirmed set). Each db (tx, block, history etc) includes a hashtable which maps the key to the respective file offset in the db file.

As a memory mapped file is just a pointer from the application point of view, the actual IO is hidden and optimized by the OS. This is one reason for the high query performance of Libbitcoin Server. The specific application of storing/indexing Bitcoin public data allows for a high performance specialized store vs a generalized one optimized for journaling/recoverability and other guarantees not needed for public Bitcoin data.


---

