SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Database replication


 Vatroslav Mileusnić, univ.bacc.inf.

 mileusnic.vatroslav@gmail.com
What is replication?
Database replication - creating and maintaining
 multiple copies of the same database
Types of replication:
  synchronous and asynchronous
  master-slave and master-master (multimaster)
  ...
Synchronous                     Asynchronous
propagates every transaction      propagates multiple
                                    transactions
creating connections for
  every transaction causes        uses less network bandwidth
  bigger overhead because           and offers better
                                    performance
stops replication if one server
   is unavailable                 high availability of replication
                                     group
                                  possibility of dana collision
                                  possibility of lost transactions
Master-slave                  Multimaster
1 master, other slaves        all servers are masters
write on master               write on any server,
propagate to slaves             propagate to others
divide reading between        divide reading between all
  slaves                        servers
configure slave to take       powerful and flexible
  over as master if the         solution, but also very
  original master falls out     complex
Multimaster replication problems
possibility of conflict in asynchronous replication
  update conflict
  unique conflict
  delete conflict
possible solutions:
  configure application to write in only one database
  configure application to write in another database if the first
    one falls out
Multimaster replication problems
very short intervals of empting queries
  uses a huge number of system resources
  starting and stopping the process requires a lot processor
     cycles
solution:
  don't exaggerate with application requrements
  intervals of 1 or more minutes are fine
Multimaster replication problems
tool for monitoring replication system
  if using synchronous replication, all servers have to be
      active and ready
  automated tool that periodicaly checks the status of all
    servers
  if the tool decides a server is unavailable, it should try to
      restart it, and if it fails, remove it from replication, so
      replication can go on
Primjer replikacije
Asynchronous master-slave replication in MySQL
Asynchronous master-slave replication in PostgreSQL
Asynchronous multimaster replication in CouchDB


Displayed solutions are not configured for production
  servers, but are good enough for learning and
  understanding
MySQL
On servers create a database (replicate_me)
On master server change /etc/mysql/my.cnf
  #skip-networking
  #bind-address         = 127.0.0.1
  log-bin = /var/log/mysql/mysql-bin.log
  binlog-do-db = replicate_me
  server-id=1
Save file and restart MySQL
MySQL
Enter MySQL and grant rights to the slave user
  GRANT REPLICATION SLAVE ON *.* TO
   slave_user@192.168.1.101 IDENTIFIED BY 'password';
  GRANT RELOAD SLAVE ON *.* TO
   slave_user@192.168.1.101 IDENTIFIED BY 'password';
  GRANT SUPER SLAVE ON *.* TO
   slave_user@192.168.1.101 IDENTIFIED BY 'password';
  FLUSH PRIVILEGES;
MySQL
Perform commands to display master's status
  USE replicate_me;
  SHOW MASTER STATUS;
     take note of File and Position columns
  UNLOCK TABLES;
MySQL
On slave server add in /etc/mysql/my.cnf
  server-id = 2
  master-host = 192.168.1.100
  master-user = slave_user
  master-password = password
  master-connect-retry = 60
  replicate-do-db = replicate_me
MySQL
On slave server, in MySQL, do
  STOP SLAVE;
  CHANGE MASTER TO MASTER_HOST = '192.168.1.100'
  MASTER_USER='slave_user',
   MASTER_PASSWORD='password',
   MASTER_LOG_FILE='mysql-bin.000001',
   MASTER_LOG_POS=106;
  START SLAVE;
PostgreSQL
As postgres user initialize cluster on both master and
  slave servers
  initdb /var/lib/pgsql/data
Allow communication of postgres user
  SSH or another way
PostgreSQL
On master in /var/lib/pgsql/data/postgresql.conf
   wal_level = hot_standby
   archive_mode = on
   archive_command =
     'scp %p postgres@192.168.1.101:/var/lib/pgsql/archive/%f'
Start cluster
   pg_ctl -D /var/lib/pgsql/data start
PostgreSQL
Perform backup
  psql -c "SELECT pg_start_backup('initial backup')"
    template1
  tar cvf pg_base_backup.tar /var/lib/pgsql/data
  psql -c "SELECT pg_stop_backup()" template1
Copy the result file to slave and unpack
  mv /var/lib/pgsql/pg_base_backup.tar /
  tar xvf pg_base_backup.tar
