Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I skip all errors on an RDS replica instance?

I use certain my.cnf settings like this. Does RDS instance allow such options?

slave-skip-errors = 1062,1054

replicate-ignore-db=verv_raw   

replicate-ignore-table=verv.ox_session

replicate-wild-ignore-table=verv_raw.ox%

replicate-wild-ignore-table=verv_raw.ox%

I am aware of the procedure that skips one error at a time.

CALL mysql.rds_skip_repl_error;

But what I am looking for is an option to skip all errors on slave. Is it possible in RDS environment?

like image 476
shantanuo Avatar asked Mar 27 '16 09:03

shantanuo


People also ask

How do you deal with read replica lag?

Follow these recommendations to improve replica lag: If the reader instance is smaller than the writer instance, the volume of changes might be too much for the reader to catch up. It's a best practice that all instances in a cluster are the same size to avoid any workload overload on the reader instances.

How many Read replicas can you have from one master instance?

You can have up to five Read Replicas per master, each with own DNS endpoint. Unlike a Multi-AZ standby replica, you can connect to each Read Replica and use them for read scaling. You can have Read Replicas of Read Replicas. Read Replicas can be Multi-AZ enabled.

How do I improve my RDS reading performance?

An Amazon RDS performance best practice is to allocate enough RAM so that your working set resides almost completely in memory. The working set is the data and indexes that are frequently in use on your instance. The more you use the DB instance, the more the working set will grow.

What are the common causes of replication lag?

Replication lag can happen in a few scenarios, such as: The primary instance can't send the changes fast enough to the replica. The replica can't receive the changes quickly enough. The replica can't apply the changes quickly enough.


2 Answers

I solved it by creating a mysql event scheduler like this :

CREATE EVENT repl_error_skipper 
ON SCHEDULE 
EVERY 15 MINUTE
COMMENT 'Calling rds_skip_repl_error to skip replication error'
Do
CALL mysql.rds_skip_repl_error;
/*also you can add other logic */

To set other global variables you can find and set those (if available for changing) in rds parameter group (you will have to create new parameter group and set the variable values).

like image 60
Nikhil Avatar answered Sep 22 '22 18:09

Nikhil


As mentioned, this command only skips one replication error. I wrote a PHP script to loop through this and ran it once a minute via cron job (my replica was log jammed with a series of thousands of bad queries than went through on the main DB)

for($i = 1; $i <= 30; $i++) {
        $db = new mysqli('someserver.rds.amazonaws.com', 'root', 'password');
        $res = $db->query('CALL mysql.rds_skip_repl_error;');
        if(!$res) {
                //echo 'Query failed: ' . $db->error . "\n";
                return;
        }
        //var_dump($res->fetch_assoc());
        $db->close();
        sleep(1);
}

You'll need to tinker with this some (not every server would tolerate only one second between calls and 30 calls per minute), but it does work (albeit in a brute force manner). You must create a new DB connection every time to run this. The loop opens, runs and then closes the connection.

like image 22
Machavity Avatar answered Sep 24 '22 18:09

Machavity