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

Getting started with postgresql
Getting started with postgresqlGetting started with postgresql
Getting started with postgresqlbotsplash.com
 
Logical replication with pglogical
Logical replication with pglogicalLogical replication with pglogical
Logical replication with pglogicalUmair Shahid
 
PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep InternalEXEM
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1Federico Campoli
 
Análise de performance usando as estatísticas do PostgreSQL
Análise de performance usando as estatísticas do PostgreSQLAnálise de performance usando as estatísticas do PostgreSQL
Análise de performance usando as estatísticas do PostgreSQLMatheus de Oliveira
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpen Gurukul
 
PostgreSQL and JDBC: striving for high performance
PostgreSQL and JDBC: striving for high performancePostgreSQL and JDBC: striving for high performance
PostgreSQL and JDBC: striving for high performanceVladimir Sitnikov
 
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 MariaDBMariaDB plc
 
PostgreSQL Security. How Do We Think?
PostgreSQL Security. How Do We Think?PostgreSQL Security. How Do We Think?
PostgreSQL Security. How Do We Think?Ohyama Masanori
 
MySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software TestMySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software TestI Goo Lee
 
SSL certificates in the Oracle Database without surprises
SSL certificates in the Oracle Database without surprisesSSL certificates in the Oracle Database without surprises
SSL certificates in the Oracle Database without surprisesNelson Calero
 
PostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsPostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsMydbops
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Alexey Lesovsky
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLCommand Prompt., Inc
 
Connection Pooling in PostgreSQL using pgbouncer
Connection Pooling in PostgreSQL using pgbouncer Connection Pooling in PostgreSQL using pgbouncer
Connection Pooling in PostgreSQL using pgbouncer Sameer Kumar
 
VictoriaMetrics 15/12 Meet Up: 2022 Features Highlights
VictoriaMetrics 15/12 Meet Up: 2022 Features HighlightsVictoriaMetrics 15/12 Meet Up: 2022 Features Highlights
VictoriaMetrics 15/12 Meet Up: 2022 Features HighlightsVictoriaMetrics
 
Webinar slides: An Introduction to Performance Monitoring for PostgreSQL
Webinar slides: An Introduction to Performance Monitoring for PostgreSQLWebinar slides: An Introduction to Performance Monitoring for PostgreSQL
Webinar slides: An Introduction to Performance Monitoring for PostgreSQLSeveralnines
 

Mais procurados (20)

Getting started with postgresql
Getting started with postgresqlGetting started with postgresql
Getting started with postgresql
 
Logical replication with pglogical
Logical replication with pglogicalLogical replication with pglogical
Logical replication with pglogical
 
PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep Internal
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1
 
PostgreSQL replication
PostgreSQL replicationPostgreSQL replication
PostgreSQL replication
 
Análise de performance usando as estatísticas do PostgreSQL
Análise de performance usando as estatísticas do PostgreSQLAnálise de performance usando as estatísticas do PostgreSQL
Análise de performance usando as estatísticas do PostgreSQL
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQL
 
PostgreSQL and JDBC: striving for high performance
PostgreSQL and JDBC: striving for high performancePostgreSQL and JDBC: striving for high performance
PostgreSQL and JDBC: striving for high performance
 
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
 
PostgreSQL Security. How Do We Think?
PostgreSQL Security. How Do We Think?PostgreSQL Security. How Do We Think?
PostgreSQL Security. How Do We Think?
 
MySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software TestMySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software Test
 
SSL certificates in the Oracle Database without surprises
SSL certificates in the Oracle Database without surprisesSSL certificates in the Oracle Database without surprises
SSL certificates in the Oracle Database without surprises
 
PostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsPostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability Methods
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Connection Pooling in PostgreSQL using pgbouncer
Connection Pooling in PostgreSQL using pgbouncer Connection Pooling in PostgreSQL using pgbouncer
Connection Pooling in PostgreSQL using pgbouncer
 
VictoriaMetrics 15/12 Meet Up: 2022 Features Highlights
VictoriaMetrics 15/12 Meet Up: 2022 Features HighlightsVictoriaMetrics 15/12 Meet Up: 2022 Features Highlights
VictoriaMetrics 15/12 Meet Up: 2022 Features Highlights
 
PostgreSQL.pptx
PostgreSQL.pptxPostgreSQL.pptx
PostgreSQL.pptx
 
Webinar slides: An Introduction to Performance Monitoring for PostgreSQL
Webinar slides: An Introduction to Performance Monitoring for PostgreSQLWebinar slides: An Introduction to Performance Monitoring for PostgreSQL
Webinar slides: An Introduction to Performance Monitoring for PostgreSQL
 
Postgresql
PostgresqlPostgresql
Postgresql
 

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
 
Gerenciamento de Backups PostgreSQL com pgbarman
Gerenciamento de Backups PostgreSQL com pgbarmanGerenciamento de Backups PostgreSQL com pgbarman
Gerenciamento de Backups PostgreSQL com pgbarmanJuliano Atanazio
 
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 (7)

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
 
Gerenciamento de Backups PostgreSQL com pgbarman
Gerenciamento de Backups PostgreSQL com pgbarmanGerenciamento de Backups PostgreSQL com pgbarman
Gerenciamento de Backups PostgreSQL com pgbarman
 
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.