Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gC09o-0001x2-CI for pgsql-general@arkaria.postgresql.org; Mon, 15 Oct 2018 10:31:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gC09l-0003ss-If for pgsql-general@arkaria.postgresql.org; Mon, 15 Oct 2018 10:31:25 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gC09l-0003sl-56 for pgsql-general@lists.postgresql.org; Mon, 15 Oct 2018 10:31:25 +0000 Received: from mail-yb1-xb44.google.com ([2607:f8b0:4864:20::b44]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gC09h-0004Ik-Vq for pgsql-general@lists.postgresql.org; Mon, 15 Oct 2018 10:31:23 +0000 Received: by mail-yb1-xb44.google.com with SMTP id x5-v6so7272582ybl.11 for ; Mon, 15 Oct 2018 03:31:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=Zy7B0kjpaamQTnWPkjxsdKEkPyAHXeEonjI+AIuy5Hk=; b=eZih2vpale5QxOM7mH5Dgdf5FY6Ecax8g/GISxeD1RPGXL3HH1Q5T191nc5sRmIc89 JfRKZ2c2WOWVjsukYO+Ba1cuDtHtj3rRjQ/dtBJMcTcQaHfPmSpMU3OuPGdClsGpp6Nk kXx3EGTCd48yOeiD6bwb7iSut6Pp1okJnRP0MsO4K0KCdfNjElEyCmy5Pes4xf4RI5tD K7U3OWEp6GPsBZTBJt43kUku+NSQWdfLQrjaXtUVX/KYx2k0v1H4RULkZtI4MqEh8POy rcF/5y6+/r7DTIenEyKfx1/GnMABEvsqt2CdhnKgE2MZqUULQCgCfVYZt02ZAElyF3fv Zq4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=Zy7B0kjpaamQTnWPkjxsdKEkPyAHXeEonjI+AIuy5Hk=; b=iV0hq1kkn6M7B6a5Hmq3BdTe9jKjt25AT5QbasTnZ+YIer9G+KOxHZsSHKINRjqCW/ oqg5yTbY1py4yeE9S2vblChC2b2Ug5FzQ7MNMW3l6ND9TJPwq+UZm6udFKfr7zuuM/At fzh0y9Msl3mkMoi+kc7W/T/O4wHv46jGsB1e2zdoa100MEkrtb5ca4k+QyAbqCPpdgPN 5Dk4KpQLzpbYiGIlqXLUsSpvygIu5g3ShxSxlBi2RZoPm0K0AQMEeQCS4iynau5yWTJS TsrJrxgw/Dg9a4t+MR3IjqBk8QJSbW+FGxdUnSreSUc3alYJSGim9sPbOZaflHfeOvAy 5q1w== X-Gm-Message-State: ABuFfoiOmiWYOi4HkB6kNpA3Wu3FJIMSEZbFFStnq4CL2Gluk1ZsAWsE vOSmgl/4W0kmbzV4YSRbMzMTV+GErUAoMQwVGw== X-Google-Smtp-Source: ACcGV61WMuUvCTHHV+j6z4EDuoxBEAsr0drLcwH1uhXbpXZnytHkMivXcxwThCmuUx0748uin/gOfTH+FEr2Z/KwU6Y= X-Received: by 2002:a25:4f44:: with SMTP id d65-v6mr8293458ybb.233.1539599480870; Mon, 15 Oct 2018 03:31:20 -0700 (PDT) MIME-Version: 1.0 References: <307588119.3233604.1537982384823@mail.yahoo.com> In-Reply-To: <307588119.3233604.1537982384823@mail.yahoo.com> From: Yuri Kanivetsky Date: Mon, 15 Oct 2018 13:31:04 +0300 Message-ID: Subject: Re: Setting up continuous archiving To: ptim007@yahoo.com Cc: pgsql-general@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, Thanks for your replies. By the way, I'm now running PostgreSQL 10 :) My idea was to start with continuous archiving, then start a log-shipping standby, then make it use streaming replication. Since I'm kind of overwhelmed with information, options to be considered. Anyways, I'm now trying to decide which one to use: pgBackRest or Barman :) Barman's documentation is easier to follow, at least for me. But it doesn't allow partial PITR. That is, you can't have full weekly backups of the last couple of months (discrete) in addition to base backups + WAL logs of the last few weeks (continuous). pgBackRest doesn't seem to allow the latter: recovery to any point in time, only to some discrete moments. Correct me if I'm wrong. Then, with pgBackRest you can run standby that uses streaming replication. Barman delegates that to repmgr. Which looks like a more mature (?) solution. Probably easier to switch the site to the slave, and back. So, ideally I'd like to have standby that uses streaming replication, plus full weekly backups of the last couple of months, plus ability to restore to any point in time within the last few weeks period. Is that doable with both of them (pgBackRest, Barman)? Does it make sense to use repmgr with pgBackRest? Regards, Yuri Kanivetsky On Wed, Sep 26, 2018 at 8:19 PM Pierre Timmermans wrote= : > > Hello > > What you are doing is called "log shipping", which means that when a wal = (write-ahead log) is filled in on the database server you ship it to a back= up server via rsync. It is fine but as you said the disadvantage is that th= e file is shipped only when it is full, so you could have data loss (the la= st wal not shipped) > > A more modern and easy way is to use streaming replication: in this case = the logs are streamed continuously to the standby or to the backup server (= one can use streaming replication without implementing a standby database).= Look at the doc on the next page than the one you referred to (https://www= .postgresql.org/docs/9.3/static/high-availability.html) > > There is a nice tool that does one you plan to do (rsync of archived file= ) but also the more modern way (streaming replication): it is called barman= : https://www.pgbarman.org/. You should probably use their tool but you can= also read the doc to get the concepts and some ideas > > Rgds, Pierre > > > On Wednesday, September 26, 2018, 9:21:29 AM GMT+2, Yuri Kanivetsky wrote: > > > Hi, > > I'm trying to compile a basic set of instruction needed to set up > continuous archiving and to recover from a backup. I'm running > PostgreSQL 9.3 on Debian Stretch system. > > I've got a database and a backup servers. The idea is to set up WAL > archiving, and occasionally do full (base) backups. A base backup plus > WAL segment files from that point onward must provide enough > information to restore database to the latest state. Except for a > window for data loss that is caused by the fact that WAL segment files > aren't transferred momentarily, and more importantly that WAL segment > files are only transferred upon being filled. > > --- > > Setting up continuous archiving > > * Set up WAL archiving > > * on backup server under postgres user > > * create /var/lib/postgresql/wal_archive dir > > $ mkdir /var/lib/postgresql/wal_archive > > * on database server under postgres user > > * generate ssh key > > $ ssh-keygen -f /var/lib/postgresql/.ssh/id_rsa # providing > path to key file makes it > # to not ask qu= estions > > * add corresponding record to known_hosts file > > $ ssh-keyscan -t rsa BACKUP_SRV >> ~/.ssh/known_hosts > > * locally > > * authorize login from database to backup server > > $ ssh DATABASE_SRV cat ~/.ssh/id_rsa.pub | ssh BACKUP_SRV > 'mkdir --mode 0700 .ssh; cat >> ~/.ssh/authorized_keys; chmod 0600 > .ssh/authorized_keys' > > * on database server under root > > * change postgresql.conf > > wal_level =3D archive > archive_mode =3D on > archive_command =3D 'rsync -a %p > BACKUP_SRV:/var/lib/postgresql/wal_archive/%f' > > * restart PostgreSQL > > # systemctl resart postgresql > > * Make a base backup > > * on database server under root > > * add a line to postgresql.conf > > max_wal_senders =3D 1 > > * add a line to pg_hba.conf > > host replication replication BACKUP_SRV_IP/BACKUP_SRV_NETMASK = trust > > * restart PostgreSQL > > # systemctl restart postgresql > > * on database server under postgres user > > * create replication user > > CREATE USER replication WITH REPLICATION; > > or > > $ createuser --replication replication > > * on backup server under postgres user > > * make base backup > > $ pg_basebackup -h DATABASE_SRV -U replication -D > /var/lib/postgresql/base_backups/$(date +%Y%m%d-%H%M%S) > > Restoring from a backup > > * under root > > * stop PostgreSQL if running > > # systemctl stop postgresql > > * under postgres user > > * move data dir > > $ mv 9.3{,-$(date +%Y%m%d-%H%M%S)} > > * copy backup > > $ mkdir 9.3 > $ cp -r base_backups/TIMESTAMP 9.3/main > > * copy unarchived segment files > > $ find 9.3-TIMESTAMP/main/pg_xlog -maxdepth 1 -type f -exec cp -t > 9.3/main/pg_xlog {} + > > * create recovery.conf in 9.3/main > > restore_command =3D 'cp /var/lib/postgresql/wal_archive/%f %p' > > * under root > > * start PostgreSQL > > # systemctl start postgresql > > A few notes. > > Running out of space on backup server can lead in its turn to database > server running out of space, since WAL segment files stop being > archived and keep piling up. The same might happen when archiving > falls behind. Which also widens the window for data loss. > > WAL archiving doesn't track changes to configuration files. > pg_basebackup will back up configuration files only if they are inside > data dir. > > If database doesn't generate much WAL traffic, there could be a long > delay between completing a transaction and archiving its results > (archive_timeout). > > You might want to prevent users from accessing the database until > you're sure the recovery was successful (pg_hba.conf). > > I'm not considering here possible issues with tablespaces and other cavea= ts: > > https://www.postgresql.org/docs/9.3/static/continuous-archiving.html#CONT= INUOUS-ARCHIVING-CAVEATS > > --- > > Most importantly, does it makes sense to keep more than one base backup? > > Also, does it look any good? Does it make sense to make ~/wal_archive > and ~/base_backups dirs not readable by group and the world? From what > I can see files in ~/wal_archive are 0600, ~/base_backups/TIMESTAMP is > 0700. How can I confirm that it's working properly? Is WAL segments > files appearing in ~/wal_archive enough? > > Thanks in advance. > > Regards, > Yuri Kanivetsky >