How to fetch records with a number of consecutive associated records?
You can use ROW_NUMBER() or RANK() setting a partition by name and ordering by datetime.

Then fetch these rows with a row number >= 2.

create table books (id int, title text);
insert into books values (1, 'title1'), (2, 'title2');

create table events(id int, title_id int, name text, datetime timestamp);
insert into events values
(1, 1, 'event1', current_timestamp),
(2, 1, 'event1', current_timestamp - interval '30 minutes'),
(3, 2, 'event2', current_timestamp),
(4, 2, 'event2', current_timestamp - interval '5 minutes'),
(5, 2, 'event3', current_timestamp);

with x as
(
    select id, title_id, name, datetime,
           row_number() over (partition by name order by datetime) rn
    from   events 
    where  datetime &gt;= current_timestamp - interval '5 minutes'
)
select   max(rn) as id, name
from     x
where    rn &gt;= 2
group by name;

id | name  
-: | :-----
 2 | event2


dbfiddle here