SlideShare a Scribd company logo
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?

More Related Content

What's hot

0wn-premises: Bypassing Microsoft Defender for Identity
0wn-premises: Bypassing Microsoft Defender for Identity0wn-premises: Bypassing Microsoft Defender for Identity
0wn-premises: Bypassing Microsoft Defender for Identity
Nikhil Mittal
 
MySQL Group Replication - Ready For Production? (2018-04)
MySQL Group Replication - Ready For Production? (2018-04)MySQL Group Replication - Ready For Production? (2018-04)
MySQL Group Replication - Ready For Production? (2018-04)
Kenny Gryp
 
Stephan Ewen - Scaling to large State
Stephan Ewen - Scaling to large StateStephan Ewen - Scaling to large State
Stephan Ewen - Scaling to large State
Flink Forward
 
Evading Microsoft ATA for Active Directory Domination
Evading Microsoft ATA for Active Directory DominationEvading Microsoft ATA for Active Directory Domination
Evading Microsoft ATA for Active Directory Domination
Nikhil Mittal
 
How to Manage Scale-Out Environments with MariaDB MaxScale
How to Manage Scale-Out Environments with MariaDB MaxScaleHow to Manage Scale-Out Environments with MariaDB MaxScale
How to Manage Scale-Out Environments with MariaDB MaxScale
MariaDB plc
 
Domain Name Service
Domain Name ServiceDomain Name Service
Domain Name Service
webhostingguy
 
Mysql-MHA
Mysql-MHAMysql-MHA
Mysql-MHA
Louis liu
 
Introduction to Galera Cluster
Introduction to Galera ClusterIntroduction to Galera Cluster
Introduction to Galera Cluster
Codership Oy - Creators of Galera Cluster
 
Fluentd with MySQL
Fluentd with MySQLFluentd with MySQL
Fluentd with MySQL
I Goo Lee
 
ProxySQL for MySQL
ProxySQL for MySQLProxySQL for MySQL
ProxySQL for MySQL
Mydbops
 
Clustering and High Availability
Clustering and High Availability Clustering and High Availability
Clustering and High Availability
Information Technology
 
ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016
Derek Downey
 
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
Severalnines
 
PostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldPostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized World
Jignesh Shah
 
Linux and firewall
Linux and firewallLinux and firewall
Linux and firewall
Mhmud Khraibene
 
4 andrii kudiurov - web application security 101
4   andrii kudiurov - web application security 1014   andrii kudiurov - web application security 101
4 andrii kudiurov - web application security 101
Ievgenii Katsan
 
Using all of the high availability options in MariaDB
Using all of the high availability options in MariaDBUsing all of the high availability options in MariaDB
Using all of the high availability options in MariaDB
MariaDB plc
 
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdfProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
Jesmar Cannao'
 
Building active directory lab for red teaming
Building active directory lab for red teamingBuilding active directory lab for red teaming
Building active directory lab for red teaming
n|u - The Open Security Community
 
Mysql data replication
Mysql data replicationMysql data replication
Mysql data replication
Tuấn Ngô
 

What's hot (20)

0wn-premises: Bypassing Microsoft Defender for Identity
0wn-premises: Bypassing Microsoft Defender for Identity0wn-premises: Bypassing Microsoft Defender for Identity
0wn-premises: Bypassing Microsoft Defender for Identity
 
MySQL Group Replication - Ready For Production? (2018-04)
MySQL Group Replication - Ready For Production? (2018-04)MySQL Group Replication - Ready For Production? (2018-04)
MySQL Group Replication - Ready For Production? (2018-04)
 
Stephan Ewen - Scaling to large State
Stephan Ewen - Scaling to large StateStephan Ewen - Scaling to large State
Stephan Ewen - Scaling to large State
 
Evading Microsoft ATA for Active Directory Domination
Evading Microsoft ATA for Active Directory DominationEvading Microsoft ATA for Active Directory Domination
Evading Microsoft ATA for Active Directory Domination
 
How to Manage Scale-Out Environments with MariaDB MaxScale
How to Manage Scale-Out Environments with MariaDB MaxScaleHow to Manage Scale-Out Environments with MariaDB MaxScale
How to Manage Scale-Out Environments with MariaDB MaxScale
 
Domain Name Service
Domain Name ServiceDomain Name Service
Domain Name Service
 
Mysql-MHA
Mysql-MHAMysql-MHA
Mysql-MHA
 
Introduction to Galera Cluster
Introduction to Galera ClusterIntroduction to Galera Cluster
Introduction to Galera Cluster
 
Fluentd with MySQL
Fluentd with MySQLFluentd with MySQL
Fluentd with MySQL
 
ProxySQL for MySQL
ProxySQL for MySQLProxySQL for MySQL
ProxySQL for MySQL
 
Clustering and High Availability
Clustering and High Availability Clustering and High Availability
Clustering and High Availability
 
ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016
 
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
 
PostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldPostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized World
 
Linux and firewall
Linux and firewallLinux and firewall
Linux and firewall
 
4 andrii kudiurov - web application security 101
4   andrii kudiurov - web application security 1014   andrii kudiurov - web application security 101
4 andrii kudiurov - web application security 101
 
Using all of the high availability options in MariaDB
Using all of the high availability options in MariaDBUsing all of the high availability options in MariaDB
Using all of the high availability options in MariaDB
 
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdfProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
 
Building active directory lab for red teaming
Building active directory lab for red teamingBuilding active directory lab for red teaming
Building active directory lab for red teaming
 
Mysql data replication
Mysql data replicationMysql data replication
Mysql data replication
 

Viewers also liked

Replication in Distributed Database
Replication in Distributed DatabaseReplication in Distributed Database
Replication in Distributed Database
Abhilasha Lahigude
 
Data Replication in Distributed System
Data Replication in  Distributed SystemData Replication in  Distributed System
Data Replication in Distributed System
Ehsan Hessami
 
Database , 13 Replication
Database , 13 ReplicationDatabase , 13 Replication
Database , 13 Replication
Ali Usman
 
Chapter 14 replication
Chapter 14 replicationChapter 14 replication
Chapter 14 replication
AbDul 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 Database
Abhilasha Lahigude
 
Data Replication In Cloud Computing
Data Replication In Cloud ComputingData Replication In Cloud Computing
Data Replication In Cloud Computing
Rahul 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-02
Computer Science Club
 
DAG
DAGDAG
NoSQL Simplified: Schema vs. Schema-less
NoSQL Simplified: Schema vs. Schema-lessNoSQL Simplified: Schema vs. Schema-less
NoSQL Simplified: Schema vs. Schema-less
InfiniteGraph
 
Replication Management
Replication ManagementReplication Management
Replication Management
Revolucion
 
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
ryanthiessen
 
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
jgoulah
 
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 agreement
AbDul ThaYyal
 
Partitioning
PartitioningPartitioning
Partitioning
Reema Gajjar
 
Scheduling in distributed systems - Andrii Vozniuk
Scheduling in distributed systems - Andrii VozniukScheduling in distributed systems - Andrii Vozniuk
Scheduling in distributed systems - Andrii Vozniuk
Andrii Vozniuk
 
MongoDB Database Replication
MongoDB Database ReplicationMongoDB Database Replication
MongoDB Database Replication
Mehdi Valikhani
 
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
Denish Patel
 
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
Corporate Excellence - Centre for Reputation Leadership
 
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
Corporate Excellence - Centre for Reputation Leadership
 

Viewers also liked (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
 
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
 
MongoDB Database Replication
MongoDB Database ReplicationMongoDB Database Replication
MongoDB Database Replication
 
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
 

Similar to Database Replication

MySQL database replication
MySQL database replicationMySQL database replication
MySQL database replication
PoguttuezhiniVP
 
MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017
Dave Stokes
 
Mysql
MysqlMysql
Mysql
abhijith
 
Architecting cloud
Architecting cloudArchitecting cloud
Architecting cloud
Tahsin Hasan
 
MySQL HA with PaceMaker
MySQL HA with  PaceMakerMySQL HA with  PaceMaker
MySQL HA with PaceMaker
Kris Buytaert
 
Mater,slave on mysql
Mater,slave on mysqlMater,slave on mysql
Mater,slave on mysql
Vasudeva Rao
 
Mysql replication @ gnugroup
Mysql replication @ gnugroupMysql replication @ gnugroup
Mysql replication @ gnugroup
Jayant Chutke
 
MySQL Failover - Cubexs Weatherly
MySQL Failover - Cubexs WeatherlyMySQL Failover - Cubexs Weatherly
MySQL Failover - Cubexs Weatherly
Weatherly Cloud Inc.
 
MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016
Dave Stokes
 
PostgreSQL Replication in 10 Minutes - SCALE
PostgreSQL Replication in 10  Minutes - SCALEPostgreSQL Replication in 10  Minutes - SCALE
PostgreSQL Replication in 10 Minutes - SCALE
PostgreSQL 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 USA
Harry 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.4
Ulf 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 Boston
Puppet
 
My sql failover test using orchestrator
My sql failover test  using orchestratorMy sql failover test  using orchestrator
My sql failover test using orchestrator
YoungHeon (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 Cluster
Amr Fawzy
 
Meb Backup & Recovery Performance
Meb Backup & Recovery PerformanceMeb Backup & Recovery Performance
Meb Backup & Recovery Performance
Keith 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 2016
Dave Stokes
 
Mysql ppt
Mysql pptMysql ppt
Mysql ppt
Sanmuga Nathan
 
My SQL 101
My SQL 101My SQL 101
My SQL 101
Dave Stokes
 

Similar to 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
 
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
 
My SQL 101
My SQL 101My SQL 101
My SQL 101
 

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