SlideShare uma empresa Scribd logo
1 de 34
PostgreSQL: Replicação com
RepManager (repmgr)
Vinicius Vale
2
Quem sou
➢Bacharel em Ciência da
Computação;
➢MBA em BigData;
➢Especialista Postgresql;
➢Especialista Java/Android;
➢Devops pela 4Linux;
Vinicius Aquino do Vale
3
Conhecendo a 4Linux
➢ Metodologia IT Experience - Cenários reais
➢ Cursos práticos, rápidos e baratos de
autores feras: www.4shot.com.br
➢ Projetos complexos de missão crítica,
com infra e desenvolvimento PHP
4
Cursos práticos, rápidos e baratos de
autores feras
5
Metodologia IT Experience
Cenários reais
6
Lançamento 4Linux
7
Ao final da minha palestra
➢ 02 Curso Online:
➢ Curso SQL para Programadores – Código
4800.
➢ 01 Elephant.
8
Ao final da minha palestra
9
Agenda
➢Replicação Nativa;
➢Limitações e Problemas;
➢Um novo mundo : RepMgr;
➢Vantagens e Facilidades;
➢Gerenciamento (replicação e failover);
➢Considerações Finais;
10
Replicação Nativa - Conceito
➢Réplica? Pra quê?
Vantagens:
➢Leituras (OLAP)
➢Failover
Desvantagens:
➢Master->Slave
➢Gerenciamento
(Virada)
11
Passo a Passo
Master:
➢ Criar usuário – REPLICATION;
➢ Liberar pg_hba;
➢ postgresql.conf:
➢wal_level;
➢wal_keep_segments;
➢max_wal_senders.
12
Passo a Passo
Slave (pg_basebackup):
➢ postgresql.conf:
➢hot_standby;
➢max_standby_archive_delay;
➢max_standby_streaming_delay.
13
Passo a Passo
Slave:
➢ recovery.conf:
➢standby_mode;
➢primary_conninfo;
➢trigger_file.
14
Limitações e Problemas
➢Tipos de Replicação
➢Assíncrona (default);
➢Síncrona;
15
Limitações e Problemas
➢ Réplica Assíncrona (default):
➢ Perda de algumas transações;
16
Limitações e Problemas
➢ Réplica Síncrona:
➢ Slave parado = Master Parado;
➢ Tempo total = master + tráfego pela rede + slave + retorno;
17
Limitações e Problemas
Múltiplas réplicas:
➢ Novo Master;
➢ O que eu faço com os meus slaves?
➢ O que eu faço com meu antigo master?
18
Repmgr: Um Novo mundo
➢ O que é?
➢ Desenvolvido pela 2ndQuadrant;
➢ Open-Source;
➢ Free;
➢ Versões:
➢ 2.0;
➢ 3.0.
19
Vantagens e Facilidades
Gerenciamento de Réplicas:
➢ Monitoramento:
➢$ repmgr cluster show;
Role | Connection String
* master | host=node1 user=repmgr_usr dbname=repmgr_db
password=123456
standby | host=node2 user=repmgr_usr dbname=repmgr_db
password=123456
➢ Failover (daemon repmgrd);
➢ Failback.
20
Gerenciamento (preparação Postgresql)
Gerenciamento de Réplicas:
➢ Usuário:
➢$ createuser -s repmgr_usr;
➢ Database:
➢$ createdb repmgr_db -O repmgr_usr;
➢ pg_hba.conf:
➢host repmgr_db repmgr_usr ip/24 trust;
➢host replication repmgr_usr ip/24 trust;
21
Gerenciamento (preparação Postgresql)
➢ Master – postgresql.conf:
➢ hot_standby = on;
➢ wal_level = hot_standby;
➢ max_wal_senders;
➢ wal_keep_segments:
➢9.4 – Utiliza slot de replicação;
➢9.3 – Espera-se 5000 (80GB de WAL);
➢ archive_mode = on
➢ archive_command = 'cd .'
22
Gerenciamento (repmgr.conf)
➢ Local Recomendado:
➢ /etc/repmgr/repmgr.conf;
➢ repmgr.conf:
➢ cluster=DBZ (mesmo para todos os hosts);
➢ node=1 (integer – único);
➢ node_name=node1 (único);
➢ pg_bindir=/path/to/postgres/bin;
23
Gerenciamento (repmgr.conf)
➢ use_replication_slots=1
➢ conninfo='host=repmgr_node1 user=repmgr dbname=repmgr';
24
Gerenciamento (repmgr)
➢ register – Registrar os nós:
➢ $ repmgr -f repmgr.conf --verbose master register;
➢ $ repmgr -f repmgr.conf --verbose standby register;
➢ clone – Preparar standby:
➢ $ repmgr -D $PGDATA -f repmgr.conf -d repmgr_db -U
repmgr_usr --verbose standby clone IP_MASTER
25
Gerenciamento (repmgr)
➢ promote – Promover um novo master:
➢ $ repmgr -f repmgr.conf --verbose standby promote;
➢ follow – Seguir novo master:
➢ $ repmgr -f repmgr.conf --verbose standby follow.
26
Gerenciamento (repmgr)
27
Gerenciamento (repmgr)
➢ Converter master com problemas para standby:
➢ $ repmgr -f repmgr.conf --force --rsync-only -h
novo_master -d repmgr_db -U repmgr_usr --verbose
standby clone;
➢ Registar o nó novamente:
➢ $ repmgr -f repmgr.conf --force standby register.
28
Gerenciamento (repmgrd)
➢ Automatic Failover:
➢ Witness;
29
Gerenciamento (repmgrd)
➢ Postgresql.conf:
➢ shared_preload_libraries = 'repmgr_funcs';
➢ psql -f /usr/share/postgresql/9.0/contrib/repmgr_funcs.sql
repmgr_db.
30
Gerenciamento (repmgrd)
➢ repmgr.conf:
➢ master_response_timeout;
➢ reconnect_attempts;
➢ reconnect_interval;
➢ failover=[automatic|manual];
➢ promote_command='promote_command.sh';
➢ follow_command='repmgr standby follow -f repmgr.conf'.
31
Gerenciamento (repmgrd)
➢ Iniciando Witness
➢ repmgr -d repmgr_db -U repmgr_usr -h IP_MASTER -D
$WITNESS_PGDATA -f repmgr.conf witness create;
➢ Daemon:
➢ $ repmgrd -f repmgr.conf --daemonize > repmgr.log 2>&1.
32
Considerações Finais
● Modelo nativo de replicação
● Díficil gerenciamento
● Failover manual e complexo
– Falha humana
● Repmgr
● Facilidade no gerenciamento
● Failover (manual ou automático)
– Fácil controle
33
Boa Sorte!!
34
Vinicius Vale
vinicius.aquino@4linux.com.br
aquino.vale@gmail.com
www.4linux.com.br
www.4shot.com.br
www.viniciusvale.com
Sigam-nos
@4linux

