Query in PostgreSQL with large quantity of squid access requests
You are representing time in 3 different was.  The query is using epoch, while the index is using timestamptz, and the partition constraints are using year and month as two separate fields.  So the query can make use of neither the index nor the partition constraints.

You should probably change them all to use timestamptz.  In the query, instead of converting timestamptz to epoch on the column "time", convert epoch to timestamptz for the BETWEEN constants. (Or just have the client send timestamptz rather than epoch in the first place)

For the check constraint, you could use date_trunc("month",NEW."time") and date_trunc("month",NEW."time" + "1 month") to arrive at the endpoints to put into the check constraint. You would want to spell out the check constraint something like "time" &gt;= low_limit and "time" &lt; high_limit rather than using BETWEEN.