Quantcast
Channel: StackExchange Replication Questions
Viewing all 17268 articles
Browse latest View live

Setting up MySQL master-slave replication

$
0
0

I am trying to setup master-slave replication on MySQL 5.6.

When I update my database in the master, the change is not reflected on the slave. When I show the process list on the slave it shows this message:

mysql> show processlist;
+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------------+------------------+
| Id | User        | Host      | db   | Command | Time | State                                                                       | Info             |
+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------------+------------------+
|  1 | system user |           | NULL | Connect | 6440 | Slave has read all relay log; waiting for the slave I/O thread to update it | NULL             |
|  2 | system user |           | NULL | Connect | 5730 | Waiting for master to send event                                            | NULL             |
| 42 | root        | localhost | NULL | Query   |    0 | NULL                                                                        | show processlist |
+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------------+-------------

Any suggestions?


developing HA clustered applications

$
0
0

I am trying to craft a software tool for IoT devices which basically should execute a distributed transaction. It will have a master, deployed on a cloud infrastructure, which is connected to devices thanks to specfic installed agent-software . While agent (and other related tools) structure and features are pretty straightforward, there are some requirements for the agent that i've found challenging

  • It must be highly avaliable, using replication
  • It must track the partial status of the distributed transaction so, if the master node fails, the failover node can resume the job where its was interrupted and get it done
  • Eventually, all the devices must be in the same status. The transaction is not strcitly atomic, but the master must be able to retry in every moment to update a failing device
  • The master exposes APIs throught http/ws endpoints

Mastr reference architecture

I've assumed a possibile solution using these components:

API server is responsibile for client auth, horizontal features and api exposing. Each instance behind load balancer connects with a well known Job executor (JE) seed, receives the list of JE replicas and asks for a leader, which is voted by majority of answers.

The leader Job Executor receives a transaction request and applies broadcasting a command to all devices, then starts to collect responses. It retries for each device that send an error response or no response at all (obiviously, it should know when a device is physically connected with a ping/pong mechanism). The leader sends to all other nodes the list of failed devices so that if it fails, a new leader is elected and can keep on retrying to execute the command on previosly failed devices

Do I really need of this or i can simply assume that all replicas can share the global state in the database? In this case Do I still need of passive nodes or I can do active replication? Since it seems a quite common problem, can you suggest me a framework/tool (eg zookeeper?) to achieve my goal?

Thanks in advance

MongoDB 3.6 create local Shard db without replica

$
0
0

This is what I want to do:

  1. Create a Config Server
  2. Create 2 Shard
  3. Create a Mongos Router

I don't want to replicate my data using replica set, I want to simulate that each shard has only a part of data like it says is shard theory.

I'm following this guide, but I understood that the guide create many replicas for config server and shared server and I don't want that. So this is what I do:

Config file of Config Server:

sharding:
  clusterRole: configsvr
replication:
  replSetName: localhost
net:
  bindIp: localhost
storage:
  dbPath: /home/christian/mongo/confsvr/metadata

Execute Config Server:

mongod --config /mongo/confsvr/mongod.conf --port 27019

Now doc uses rs.initiate() for adding a replica of config server (if I understood right), so I dropped this part.

After that, I created two config file for Shard Server.

sharding:
 clusterRole: shardsvr
replication:
  replSetName: localhost
net:
  bindIp: localhost
storage:
  dbPath: /home/christian/mongo/shard[1|2]

I started two shard:

mongod --config mongo/shard[1|2]/shard.conf  --port 2703[1|2]

Created conf file for Mongos Router:

sharding:
  configDB:localhost/localhost:27019
net:
  bindIp: localhost

So i tried to start mongos:

mongos --config /home/christian/mongo/router/mongos.conf

But terminal print in loop this:

Unable to reach primary for set localhost

Cannot Reach any nodes for set localhost

Last steps were connecting to mongos, and add the Shards to DB

How could I obtain what I want?

Creating and executing a Merge Replication programmatically

$
0
0

Let me preface this by saying I now realize how stupid I am and was. I have been developing for 1 year (to the day) and this was the first thing I wrote. I now have come back to it and I can't make heads or tails of it. It worked at one point on a very simple app but that was a while ago.

Specifically I am having problems with LocalDBConn which uses out but for the life of me I can't remember why.

Guidance, pointer's, refactoring, slaps up side the head are ALL welcome and appreciated!

public class MergeRepl
{
            // Declare nessesary variables
    private string subscriberName;
    private string publisherName;
    private string publicationName;
    private string subscriptionDbName;
    private string publicationDbName;
    private MergePullSubscription mergeSubscription;
    private MergePublication mergePublication;
    private ServerConnection subscriberConn;
    private ServerConnection publisherConn;
    private Server theLocalSQLServer;
    private ReplicationDatabase localRepDB;