Mais conteúdo relacionado

Mais procurados

MySQL Backup and Security Best Practices
MySQL Backup and Security Best PracticesMySQL Backup and Security Best Practices
MySQL Backup and Security Best PracticesLenz Grimmer
 
DB2 LUW - Backup and Recovery
DB2 LUW - Backup and RecoveryDB2 LUW - Backup and Recovery
DB2 LUW - Backup and Recoveryimranasayed
 
Postgres connections at scale
Postgres connections at scalePostgres connections at scale
Postgres connections at scaleMydbops
 
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015PostgreSQL-Consulting
 
PostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsPostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsMydbops
 
Introduction to Oracle Data Guard Broker
Introduction to Oracle Data Guard BrokerIntroduction to Oracle Data Guard Broker
Introduction to Oracle Data Guard BrokerZohar Elkayam
 
EXPLicando o Explain no PostgreSQL
EXPLicando o Explain no PostgreSQLEXPLicando o Explain no PostgreSQL
EXPLicando o Explain no PostgreSQLFabrízio Mello
 
Linux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performanceLinux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performancePostgreSQL-Consulting
 
PostgreSQL HA
PostgreSQL   HAPostgreSQL   HA
PostgreSQL HAharoonm
 
[오픈소스컨설팅]Day #1 MySQL 엔진소개, 튜닝, 백업 및 복구, 업그레이드방법
[오픈소스컨설팅]Day #1 MySQL 엔진소개, 튜닝, 백업 및 복구, 업그레이드방법[오픈소스컨설팅]Day #1 MySQL 엔진소개, 튜닝, 백업 및 복구, 업그레이드방법
[오픈소스컨설팅]Day #1 MySQL 엔진소개, 튜닝, 백업 및 복구, 업그레이드방법Ji-Woong Choi
 
Arquitetura de Memoria do PostgreSQL
Arquitetura de Memoria do PostgreSQLArquitetura de Memoria do PostgreSQL
Arquitetura de Memoria do PostgreSQLRaul Oliveira
 
