From 2a835e0c024eca63bf06b36a34a44a702c07c7ef Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Sun, 6 Sep 2020 13:31:36 +0200 Subject: [PATCH] Limit notification payload sizes to 8 Kb --- etc/db/database-template.sql | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/etc/db/database-template.sql b/etc/db/database-template.sql index f9230c2..7cec03c 100644 --- a/etc/db/database-template.sql +++ b/etc/db/database-template.sql @@ -153,15 +153,23 @@ CREATE FUNCTION public.notify() RETURNS trigger AS $$ DECLARE channel text := TG_ARGV[0]; +payload text; BEGIN -PERFORM pg_notify(channel, json_build_object( +payload := json_build_object( 'tstamp', CURRENT_TIMESTAMP, 'operation', TG_OP, 'schema', TG_TABLE_SCHEMA, 'table', TG_TABLE_NAME, 'old', row_to_json(OLD), 'new', row_to_json(NEW) -)::text); +)::text; + +IF octet_length(payload) < 8000 THEN +PERFORM pg_notify(channel, payload); +ELSE +-- We need to find another solution +RAISE INFO 'Payload over limit'; +END IF; RETURN NULL; END; $$; @@ -193,7 +201,8 @@ SET default_table_access_method = heap; CREATE TABLE public.projects ( pid text NOT NULL, name text NOT NULL, - schema text NOT NULL + schema text NOT NULL, + meta jsonb DEFAULT '{}'::jsonb NOT NULL );