Closed ZBernik closed 2 months ago
Hello and welcome to SQLPage! are you sure the problem comes from SQLPage? This looks like a timezone problem, since you are importing data without timezone information.
You can debug that by selecting the current time and the time difference with stored timestamps in a table, you should quickly see where the issue comes from:
SELECT Last_update, now(), now()-last_update;
Hello, Ophir,
it works like a charm, thank you so much! I have made this changes.
dbamonitor=> \d monitoring.db_availability
Table "monitoring.db_availability"
Column | Type | Collation | Nullable |
Default
--------------+--------------------------+-----------+----------+-----------
----------------------------------
id | integer | | not null | nextval('db
_availability_id_seq'::regclass)
hostname | character varying(50) | | |
db_version | character varying(30) | | |
databases | character varying(100) | | |
port | character varying(10) | | |
availability | character varying(5) | | |
last_update | timestamp with time zone | | |
Indexes:
"db_availability_pkey" PRIMARY KEY, btree (id)
cat imp_csv_dbamonitor.sql
SET TIMEZONE to 'Europe/Prague';
COPY monitoring.db_availability(Hostname, DB_version, Databases, Port,
Availability,Last_update) FROM '/var/lib/pgsql/log/db_availability_imp.csv'
DELIMITER '|';
Index.sql
set timezone 'Europe/Prague';
select 'shell' as component, 300 as refresh;
select
'hero' as component,
'Databases availability' as title,
TRUE as reverse,
'http://10.1.4.69:8080/spcss.png' as image;
select 'table' as component, 1 as sort, 1 as search;
SELECT hostname, db_version, databases, port, availability, to_char(last_
update, 'YYYY/MM/DD HH24:MI:SS') as last_refresh,'red' as _sqlpage_color
FROM monitoring.db_availability where availability = 'DOWN' AND last_update
> NOW() - INTERVAL '15 minutes';
SELECT hostname, db_version, databases, port, availability, to_char(last_
update, 'YYYY/MM/DD HH24:MI:SS') as last_refresh,'green' as _sqlpage_color
FROM monitoring.db_availability where availability = 'UP' and last_update >
NOW() - INTERVAL '15 minutes';
Best regards,
Zdeněk
You can use sqlpage/on_connect.sql
to set the timezone on connection, so that it will be used in all your requests.
Introduction
Cannot select data with time conditions.
To Reproduce
List of steps to reproduce the behavior. Include the sql file you are using and the eventual relevant parts of your database schema
Actual behavior
IGNORE time condition: age(now(), last_update) < '15 minutes'; or
Expected behavior
select data according where clausule
Version information