Skip to content

Commit

Permalink
Fixes #3, fixes #4
Browse files Browse the repository at this point in the history
Adds tested replica telemetry readings from slaves
Adds wait event details reports
Bumps up version numbers for new release
  • Loading branch information
einhverfr committed Aug 30, 2017
1 parent 0716a13 commit 71f1ce1
Show file tree
Hide file tree
Showing 6 changed files with 588 additions and 19 deletions.
7 changes: 4 additions & 3 deletions META.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pgtelemetry",
"abstract": "Useful monitoring and metrics views for PostgreSQL",
"version": "0.2.0",
"version": "1.0.0",
"maintainer": [ "Chris Travers <christravers@adjust.com>" ],
"license": {
"PostgreSQL": "http://www.postgresql.org/about/licence"
Expand All @@ -10,7 +10,7 @@
"pgtelemetry": {
"file": "extension/pgtelemetry-HEAD.sql",
"docfile": "doc/pgtelemetry.html",
"version": "0.2.0",
"version": "1.0.0",
"abstract": "Useful monitoring and metrics for PostgreSQL"
}
},
Expand All @@ -24,7 +24,8 @@
"runtime": {
"requires": {
"PostgreSQL": "9.6.0",
"pg_stat_statements": 0
"pg_stat_statements": 0,
"plpgsql": 0
}
}
},
Expand Down
41 changes: 41 additions & 0 deletions extension/pgtelemetry--0.2--1.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

create function wal_telemetry_create_or_select_record()
returns pg_telemetry_wal_log language plpgsql as
$$
declare log_entry pg_telemetry_wal_log;
begin
if pg_is_in_recovery() then
select * into log_entry from pg_telemetry_wal_log order by current_epoch desc limit 1;
else
insert into pg_telemetry_wal_log
select extract('epoch' from now()), now(),
pg_current_xlog_location() end as wal_location
WHERE NOT is_replica()
returning * into log_entry;
end if;
return log_entry;
end;
$$;

create function wal_telemetry() returns table (
current_epoch numeric, last_epoch numeric, secs_elapsed numeric,
current_lsn pg_lsn, last_lsn pg_lsn, bytes_elapsed numeric,
bytes_per_sec numeric
) language sql as $$
WITH insert_record AS
select c.run_time as current_epoch, l.run_time as last_epoch,
c.run_time - l.run_time as secs_elapsed,
c.lsn as current_lsn, l.lsn as last_lsn,
c.lsn - l.lsn as bytes_elapsed,
(c.lsn - l.lsn)::numeric / (c.run_time - l.run_time) as bytes_per_sec
FROM wal_telemetry_create_or_select_record() c,
lateral (select * from pg_telemetry_wal_log where run_time < c.run_time
order by run_time desc limit 1) l;
$$ set search_path from current;

select wal_telemetry();

CREATE VIEW waiting_queries_reason_details AS
select wait_event_type, wait_event, count(*) from pg_stat_activity
WHERE wait_event is not null
GROUP BY wait_event_type, wait_event;`
Loading

0 comments on commit 71f1ce1

Please sign in to comment.