On slave, delete /data/postmaster.pid
PostgreSQL
Master, /var/lib/pgsql/data/postgresql.conf
  listen_addresses = '*'
  max_wal_senders = 5
  wal_keep_segments = 32
Master, /var/lib/pgsql/data/pg_hba.conf
  host replication postgres 192.168.1.101/24 trust
PostgreSQL
On slave server /var/lib/pgsql/data/postgresql.conf
  hot_standby = on
Add recovery.conf
  standby_mode = 'on'
  primary_conninfo = 'host=192.168.1.100 port=5432
     user=postgres'
  should contain additional settings
Start servers
  pg_ctl -D /var/lib/pgsql/data start
CouchDB
Access administration console Futon
   <computer's IP address>:5984/_utils
In Configuration set it so it listens to all IP addresses
   bind_address = 0.0.0.0
Create databases
In Replicator set
   <another computer's IP
     address>/database_on_other_computer
   turn on Continuous, click Replicate
CouchDB
To do multimaster replication, repeat steps on other
  computer
  <another computer's IP
    address>/database_on_first_computer
  turn on Continuous
  click Replicate
Zaključak
Impressions
  usual MySQL vs PostgreSQL discussion
  realisticaly: we won't choose a system solely based on
    whose replication is better
  for small projects and home usage, CouchDB


hr.linkedin.com/in/vatroslavmileusnic
Questions?

Weitere ähnliche Inhalte

Was ist angesagt?

Indexing & Query Optimization
Indexing & Query OptimizationIndexing & Query Optimization
Indexing & Query OptimizationMongoDB
 
KSQL-ops! Running ksqlDB in the Wild (Simon Aubury, ThoughtWorks) Kafka Summi...
KSQL-ops! Running ksqlDB in the Wild (Simon Aubury, ThoughtWorks) Kafka Summi...KSQL-ops! Running ksqlDB in the Wild (Simon Aubury, ThoughtWorks) Kafka Summi...
KSQL-ops! Running ksqlDB in the Wild (Simon Aubury, ThoughtWorks) Kafka Summi...confluent
 
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013mumrah
 
ProxySQL Cluster - Percona Live 2022
ProxySQL Cluster - Percona Live 2022ProxySQL Cluster - Percona Live 2022
ProxySQL Cluster - Percona Live 2022René Cannaò
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDBvaluebound
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisDvir Volk
 
MySQL Group Replication
MySQL Group ReplicationMySQL Group Replication
MySQL Group ReplicationKenny Gryp
 
Sql server logshipping
Sql server logshippingSql server logshipping
Sql server logshippingZeba Ansari
 
Sharding
ShardingSharding
ShardingMongoDB
 
NOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQLNOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQLRamakant Soni
 
Grokking Techtalk #40: Consistency and Availability tradeoff in database cluster
Grokking Techtalk #40: Consistency and Availability tradeoff in database clusterGrokking Techtalk #40: Consistency and Availability tradeoff in database cluster
Grokking Techtalk #40: Consistency and Availability tradeoff in database clusterGrokking VN
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBRavi Teja
 
High Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando PatroniHigh Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando PatroniZalando Technology
 
ProxySQL for MySQL
ProxySQL for MySQLProxySQL for MySQL
ProxySQL for MySQLMydbops
 

Was ist angesagt? (20)

Indexing & Query Optimization
Indexing & Query OptimizationIndexing & Query Optimization
Indexing & Query Optimization
 
KSQL-ops! Running ksqlDB in the Wild (Simon Aubury, ThoughtWorks) Kafka Summi...
KSQL-ops! Running ksqlDB in the Wild (Simon Aubury, ThoughtWorks) Kafka Summi...KSQL-ops! Running ksqlDB in the Wild (Simon Aubury, ThoughtWorks) Kafka Summi...
KSQL-ops! Running ksqlDB in the Wild (Simon Aubury, ThoughtWorks) Kafka Summi...
 
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
 
MySQL Backup & Recovery
MySQL Backup & RecoveryMySQL Backup & Recovery
MySQL Backup & Recovery
 
ProxySQL Cluster - Percona Live 2022
ProxySQL Cluster - Percona Live 2022ProxySQL Cluster - Percona Live 2022
ProxySQL Cluster - Percona Live 2022
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDB
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
PostgreSQL replication
PostgreSQL replicationPostgreSQL replication
PostgreSQL replication
 
MySQL Group Replication
MySQL Group ReplicationMySQL Group Replication
MySQL Group Replication
 
