@@ -18,6 +18,10 @@ DROP FUNCTION pgautofailover.get_other_nodes(int);
1818DROP FUNCTION pgautofailover .get_other_nodes
1919 (integer ,pgautofailover .replication_state );
2020
21+ DROP FUNCTION pgautofailover .last_events (int );
22+ DROP FUNCTION pgautofailover .last_events (text ,int );
23+ DROP FUNCTION pgautofailover .last_events (text ,int ,int );
24+
2125DROP FUNCTION pgautofailover .current_state (text );
2226DROP FUNCTION pgautofailover .current_state (text ,int );
2327
@@ -158,6 +162,51 @@ INSERT INTO pgautofailover.node
158162 candidatepriority, replicationquorum, nodecluster
159163 FROM pgautofailover .node_upgrade_old ;
160164
165+
166+ ALTER TABLE pgautofailover .event
167+ RENAME TO event_upgrade_old;
168+
169+ CREATE TABLE pgautofailover .event
170+ (
171+ eventid bigint not null DEFAULT nextval(' pgautofailover.event_eventid_seq' ::regclass),
172+ eventtime timestamptz not null default now(),
173+ formationid text not null ,
174+ nodeid bigint not null ,
175+ groupid int not null ,
176+ nodename text not null ,
177+ nodehost text not null ,
178+ nodeport integer not null ,
179+ reportedstate pgautofailover .replication_state not null ,
180+ goalstate pgautofailover .replication_state not null ,
181+ reportedrepstate text ,
182+ reportedtli int not null default 1 check (reportedtli > 0 ),
183+ reportedlsn pg_lsn not null default ' 0/0' ,
184+ candidatepriority int ,
185+ replicationquorum bool,
186+ description text ,
187+
188+ PRIMARY KEY (eventid)
189+ );
190+
191+ ALTER SEQUENCE pgautofailover .event_eventid_seq
192+ OWNED BY pgautofailover .event .eventid;
193+
194+ INSERT INTO pgautofailover .event
195+ (
196+ eventid, eventtime, formationid, nodeid, groupid,
197+ nodename, nodehost, nodeport,
198+ reportedstate, goalstate, reportedrepstate,
199+ reportedtli, reportedlsn, candidatepriority, replicationquorum,
200+ description
201+ )
202+ SELECT eventid, eventtime, formationid, nodeid, groupid,
203+ nodename, nodehost, nodeport,
204+ reportedstate, goalstate, reportedrepstate,
205+ 1 as reportedtli, reportedlsn, candidatepriority, replicationquorum,
206+ description
207+ FROM pgautofailover .event_upgrade_old as event;
208+
209+ DROP TABLE pgautofailover .event_upgrade_old ;
161210DROP TABLE pgautofailover .node_upgrade_old ;
162211DROP TYPE pgautofailover .old_replication_state ;
163212
@@ -405,6 +454,91 @@ CREATE TRIGGER disable_secondary_check
405454 EXECUTE PROCEDURE pgautofailover .update_secondary_check ();
406455
407456
457+ CREATE FUNCTION pgautofailover .last_events
458+ (
459+ count int default 10
460+ )
461+ RETURNS SETOF pgautofailover .event LANGUAGE SQL STRICT
462+ AS $$
463+ with last_events as
464+ (
465+ select eventid, eventtime, formationid,
466+ nodeid, groupid, nodename, nodehost, nodeport,
467+ reportedstate, goalstate,
468+ reportedrepstate, reportedtli, reportedlsn,
469+ candidatepriority, replicationquorum, description
470+ from pgautofailover .event
471+ order by eventid desc
472+ limit count
473+ )
474+ select * from last_events order by eventtime, eventid;
475+ $$;
476+
477+ comment on function pgautofailover .last_events (int )
478+ is ' retrieve last COUNT events' ;
479+
480+ grant execute on function pgautofailover .last_events (int )
481+ to autoctl_node;
482+
483+ CREATE FUNCTION pgautofailover .last_events
484+ (
485+ formation_id text default ' default' ,
486+ count int default 10
487+ )
488+ RETURNS SETOF pgautofailover .event LANGUAGE SQL STRICT
489+ AS $$
490+ with last_events as
491+ (
492+ select eventid, eventtime, formationid,
493+ nodeid, groupid, nodename, nodehost, nodeport,
494+ reportedstate, goalstate,
495+ reportedrepstate, reportedtli, reportedlsn,
496+ candidatepriority, replicationquorum, description
497+ from pgautofailover .event
498+ where formationid = formation_id
499+ order by eventid desc
500+ limit count
501+ )
502+ select * from last_events order by eventtime, eventid;
503+ $$;
504+
505+ comment on function pgautofailover .last_events (text ,int )
506+ is ' retrieve last COUNT events for given formation' ;
507+
508+ grant execute on function pgautofailover .last_events (text ,int )
509+ to autoctl_node;
510+
511+ CREATE FUNCTION pgautofailover .last_events
512+ (
513+ formation_id text ,
514+ group_id int ,
515+ count int default 10
516+ )
517+ RETURNS SETOF pgautofailover .event LANGUAGE SQL STRICT
518+ AS $$
519+ with last_events as
520+ (
521+ select eventid, eventtime, formationid,
522+ nodeid, groupid, nodename, nodehost, nodeport,
523+ reportedstate, goalstate,
524+ reportedrepstate, reportedtli, reportedlsn,
525+ candidatepriority, replicationquorum, description
526+ from pgautofailover .event
527+ where formationid = formation_id
528+ and groupid = group_id
529+ order by eventid desc
530+ limit count
531+ )
532+ select * from last_events order by eventtime, eventid;
533+ $$;
534+
535+ comment on function pgautofailover .last_events (text ,int ,int )
536+ is ' retrieve last COUNT events for given formation and group' ;
537+
538+ grant execute on function pgautofailover .last_events (text ,int ,int )
539+ to autoctl_node;
540+
541+
408542CREATE FUNCTION pgautofailover .current_state
409543 (
410544 IN formation_id text default ' default' ,
0 commit comments