    public MergeRepl(string subscriber, string publisher, string publication, string subscriptionDB, string publicationDB)
    {
        subscriberName = subscriber;
        publisherName = publisher;
        publicationName = publication;
        subscriptionDbName = subscriptionDB;
        publicationDbName = publicationDB;

        //Create connections to the Publisher and Subscriber.
        subscriberConn = new ServerConnection(subscriberName);
        publisherConn = new ServerConnection(publisherName);


        // Define the pull mergeSubscription
        mergeSubscription = new MergePullSubscription
                                {
                                    ConnectionContext = subscriberConn,
                                    DatabaseName = subscriptionDbName,
                                    PublisherName = publisherName,
                                    PublicationDBName = publicationDbName,
                                    PublicationName = publicationName
                                };

        // Ensure that the publication exists and that it supports pull subscriptions.
        mergePublication = new MergePublication
                               {
                                   Name = publicationName,
                                   DatabaseName = publicationDbName,
                                   ConnectionContext = publisherConn
                               };

        // Create the local SQL Server instance
        theLocalSQLServer = new Server(subscriberConn);
        // Create a Replication DB Object to initiate Replication settings on local DB
        localRepDB = new ReplicationDatabase(subscriptionDbName, subscriberConn);

        // Check that the database exists locally
        CreateDatabase(subscriptionDbName);
    }

    public void RunDataSync()
    {
        // Keep program from appearing 'Not Responding'
        ///// Application.DoEvents();

        // Does the needed Databases exist on local SQLExpress Install
        /////CreateDatabase("ContactDB");

        try
        {
                 //  Connect to the Subscriber
                 subscriberConn.Connect();

            // if the Subscription exists, then start the sync
                 if (mergeSubscription.LoadProperties())
                 {
                     // Check that we have enough metadata to start the agent
                     if (mergeSubscription.PublisherSecurity != null || mergeSubscription.DistributorSecurity != null)
                     {
                         //  Synchronously start the merge Agent for the mergeSubscription
                         //  lblStatus.Text = "Data Sync Started - Please Be Patient!";
                         mergeSubscription.SynchronizationAgent.Synchronize();
                     }
                     else
                     {
                         throw new ApplicationException("There is insufficient metadata to synchronize the subscription." +
                             "Recreate the subscription with the agent job or supply the required agent properties at run time.");
                     }
                 }
                 else
                 {
                     // do something here if the pull mergeSubscription does not exist
                     // throw new ApplicationException(String.Format("A mergeSubscription to '{0}' does not exist on {1}", publicationName, subscriberName));
                     CreateMergeSubscription();
                 }
        }
        catch (Exception ex)
        {
            // Implement appropriaate error handling here
            throw new ApplicationException("The subscription could not be synchronized.  Verify that the subscription has been defined correctly.", ex);
            //CreateMergeSubscription();
        }
        finally
        {
            subscriberConn.Disconnect();
        }
    }

    public void CreateMergeSubscription()
    {
        // Keep program from appearing 'Not Responding'
        // Application.DoEvents();

        try
        {

            if (mergePublication.LoadProperties())
            {
                if ((mergePublication.Attributes & PublicationAttributes.AllowPull) == 0)
                {
                    mergePublication.Attributes |= PublicationAttributes.AllowPull;
                }

                // Make sure that the agent job for the mergeSubscription is created.
                mergeSubscription.CreateSyncAgentByDefault = true;

                // Create the pull mergeSubscription at the Subscriber.
                mergeSubscription.Create();

                Boolean registered = false;

                // Verify that the mergeSubscription is not already registered.
                foreach (MergeSubscription existing in mergePublication.EnumSubscriptions())
                {
                    if (existing.SubscriberName == subscriberName
                        && existing.SubscriptionDBName == subscriptionDbName&& existing.SubscriptionType == SubscriptionOption.Pull)
                    {
                        registered = true;
                    }
                }
                if (!registered)
                {
                    // Register the local mergeSubscription with the Publisher.
                    mergePublication.MakePullSubscriptionWellKnown(
                        subscriberName, subscriptionDbName,
                        SubscriptionSyncType.Automatic,
                        MergeSubscriberType.Local, 0);
                }
            }
            else
            {
                // Do something here if the publication does not exist.
                throw new ApplicationException(String.Format(
                    "The publication '{0}' does not exist on {1}.",
                    publicationName, publisherName));
            }
        }
        catch (Exception ex)
        {
            // Implement the appropriate error handling here.
            throw new ApplicationException(String.Format("The subscription to {0} could not be created.", publicationName), ex);

        }
        finally
        {
            publisherConn.Disconnect();
        }
    }

    /// <summary>
    /// This will make sure the needed DataBase exists locally before allowing any interaction with it.
    /// </summary>
    /// <param name="whichDataBase">The name of the DataBase to check for.</param>
    /// <returns>True if the specified DataBase exists, False if it doesn't.</returns>
     public void CreateDatabase(string whichDataBase)
    {
        Database db;
        LocalDBConn(whichDataBase, out theLocalSQLServer, out localRepDB, out db);


        if (!theLocalSQLServer.Databases.Contains(whichDataBase))
        {
            //Application.DoEvents();
            // Create the database on the instance of SQL Server.
            db = new Database(theLocalSQLServer, whichDataBase);
            db.Create();

        }

        localRepDB.Load();
        localRepDB.EnabledMergePublishing = false;
        localRepDB.CommitPropertyChanges();

        if (!mergeSubscription.LoadProperties())
        {
            CreateMergeSubscription();
        }

    }

    private void LocalDBConn(string databaseName, out Server server, out ReplicationDatabase replicationDatabase, out Database db)
    {
        db = server.Databases[replicationDatabase.Name];
    }