Sql server logshipping
Sql server logshippingSql server logshipping
Sql server logshipping
 
Sharding
ShardingSharding
Sharding
 
NOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQLNOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQL
 
Grokking Techtalk #40: Consistency and Availability tradeoff in database cluster
Grokking Techtalk #40: Consistency and Availability tradeoff in database clusterGrokking Techtalk #40: Consistency and Availability tradeoff in database cluster
Grokking Techtalk #40: Consistency and Availability tradeoff in database cluster
 
Postgresql
PostgresqlPostgresql
Postgresql
 
Nosql databases
Nosql databasesNosql databases
Nosql databases
 
Polyglot Persistence
Polyglot Persistence Polyglot Persistence
Polyglot Persistence
 
MySQL Transactions
MySQL TransactionsMySQL Transactions
MySQL Transactions
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
High Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando PatroniHigh Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando Patroni
 
ProxySQL for MySQL
ProxySQL for MySQLProxySQL for MySQL
ProxySQL for MySQL
 

Andere mochten auch

Replication in Distributed Database
Replication in Distributed DatabaseReplication in Distributed Database
Replication in Distributed DatabaseAbhilasha Lahigude
 
Data Replication in Distributed System
Data Replication in  Distributed SystemData Replication in  Distributed System
Data Replication in Distributed SystemEhsan Hessami
 
Database , 13 Replication
Database , 13 ReplicationDatabase , 13 Replication
Database , 13 ReplicationAli Usman
 
Chapter 14 replication
Chapter 14 replicationChapter 14 replication
Chapter 14 replicationAbDul ThaYyal
 
Fragmentation and types of fragmentation in Distributed Database
Fragmentation and types of fragmentation in Distributed DatabaseFragmentation and types of fragmentation in Distributed Database
Fragmentation and types of fragmentation in Distributed DatabaseAbhilasha Lahigude
 
Mysql data replication
Mysql data replicationMysql data replication
Mysql data replicationTuấn Ngô
 
Data Replication In Cloud Computing
Data Replication In Cloud ComputingData Replication In Cloud Computing
Data Replication In Cloud ComputingRahul Garg
 
20100522 from object_to_database_replication_pedone_lecture01-02
20100522 from object_to_database_replication_pedone_lecture01-0220100522 from object_to_database_replication_pedone_lecture01-02
20100522 from object_to_database_replication_pedone_lecture01-02Computer Science Club
 
NoSQL Simplified: Schema vs. Schema-less
NoSQL Simplified: Schema vs. Schema-lessNoSQL Simplified: Schema vs. Schema-less
NoSQL Simplified: Schema vs. Schema-lessInfiniteGraph
 
Replication Management
Replication ManagementReplication Management
Replication ManagementRevolucion
 
MySQL Conference 2011 -- The Secret Sauce of Sharding -- Ryan Thiessen
MySQL Conference 2011 -- The Secret Sauce of Sharding -- Ryan ThiessenMySQL Conference 2011 -- The Secret Sauce of Sharding -- Ryan Thiessen
MySQL Conference 2011 -- The Secret Sauce of Sharding -- Ryan Thiessenryanthiessen
 
The Shard Revisited: Tools and Techniques Used at Etsy
The Shard Revisited: Tools and Techniques Used at EtsyThe Shard Revisited: Tools and Techniques Used at Etsy
The Shard Revisited: Tools and Techniques Used at Etsyjgoulah
 
Distributed process and scheduling
Distributed process and scheduling Distributed process and scheduling
Distributed process and scheduling SHATHAN
 
Chapter 11c coordination agreement
Chapter 11c coordination agreementChapter 11c coordination agreement
Chapter 11c coordination agreementAbDul ThaYyal
 
Scheduling in distributed systems - Andrii Vozniuk
Scheduling in distributed systems - Andrii VozniukScheduling in distributed systems - Andrii Vozniuk
Scheduling in distributed systems - Andrii VozniukAndrii Vozniuk
 
Out of the box replication in postgres 9.4
Out of the box replication in postgres 9.4Out of the box replication in postgres 9.4
Out of the box replication in postgres 9.4Denish Patel
 

Andere mochten auch (20)

Replication in Distributed Database
Replication in Distributed DatabaseReplication in Distributed Database
Replication in Distributed Database
 
