\pset tuples_only on
\pset format unaligned
\timing off
BEGIN READ ONLY;
select json_build_object('db_now_shanghai', to_char(now() at time zone 'Asia/Shanghai','YYYY-MM-DD HH24:MI:SS'), 'current_user', current_user)::text;
select json_build_object('table','request_audit_logs','exists', to_regclass('public.request_audit_logs') is not null)::text;
select json_build_object('table','ops_error_logs','exists', to_regclass('public.ops_error_logs') is not null)::text;
select 'request_audit_columns|' || string_agg(column_name || ':' || data_type, ',' order by ordinal_position)
from information_schema.columns where table_schema='public' and table_name='request_audit_logs';
select 'ops_error_columns|' || string_agg(column_name || ':' || data_type, ',' order by ordinal_position)
from information_schema.columns where table_schema='public' and table_name='ops_error_logs';
select 'request_audit_range|' || coalesce(count(*)::text,'0') || '|' || coalesce(to_char(min(created_at) at time zone 'Asia/Shanghai','YYYY-MM-DD HH24:MI:SS'),'') || '|' || coalesce(to_char(max(created_at) at time zone 'Asia/Shanghai','YYYY-MM-DD HH24:MI:SS'),'')
from public.request_audit_logs
where created_at >= now() - interval '3 days';
select 'ops_error_range|' || coalesce(count(*)::text,'0') || '|' || coalesce(to_char(min(created_at) at time zone 'Asia/Shanghai','YYYY-MM-DD HH24:MI:SS'),'') || '|' || coalesce(to_char(max(created_at) at time zone 'Asia/Shanghai','YYYY-MM-DD HH24:MI:SS'),'')
from public.ops_error_logs
where created_at >= now() - interval '3 days';
COMMIT;