    /// <summary>
    /// Checks for the existince of the Publication.  If there is one it verify's Allow Pull is set
    /// </summary>
    /// <returns>True if Publication is present. False if not.</returns>
    public bool CheckForPublication()
    {
        // If LoadProperties() returns TRUE then the Publication exists and is reachable
        if (mergePublication.LoadProperties())
            return true;

        if ((mergePublication.Attributes & PublicationAttributes.AllowPull) == 0)
        {
            mergePublication.Attributes |= PublicationAttributes.AllowPull;
        }

        return false;
    } // end CheckForPublication()

    /// <summary>
    /// Checks for the existence of a Subscription.
    /// </summary>
    /// <returns>True if a Subscription is present.  False if not</returns>
    public bool CheckForSubscription()
    {
        // Check for the existence of the Subscription
        return mergeSubscription.IsExistingObject;
    } // end CheckForSubscription()
}

Edit 1

Opps, I forgot the specific errors. On server and replicationDatabase I am getting a "Out parameter might not be initialized before accessing"

        private void LocalDBConn(string databaseName, out Server server, out ReplicationDatabase replicationDatabase, out Database db)
    {
        db = server.Databases[replicationDatabase.Name];
    }

Logical Replication to different schema name

$
0
0

We have PostgreSQL 11 database with structure one database one schema (public).

dbname : production_one
schema : public

dbname : production_two
schema : public

I would like to set up a logical replication, so that it will have structure One database, multiple schema as below:

dbname : prod_slave
schema : prod_one, prod_two

is it possible to do logical replication as above?

I have successful replication using streaming replication, but the situation need us to use logical replication as above.

Can any one Explain me What is the Use of Cascading Replication in Postgresql?

$
0
0

What are the advantages of cascading replication in PostgreSQL.

I have done Testing On this With three nodes.

M1---->S1----->S2

What is the Use if My master(M1) goes Down(failover). Where the secondary Slave(s2) Server Useful for us in this setup.

The merge process could not connect to the Publisher ' '. Check to ensure that the server is running. (

$
0
0

I have 2 servers with 2 kinds of replications between them. One is Transactional and the other is merge.

The Transactional replication is working fine but in the merge replication, I'm getting error messages.

Error messages:

The merge process could not connect to the Publisher ' '. Check to ensure that the server is running. (Source: MSSQL_REPL, Error number: MSSQL_REPL-2147198719) Get help: http://help/MSSQL_REPL-2147198719 The process could not connect to Publisher ' '. (Source: MSSQL_REPL, Error number: MSSQL_REPL20084) Get help: http://help/MSSQL_REPL20084 Login failed. The login is from an untrusted domain and cannot be used with Windows authentication. (Source: MSSQLServer, Error number: 18452) Get help: http://help/18452

Two weeks ago everything was working fine (we didn't change anything and they didn't change as well).

I've read and check that the user is db_owner. Telnet is open (and the transactional replication is working) so there are not any network problems. I deleted and recreated both replications.

when I'm looking at the publisher server events log I see the error

SSPI handshake failed with error code 0x80090301, state 14 while establishing a connection with integrated security; the connection has been closed. Reason: AcceptSecurityContext failed. The Windows error code indicates the cause of failure.

Any ideas?

MySQL Replication Slave Status OK but Data inconsistent

$
0
0

We are using MySQL 5.7, and have a Master and 3 Slave servers replication setup. All the 4 servers are dedicated for MySQL use only, and belong to the same data-center, connected over Private Network. So I believe that the network issues for replication should be minimal.

So, I did SHOW SLAVE STATUS\G on the Slave 1 server:

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: <removed for anonymity>
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.004803
          Read_Master_Log_Pos: 885020002
               Relay_Log_File: ubuntu-s-4vcpu-8gb-blr1-slave02-relay-bin.001056
                Relay_Log_Pos: 885020215
        Relay_Master_Log_File: mysql-bin.004803
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 885020002
              Relay_Log_Space: 885020495
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 103
                  Master_UUID: 78e93502-d3af-11e7-9af0-5aaa686987ef
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)

It clearly states that everything is fine. We also have quite a bit of monitoring tools like Zabbix, Packetbeat (Kibana) setup; which also gives us alerts if there is lag in the replication in any of the three Slave servers. We did not get any alerts about possible replication issues as well.

Now, I ran a query on Slave 1 server:

mysql> select order_id, order_status_id, buyer_invoice_id 
       from oc_suborder where order_id = 62284;
+----------+-----------------+------------------+
| order_id | order_status_id | buyer_invoice_id |
+----------+-----------------+------------------+
|    62284 |               1 |             NULL |
|    62284 |              15 |            76729 |
+----------+-----------------+------------------+
2 rows in set (0.01 sec)

It returns two rows in this case, which is wrong.

I ran the same query on the Master Server:

mysql> select order_id, order_status_id, buyer_invoice_id 
       from oc_suborder where order_id = 62284;
+----------+-----------------+------------------+
| order_id | order_status_id | buyer_invoice_id |
+----------+-----------------+------------------+
|    62284 |              15 |            76729 |
+----------+-----------------+------------------+
1 row in set (0.18 sec)

It returns one row only, which is correct; so the Slave is definitely having inconsistent data despite showing Slave Status as OK.

I also performed some DML operations on Master, and those changes did get replicated on the Slave server; so the replication is running. We are using third party DBA services, and every-time this happens; all they would suggest is to rebuild the Slave server(s). We are already sitting at 100 GB+ data, and it takes quite a few hours for this process (they have already done it 4 times in last few months); but the data inconsistency keeps on popping up time and again.

My questions are manifold:

  1. Is there any way to simply identify the data mismatch related tables/rows only, across multiple Schemas (Databases); and fix these specific rows instead of rebuilding the Slave again. My doubt is that I may have multiple tables with this data mismatch. We discover these mismatches only when some specific report contains suspicious data.

  2. What could be the possible reasons of the data mismatch appearing; even when Slave is 0 seconds behind Master. The example table in the queries above is using InnoDB. There are a few Transactions running on that table, and I am starting to suspect that a Transaction gets successfully committed on the Master, but not on the Slave sometimes.

  3. Using SHOW GLOBAL VARIABLES LIKE 'binlog_format';, I found that binlog_format on my Master server is set as MIXED, while on the Slave server it is set as ROW. Can this be source of this error or some other undiscovered errors ?

Please bear with me if the question seems Too Broad (as per Stack Overflow rules). I will be happy to provide as many details as needed, or Edit the question down to specific details. I am regular Stack Overflow user, and posting first time here. Any pointers would be really helpful.

Edit #1:

Are all the slaves configured with read-only=1? Is there any chance that your application could be writing directly to the slaves?

Yes. Also, in our application code, we do have an elaborate code for Read-Write separation. Infact, all the queries inside a Transaction (START TRANSACTION .. COMMIT/ROLLBACK) are always routed to the Master Server, even if there are SELECT queries within this block. Even, to cover for replication lag (sometimes), we route the next 2 SELECT queries after a DML operation to Master only.

Are any of the slaves configured with slave-skip-errors by any chance? If so, what is the value of this parameter?

Please find below:

mysql> select @@slave_skip_errors;
+---------------------+
| @@slave_skip_errors |
+---------------------+
| 1032,1062           |
+---------------------+
1 row in set (0.10 sec)

Edit #2

Please provide SHOW CREATE TABLE oc_suborder for both the Master and the Slave with the problem you detailed.

Master Server:

mysql> show create table oc_suborder\G;
*************************** 1. row ***************************
       Table: oc_suborder
Create Table: CREATE TABLE `oc_suborder` (
  `order_id` int(11) NOT NULL,
  `suborder_id` varchar(20) NOT NULL,
  `gst` tinyint(1) NOT NULL DEFAULT '1',
  `buyer_invoice_id` int(11) unsigned DEFAULT NULL,
  `invoice_no` int(11) NOT NULL DEFAULT '0',
  `invoice_date` datetime DEFAULT NULL,
  `invoice_prefix` varchar(26) NOT NULL,
  `shipping_method` varchar(128) NOT NULL,
  `shipping_code` varchar(128) NOT NULL,
  `total` decimal(15,4) DEFAULT NULL,
  `order_status_id` int(11) NOT NULL,
  `date_added` datetime NOT NULL,
  `date_modified` datetime NOT NULL,
  `cform_submit` enum('no_submit','will_submit','submitted','') NOT NULL DEFAULT 'no_submit',
  `cst_with_cform` decimal(15,4) DEFAULT NULL,
  `refundable_cform` decimal(15,4) DEFAULT NULL,
  `refund_status` enum('refunded','not_refunded','not_applicable','') NOT NULL DEFAULT 'not_applicable',
  `courier_partner` varchar(100) DEFAULT NULL,
  `tracking_no` varchar(64) DEFAULT NULL,
  `shipping_charge` decimal(15,2) DEFAULT NULL,
  `custom_totals` text,
  `no_wsb_tape` tinyint(1) NOT NULL DEFAULT '0',
  `no_invoice_with_shipment` tinyint(1) NOT NULL DEFAULT '0',
  `courier_partner_preference` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`suborder_id`),
  UNIQUE KEY `order_id` (`order_id`,`suborder_id`),
  UNIQUE KEY `buyer_invoice_id` (`buyer_invoice_id`),
  KEY `invoice_date` (`invoice_date`),
  KEY `shipping_method` (`shipping_method`),
  KEY `order_status_id` (`order_status_id`),
  KEY `date_added` (`date_added`),
  KEY `tracking_no` (`tracking_no`),
  CONSTRAINT `oc_suborder_order_id_fk` FOREIGN KEY (`order_id`) REFERENCES `oc_order` (`order_id`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.08 sec)

Slave server:

mysql> show create table oc_suborder\G;
*************************** 1. row ***************************
       Table: oc_suborder
