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?

질문됨 2달 전147회 조회
2개 답변
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
전문가
답변함 2달 전
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.

답변함 2달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인