In detail
Tested: the example runs with nhydb 0.28.2 from PyPI.
Three files belong together
| File |
Content |
Note |
X.nhydb |
data |
not encrypted |
X.nhydb.layout.enc |
layout plan: realms, record shapes, layouts, indexes, MATH |
encrypted |
X.nhydb.layout.key |
32-byte key of the layout plan |
without it the database will not open |
X.nhydb.lock |
lock file, empty |
may be deleted while the database is closed |
limiter.txt |
statistics of the memory limiter |
one JSON line every 30 minutes |
Keeping the key elsewhere: give key_path= (and optionally layout_path=) when creating and on every opening, or as a path template in [paths] of the configuration. On Unix the key file is created with permissions 0600; if they are wider, opening warns. On Windows it inherits the permissions of its folder – put it in a folder that only you can access.
Encrypted layout plan
AES-256-GCM and HMAC-SHA256. The plan is bound to the data file; opening fails (fail closed) if file, plan and key do not match. The file name is also part of the identity: a renamed .nhydb does not open, not even with changed upper/lower case.
Limits: NHyDB is not a security product. Only the layout plan is encrypted. While a database is open, key material is in the working memory of the process, and not every internal copy is guaranteed to be erased.
One writer, many readers
- Every opening for writing takes the exclusive lock
<db>.lock, even within the same process; otherwise DatabaseLockedError. lock_timeout_ms waits instead.
readonly=True: no lock, no change to the file, write calls raise NHyDBError. The reader sees the committed state at opening; for a newer state you open again.
lock=False switches the lock off – only if no other process can open the database at the same time. The lock file does not follow a symbolic link.
- There are no transactions across several processes.
Limits for size and memory
- Database size:
[database] db_max_size_bytes for new databases (default 50 GiB, at least 64 KiB), later set_max_db_size(...). When exceeded: DatabaseSizeLimitError.
- Result size:
[query] max_result_bytes (default 4 GiB, 0 = off) for calls that return their whole result at once; otherwise QueryLimitError. Large results can be fetched step by step, see Queries.
- Memory limiter (
[limiter]): one per process. It measures the memory of the whole process, empties caches when memory runs short, makes new large operations wait and, as a last resort, aborts the only one still growing (ResourceLimitError; a write call is rolled back completely). Single operations are not affected. nhydb.resource_status() shows the state, nhydb.cancel_job(id) aborts an operation. It protects on a best-effort basis and does not promise a fixed limit; it does not protect other processes on the computer.
Configuration: nhydb_config.toml is searched in this order: argument config=, environment variable NHYDB_CONFIG, file next to the database, built-in defaults. Explicit arguments take precedence; unknown keys are errors. Example configuration
Backing up, cleaning up, moving
NHyDB.compact_file(path, output=None, make_backup=True) needs a closed database.
- Without
output: replaces the file in place and first creates a backup <db>.before_compact_<time> including the layout plan.
- With
output=: writes a new database with its own companion files – this is how a copy under a new name is created.
- If compaction fails, the source stays unchanged. Working memory depends on the batch size, not on the database size; you need disk space for the new file and the backup.
A backup copy on write-protected media can be opened with readonly=True.
Older files: databases from NHyDB 0.28.0 or earlier do not open with 0.28.2 (CorruptionError, the file stays unchanged); there is no migration path. More under Limits and status.
nhydb stats warehouse.nhydb
nhydb health warehouse.nhydb --deep
nhydb verify warehouse.nhydb
nhydb to-n --realm 1 --u 11 --v 13 --lane NR
Further commands: from-n, get, cell, find, describe, layout-check, rebuild-indexes, repair (report only, unless with --apply), restore, compact and others; --help shows all of them, --json gives machine-readable output. Exit codes: 0 success, 1 a check found problems, 2 usage error or rejected operation, 3 error.
Read more: Python Cookbook, chapter 19 “Configuration and limits” · chapter 21 “Database files, backup, restore and moving” · chapter 22 “Errors, locks and concurrent access” · chapter 24 “Command line” · Technical documentation, section 15.6
# In detail **Tested:** the example runs with nhydb 0.28.2 from PyPI. ## Three files belong together | File | Content | Note ||---|---|---|| `X.nhydb` | data | not encrypted || `X.nhydb.layout.enc` | layout plan: realms, record shapes, layouts, indexes, MATH | encrypted || `X.nhydb.layout.key` | 32-byte key of the layout plan | without it the database will not open || `X.nhydb.lock` | lock file, empty | may be deleted while the database is closed || `limiter.txt` | statistics of the memory limiter | one JSON line every 30 minutes | **Keeping the key elsewhere:** give `key_path=` (and optionally `layout_path=`) when creating and on every opening, or as a path template in `[paths]` of the configuration. On Unix the key file is created with permissions `0600`; if they are wider, opening warns. On Windows it inherits the permissions of its folder – put it in a folder that only you can access. ## Encrypted layout plan AES-256-GCM and HMAC-SHA256. The plan is bound to the data file; opening fails (fail closed) if file, plan and key do not match. The file name is also part of the identity: a renamed `.nhydb` does not open, not even with changed upper/lower case. **Limits:** NHyDB is not a security product. Only the layout plan is encrypted. While a database is open, key material is in the working memory of the process, and not every internal copy is guaranteed to be erased. ## One writer, many readers - Every opening for writing takes the exclusive lock `<db>.lock`, even within the same process; otherwise `DatabaseLockedError`. `lock_timeout_ms` waits instead.- `readonly=True`: no lock, no change to the file, write calls raise `NHyDBError`. The reader sees the committed state at opening; for a newer state you open again.- `lock=False` switches the lock off – only if no other process can open the database at the same time. The lock file does not follow a symbolic link.- There are no transactions across several processes. ## Limits for size and memory - **Database size:** `[database] db_max_size_bytes` for new databases (default 50 GiB, at least 64 KiB), later `set_max_db_size(...)`. When exceeded: `DatabaseSizeLimitError`.- **Result size:** `[query] max_result_bytes` (default 4 GiB, 0 = off) for calls that return their whole result at once; otherwise `QueryLimitError`. Large results can be fetched step by step, see [Queries](/en/queries/).- **Memory limiter (`[limiter]`):** one per process. It measures the memory of the whole process, empties caches when memory runs short, makes new large operations wait and, as a last resort, aborts the only one still growing (`ResourceLimitError`; a write call is rolled back completely). Single operations are not affected. `nhydb.resource_status()` shows the state, `nhydb.cancel_job(id)` aborts an operation. It protects on a best-effort basis and does not promise a fixed limit; it does not protect other processes on the computer. **Configuration:** `nhydb_config.toml` is searched in this order: argument `config=`, environment variable `NHYDB_CONFIG`, file next to the database, built-in defaults. Explicit arguments take precedence; unknown keys are errors. [Example configuration](https://github.com/nhydb-run4/NHyDB/blob/main/config/nhydb_config.example.toml) ## Backing up, cleaning up, moving `NHyDB.compact_file(path, output=None, make_backup=True)` needs a closed database. - **Without `output`:** replaces the file in place and first creates a backup `<db>.before_compact_<time>` including the layout plan.- **With `output=`:** writes a new database with its own companion files – this is how a copy under a new name is created.- If compaction fails, the source stays unchanged. Working memory depends on the batch size, not on the database size; you need disk space for the new file and the backup. A backup copy on write-protected media can be opened with `readonly=True`. **Older files:** databases from NHyDB 0.28.0 or earlier do not open with 0.28.2 (`CorruptionError`, the file stays unchanged); there is no migration path. More under [Limits and status](/en/limits-and-status/). ## Tools for operation ```bashnhydb stats warehouse.nhydbnhydb health warehouse.nhydb --deepnhydb verify warehouse.nhydbnhydb to-n --realm 1 --u 11 --v 13 --lane NR``` Further commands: `from-n`, `get`, `cell`, `find`, `describe`, `layout-check`, `rebuild-indexes`, `repair` (report only, unless with `--apply`), `restore`, `compact` and others; `--help` shows all of them, `--json` gives machine-readable output. Exit codes: `0` success, `1` a check found problems, `2` usage error or rejected operation, `3` error. **Read more:** Python Cookbook, [chapter 19 “Configuration and limits”](https://github.com/nhydb-run4/NHyDB/blob/main/docs/cookbook/PYTHON_COOKBOOK.md#19-configuration-and-limits) · [chapter 21 “Database files, backup, restore and moving”](https://github.com/nhydb-run4/NHyDB/blob/main/docs/cookbook/PYTHON_COOKBOOK.md#21-database-files-backup-restore-and-moving) · [chapter 22 “Errors, locks and concurrent access”](https://github.com/nhydb-run4/NHyDB/blob/main/docs/cookbook/PYTHON_COOKBOOK.md#22-errors-locks-and-concurrent-access) · [chapter 24 “Command line”](https://github.com/nhydb-run4/NHyDB/blob/main/docs/cookbook/PYTHON_COOKBOOK.md#24-command-line) · [Technical documentation, section 15.6](https://github.com/nhydb-run4/NHyDB/blob/main/docs/en/NHyDB_Technical_Documentation.md#156-safety-mechanisms-and-their-limits)