Data Replication in Distributed System
Data Replication in  Distributed SystemData Replication in  Distributed System
Data Replication in Distributed System
 
Database , 13 Replication
Database , 13 ReplicationDatabase , 13 Replication
Database , 13 Replication
 
Chapter 14 replication
Chapter 14 replicationChapter 14 replication
Chapter 14 replication
 
Fragmentation and types of fragmentation in Distributed Database
Fragmentation and types of fragmentation in Distributed DatabaseFragmentation and types of fragmentation in Distributed Database
Fragmentation and types of fragmentation in Distributed Database
 
Mysql data replication
Mysql data replicationMysql data replication
Mysql data replication
 
Data Replication In Cloud Computing
Data Replication In Cloud ComputingData Replication In Cloud Computing
Data Replication In Cloud Computing
 
20100522 from object_to_database_replication_pedone_lecture01-02
20100522 from object_to_database_replication_pedone_lecture01-0220100522 from object_to_database_replication_pedone_lecture01-02
20100522 from object_to_database_replication_pedone_lecture01-02
 
DAG
DAGDAG
DAG
 
NoSQL Simplified: Schema vs. Schema-less
NoSQL Simplified: Schema vs. Schema-lessNoSQL Simplified: Schema vs. Schema-less
NoSQL Simplified: Schema vs. Schema-less
 
Replication Management
Replication ManagementReplication Management
Replication Management
 
MySQL Conference 2011 -- The Secret Sauce of Sharding -- Ryan Thiessen
MySQL Conference 2011 -- The Secret Sauce of Sharding -- Ryan ThiessenMySQL Conference 2011 -- The Secret Sauce of Sharding -- Ryan Thiessen
MySQL Conference 2011 -- The Secret Sauce of Sharding -- Ryan Thiessen
 
The Shard Revisited: Tools and Techniques Used at Etsy
The Shard Revisited: Tools and Techniques Used at EtsyThe Shard Revisited: Tools and Techniques Used at Etsy
The Shard Revisited: Tools and Techniques Used at Etsy
 
Distributed process and scheduling
Distributed process and scheduling Distributed process and scheduling
Distributed process and scheduling
 
Chapter 11c coordination agreement
Chapter 11c coordination agreementChapter 11c coordination agreement
Chapter 11c coordination agreement
 
Partitioning
PartitioningPartitioning
Partitioning
 
Scheduling in distributed systems - Andrii Vozniuk
Scheduling in distributed systems - Andrii VozniukScheduling in distributed systems - Andrii Vozniuk
Scheduling in distributed systems - Andrii Vozniuk
 
Out of the box replication in postgres 9.4
Out of the box replication in postgres 9.4Out of the box replication in postgres 9.4
Out of the box replication in postgres 9.4
 
Best examples of reputation management: international experience
Best examples of reputation management: international experienceBest examples of reputation management: international experience
Best examples of reputation management: international experience
 
L15 marcas que destacan más y obtienen mejores resultados eng
L15 marcas que destacan más y obtienen mejores resultados engL15 marcas que destacan más y obtienen mejores resultados eng
L15 marcas que destacan más y obtienen mejores resultados eng
 

Ähnlich wie Database Replication

MySQL database replication
MySQL database replicationMySQL database replication
MySQL database replicationPoguttuezhiniVP
 
MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017Dave Stokes
 
Architecting cloud
Architecting cloudArchitecting cloud
Architecting cloudTahsin Hasan
 
MySQL HA with PaceMaker
MySQL HA with  PaceMakerMySQL HA with  PaceMaker
MySQL HA with PaceMakerKris Buytaert
 
Mater,slave on mysql
Mater,slave on mysqlMater,slave on mysql
Mater,slave on mysqlVasudeva Rao
 
Mysql replication @ gnugroup
Mysql replication @ gnugroupMysql replication @ gnugroup
Mysql replication @ gnugroupJayant Chutke
 
MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016Dave Stokes
 
PostgreSQL Replication in 10 Minutes - SCALE
PostgreSQL Replication in 10  Minutes - SCALEPostgreSQL Replication in 10  Minutes - SCALE
PostgreSQL Replication in 10 Minutes - SCALEPostgreSQL Experts, Inc.
 
MySqL Failover by Weatherly Cloud Computing USA
MySqL Failover by Weatherly Cloud Computing USAMySqL Failover by Weatherly Cloud Computing USA
MySqL Failover by Weatherly Cloud Computing USAHarry Gonzalez
 
MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4
MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4
MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4Ulf Wendel
 
Writing & Sharing Great Modules - Puppet Camp Boston
Writing & Sharing Great Modules - Puppet Camp BostonWriting & Sharing Great Modules - Puppet Camp Boston
Writing & Sharing Great Modules - Puppet Camp BostonPuppet
 
My sql failover test using orchestrator
My sql failover test  using orchestratorMy sql failover test  using orchestrator
My sql failover test using orchestratorYoungHeon (Roy) Kim
 
Highly Available Load Balanced Galera MySql Cluster
Highly Available Load Balanced  Galera MySql ClusterHighly Available Load Balanced  Galera MySql Cluster
Highly Available Load Balanced Galera MySql ClusterAmr Fawzy
 
Meb Backup & Recovery Performance
Meb Backup & Recovery PerformanceMeb Backup & Recovery Performance
Meb Backup & Recovery PerformanceKeith Hollman
 
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Milan ...
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Milan ...Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Milan ...
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Milan ...Codemotion
 
MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016Dave Stokes
 

Ähnlich wie Database Replication (20)

MySQL database replication
MySQL database replicationMySQL database replication
MySQL database replication
 
MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017
 
Mysql
MysqlMysql
Mysql
 
Architecting cloud
Architecting cloudArchitecting cloud
Architecting cloud
 
MySQL HA with PaceMaker
MySQL HA with  PaceMakerMySQL HA with  PaceMaker
MySQL HA with PaceMaker
 
Mater,slave on mysql
Mater,slave on mysqlMater,slave on mysql
Mater,slave on mysql
 
Mysql replication @ gnugroup
Mysql replication @ gnugroupMysql replication @ gnugroup
Mysql replication @ gnugroup
 
MySQL Failover - Cubexs Weatherly
MySQL Failover - Cubexs WeatherlyMySQL Failover - Cubexs Weatherly
MySQL Failover - Cubexs Weatherly
 
MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016
 
PostgreSQL Replication in 10 Minutes - SCALE
PostgreSQL Replication in 10  Minutes - SCALEPostgreSQL Replication in 10  Minutes - SCALE
PostgreSQL Replication in 10 Minutes - SCALE
 
MySqL Failover by Weatherly Cloud Computing USA
MySqL Failover by Weatherly Cloud Computing USAMySqL Failover by Weatherly Cloud Computing USA
MySqL Failover by Weatherly Cloud Computing USA
 
MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4
MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4
MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4
 
Writing & Sharing Great Modules - Puppet Camp Boston
Writing & Sharing Great Modules - Puppet Camp BostonWriting & Sharing Great Modules - Puppet Camp Boston
Writing & Sharing Great Modules - Puppet Camp Boston
 
Introduction to Galera Cluster
Introduction to Galera ClusterIntroduction to Galera Cluster
Introduction to Galera Cluster
 
My sql failover test using orchestrator
My sql failover test  using orchestratorMy sql failover test  using orchestrator
My sql failover test using orchestrator
 
Highly Available Load Balanced Galera MySql Cluster
Highly Available Load Balanced  Galera MySql ClusterHighly Available Load Balanced  Galera MySql Cluster
Highly Available Load Balanced Galera MySql Cluster
 
Meb Backup & Recovery Performance
Meb Backup & Recovery PerformanceMeb Backup & Recovery Performance
Meb Backup & Recovery Performance
 
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Milan ...
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Milan ...Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Milan ...
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Milan ...
 
MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016
 
Mysql ppt
Mysql pptMysql ppt
Mysql ppt
 

