First connect from Prestashop to Google Cloud SQL always fails

I'm setting up a PrestaShop installation on a development server which is a GCE instance and using Cloud SQL as a database server. Everything works just fine except one thing: whenever there is a long period of inactivity on the site, the first page load after that always gives me this error:

Link to database cannot be established: SQLSTATE[HY000] [2003]

If I refresh the page the error is gone and never appears again until I stop using the site for an hour or so. It almost looks like database instance is going into sleep mode or something like that.

The reason I mentioned Prestashop is the fact that I never get this error when using Adminer or connecting to the database from mysql console client.


With the per use billing model, instances are spun down after a 15 minute timeout to save you money. They then take a few seconds to be spun up when next accessed. It may be the Prestashop is timing out on these first requests (though I have no experience with that application).

Try changing your instance to a package billing, which has a 12 hour timeout, to see if this helps

According to GCE documentation,

Once a connection has been established with an instance, traffic is permitted in both directions over that connection, until the connection times out after 10 minutes of inactivity

I suspect that might be the cause. To get around it, you can try to lower the tcp keepalive time.

Refer here:

To keep long-lived unused connections alive, you can set the TCP keepalive. The following commands set the TCP keepalive value to one minute and make the configuration permanent across instance reboots.

# Display the current tcp_keepalive_time value.
$ cat /proc/sys/net/ipv4/tcp_keepalive_time

# Set tcp_keepalive_time to 60 seconds and make it permanent across reboots.
$ echo 'net.ipv4.tcp_keepalive_time = 60' | sudo tee -a /etc/sysctl.conf

# Apply the change.
$ sudo /sbin/sysctl --load=/etc/sysctl.conf

# Display the tcp_keepalive_time value to verify the change was applied.
$ cat /proc/sys/net/ipv4/tcp_keepalive_time

Need Your Help

SSRS export to excel on separate worksheets issue

excel reporting-services ssrs-2008

I'm using SSRS 2008 to export data to an excel file. I need 4 worksheets in the file. As a result, I'm inserting a page break after each Tablix. But when there's no data in the page,it's merging the

Implement save() Action for Object with Relationship?

java grails groovy gorm

I have the following Grails GORM domain classes: