Description
I am using Laravel 11 with Inertia.js and React. Until now, as I was prototyping, I was using SQLite in development environment as well as in a test prod environnement I had set up.
Recently attempted to deploy to a real production server based in Switzerland (I'm based in Montréal), with Laravel Forge to provision the server, and Postgresql instead of SQLite (hosted on the same server).
Ever since doing the switch from SQLite to Postgresql, I observe huge performances issues, on every page change, to the point where, when deployed, most pages return 504 timeout. In my local environnement, when connected to the same database, I don't have 504, but the requests are very noticeably slow, taking 10, 40 seconds sometimes.
I considered that the issue might come from latency, but while the exact delay changes, I observed the same behaviour with running the database:
- On the Forge provisionned server I mentioned and accessing the website hosted on that server (so no network latency)
- On that same server but connecting with a VPS tunnel on my machine
- On my local machine (macbook pro M3) with psql
- On Supabase with a database hosted in Paris (further from me)
- On Supabase with a database hosted in Canada (closer to me)
I attempted to refactor my code, my migrations, adding indexes, changing types.
Debugbar show relatively efficient requests, I do eager loading when necessary. Most are around 300ms.
When switching back to SQLite, on the exact version of the code, the website is back to being snappy and performant. I know that, SQLite being in memory, it's supposedly faster, but here the performances with posgresql are really abyssimal.
As such, I assume that there might be some framework related overhead of my doing, like a missing constraint, etc, but I can't identify it on my own and I wonder if anyone came across such behaviour?
I am not excluding that the issue might come from somewhere else in my code (controllers, services, API resources, etc), but just that it only appears when i switch from SQLite to Postgresql.
Relevant code
I don't have any specific relevant code to show as it applies to pretty much every page/controller. I will be open to showing anything you think might me relevant though.
Thank you in advance for your help!