pg_snakeoil
The PostgreSQL Antivirus
Repository
credativ/pg_snakeoil
https://github.com/credativ/pg_snakeoil
Source
pg_snakeoil-1.4.tar.gz
pg_snakeoil-1.4.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_snakeoil | 1.4 | SEC | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 7380 | pg_snakeoil | No | Yes | Yes | No | No | Yes | - |
| Related | pg_crash pg_cheat_funcs pg_dirtyread pg_savior pg_surgery pageinspect pg_catcheck amcheck |
|---|
require clamV libs
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | MIXED | 1.4 | 1817161514 | pg_snakeoil | - |
| RPM | PIGSTY | 1.4 | 1817161514 | pg_snakeoil_$v | - |
| DEB | PGDG | 1.4 | 1817161514 | postgresql-$v-snakeoil | - |
Build
You can build the RPM packages for pg_snakeoil using pig build:
pig build pkg pg_snakeoil # build RPM packages
Install
You can install pg_snakeoil directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
pig repo add pgsql -u # Add repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install pg_snakeoil; # Install for current active PG version
pig ext install -y pg_snakeoil -v 18 # PG 18
pig ext install -y pg_snakeoil -v 17 # PG 17
pig ext install -y pg_snakeoil -v 16 # PG 16
pig ext install -y pg_snakeoil -v 15 # PG 15
pig ext install -y pg_snakeoil -v 14 # PG 14
dnf install -y pg_snakeoil_18 # PG 18
dnf install -y pg_snakeoil_17 # PG 17
dnf install -y pg_snakeoil_16 # PG 16
dnf install -y pg_snakeoil_15 # PG 15
dnf install -y pg_snakeoil_14 # PG 14
apt install -y postgresql-18-snakeoil # PG 18
apt install -y postgresql-17-snakeoil # PG 17
apt install -y postgresql-16-snakeoil # PG 16
apt install -y postgresql-15-snakeoil # PG 15
apt install -y postgresql-14-snakeoil # PG 14
Preload:
shared_preload_libraries = 'pg_snakeoil';
Usage
pg_snakeoil provides ClamAV virus scanning of data stored in PostgreSQL without interfering with normal database operations.
CREATE EXTENSION pg_snakeoil;
Functions
| Function | Returns | Description |
|---|---|---|
so_is_infected(text) | bool | Check if text data matches a virus signature |
so_is_infected(bytea) | bool | Check if bytea data matches a virus signature |
so_virus_name(text) | text | Return virus name if infected, empty string otherwise |
so_virus_name(bytea) | text | Return virus name if infected, NULL otherwise |
so_update_signatures() | bool | Reload virus signatures, true if changed |
Ad-hoc Scanning
SELECT so_is_infected('Not a virus!');
-- f
SELECT so_is_infected('X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*');
-- t
SELECT so_virus_name('X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*');
-- Eicar-Test-Signature
On-Access Protection with Domains
CREATE DOMAIN safe_text AS text CHECK (NOT so_is_infected(value));
CREATE TABLE t1 (safe safe_text);
INSERT INTO t1 VALUES ('This text is safe!');
-- INSERT
INSERT INTO t1 VALUES('X5O!P%@AP...');
-- NOTICE: Virus found: Eicar-Test-Signature
-- ERROR: value for domain safe_text violates check constraint "safe_text_check"
On-Access Protection with Triggers
CREATE OR REPLACE FUNCTION check_virus() RETURNS trigger AS $$
BEGIN
IF so_is_infected(NEW.content) THEN
RAISE EXCEPTION 'Virus detected: %', so_virus_name(NEW.content);
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER virus_check BEFORE INSERT OR UPDATE ON uploads
FOR EACH ROW EXECUTE FUNCTION check_virus();
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.