Install acdat and build a complete comment moderation and redaction pipeline in PostgreSQL in three minutes.
1. Install acdat
Install from Pigsty packages
CI covers PostgreSQL 14–18, and Pigsty ships packages for PostgreSQL 15–19 across Linux distributions. Check Downloads for OS and architecture availability.
pig repo add pgsql -u
pig ext add acdat
Or build from the release tag
Point PG_CONFIG to your target PostgreSQL installation:
git clone --branch v0.1.1 --depth 1 https://github.com/pgsty/acdat.git
cd acdat
make PG_CONFIG=pg_config
sudo make install PG_CONFIG=pg_config
2. Enable the extension
Connect to a UTF8 database as a superuser and create the extension. All functions and types live in the fixed acdat schema:
CREATEEXTENSIONIFNOTEXISTSacdat;
3. Build and run a moderation pipeline
Instead of scanning rows one keyword at a time, keep rules in a table, compile them into one acdat.machine, and run filtering, annotation, and redaction in a single pass.
Create a rule table and sample comments:
CREATETEMPTABLEmoderation_rules(pattern_idbigintPRIMARYKEY,patterntextNOTNULL,replacementtextNOTNULL,priorityintegerNOTNULLDEFAULT0,categorytextNOTNULL);INSERTINTOmoderation_rules(pattern_id,pattern,replacement,priority,category)VALUES(101,'insider tip','[BLOCKED]',10,'compliance'),(102,'guaranteed return','[BLOCKED]',10,'compliance'),(103,'DM on Telegram','[CONTACT]',5,'spam');CREATETEMPTABLEcomments(comment_idbigintPRIMARYKEY,bodytextNOTNULL);INSERTINTOcommentsVALUES(1,'DM on Telegram for a guaranteed return today'),(2,'PostgreSQL 18 release notes'),(3,'Never act on an insider tip');
Compile the rule table into a single acdat.machine:
comment_id | body
------------+----------------------------------------------
1 | DM on Telegram for a guaranteed return today
3 | Never act on an insider tip
Extract every match with its position and join back to your rule table for business labels:
comment_id | sanitized
------------+----------------------------------
1 | [CONTACT] for a [BLOCKED] today
2 | PostgreSQL 18 release notes
3 | Never act on an [BLOCKED]
Tip
Notice the scalar subquery (SELECT machine FROM compiled_dict) above. Writing the machine lookup as an uncorrelated subquery lets PostgreSQL load the automaton once in an InitPlan rather than re-reading it per row during parallel scans.
For one-off ad-hoc checks without a rule table, you can also compile an inline array directly:
SELECTacdat.contains('PostgreSQL timeout error',acdat.compile(ARRAY['timeout','deadlock']))ASmatched;-- t
Next steps
Examples and workflows — Explore overlap policies, log IOC extraction, managed dictionary publishing & rollback, binary matching, and cross-database export/import.
Performance and tuning — Benchmark charts, avoiding the 22x parallel-plan trap, and per-worker memory budgets.
Operations — Separate dictionary admin privileges, backups, and error troubleshooting.
Run the tagged end-to-end SQL script examples/demo.sql inside a single rolled-back psql transaction.