a year ago
And one more question, postgre sql query is too slow.
Just simple query
```
SELECT "rewards_pointhistory"."id",
"rewards_pointhistory"."user_id",
"rewards_pointhistory"."child_id",
"rewards_pointhistory"."points",
"rewards_pointhistory"."description",
"rewards_pointhistory"."created_at",
"rewards_pointhistory"."goal_id",
"rewards_pointhistory"."checkin_id",
"rewards_pointhistory"."reward_id",
"goals_goal"."id",
"goals_goal"."user_id",
"goals_goal"."child_id",
"goals_goal"."category_id",
"goals_goal"."title",
"goals_goal"."description",
"goals_goal"."language",
"goals_goal"."min_points",
"goals_goal"."max_points",
"goals_goal"."start_date",
"goals_goal"."end_date",
"goals_goal"."active_days",
"goals_goal"."is_default",
"goals_goal"."order",
"goals_goal"."status",
"goals_goal"."is_active",
"goals_goal"."created_at",
"goals_goal"."updated_at",
"goals_goal"."recommended_age_min",
"goals_goal"."recommended_age_max",
"goals_goalcheckin"."id",
"goals_goalcheckin"."goal_id",
"goals_goalcheckin"."date",
"goals_goalcheckin"."status",
"goals_goalcheckin"."note",
"goals_goalcheckin"."created_at",
"goals_goalcheckin"."updated_at",
"goals_goalcheckin"."cancel_count"
FROM "rewards_pointhistory"
LEFT OUTER JOIN "goals_goal"
ON ("rewards_pointhistory"."goal_id" = "goals_goal"."id")
LEFT OUTER JOIN "goals_goalcheckin"
ON ("rewards_pointhistory"."checkin_id" = "goals_goalcheckin"."id")
WHERE "rewards_pointhistory"."child_id" IN (4, 3)
ORDER BY "rewards_pointhistory"."created_at" DESC
```
It just takes 5ms in my pc, but railway taks 200x times(over 1second)
What's the issue?
1 Replies
a year ago
Your local machine and a cloud platform like Railway aren’t apples-to-apples. A database on your laptop has some unfair advantages:
Zero Network Latency: On your PC, the query runs locally—no hopping over the internet or between servers. On Railway, your app might be talking to a database in a different container or region, adding latency.
Resource Competition: Your PC is (probably) just serving you. Railway’s a shared environment—other users, containers, and processes might be hogging CPU, memory, or disk I/O.
Hardware: Your laptop might have a beefy SSD and plenty of RAM.
Configuration: PostgreSQL on your local setup might be tuned differently—or not tuned at all—compared to Railway’s defaults.
The other thing I noticed about your query:
Two LEFT JOINs: You’re pulling from rewards_pointhistory, joining with goals_goal and goals_goalcheckin. If these tables are big or unindexed, those joins can slow things down.
WHERE Clause: Filtering on child_id IN (4, 3) is fine, but if child_id isn’t indexed, it’s a full table scan.
ORDER BY: Sorting by created_at DESC means PostgreSQL has to fetch all matching rows, then sort them. No index? More pain.
On your PC, with small data or cached results, this flies. On Railway, with real-world conditions, it chokes.
Hopefully this adds some color. Metal Volumes should help but you'll never get as fast as an M-series chip. (So far.)
Status changed to Awaiting User Response Railway • 12 months ago
7 months ago
This thread has been marked as solved automatically due to a lack of recent activity. Please re-open this thread or create a new one if you require further assistance. Thank you!
Status changed to Solved Railway • 7 months ago