-- ----------------------------------------------------------------------
-- Function: pgq.current_event_table(1)
--
--- Return active event table for particular queue.
+-- Return active event table for particular queue.
+-- Event can be added to it without going via functions,
+-- e.g. by COPY.
--
-- Note:
--- The result is valid only during current transaction.
+-- The result is valid only during current transaction.
+--
+-- Permissions:
+-- Actual insertion requires superuser access.
--
-- Parameters:
--- x_queue_name - Queue name.
+-- x_queue_name - Queue name.
-- ----------------------------------------------------------------------
declare
res text;
-- Should be called in loop, with some delay until last tick
-- changes or too much time is passed.
--
--- Such function is needed because paraller calls o ticker() are
+-- Such function is needed because paraller calls of pgq.ticker() are
-- dangerous, and cannot be protected with locks as snapshot
--- is taken before.
+-- is taken before locking.
--
-- Parameters:
-- i_queue_name - Name of the queue
-- nothing
-- ----------------------------------------------------------------------
declare
- q record;
- i integer;
+ q record;
+ i integer;
+ tbl_perms text;
+ seq_perms text;
begin
select * from pgq.queue into q
where queue_name = x_queue_name;
if not found then
raise exception 'Queue not found';
end if;
- execute 'grant select, update on '
- || q.queue_event_seq || ',' || q.queue_tick_seq
- || ' to public';
- execute 'grant select on '
- || q.queue_data_pfx
- || ' to public';
+
+ if true then
+ -- safe, all access must go via functions
+ seq_perms := 'select';
+ tbl_perms := 'select';
+ else
+ -- allow ordinery users to directly insert
+ -- to event tables. dangerous.
+ seq_perms := 'select, update';
+ tbl_perms := 'select, insert';
+ end if;
+
+ -- tick seq, normal users don't need to modify it
+ execute 'grant ' || seq_perms
+ || ' on ' || q.queue_tick_seq || ' to public';
+
+ -- event seq
+ execute 'grant ' || seq_perms
+ || ' on ' || q.queue_event_seq || ' to public';
+
+ -- parent table for events
+ execute 'grant select on ' || q.queue_data_pfx || ' to public';
+
+ -- real event tables
for i in 0 .. q.queue_ntables - 1 loop
- execute 'grant select, insert on '
- || q.queue_data_pfx || '_' || i
+ execute 'grant ' || tbl_perms
+ || ' on ' || q.queue_data_pfx || '_' || i
|| ' to public';
end loop;
+
return 1;
end;
$$ language plpgsql security definer;
begin
return pgq.insert_event(queue_name, ev_type, ev_data, null, null, null, null);
end;
-$$ language plpgsql; -- event inserting needs no special perms
+$$ language plpgsql security definer;
return pgq.insert_event_raw(queue_name, null, now(), null, null,
ev_type, ev_data, ev_extra1, ev_extra2, ev_extra3, ev_extra4);
end;
-$$ language plpgsql; -- event inserting needs no special perms
+$$ language plpgsql security definer;
begin
return pgq.register_consumer(x_queue_name, x_consumer_id, NULL);
end;
-$$ language plpgsql; -- no perms needed
+$$ language plpgsql security definer;
create or replace function pgq.register_consumer(