Same code, different environment. First thing I ask myself: where could the problem be?
First suspect is index. Dev has 1,000 rows, prod has 10 million. Without an index, the query scans the entire table. Run EXPLAIN ANALYZE and see what the query is doing. If you see Seq Scan, add an index and you are done.
If the index exists, next I check connection pool. In dev, a single user is hitting the query. In prod, hundreds of requests are coming in simultaneously. If the pool is full, queries are queuing up and waiting for a slot. Increasing the pool size usually fixes this immediately.
Still not found? Could be an N+1 problem. Sounds harmless but it is a killer in prod. You are firing 1000 queries instead of 1 without realizing it. Each loop iteration hits the DB separately. If using an ORM, check eager loading. One query with a join beats a thousand individual queries every time.
Also check DB server resources. Dev might have 16GB RAM, prod might have 2GB. Same query, completely different hardware. Query cache also comes into play here. A cold cache in prod means every query hits disk instead of memory.
Finally, network latency. In dev, the app and DB are on the same machine. In prod, they might be on different servers or even different regions. That difference alone can turn milliseconds into seconds.