#!/bin/bash
set -uo pipefail
#==============================================================#
# File      :   pg-heartbeat
# Desc      :   generate heartbeat record to local
# Ctime     :   2022-12-31
# Mtime     :   2025-12-30
# Path      :   /pg/bin/pg-heartbeat
# Deps      :   psql
# License   :   Apache-2.0 @ https://pigsty.io/docs/about/license/
# Copyright :   2018-2026  Ruohang Feng / Vonng (rh@vonng.com)
#==============================================================#

SQL="SELECT *, now()::TIME AS now, date_trunc('seconds',now()-ts) AS elapse FROM monitor.beating();"
while true; do
  psql postgres -qwXc "${SQL}"
  sleep 1;
done