1. check starttime
teguhth=# SELECT pg_postmaster_start_time() as StartTime;
starttime
-------------------------------
2023-10-19 09:12:12.569427+07
(1 row)
teguhth=#
2. check uptime detail
teguhth=# SELECT current_timestamp - pg_postmaster_start_time() as Uptime;
uptime
----------------
00:02:57.35956
(1 row)
teguhth=#
teguhth=# SELECT now() - pg_postmaster_start_time() as Uptime;
uptime
----------------
01:03:29.52471
(1 row)
teguhth=#
3. using trunch second, minute, hour
SELECT date_trunc('second', current_timestamp - pg_postmaster_start_time()) as uptime_in_second;
SELECT date_trunc('minute', current_timestamp - pg_postmaster_start_time()) as uptime_in_minute;
SELECT date_trunc('hour', current_timestamp - pg_postmaster_start_time()) as uptime_in_hour;
teguhth=# SELECT date_trunc('second', current_timestamp - pg_postmaster_start_time()) as uptime_in_second;
uptime_in_second
------------------
01:43:19
(1 row)
teguhth=# SELECT date_trunc('minute', current_timestamp - pg_postmaster_start_time()) as uptime_in_minute;
uptime_in_minute
------------------
01:43:00
(1 row)
teguhth=# SELECT date_trunc('hour', current_timestamp - pg_postmaster_start_time()) as uptime_in_hour;
uptime_in_hour
----------------
01:00:00
(1 row)
teguhth=#
4. using trunch second, minute, hour combination
SELECT pg_read_file('/etc/hostname') as hostname,now() as Current_time,pg_postmaster_start_time() as Start_Time,
now() - pg_postmaster_start_time() as Uptime_detail,
date_trunc('second',current_timestamp - pg_postmaster_start_time()) as Uptime_in_Second,
date_trunc('minute', current_timestamp - pg_postmaster_start_time()) as Uptime_in_Minute,
date_trunc('hour', current_timestamp - pg_postmaster_start_time()) as Uptime_in_Hour;
No comments:
Post a Comment