Create Table: CREATE TABLE `oc_suborder` (
  `order_id` int(11) NOT NULL,
  `suborder_id` varchar(20) NOT NULL,
  `gst` tinyint(1) NOT NULL DEFAULT '1',
  `buyer_invoice_id` int(11) unsigned DEFAULT NULL,
  `invoice_no` int(11) NOT NULL DEFAULT '0',
  `invoice_date` datetime DEFAULT NULL,
  `invoice_prefix` varchar(26) NOT NULL,
  `shipping_method` varchar(128) NOT NULL,
  `shipping_code` varchar(128) NOT NULL,
  `total` decimal(15,4) DEFAULT NULL,
  `order_status_id` int(11) NOT NULL,
  `date_added` datetime NOT NULL,
  `date_modified` datetime NOT NULL,
  `cform_submit` enum('no_submit','will_submit','submitted','') NOT NULL DEFAULT 'no_submit',
  `cst_with_cform` decimal(15,4) DEFAULT NULL,
  `refundable_cform` decimal(15,4) DEFAULT NULL,
  `refund_status` enum('refunded','not_refunded','not_applicable','') NOT NULL DEFAULT 'not_applicable',
  `courier_partner` varchar(100) DEFAULT NULL,
  `tracking_no` varchar(64) DEFAULT NULL,
  `shipping_charge` decimal(15,2) DEFAULT NULL,
  `custom_totals` text,
  `no_wsb_tape` tinyint(1) NOT NULL DEFAULT '0',
  `no_invoice_with_shipment` tinyint(1) NOT NULL DEFAULT '0',
  `courier_partner_preference` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`suborder_id`),
  UNIQUE KEY `order_id` (`order_id`,`suborder_id`),
  UNIQUE KEY `buyer_invoice_id` (`buyer_invoice_id`),
  KEY `invoice_date` (`invoice_date`),
  KEY `shipping_method` (`shipping_method`),
  KEY `order_status_id` (`order_status_id`),
  KEY `date_added` (`date_added`),
  KEY `tracking_no` (`tracking_no`),
  CONSTRAINT `oc_suborder_order_id_fk` FOREIGN KEY (`order_id`) REFERENCES `oc_order` (`order_id`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.07 sec)

How to configure mongodb replicaset of 3 nodes in authentication mode

$
0
0

I had configured a mongodb replicaSet of 3 nodes. It was running fine But WHen i created a adminUser and dbuser on primary node and enabled the authorization in mongodb.conf file of all nodes then they are not connecting. Below is the output of rs.status() after enabling authorization. Kindly Help.

{
    "set" : "replset1",
    "date" : ISODate("2017-07-15T04:09:41.796Z"),
    "myState" : 3,
    "term" : NumberLong(1),
    "heartbeatIntervalMillis" : NumberLong(2000),
    "members" : [
        {
            "_id" : 1,
            "name" : "10.10.8.1:27017",
            "health" : 1,
            "state" : 3,
            "stateStr" : "RECOVERING",
            "uptime" : 54841,
            "optime" : {
                    "ts" : Timestamp(1500033801, 1),
                    "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2017-07-14T12:03:21Z"),
            "infoMessage" : "could not find member to sync from",
            "configVersion" : 1,
            "self" : true
        },
        {
            "_id" : 2,
            "name" : "10.10.8.2:27017",
            "health" : 0,
            "state" : 6,
            "stateStr" : "(not reachable/healthy)",
            "uptime" : 0,
            "optime" : {
                    "ts" : Timestamp(0, 0),
                    "t" : NumberLong(-1)
            },
            "optimeDate" : ISODate("1970-01-01T00:00:00Z"),
            "lastHeartbeat" : ISODate("2017-07-15T04:09:37.008Z"),
            "lastHeartbeatRecv" : ISODate("1970-01-01T00:00:00Z"),
            "pingMs" : NumberLong(0),
            "authenticated" : false,
            "configVersion" : -1
        },
        {
            "_id" : 3,
            "name" : "10.10.8.3:27017",
            "health" : 0,
            "state" : 6,
            "stateStr" : "(not reachable/healthy)",
            "uptime" : 0,
            "optime" : {
                    "ts" : Timestamp(0, 0),
                    "t" : NumberLong(-1)
            },
            "optimeDate" : ISODate("1970-01-01T00:00:00Z"),
            "lastHeartbeat" : ISODate("2017-07-15T04:09:37.136Z"),
            "lastHeartbeatRecv" : ISODate("1970-01-01T00:00:00Z"),
            "pingMs" : NumberLong(0),
            "authenticated" : false,
            "configVersion" : -1
        }
    ],
    "ok" : 1
}

Aurora rds -> MySQL rds cross region replication

$
0
0

I am looking to do cross region replication. I know exactly how to do it but want to do it in safest way possible from a networking perspective. I will call set external master but I don’t want my instances to be publicly accessible.

How does amazon do cross region replication via control panel securely without using publicly accessible option for rds

The reason I am using MySQL on other region is cost savings. Since it isn’t aurora to aurora I need to use set external master and setup replication manually.

Do I just put everything in same VPC?

Year Sequence with group

$
0
0

I want to create a new column, a sequence year from 2003 to 2006, with each groups.

# dt
NAME    ID    col3
AAA      1      SB
ABC      2      LA
CCC      3      AL

What I want is:

NAME    ID    col3    Year
AAA      1      SB    2003
AAA      1      SB    2004
AAA      1      SB    2005
AAA      1      SB    2006
ABC      2      LA    2003
ABC      2      LA    2004
ABC      2      LA    2005
ABC      2      LA    2006
CCC      3      AL    2003
CCC      3      AL    2004
CCC      3      AL    2005
CCC      3      AL    2006

I tried this:

dt[rep(1:.N, 4)][, Year := seq(2003, 2006), by = .(NAME, ID)]

I got the result. What I want to know is any better solution for this?

