Aurora MySQL cluster failing to connect internmently

0

Hello,

We have a PHP based ecommerce site hosted on AWS. We have recently migrated from RDS to an Aurora MySQL Cluster and we have noticed that pointing our API to the writer and reader endpoints we get intermittently errors when connecting to the database. This is the error we get:

Uncaught PDOException: SQLSTATE[HY000]: General error: 2002 php_network_getaddresses: getaddrinfo failed: Name or service not known

We solved this temporary by pointing to each instance endpoint of this cluster but we were planning on using Aurora's autoscalling features. Any idea why this is happening or how can we solve this using Aurora's cluster endpoints?

posta 7 mesi fa278 visualizzazioni
2 Risposte
0

The intermittent errors when connecting to the Aurora MySQL cluster endpoints are likely occurring due to your application connecting to reader instances instead of the primary writer instance.

Some things to check:

Verify that your application connection string is using the cluster endpoint URL, which will always route to the primary writer instance.

If using individual instance endpoints, there is a chance of connecting to readers which could result in errors for write operations.

Check the value of the @@innodb_read_only variable after connecting to determine if it's a reader (value 1) or writer (value 0).

You can run the following query to identify which instance you are connected to:



select concat( 'You are connected to ', server_id, ', which is a ', 
  if(SESSION_ID='MASTER_SESSION_ID', 'Writer', 'Reader')) 
  as CONNECTION_STATUS 
from information_schema.replica_host_status
where SERVER_ID in (select @@aurora_server_id);

Using the cluster endpoint is recommended to take advantage of Aurora's high availability and auto-scaling features in a transparent manner.

profile picture
ESPERTO
con risposta 7 mesi fa
0

Thank you for your answer, I will check on that, however connecting to only the the cluster instance, routes everything to the writer instance instead of routing reads only to the readers and thus overloading the writer.

con risposta 7 mesi fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande