Synchronize time sampling in grafana with postgreSQL

  • Grafana 10.05 with docker (debian)

Good afternoon!
Please advise how to interconnect time sampling in postgreSQL database depending on time period in grafana.
Now I observe the following picture:

my sql code
SELECT "Closed" AS "time", "Taskid" FROM "PyrusTasks" ORDER BY "Closed" LIMIT 5000

i think i should use macros for this, but can i get some code example ?