Intermittent query timeout & incorrect results

I’m using AWS hosted Grafana and querying an RDS Postgres database.

I’ve added the appropriate entries in the security groups to allow the hosted Grafana service to access the database, and confirmed success with the connectivity test in the data source.

I am getting somewhat regular 504 Gateway Timeouts, and upstream request timeouts from the query.

On the times it does work, it returns an incorrect result set. It is a pretty simple query, just returning a 0 or a 1 to indicate if a system has updated a log.

  SELECT case when ((DATE_PART('day', now() - LastLog) * 24 + 
               DATE_PART('hour', now() - LastLog)) * 60 +
               DATE_PART('minute', now() - LastLog)) > 15 
               then 0
               else 1
               end as Status
  from SystemStatus
  where System = 'Murray' ;

When I run this is Grafana and it returns a result, it just gives 1, but when I check on the DB directly it is retuning 0.

Anyone know how I can a) increase the query timeout interval for the data source in AWS hosted Grafana, and b) if Grafana caches results (and if so how I can stop it) or why it would be returning an incorrect result set?

Many thanks.

Bit more info, if I change to table view I can see it is returning 1 as the status, but if I run Query Inspector it returns 0 as expected…

MainPanel.png