An overview of reference architectures for Postgres
An overview of reference architectures for PostgresAn overview of reference architectures for Postgres
An overview of reference architectures for PostgresEDB
 
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenKevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenPostgresOpen
 
mysql 8.0 architecture and enhancement
mysql 8.0 architecture and enhancementmysql 8.0 architecture and enhancement
mysql 8.0 architecture and enhancementlalit choudhary
 
HCL Notes and Nomad Troubleshooting for Dummies
HCL Notes and Nomad Troubleshooting for DummiesHCL Notes and Nomad Troubleshooting for Dummies
HCL Notes and Nomad Troubleshooting for Dummiespanagenda
 
PostgreSQL: Performance Tuning
PostgreSQL: Performance TuningPostgreSQL: Performance Tuning
PostgreSQL: Performance TuningFernando Ike
 

Mais procurados (20)

MySQL Backup and Security Best Practices
MySQL Backup and Security Best PracticesMySQL Backup and Security Best Practices
MySQL Backup and Security Best Practices
 
DB2 LUW - Backup and Recovery
DB2 LUW - Backup and RecoveryDB2 LUW - Backup and Recovery
DB2 LUW - Backup and Recovery
 
Postgres connections at scale
Postgres connections at scalePostgres connections at scale
Postgres connections at scale
 
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
 
PostgreSQL replication
PostgreSQL replicationPostgreSQL replication
PostgreSQL replication
 
PostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsPostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability Methods
 
Introduction to Oracle Data Guard Broker
Introduction to Oracle Data Guard BrokerIntroduction to Oracle Data Guard Broker
Introduction to Oracle Data Guard Broker
 
Get to know PostgreSQL!
Get to know PostgreSQL!Get to know PostgreSQL!
Get to know PostgreSQL!
 
EXPLicando o Explain no PostgreSQL
EXPLicando o Explain no PostgreSQLEXPLicando o Explain no PostgreSQL
EXPLicando o Explain no PostgreSQL
 
Linux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performanceLinux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performance
 
PostgreSQL HA
PostgreSQL   HAPostgreSQL   HA
PostgreSQL HA
 
[오픈소스컨설팅]Day #1 MySQL 엔진소개, 튜닝, 백업 및 복구, 업그레이드방법
[오픈소스컨설팅]Day #1 MySQL 엔진소개, 튜닝, 백업 및 복구, 업그레이드방법[오픈소스컨설팅]Day #1 MySQL 엔진소개, 튜닝, 백업 및 복구, 업그레이드방법
[오픈소스컨설팅]Day #1 MySQL 엔진소개, 튜닝, 백업 및 복구, 업그레이드방법
 
MySQL Backup & Recovery
MySQL Backup & RecoveryMySQL Backup & Recovery
MySQL Backup & Recovery
 
Arquitetura de Memoria do PostgreSQL
Arquitetura de Memoria do PostgreSQLArquitetura de Memoria do PostgreSQL
Arquitetura de Memoria do PostgreSQL
 
An overview of reference architectures for Postgres
An overview of reference architectures for PostgresAn overview of reference architectures for Postgres
An overview of reference architectures for Postgres
 
5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance
 
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenKevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
 
mysql 8.0 architecture and enhancement
mysql 8.0 architecture and enhancementmysql 8.0 architecture and enhancement
mysql 8.0 architecture and enhancement
 
HCL Notes and Nomad Troubleshooting for Dummies
HCL Notes and Nomad Troubleshooting for DummiesHCL Notes and Nomad Troubleshooting for Dummies
HCL Notes and Nomad Troubleshooting for Dummies
 
PostgreSQL: Performance Tuning
PostgreSQL: Performance TuningPostgreSQL: Performance Tuning
PostgreSQL: Performance Tuning
 

Destaque

Alta disponibilidade com PostgreSQL
Alta disponibilidade com PostgreSQLAlta disponibilidade com PostgreSQL
Alta disponibilidade com PostgreSQLLeonardo Cezar
 
PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)
PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)
PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)Gabriele Bartolini
 
#DevOps in a windows world - @DevOpsGuys
#DevOps in a windows world - @DevOpsGuys#DevOps in a windows world - @DevOpsGuys
#DevOps in a windows world - @DevOpsGuysDevOpsGroup
 
Odoo disaster recovery with barman
Odoo disaster recovery with barmanOdoo disaster recovery with barman
Odoo disaster recovery with barmanOdoo
 
