Limit notification payload sizes to 8 Kb

This commit is contained in:
D. Berge
2020-09-06 13:31:36 +02:00
parent 9c20c4295f
commit 2a835e0c02

View File

@@ -153,15 +153,23 @@ CREATE FUNCTION public.notify() RETURNS trigger
AS $$ AS $$
DECLARE DECLARE
channel text := TG_ARGV[0]; channel text := TG_ARGV[0];
payload text;
BEGIN BEGIN
PERFORM pg_notify(channel, json_build_object( payload := json_build_object(
'tstamp', CURRENT_TIMESTAMP, 'tstamp', CURRENT_TIMESTAMP,
'operation', TG_OP, 'operation', TG_OP,
'schema', TG_TABLE_SCHEMA, 'schema', TG_TABLE_SCHEMA,
'table', TG_TABLE_NAME, 'table', TG_TABLE_NAME,
'old', row_to_json(OLD), 'old', row_to_json(OLD),
'new', row_to_json(NEW) '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; RETURN NULL;
END; END;
$$; $$;
@@ -193,7 +201,8 @@ SET default_table_access_method = heap;
CREATE TABLE public.projects ( CREATE TABLE public.projects (
pid text NOT NULL, pid text NOT NULL,
name text NOT NULL, name text NOT NULL,
schema text NOT NULL schema text NOT NULL,
meta jsonb DEFAULT '{}'::jsonb NOT NULL
); );