# Getting Started with SWI-Prolog RocksDB on Windows 11

**URL:** <https://swi-prolog.discourse.group/t/getting-started-with-swi-prolog-rocksdb-on-windows-11/9453>\
**Category:** Wiki\
**Created:** [December 24, 2025, 5:31pm UTC](https://swi-prolog.discourse.group/t/getting-started-with-swi-prolog-rocksdb-on-windows-11/9453 "2025-12-24T17:31:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [December 24, 2025, 5:31pm UTC](https://swi-prolog.discourse.group/t/getting-started-with-swi-prolog-rocksdb-on-windows-11/9453/1 "2025-12-24T17:31:36Z")

</div>

> Note: Do not reply to this topic; questions, concerns, comments, etc. are to be handled in  
> [Wiki Discussion: Getting Started with SWI-Prolog RocksDB on Windows 11](https://swi-prolog.discourse.group/t/wiki-discussion-getting-started-with-swi-prolog-rocksdb-on-windows-11/9454)

* * *

* * *

# Getting Started with SWI-Prolog RocksDB on Windows 11

December 24, 2025

A beginner’s guide to installing and using RocksDB with SWI-Prolog on Windows 11.

## What is This?

**RocksDB** is a high-performance database that stores information as key-value pairs. Think of it like a very fast filing cabinet where you can store and retrieve data.

**SWI-Prolog** is a programming language particularly good at working with logical rules and relationships.

**rocks-predicates** lets you store Prolog facts (like “John is a person” or “Paris is in France”) in RocksDB so they survive even after you close your program.

### Key Benefit: Not Limited by RAM

Unlike regular Prolog which keeps everything in RAM (memory), RocksDB stores data on your hard drive, SSD, or even USB flash drives. This means:

- **No RAM limits** : Store millions or billions of facts without running out of memory
- **Persistent storage** : Data survives computer restarts and power loss
- **Flexible storage** : Use fast SSDs for speed, or USB drives for portability
- **Trade-off** : Hard drive access is slower than RAM, but RocksDB is optimized to be very fast (queries in microseconds)

Think of it like the difference between keeping notes in your head (RAM) versus writing them in a notebook (disk). The notebook can hold far more information, though accessing it takes slightly longer.

## Why MSYS2?

Currently, RocksDB doesn’t work with native Windows SWI-Prolog. We need MSYS2, which provides a Linux-like environment on Windows where we can compile and run RocksDB.

## Prerequisites

- Windows 11 (this guide is specifically for Windows 11)
- About 2 GB of free disk space
- Administrator access to install software
- About 30-45 minutes of time

## Step 1: Install MSYS2

MSYS2 provides the environment we need to run RocksDB.

1. **Download MSYS2**

2. **Run the Installer**

3. **Update MSYS2**

## Step 2: Install Required Tools

Now we’ll install the tools needed to build RocksDB.

1. **Close the MSYS2 MSYS terminal if it’s open**

2. **Open MSYS2 MINGW64** (this is important - not the regular MSYS2)

3. **Install Git** (needed to download code)

4. **Install the C++ Compiler**

5. **Install RocksDB Library**

6. **Install SWI-Prolog for MSYS2**

7. **Verify SWI-Prolog Installed**

## Step 3: Build the RocksDB Interface

Now we need to build the connection between SWI-Prolog and RocksDB.

1. **Download the RocksDB Pack**

2. **Fix Compatibility Issues**

3. **Create Output Directory**

4. **Compile the Interface**

5. **Install to SWI-Prolog Pack Directory**

## Step 4: Test Basic RocksDB

Let’s verify RocksDB works!

1. **Start SWI-Prolog**

2. **Load RocksDB**

3. **Test Basic Operations**

4. **Exit SWI-Prolog**

## Step 5: Install rocks-predicates

This gives you a way to store Prolog facts persistently.

1. **Download rocks-predicates**

2. **Create Database Directory**

3. **Start SWI-Prolog**

4. **Load the Libraries**

5. **Test Storing Data**

## Common Commands Reference

### Opening a Database

```prolog
?- rdb_open('dbs/my_database', DB).

```

### Storing Facts

```prolog
?- rdb_assertz('dbs/my_database', parent(tom, bob)).
?- rdb_assertz('dbs/my_database', parent(bob, alice)).

```

### Querying Facts

```prolog
?- rdb_clause('dbs/my_database', parent(X, Y), Body).

```

This will show all parent relationships.

### Closing a Database

```prolog
?- rdb_close('dbs/my_database').

```

## Storing Databases on Different Drives

Since RocksDB stores data on disk (not in RAM), you can put databases anywhere:

### On Your Main Hard Drive

```prolog
?- rdb_open('C:/data/my_database', DB).

```

### On an External USB Drive

```prolog
?- rdb_open('E:/portable_data/my_database', DB).

```

### On a Network Drive

```prolog
?- rdb_open('Z:/shared/my_database', DB).

```

**Performance Tips:**

- **SSD drives** : Fastest option for frequent queries
- **Regular hard drives** : Slower but fine for occasional access
- **USB flash drives** : Portable but slowest; good for backups or moving data between computers
- **Network drives** : Convenient for sharing but speed depends on network connection

## Troubleshooting

### “bash: git: command not found”

**Solution:** Install git:

```bash
pacman -S git

```

### “cannot open output file lib/x64-win64/rocksdb4pl.dll”

**Solution:** Create the directory first:

```bash
mkdir -p lib/x64-win64

```

### “The specified module could not be found”

**Solution:** Make sure you copied the DLL to the pack directory:

```bash
mkdir -p ~/.local/share/swi-prolog/pack/rocksdb/lib/x64-win64
cp lib/x64-win64/rocksdb4pl.dll ~/.local/share/swi-prolog/pack/rocksdb/lib/x64-win64/

```

### Missing rocksdb4pl.dll when running rocks\_open

**Symptoms:**  
When running `rocks_open('test.db', DB, [])`, you get an error like:

```prolog
ERROR: Initialization goal raised exception:
ERROR: The specified module could not be found.
ERROR: Exported procedure rocksdb:rocks_open_/3 is not defined

```

**Cause:** The `rocksdb4pl.dll` file is missing from the expected location.

**How to verify the DLL location:**  
You can check where SWI-Prolog expects to find the DLL:

```prolog
?- absolute_file_name(foreign(rocksdb4pl), Path, [file_type(executable), access(exist)]).

```

This will show the expected path, typically:

```prolog
~/.local/share/swi-prolog/pack/rocksdb/lib/x64-win64/rocksdb4pl.dll

```

**Solution:**

1. Make sure you completed Step 3, substep 5 from the installation instructions:

2. Verify the DLL exists:

### “Unknown procedure: rdb\_open/2”

**Solution:** Make sure you loaded both libraries:

```prolog
?- use_module(library(rocksdb)).
?- consult('rocks_preds.pl').

```

### Wrong Terminal Type

Make sure you’re using **MSYS2 MINGW64** (purple/blue terminal), not “MSYS2 MSYS” (yellow terminal).

## What’s Next?

Now that you have RocksDB working, you can:

1. **Store large amounts of data** - RocksDB can handle millions of facts efficiently
2. **Persist data across sessions** - Unlike regular Prolog, your data survives when you close the program
3. **Index your data** - Use `rdb_index/3` to make queries faster on large datasets
4. **Use external storage** - Put databases on USB drives or network drives for portability

## Performance Examples

According to the rocks-predicates README (tested on AMD3950X with SSD):

| Dataset | Facts | Load Time | Query Time | Database Size |
| --- | --- | --- | --- | --- |
| WordNet 3.0 | 821,492 clauses | 11.7 sec | 10 microseconds | 99 MB |
| Geonames RDF | 123 million triples | 35 minutes | 30 microseconds | 5.2 GB |

**What this means:**

- You can store **millions of facts** without running out of RAM
- Queries are still **very fast** (microseconds)
- The data is **persistently saved** on disk

## Future: Native Windows Support

Currently, this setup requires MSYS2. There’s a potential path to native Windows support using **vcpkg** (Microsoft’s C++ package manager). This would eliminate the need for MSYS2 but requires modifying the rocksdb pack.

## Getting Help

If you encounter issues:

1. Check the Troubleshooting section above
2. Visit the SWI-Prolog Discourse: [https://swi-prolog.discourse.group/](https://swi-prolog.discourse.group/)
3. Check the rocksdb pack page: ["rocksdb" pack for SWI-Prolog](https://www.swi-prolog.org/pack/list?p=rocksdb)
4. Open an issue on GitHub: [GitHub - JanWielemaker/rocksdb: SWI-Prolog interface for RocksDB](https://github.com/JanWielemaker/rocksdb)

## Credits

- **RocksDB Pack** : Jan Wielemaker
- **rocks-predicates** : Jan Wielemaker
- **MSYS2 Integration** : mgondan - [Discourse forum](https://swi-prolog.discourse.group/u/mgondan1/summary) - [msys2](https://github.com/msys2/MINGW-packages/commits?author=mgondan)
- **This Guide** : Based on successful Windows 11 installation (December 2025)

## License

This guide is provided as-is for educational purposes. The software packages mentioned have their own licenses:

- RocksDB: GPL-2.0-only OR Apache-2.0
- SWI-Prolog: BSD-2-Clause
- MSYS2: Various open source licenses