Upgrade SQL Server 2008 R2 to SQL Server 2012 and then set up data replication to SQL Server 2016

$
0
0

Currently I have a Windows 2008 server with SQL Server 2008 R2 and I want set up a data replication to a Windows 2016 Server with SQL Server 2016.

I am aware that the aforementioned is not possible because replication is only supported if each SQL Server endpoint is within two major versions of the current version of SQL Server.

If I upgrade SQL Server 2008 R2 to SQL Server 2012 on the Windows 2008 server then will I be able to set up replication to the Windows 2016 Server with SQL Server 2016?

Please help me on this.

Sync two postgres databases from two sperate locations with no network

$
0
0

I have 2 postgres databases running the same schemes on two different computers, that are not guaranteed to have any network connection while having to handle read/write requests.

Because they operate on two different locations, I'm trying to find a solution to merge them once in a while to keep data updated in both (I can connect them every couple of week, or pass files with a flash drive).

My main concern is that this databases have unique values in some of the tables (Auto Increment Primary Keys), and I'm not sure how to handle this - what if both dbs create the same key, for different data? Are there any tools that can merge automatically and output changes that were done?

(If it matters, using postgres 10, ubuntu env.)

Thanks

Amazon CDC replication with Mysql auora to SQL Server

$
0
0

I need Mysql auora to SQL Server data replication with Amazon RDS. I am not able to see any document which help me for this.

Steps for creating Mysql auora to SQL Server

Step 1: I created a Mysql RDS on Amazon account.

Step 2:

I need to enable CDC(change data capture) into mysql server, but I am not able to find any document which help me to enable the CDC (Mysql server)

Please help me on this,

Thanks

Aman middha

MySQL slave stuck on Applying batch of row changes (write)

$
0
0

I'm using Amazon RDS as a slave for my dedicated MySQL server (running outside of AWS).

Replication has been working alright for the past few months, until yesterday when I updated the structure of tables with 100+ million rows on the master.

My main database server has NVMe SSD drives rated up to 26000 write IOPS, while my RDS storage of 365 GB should have a baseline speed of 1095 IOPS according to the docs.

I ran several consecutive ALTER TABLE statements, that may have taken around one hour in total to complete on the master.

Due to the figures above, I was expecting some delay in replication, but it's now been 24+ hours and it looks like something is broken somewhere.

First, I have been receiving these email notifications from RDS every 10 minutes since yesterday:

  • 2019-01-24 13:27:21.825 Read Replica Replication Error - SQLError: 1205, reason: Slave SQL thread retried transaction 10 time(s) in vain, giving up. Consider raising the value of the slave_transaction_retries variable.
  • 2019-01-24 13:28:21.871 Replication for the Read Replica resumed
  • 2019-01-24 13:37:21.827 Read Replica Replication Error - SQLError: 1205, reason: Slave SQL thread retried transaction 10 time(s) in vain, giving up. Consider raising the value of the slave_transaction_retries variable.
  • 2019-01-24 13:38:21.814 Replication for the Read Replica resumed
  • ...

The pattern is always the same:

  • T: Replication error
  • T + 1min: Replication resumed
  • T + 10min: Replication error
  • T + 11min: Replication resumed
  • ...

SHOW SLAVE STATUS has been returning the same Exec_Master_Log_Pos value from the very beginning. Slave_SQL_Running_State says Applying batch of row changes (write).

SHOW PROCESSLIST on the slave shows a single query, running for 90000+ seconds:

Applying batch of row changes (write)

The CPU usage and write IOPS metrics of the slave show peaks every 5 minutes:

CPU

CPU

Write IOPS

Write IOPS

SHOW CREATE TABLE on the slave shows an updated table structure, so it looks to me that the changes have started to replicate.

The average write IOPS on the slave is ~300, average read IOPS ~40, which alone is weird as the total is way below the baseline of 1095 IOPS the storage should provide.

Given the average write IOPS, it may just be a matter of waiting a bit more for replication to complete, but I'm really starting to wonder if it will ever complete successfully.

Q: What do these "Replication Error" / "Replication Resumed" messages mean?

The message says that it's giving up, then that it's resuming, which is confusing me.

Moreover, I don't understand how a transaction could be failing: the slave should be executing only one transaction at a time, so there should be no deadlock or lock wait timeout occurring. If it's not a concurrency issue, and only one transaction is running, why would it give it up after only 10 minutes?

Is my replication failing? Or are these error messages due to some kind of system query issued by RDS, that could not complete due to the long running transaction?

If there is a permanent error here, how do I fix it?


Mark Pull subscriptions for reinitialization from Publisher

$
0
0

I have a transactional replication created where the subscriber gets initialized with a snapshot.I want to mark the subscriber for reinitialization from the publisher end.

I ran EXEC sp_reinitpullsubscription on publisher DB but that can only be run on the subscriber. exec sp_changepublication is not my friend either. There is an option using the UI "Reinitialize All Subscriptions" when right-clicked on the publisher but I am not able to find the SP that matches that.

enter image description hereMark for reinit option

Both - using the UI, running TSQL at the subscriber are not options for my scenario. I can only run TSQL at publisher. What repl sp can I use?

Problems when Reinitalizing MySQL Replication using LVM on a very large Database

$
0
0