PostgreSQL Disaster Recovery with Barman
PostgreSQL Disaster Recovery with BarmanPostgreSQL Disaster Recovery with Barman
PostgreSQL Disaster Recovery with BarmanGabriele Bartolini
 
Postgres-XC Write Scalable PostgreSQL Cluster
Postgres-XC Write Scalable PostgreSQL ClusterPostgres-XC Write Scalable PostgreSQL Cluster
Postgres-XC Write Scalable PostgreSQL ClusterMason Sharp
 

Destaque (6)

Alta disponibilidade com PostgreSQL
Alta disponibilidade com PostgreSQLAlta disponibilidade com PostgreSQL
Alta disponibilidade com PostgreSQL
 
PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)
PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)
PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)
 
#DevOps in a windows world - @DevOpsGuys
#DevOps in a windows world - @DevOpsGuys#DevOps in a windows world - @DevOpsGuys
#DevOps in a windows world - @DevOpsGuys
 
Odoo disaster recovery with barman
Odoo disaster recovery with barmanOdoo disaster recovery with barman
Odoo disaster recovery with barman
 
PostgreSQL Disaster Recovery with Barman
PostgreSQL Disaster Recovery with BarmanPostgreSQL Disaster Recovery with Barman
PostgreSQL Disaster Recovery with Barman
 
Postgres-XC Write Scalable PostgreSQL Cluster
Postgres-XC Write Scalable PostgreSQL ClusterPostgres-XC Write Scalable PostgreSQL Cluster
Postgres-XC Write Scalable PostgreSQL Cluster
 

Semelhante a PostgreSQL Replicação RepMgr

PHP Jedi - Boas Práticas e Alta Performance
PHP Jedi - Boas Práticas e Alta PerformancePHP Jedi - Boas Práticas e Alta Performance
PHP Jedi - Boas Práticas e Alta PerformanceFelipe Ribeiro
 
Phpjedi 090307090434-phpapp01 2
Phpjedi 090307090434-phpapp01 2Phpjedi 090307090434-phpapp01 2
Phpjedi 090307090434-phpapp01 2PrinceGuru MS
 
A crash course on Crash (FISL12)
A crash course on Crash (FISL12)A crash course on Crash (FISL12)
A crash course on Crash (FISL12)Rafael Aquini
 
PHP e PostgreSQL - Dois Elefantes trabalham muito mais !
PHP e PostgreSQL - Dois Elefantes trabalham muito mais !PHP e PostgreSQL - Dois Elefantes trabalham muito mais !
PHP e PostgreSQL - Dois Elefantes trabalham muito mais !William Felipe
 
TDC2016POA | Trilha Python - Heimdall Guard - Spam Filter
TDC2016POA | Trilha Python - Heimdall Guard - Spam FilterTDC2016POA | Trilha Python - Heimdall Guard - Spam Filter
TDC2016POA | Trilha Python - Heimdall Guard - Spam Filtertdc-globalcode
 
Linux e zephyr conversando no mesmo SoC
Linux e zephyr conversando no mesmo SoCLinux e zephyr conversando no mesmo SoC
Linux e zephyr conversando no mesmo SoCEmbarcados
 
Uma implementação de suporte a
Uma implementação de suporte a Uma implementação de suporte a
Uma implementação de suporte a Rômulo Jales
 
Imergindo jvm[Apresentação ]
Imergindo jvm[Apresentação ]Imergindo jvm[Apresentação ]
Imergindo jvm[Apresentação ]Otávio Santana
 
Palestra Desenvolvimento Ágil para Web com ROR UVA
Palestra Desenvolvimento Ágil para Web com ROR UVAPalestra Desenvolvimento Ágil para Web com ROR UVA
Palestra Desenvolvimento Ágil para Web com ROR UVAThiago Cifani
 
Tunando sua aplicação LNMP
Tunando sua aplicação LNMPTunando sua aplicação LNMP
Tunando sua aplicação LNMPLeandro Mendes
 
Java Virtual Threads.pptx
Java Virtual Threads.pptxJava Virtual Threads.pptx
Java Virtual Threads.pptxssuser980608
 
Google App Engine e PHP
Google App Engine e PHPGoogle App Engine e PHP
Google App Engine e PHPLuiz Messias
 
Apresentação PGDAY - Replicação Nativa - PostgreSQL
Apresentação PGDAY - Replicação Nativa - PostgreSQLApresentação PGDAY - Replicação Nativa - PostgreSQL
Apresentação PGDAY - Replicação Nativa - PostgreSQLJohnes Castro
 

