Postgres audit triggers for Django
Project description
Postgres audit database via triggers
This app sets up a postgres audit database via triggers. See https://wiki.postgresql.org/wiki/Audit_trigger_91plus and https://github.com/2ndQuadrant/audit-trigger/ for more information.
Installation
pip install postgres_audit_triggers
Usage
- Add the
postgres_audit_triggers
app toINSTALLED_APPS
before any apps that will be audited:
# settings.py
INSTALLED_APPS = {
'django.contrib.postgres',
'postgres_audit_triggers',
...
}
- Install the
postgres_audit_triggers
middleware:
# settings.py
MIDDLEWARE = [
...
'postgres_audit_triggers.middleware.AuditMiddleware',
]
This middleware will add metadata to the audit row. To send metadata, the client must send a
Postgres-Audit-Triggers-Meta
header in the request to your Django view. The data within
that header must be JSON serializable to a python dictionary.
-
Run migrations:
python manage.py migrate postgres_audit_triggers
-
Add
audit_trigger = True
to the Model Meta options of the models that will be audited:
# models.py
class MyAuditedModel(models.Model):
...
class Meta:
audit_trigger = True
...
- Make migrations:
python manage.py makemigrations
- Run migrations:
python manage.py migrate
Triggers introduce performance overhead. In certain cases, you may need to disable triggers while performing bulk operations. To turn off all triggers, a decorator is provided:
from postgres_audit_triggers.decorators import disable_triggers
@disable_triggers
def foo():
# auditing will not be triggered on any database operations performed here
Bar.objects.bulk_create(items)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file postgres-audit-triggers-1.2.0.tar.gz
.
File metadata
- Download URL: postgres-audit-triggers-1.2.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a07d220ad0374e7c47d7aa26f11e87696a1cd816f50eeb29c906dc6c3ad8d26d |
|
MD5 | eb255661410face53086cc3ffc8943ff |
|
BLAKE2b-256 | 15a1df10e4b22d7d202acf2e1664ea4f0a525d123b03a927951ba8aed6e2fb63 |