Topics
Information for ZODB users
Newt DB builds on RelStorage and PostgreSQL, adding JSON conversion and search support. If you already run a ZODB application, most of what you know still applies.
What Newt DB adds
Newt DB provides some significant enhancements to ZODB applications:
- Access to data outside Python. Data are stored in a JSON representation that can be accessed by tools that are not written in Python.
- Fast, powerful search through PostgreSQL SQL and indexes.
- Fewer objects in the database. Because indexes are maintained in PostgreSQL rather than in the application, far fewer objects are stored in the database.
- Smaller writes. Database writes may be much smaller, again because indexing data structures do not have to be updated at the database level, and the likelihood of conflict errors is reduced.
Bringing an existing application across
It is easy to migrate existing applications to Newt DB. The standard RelStorage zodbconvert tool works with Newt DB. The ZODB documentation covers the object model that both systems share.
A future version of Newt DB will provide options for batch computation of JSON data, which will allow the conversion of existing PostgreSQL RelStorage databases in place.
Updating an existing PostgreSQL RelStorage application
There are two ways to add Newt DB to an existing PostgreSQL RelStorage ZODB application.
Route one: update the text configuration
Update your database text configuration to include a newt tag and optionally a newtdb tag. After all of your database clients have been updated and restarted, new database records will be written to the newt table.
You will need to run the Newt updater with the --compute-missing option to write newt records for your older data:
newt-updater --compute-missing CONNECTION_STRINGThis option requires PostgreSQL 9.5 or later. The asynchronous updater topic documents the other options.
Route two: run the updater asynchronously
Use the Newt DB updater to maintain Newt data asynchronously. This requires no change to your database setup, but it requires managing a separate process. Because updates are asynchronous, Newt JSON data may be slightly out of date at times.
Which route? Route one writes JSON in the application transaction and is simpler to reason about. Route two keeps writes fast and lets you add search gradually, at the cost of a second process to run and monitor.