Topics
Database administration
Because Newt DB stores its data in PostgreSQL, you will want to become familiar with PostgreSQL database administration. You can forego much of this if you use a hosted PostgreSQL server, especially for production deployments.
Installing PostgreSQL
If you decide to install PostgreSQL, consider one of the binary distributions, which can make installation and simple operation very easy. Another option is to use Docker images, which have self contained PostgreSQL installations. Simple binary installations are a good choice for development environments.
Packing
In addition to administration of the underlying PostgreSQL database, Newt DB databases need to be packed periodically. Packing performs two functions.
- For history preserving databases, packing removes records that are no longer current and were written before the pack time.
- Packing detects and removes garbage object records. Garbage objects are objects that are no longer reachable from the database root object. When you remove an object from a container, making it unreachable, it is not deleted right away. It is removed the next time the database is garbage collected.
The zodbpack command
When you install Newt DB with pip, a zodbpack script is also installed:
pip install newt.dbThis is a command line script used to pack a database, typically through some sort of scheduled process such as a cron job. The basic usage is:
zodbpack -d 1 CONFIG_FILEThe -d option specifies the number of days in the past to pack to. The default is to pack 0 days in the past. CONFIG_FILE is the path to a Newt configuration file. For more information, read the zodbpack documentation.
History preserving databases. They allow time travel to times and undo of transactions written before the pack time. They are slower and require more frequent packing than history free databases. This is why Newt DB makes history free databases its default configuration.
Two practical notes
If you use another tool, you may have to make sure the scripts from the RelStorage package are installed. For example, Buildout will not install RelStorage scripts unless RelStorage is explicitly listed. The RelStorage documentation covers the script packaging.
You may want to pack to a day in the past rather than 0 days, to guard against an application bug in which an object is removed from a container in one transaction and added to another container in a separate transaction. In that case the object is temporarily garbage, and if you are unlucky it could be collected while it is temporarily garbage.