How can you tell which table partitions were actually scanned?

In PostgreSQL 16, the orders_part table uses monthly partitions defined by PARTITION BY RANGE (created_at). It contains several years of order data. The application repeatedly executes the prepared query SELECT id, total FROM orders_part WHERE created_at >= $1 AND created_at < $2. The month boundaries are passed as parameters: for February 2026, they are '2026-02-01 00:00:00' and '2026-03-01 00:00:00'. Depending on the plan PostgreSQL chooses, some monthly partitions may be missing from the plan entirely, while others may remain in the plan even though PostgreSQL never scans their data. Why does this happen? How can you tell from the plan how many partitions were actually scanned? How does partition pruning differ from an index lookup?

ExplainEXPLAIN and optimizationMiddleAnalystBackendData Engineer