This is MySQL Ver 14.14 Distrib 5.5.57, for debian-linux-gnu (x86_64) using readline 6.3 on Debian 8. This MYSQL only hosts Zabbix but it is a very active Zabbix with over 600 hosts constantly sending it metrics. The Zabbix database itself weighs over 350GB.

The monitoring team recently failed Zabbix over to a secondary MySQL server that has now become the principal. For some unknown reason, we started getting Primary Key constraint errors, so the decision was made to reinitialize replication from scratch on the old principal.

Here are the steps I'm taking to reinitalize replication:

On the Secodary (SECONDARY SERVER)

service mysql stop

On (PRIMARY SERVER) (NEED TWO OPEN SESSIONS IN SSH)

In the first SSH session connect to MySQL

  1. flush tables; flush tables with read lock; show master status;
  2. write down the bin file and log-file position Example: 'mysql-bin.001871', MASTER_LOG_POS = 21103447

In the second SSH session

  1. Create the snapshot: lvcreate --size 10G --snapshot --name snapMY01 /dev/mapper/vg_01-lv_mysql00

In the first SSH session still connected to MySQL

  1. unlock tables;

In the second SSH session

SCP copy the snapshot contents from snapshot to /var/lib/mysql to secondary

  1. mount /dev/vg_01/lv_mysql00 /tmp/mysql_restore/
  2. cd /tmp/mysql_restore/var/lib/mysql/
  3. scp -i ~/.ssh/some_ssh_key -r ./ somelogin@SECONDARY_SERVER:/var/lib/mysql/ or alternatively you can use netcat

On (SECONDARY SERVER)

  1. switch to root account: sudo su -
  2. cd /var/lib/mysql
  3. rm debian-5.5.flag master.info mysqld-relay-bin.* relay-log.info mysql_upgrade_info
  4. service mysql start
  5. Connect to MySQL
  6. stop slave;
  7. change master to MASTER_HOST = 'IP.ADDRESS.PRIMARY.SERVER', MASTER_USER = 'repli', MASTER_PASSWORD = 'repli', MASTER_LOG_FILE = 'mysql-bin.somefilenumber', MASTER_LOG_POS = some_log_pos;
  8. start slave;
  9. show slave status\G;

On (PRIMARY SERVER)

  1. Cleanup mount
  2. umount /tmp/mysql_restore
  3. lvremove /dev/vg_01/snapMY01 Do you really want to remove and DISCARD active logical volume snapMY01? [y/n]: y

But, at the point that MySQL is started, there are lots of innodb corruption errors and a memory dump of the application.

InnoDB: Failing assertion: !page || (ibool)!!page_is_comp(page) == dict_table_is_comp(index->table)
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.
Fatal signal 6 while backtracing

The innodb db and logs files match in size between the principal and secondary so I don't understand where the corruption is coming from. I am able to start MySQL with force_recovery = 4 on the secondary but that's useless to me.

So these are my questions so far:

Is flush tables; flush tables with read lock; sufficent when taking an LVM snapshot of a very active database?

If not, is there anyway to take a coherent and viable snapshot of /var/lib/mysql without shutting down MySQL and Zabbix?

I am also considering mylvmbackup but I don't see what difference that would make since I'm already creating a lvm snapshot.

I have another working replica, so is it possible to chain replicas?

This would result in master -> slave -> slave

UPDATE 10/11/2017

2nd attempt, this time I shutdown the first secondary and copied its data via SCP to the second server. I am still getting corruption errors on the ibdata and ib_logfile files.

I ran a mysqlcheck on the whole server and can see entries like this:

zabbix.alerts
Warning  : InnoDB: Index 'alerts_1' contains 1525245 entries, should be 1525262.
Warning  : InnoDB: Index 'alerts_2' contains 1525245 entries, should be 1525262.
Warning  : InnoDB: Index 'alerts_3' contains 1525245 entries, should be 1525262.

CHECK TABLE alerts; on the secondary I copied from, runs without error.

Still no solution at hand to bring back the other secondary server.

UPDATE 10/12/2017

Yesterday I stopped MySQL and took a snapshot after shutdown. Copied the files with the netcat soltuion

source: tar cfv - * | netcat source_server_ip 9999

target: netcat -l -p 9999 | tar xfv -

And then started MySQL.

Server start resulted in MySQL replaying transactions and then getting these errors over and over.

InnoDB: A new raw disk partition was initialized or
InnoDB: innodb_force_recovery is on: we do not allow
InnoDB: database modifications by the user. Shut down
InnoDB: mysqld and edit my.cnf so that newraw is replaced
InnoDB: with raw, and innodb_force_... is removed.
171011 13:12:24 [ERROR] Slave SQL: Error 'Got error -1 from storage engine' on query. Default database: 'zabbix'. Query: 'insert into history_log (id,itemid,clock,ns,timestamp,source,severity,value,logeventid) values (2371918228,443643,1507721727,565645171,0,'',0,'11/10
/2017 13:30:41.558 [EC_CORE]Processing element \'variable\' with name \'tmpData_PositionFiscale\'.',0)', Error_code: 1030
171011 13:12:24 [Warning] Slave: Got error -1 from storage engine Error_code: 1030
171011 13:12:24 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.008917' position 447481453
171011 13:12:36 [Note] /usr/sbin/mysqld: Normal shutdown

