Ticket
The shipping status service looks up one shipment at a time with: select status, fee, created_at from shipments where shipment_id = $1 and customer_id = $2. It logs in as the role shipping_api and uses server-side prepared statements: each connection prepares this statement once and executes it for every lookup. Its connection pool replaces each connection after 15 seconds. The service team wants to cut the planning time of this lookup and asks to set plan_cache_mode = force_generic_plan for the role shipping_api, so that the plan is made once per connection and reused. From one service connection today, pg_prepared_statements shows generic_plans = 0 for this statement and custom_plans equal to its number of executions. The primary has 4 vCPUs. Statistics in the context below cover about the last minute.
Postgres 18 context
select count(*) as partitions, pg_get_partkeydef('public.shipments'::regclass) as partition_key, pg_size_pretty(sum(pg_total_relation_size(inhrelid))) as total_size from pg_inherits where inhparent = 'public.shipments'::regclass
select indexrelid::regclass as index, pg_get_indexdef(indexrelid) as definition from pg_index where indrelid = 'public.shipments'::regclass order by 1
explain (costs off) select status, fee, created_at from shipments where shipment_id = 1001 and customer_id = 1002
explain (generic_plan, costs off) select status, fee, created_at from shipments where shipment_id = $1 and customer_id = $2
select calls, round(mean_plan_time::numeric, 4) as mean_plan_ms, round(mean_exec_time::numeric, 4) as mean_exec_ms, left(regexp_replace(query, '\s+', ' ', 'g'), 120) as query from pg_stat_statements where query like '%from public.shipments%' order by calls desc limit 3
select r.rolname, s.setdatabase, s.setconfig from pg_db_role_setting s join pg_roles r on r.oid = s.setrole order by 1
select name, setting, context from pg_settings where name in ('plan_cache_mode', 'max_locks_per_transaction', 'pg_stat_statements.track_planning') order by name
select state, coalesce(wait_event_type || ':' || wait_event, 'none') as wait_event, count(*) from pg_stat_activity where usename = 'shipping_api' group by 1, 2 order by 3 desc