\pset pager off
\timing on

select now() at time zone 'utc' as checked_at_utc;
select version();
select pg_is_in_recovery() as is_replica;

select
  application_name,
  client_addr,
  state,
  sync_state,
  pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn) as replay_bytes_behind
from pg_stat_replication
order by application_name;

select state, count(*)
from pg_stat_activity
group by state
order by count(*) desc;

select wait_event_type, wait_event, count(*)
from pg_stat_activity
where wait_event is not null
group by 1, 2
order by 3 desc;

select
  pid,
  usename,
  application_name,
  now() - xact_start as transaction_age,
  state,
  left(query, 160) as query
from pg_stat_activity
where xact_start is not null
order by xact_start;

select
  checkpoints_timed,
  checkpoints_req,
  checkpoint_write_time,
  checkpoint_sync_time,
  buffers_checkpoint
from pg_stat_bgwriter;