Semelhante a PostgreSQL Replicação RepMgr (20)

Jsummit 2014
Jsummit 2014Jsummit 2014
Jsummit 2014
 
PHP Jedi - Boas Práticas e Alta Performance
PHP Jedi - Boas Práticas e Alta PerformancePHP Jedi - Boas Práticas e Alta Performance
PHP Jedi - Boas Práticas e Alta Performance
 
Phpjedi 090307090434-phpapp01 2
Phpjedi 090307090434-phpapp01 2Phpjedi 090307090434-phpapp01 2
Phpjedi 090307090434-phpapp01 2
 
A crash course on Crash (FISL12)
A crash course on Crash (FISL12)A crash course on Crash (FISL12)
A crash course on Crash (FISL12)
 
PHP e PostgreSQL - Dois Elefantes trabalham muito mais !
PHP e PostgreSQL - Dois Elefantes trabalham muito mais !PHP e PostgreSQL - Dois Elefantes trabalham muito mais !
PHP e PostgreSQL - Dois Elefantes trabalham muito mais !
 
TDC2016POA | Trilha Python - Heimdall Guard - Spam Filter
TDC2016POA | Trilha Python - Heimdall Guard - Spam FilterTDC2016POA | Trilha Python - Heimdall Guard - Spam Filter
TDC2016POA | Trilha Python - Heimdall Guard - Spam Filter
 
Linux e zephyr conversando no mesmo SoC
Linux e zephyr conversando no mesmo SoCLinux e zephyr conversando no mesmo SoC
Linux e zephyr conversando no mesmo SoC
 
Conceitoseaplicaes
ConceitoseaplicaesConceitoseaplicaes
Conceitoseaplicaes
 
Uma implementação de suporte a
Uma implementação de suporte a Uma implementação de suporte a
Uma implementação de suporte a
 
Automatizando Nmap com NSE
Automatizando Nmap com NSEAutomatizando Nmap com NSE
Automatizando Nmap com NSE
 
Imergindo jvm[Apresentação ]
Imergindo jvm[Apresentação ]Imergindo jvm[Apresentação ]
Imergindo jvm[Apresentação ]
 
Palestra Desenvolvimento Ágil para Web com ROR UVA
Palestra Desenvolvimento Ágil para Web com ROR UVAPalestra Desenvolvimento Ágil para Web com ROR UVA
Palestra Desenvolvimento Ágil para Web com ROR UVA
 
A busca pelo deploy continuo
A busca pelo deploy continuoA busca pelo deploy continuo
A busca pelo deploy continuo
 
Tunando sua aplicação LNMP
Tunando sua aplicação LNMPTunando sua aplicação LNMP
Tunando sua aplicação LNMP
 
GlusterFs
GlusterFsGlusterFs
GlusterFs
 
Java Virtual Threads.pptx
Java Virtual Threads.pptxJava Virtual Threads.pptx
Java Virtual Threads.pptx
 
Vagrant + Puppet
Vagrant + PuppetVagrant + Puppet
Vagrant + Puppet
 
Google App Engine e PHP
Google App Engine e PHPGoogle App Engine e PHP
Google App Engine e PHP
 
Apresentação PGDAY - Replicação Nativa - PostgreSQL
Apresentação PGDAY - Replicação Nativa - PostgreSQLApresentação PGDAY - Replicação Nativa - PostgreSQL
Apresentação PGDAY - Replicação Nativa - PostgreSQL
 
Consegi 2011: Puppet
Consegi 2011: PuppetConsegi 2011: Puppet
Consegi 2011: Puppet
 

PostgreSQL Replicação RepMgr

Notas do Editor

  1. RankDone será lançado em Agosto e tem como objetivo fazer o rankeamento de candidados para vagas técnicas
  2. Outras altetrnativas – Como crescimento vertical, maior capacidade de IO e ferramentas especificas para ambientes OLTP * Bucardo * Postgres-XC * Postgres-XL
  3. Total de slaves + 1 hot_standby – sera mudado por causa dos slaves Não obrigatorio, porem recomendado
  4. pg_ctl e pg_basebackup não estiverem no PATH.
  5. Nunca use localhost no host; user/dbname devem ser os mesmos para todos os hosts; Outros parametros podem ser diferentes.
  6. 1 - Master deve ser registrado primeiro. 2 – Antes de registar o slave deve-se preparar o standby
  7. * Witness porta - (port 5499) * Daemon deve estar em todos os servidores envolvidos.