Database Replication

  • 1. Database replication Vatroslav Mileusnić, univ.bacc.inf. mileusnic.vatroslav@gmail.com
  • 2. What is replication? Database replication - creating and maintaining multiple copies of the same database Types of replication: synchronous and asynchronous master-slave and master-master (multimaster) ...
  • 3. Synchronous Asynchronous propagates every transaction propagates multiple transactions creating connections for every transaction causes uses less network bandwidth bigger overhead because and offers better performance stops replication if one server is unavailable high availability of replication group possibility of dana collision possibility of lost transactions
  • 4. Master-slave Multimaster 1 master, other slaves all servers are masters write on master write on any server, propagate to slaves propagate to others divide reading between divide reading between all slaves servers configure slave to take powerful and flexible over as master if the solution, but also very original master falls out complex
  • 5. Multimaster replication problems possibility of conflict in asynchronous replication update conflict unique conflict delete conflict possible solutions: configure application to write in only one database configure application to write in another database if the first one falls out
  • 6. Multimaster replication problems very short intervals of empting queries uses a huge number of system resources starting and stopping the process requires a lot processor cycles solution: don't exaggerate with application requrements intervals of 1 or more minutes are fine
  • 7. Multimaster replication problems tool for monitoring replication system if using synchronous replication, all servers have to be active and ready automated tool that periodicaly checks the status of all servers if the tool decides a server is unavailable, it should try to restart it, and if it fails, remove it from replication, so replication can go on
  • 8. Primjer replikacije Asynchronous master-slave replication in MySQL Asynchronous master-slave replication in PostgreSQL Asynchronous multimaster replication in CouchDB Displayed solutions are not configured for production servers, but are good enough for learning and understanding
  • 9. MySQL On servers create a database (replicate_me) On master server change /etc/mysql/my.cnf #skip-networking #bind-address = 127.0.0.1 log-bin = /var/log/mysql/mysql-bin.log binlog-do-db = replicate_me server-id=1 Save file and restart MySQL
  • 10. MySQL Enter MySQL and grant rights to the slave user GRANT REPLICATION SLAVE ON *.* TO slave_user@192.168.1.101 IDENTIFIED BY 'password'; GRANT RELOAD SLAVE ON *.* TO slave_user@192.168.1.101 IDENTIFIED BY 'password'; GRANT SUPER SLAVE ON *.* TO slave_user@192.168.1.101 IDENTIFIED BY 'password'; FLUSH PRIVILEGES;
  • 11. MySQL Perform commands to display master's status USE replicate_me; SHOW MASTER STATUS; take note of File and Position columns UNLOCK TABLES;
  • 12. MySQL On slave server add in /etc/mysql/my.cnf server-id = 2 master-host = 192.168.1.100 master-user = slave_user master-password = password master-connect-retry = 60 replicate-do-db = replicate_me
  • 13. MySQL On slave server, in MySQL, do STOP SLAVE; CHANGE MASTER TO MASTER_HOST = '192.168.1.100' MASTER_USER='slave_user', MASTER_PASSWORD='password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=106; START SLAVE;
  • 14. PostgreSQL As postgres user initialize cluster on both master and slave servers initdb /var/lib/pgsql/data Allow communication of postgres user SSH or another way
  • 15. PostgreSQL On master in /var/lib/pgsql/data/postgresql.conf wal_level = hot_standby archive_mode = on archive_command = 'scp %p postgres@192.168.1.101:/var/lib/pgsql/archive/%f' Start cluster pg_ctl -D /var/lib/pgsql/data start
  • 16. PostgreSQL Perform backup psql -c "SELECT pg_start_backup('initial backup')" template1 tar cvf pg_base_backup.tar /var/lib/pgsql/data psql -c "SELECT pg_stop_backup()" template1 Copy the result file to slave and unpack mv /var/lib/pgsql/pg_base_backup.tar / tar xvf pg_base_backup.tar On slave, delete /data/postmaster.pid
  • 17. PostgreSQL Master, /var/lib/pgsql/data/postgresql.conf listen_addresses = '*' max_wal_senders = 5 wal_keep_segments = 32 Master, /var/lib/pgsql/data/pg_hba.conf host replication postgres 192.168.1.101/24 trust
  • 18. PostgreSQL On slave server /var/lib/pgsql/data/postgresql.conf hot_standby = on Add recovery.conf standby_mode = 'on' primary_conninfo = 'host=192.168.1.100 port=5432 user=postgres' should contain additional settings Start servers pg_ctl -D /var/lib/pgsql/data start
  • 19. CouchDB Access administration console Futon <computer's IP address>:5984/_utils In Configuration set it so it listens to all IP addresses bind_address = 0.0.0.0 Create databases In Replicator set <another computer's IP address>/database_on_other_computer turn on Continuous, click Replicate
  • 20. CouchDB To do multimaster replication, repeat steps on other computer <another computer's IP address>/database_on_first_computer turn on Continuous click Replicate
  • 21. Zaključak Impressions usual MySQL vs PostgreSQL discussion realisticaly: we won't choose a system solely based on whose replication is better for small projects and home usage, CouchDB hr.linkedin.com/in/vatroslavmileusnic