171011 13:12:36 [Note] Event Scheduler: Purging the queue. 0 events
171011 13:12:36 [Note] Slave I/O thread killed while reading event
171011 13:12:36 [Note] Slave I/O thread exiting, read up to log 'mysql-bin.008919', position 199662133
171011 13:12:36  InnoDB: Starting shutdown...
171011 13:12:38  InnoDB: Shutdown completed; log sequence number 17456777783702
171011 13:12:38 [Note] /usr/sbin/mysqld: Shutdown complete

I then put force recovery to 3 which stopped the endless stop and start loops. This option stops transaction rollbacks from occuring.

Today I

  1. Stopped MySQL on the other secondary
  2. Unmounted /var/lib/mysql
  3. lvm snapshot of /var/lib/mysql
  4. reformatted /var/lib/mysql on secondary I'm repairing.

Tomorrow, if this fails, I am going to restore the secondary with a backup of the working secondary.

Secondary and Arbiter stuck in Startup

$
0
0

I'm using MongoDB version 3.0.0. I'm trying to setup mongodb replication on our machine. Replication was initially setup but due to some changes on the VM the entire thing crashed. When I tried to set it up again, the secondary and Arbiter became stuck in StartUp Mode.

In the mongoDB conf file I have set

replSet=ReplicaSet1

I added 2 machines using the command

rs.add("10.235.96.12:27017")
rs.add("10.235.96.12:27017")

But after this on the primary when I do a rs.status() secondary and arbiter are still shown in StartUp

ReplicaSet1:PRIMARY> rs.status()
{
    "set" : "ReplicaSet1",
    "date" : ISODate("2015-07-31T04:45:57.260Z"),
    "myState" : 1,
    "members" : [
            {
                    "_id" : 0,
                    "name" : "BOSPROD9:27017",
                    "health" : 1,
                    "state" : 1,
                    "stateStr" : "PRIMARY",
                    "uptime" : 63104,
                    "optime" : Timestamp(1438257913, 1),
                    "optimeDate" : ISODate("2015-07-30T12:05:13Z"),
                    "electionTime" : Timestamp(1438254975, 2),
                    "electionDate" : ISODate("2015-07-30T11:16:15Z"),
                    "configVersion" : 7,
                    "self" : true
            },
            {
                    "_id" : 1,
                    "name" : "10.235.96.12:27017",
                    "health" : 1,
                    "state" : 0,
                    "stateStr" : "STARTUP",
                    "uptime" : 62663,
                    "optime" : Timestamp(0, 0),
                    "optimeDate" : ISODate("1970-01-01T00:00:00Z"),
                    "lastHeartbeat" : ISODate("2015-07-31T04:45:56.520Z"),
                    "lastHeartbeatRecv" : ISODate("1970-01-01T00:00:00Z"),
                    "pingMs" : 0,
                    "configVersion" : -2
            },
            {
                    "_id" : 2,
                    "name" : "10.235.96.13:27017",
                    "health" : 1,
                    "state" : 0,
                    "stateStr" : "STARTUP",
                    "uptime" : 60043,
                    "lastHeartbeat" : ISODate("2015-07-31T04:45:55.786Z"),
                    "lastHeartbeatRecv" : ISODate("1970-01-01T00:00:00Z"),
                    "pingMs" : 0,
                    "configVersion" : -2
            }
    ],
    "ok" : 1
}

When I try to do a rs.conf on the Secondary or Arbiter I get the message

2015-07-31T05:23:07.927+0000 E QUERY    Error: Could not retrieve replica set config: {
    "info" : "run rs.initiate(...) if not yet done for the set",
    "ok" : 0,
    "errmsg" : "no replset config has been received",
    "code" : 94
}

I did try multiple times to clean all the local.0, local.1 files in all the machines and also removed all the journal files from the journal folder as well. Still I'm getting the same issue. Can someone tell me what is it I'm doing wrong here?

I have set replset on all the members. Tried starting in standalone mode and it works.

MongoDB 3.2.10 Index rebuilding did not complete: 11000 E11000 duplicate key error collection

$
0
0

MongoDB 3.2.10

Getting the following error when adding a replica set as WiredTiger. This is sharded cluster ( 3 shards nodes ).

2 Shards replica sets created using wiredTiger storage so only 1 shard is having a problem when creating the replica set.

2016-11-11T00:51:55.005+0000 I -     [initandlisten]   Index Build: 39291000/39372845 99%
2016-11-11T00:51:58.032+0000 I -     [initandlisten]   Index Build: 39345000/39372845 99%
2016-11-11T00:52:04.696+0000 E INDEX [initandlisten] Index rebuilding did not complete: 11000 E11000 duplicate key error collection: XYZ.ALBUM index: _id_                                                                         dup key: { : 59000012923579 }
2016-11-11T00:52:04.696+0000 I INDEX [initandlisten] note: restart the server with --noIndexBuildRetry to skip index rebuilds
2016-11-11T00:52:04.696+0000 I -     [initandlisten] Fatal Assertion 26100
2016-11-11T00:52:04.696+0000 I -     [initandlisten]

I did not have issue when I was using mmapv1 replica set but now I have dropped old replica set.

How to fix this issue?

differences between hot standby vs warm standby postgresql?

Viewing all 17268 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>