Re: Replicación simple en PG9.6 que no funciona

From: Anthony Sotolongo <asotolongo(at)gmail(dot)com>
To: Ekaterina Amez <ekaterina(dot)amez(at)zunibal(dot)com>, pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: Replicación simple en PG9.6 que no funciona
Date: 2021-09-20 16:30:48
Message-ID: ef5d824c-272a-576d-2df1-00da40eecdc2@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Hola Ekaterina, ¿Qué valor tiene hot_standby en el esclavo?

Saludos

On 20/9/21 11:48, Ekaterina Amez wrote:
> Hola Lista,
>
> Estoy probando a montar una réplica sencilla entre mi ordenador
> (Ubuntu 18.04) y un ordenador que tengo para pruebas (CentOS7).
> El CentOS es el servidor maestro y el Ubuntu el esclavo. Ambos con PG
> 9.6.23 instalado. Uno está en la IP 192.168.1.65:5433
> <http://192.168.1.65:5433> (maestro) y el otro en la 60 (esclavo).
> Como veis, el maestro está ejecutándose en otro puerto que no es el de
> por defecto.
>
> El maestro está configurado así (postgresql.conf):
> wal_level = replica
> archive_mode = on
> archive_command = 'cp %p /var/lib/pgsql/9.6/wal_archive/%f'
> max_wal_senders = 2
> wal_keep_segments = 8
> synchronous_standby_names = 'pgslave001'
> hot_standby = on
>
> Y las conexiones están configuradas así (pg_hba.conf):
> # TYPE  DATABASE        USER            ADDRESS     METHOD
> # "local" is for Unix domain socket connections only
> local   all             all   trust
> # IPv4 local connections:
> host   all   all 0.0.0.0/0 <http://0.0.0.0/0> trust
> # IPv6 local connections:
> host    all             all             ::1/128   trust
> # Allow replication connections from localhost, by a user with the
> # replication privilege.
> host replication all 192.168.1.0/24 <http://192.168.1.0/24> trust
>
> Utilizo esta configuración porque quiero asegurarme de que no tengo
> problemas de conexión. El firewall de CentOS está abierto:
> [root(at)test-eka data]# sestatus
> SELinux status:                 disabled
> [root(at)test-eka data]# firewall-cmd --list-services
> dhcpv6-client http postgresql ssh
> [root(at)test-eka data]# firewall-cmd --service=postgresql
> --add-port=5433/tcp --permanent
> Warning: ALREADY_ENABLED: '5433:tcp'
> success
>
> Desde el servidor esclavo puedo conectarme sin problemas al maestro:
> $ /usr/lib/postgresql/9.6/bin/psql -h 192.168.1.65 -p 5433 -U postgres
> psql (9.6.23)
> Digite «help» para obtener ayuda.
> postgres=#  \q
>
> Con esto así, hago el backup inicial:
> sudo -u postgres /usr/lib/postgresql/9.6/bin/pg_basebackup -h
> 192.168.1.65 -p 5433 -U replicador -D /var/lib/postgresql/9.6/main
> --verbose --progress --xlog
>
> Creo el archivo recovery.conf
> restore_command = 'scp 192.168.1.65:/var/lib/pgsql/9.6/wal_archive/%f %p'
> standby_mode = on
> primary_conninfo = 'host=192.168.1.65 port=5433 user=replicador
> password=replicador application_name=pgslave001'
>
> Y arranco el esclavo:
> ekaterina(at)ekaterina-ubuntu:$ sudo systemctl start
> postgresql(at)9(dot)6-main(dot)service
> ekaterina(at)ekaterina-ubuntu:$ sudo systemctl status
> postgresql(at)9(dot)6-main(dot)service
> ● postgresql(at)9(dot)6-main(dot)service - PostgreSQL Cluster 9.6-main
>    Loaded: loaded (/lib/systemd/system/postgresql(at)(dot)service; indirect;
> vendor preset: enabled)
>    Active: active (running) since Mon 2021-09-20 16:41:52 CEST; 4s ago
>   Process: 9783 ExecStop=/usr/bin/pg_ctlcluster
> --skip-systemctl-redirect -m fast 9.6-main stop (code=exited,
> status=0/SUCCESS)
>   Process: 10060 ExecStart=/usr/bin/pg_ctlcluster
> --skip-systemctl-redirect 9.6-main start (code=exited, status=0/SUCCESS)
>  Main PID: 10065 (postgres)
>     Tasks: 5 (limit: 4915)
>    CGroup:
> /system.slice/system-postgresql.slice/postgresql(at)9(dot)6-main(dot)service
>            ├─10065 /usr/lib/postgresql/9.6/bin/postgres -D
> /var/lib/postgresql/9.6/main -c
> config_file=/etc/postgresql/9.6/main/postgresql.conf
>            ├─10066 postgres: 9.6/main: startup process recovering
> 00000001000000000000001A
>            ├─10070 postgres: 9.6/main: checkpointer process
>            ├─10071 postgres: 9.6/main: writer process
>            └─10072 postgres: 9.6/main: wal receiver process streaming
> 0/1A01D7B8
>
> sep 20 16:41:46 ekaterina-ubuntu systemd[1]: Starting PostgreSQL
> Cluster 9.6-main...
> sep 20 16:41:52 ekaterina-ubuntu postgresql(at)9(dot)6-main[10060]: Warning:
> connection to the database failed, disabling startup checks:
> sep 20 16:41:52 ekaterina-ubuntu postgresql(at)9(dot)6-main[10060]: psql:
> FATAL:  el sistema de base de datos está iniciándose
> sep 20 16:41:52 ekaterina-ubuntu systemd[1]: Started PostgreSQL
> Cluster 9.6-main.
>
> Me da igual arrancarlo con pg_ctl que con systemctl. El esclavo parece
> arrancado (la última línea dice Started) pero cuando intento conectar
> con la bd esclava me da error:
> ekaterina(at)ekaterina-ubuntu:$ /usr/lib/postgresql/9.6/bin/psql  -U postgres
> psql: FATAL:  el sistema de base de datos está iniciándose
>
> Sin embargo, algo está arrancado porque cuando lanzo de nuevo sudo
> systemctl status postgresql(at)9(dot)6-main(dot)service veo que en "wal receiver
> process" va avanzando y encaja con lo que se puede ver en el maestro:
> postgres=# select * from  pg_stat_replication ;
> -[ RECORD 1 ]----+------------------------------
> pid              | 3556
> usesysid         | 16404
> usename          | replicador
> application_name | pgslave001
> client_addr      | 192.168.1.60
> client_hostname  |
> client_port      | 52418
> backend_start    | 2021-09-20 16:41:46.648487+02
> backend_xmin     |
> state            | streaming
> sent_location    | 0/1A01D898
> write_location   | 0/1A01D898
> flush_location   | 0/1A01D898
> replay_location  | 0/1A01D898
> sync_priority    | 1
> sync_state       | sync
>
> ¿Qué es lo que estoy haciendo mal? Aviso por adelantado de que mis
> conocimientos de Linux son limitados.
>
> Muchas gracias,
> Ekaterina

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Ekaterina Amez 2021-09-20 16:42:50 Re: Replicación simple en PG9.6 que no funciona
Previous Message Ekaterina Amez 2021-09-20 14:48:38 Replicación simple en PG9.6 que no funciona