From: Stephen Frost <sfrost@snowman.net>
To: Joao Junior <jcoj2006@gmail.com>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: archive_command too slow.
Date: Tue, 8 Nov 2016 10:47:01 -0500
Message-ID: <20161108154701.GD13284@tamriel.snowman.net> (raw)
In-Reply-To: <CABnPa_gPL8hxYwrLUmtaLUiN_KyVaJSEWE_LD+VzNJBNS4ELcw@mail.gmail.com>
References: <CABnPa_gPL8hxYwrLUmtaLUiN_KyVaJSEWE_LD+VzNJBNS4ELcw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>
Greetings,
* Joao Junior (jcoj2006@gmail.com) wrote:
> I am running 2 Linux machines, kernel 3.13.0-45-generic #74-Ubuntu SMP.
> Postgresql version 9.4 in both machine, in a Hot Standby cenario.
>
> Master-Slave using WAL files, not streaming replication.
>
> The archive_command from master is:
>
> archive_command = '/usr/bin/rsync -a -e "ssh" "%p"
> slave:/data2/postgres/standby/main/incoming/"%f"' #
Admittedly, you're talking about this for only WAL replay, but I wanted
to point out that this is not a safe archive_command setting because
you are not forcing an fsync() on the remote side to be sure that the
WAL is saved out to disk before telling PG that it can remove that WAL
segment.
What that means is that a crash on the remote system at just the wrong
time will create a hole in your WAL, possibly meaning that you wouldn't
be able to replay WAL on the remote side past that point and would have
to rebuild/re-sync your replica.
There's a lot more that needs to be done carefully and correctly to
ensure proper backups than this also.
In short, don't try to write your own software for doing this. Use one
of the existing tools which do the correct things for you. In
particular, when it comes to dealing with archive_command being a
bottleneck, pgbackrest has an async mode where it will keep open a
long-running SSH session to the remote side to avoid the overhead
associated with re-exec'ing SSH. The ControlMaster approach helps too,
but you still have to exec rsync and ssh and it's ultimately expensive
to even do that. Unfortunatly, restore_command is single threaded and
is going to be pretty expensive too, though pgbackrest's archive-get
tries to be as fast as it can be.
pgbackrest also has the ability to perform incremental backups and
incremental restores, in parallel, allowing you to periodically bring
your replica up to speed very quickly using file transfers instead of
using WAL replay. This does mean that you have a period of downtime for
your replica, of course, but that might be a worthwhile trade-off.
For pure backups, another approach is to use pg_receivexlog and a tool
like barman which supports verifying that the WAL for a given backup has
reached the remote side.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: sfrost@snowman.net, jcoj2006@gmail.com
Subject: Re: archive_command too slow.
In-Reply-To: <20161108154701.GD13284@tamriel.snowman.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox