I've been testing Google Cloud SQL with Postgresql, but I have random queries taking ~3s instead of a few ms.
Troubleshooting I did:
- The queries themselves aren't problems, rerunning the same query will work.
- Indexes are properly set. The database is also very very small, it shouldn't do this, even if there weren't any index.
- The Kubernetes container is connecting to the database through SQL Proxy (I followed this https://cloud.google.com/sql/docs/postgres/connect-kubernetes-engine). It is not the problem though as I tried to connect directly to the database, with the same issue.
- I configured
net.ipv4.tcp_keepalive_time
to 60 to make sure the connection weren't dropping. - I also have a pool of connection that are never disconnected to make sure it wasn't from that.
- When I run queries directly through my local Postgresql client, I never have the problem.
- I don't have this issue when developing locally either and connecting to my local database.
What I'm getting at is: I feel there's some weird connection/link issue between my Google Compute instances and my Google SQL instance that I can't seem to figure out. Any idea?
Edit:
I also noticed these logs in my SQL Cloud instance every 30s:
ERROR: recovery is not in progress
HINT: Recovery control functions can only be executed during recovery.
STATEMENT: SELECT pg_is_xlog_replay_paused(), current_timestamp