Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hkqBf-0006md-7N for pgsql-general@arkaria.postgresql.org; Tue, 09 Jul 2019 13:29:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hkqAf-0005yo-4U for pgsql-general@arkaria.postgresql.org; Tue, 09 Jul 2019 13:28:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hkdn7-0003rm-V7 for pgsql-general@lists.postgresql.org; Tue, 09 Jul 2019 00:15:30 +0000 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hkdn5-0006t7-Mv for pgsql-general@postgresql.org; Tue, 09 Jul 2019 00:15:29 +0000 Received: by mail-io1-xd31.google.com with SMTP id m24so29889058ioo.2 for ; Mon, 08 Jul 2019 17:15:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:mime-version:subject:message-id:date:to; bh=J7SAf6v1AijItIHHsueN5VTiQw1dfxRSgjsK/dOH8ww=; b=H9gfMuU8JxIqjUfLK4KNeTNW87I6wqfsFun8EoaelviCBO4fGufwFBiAOD1UalooyE 2hQEdvawG9jfGyh6KsgJlG4WbUyFZQcdhrb4JPKXeW9G6zlknEFsCBY17y0voeAE1736 tDxaqdw2koFVF9wLq6mE63L4VmPXAV0aUKqLWx6LgW6W1F3SXo6ARxwIwf9i5ieXPbcD V5sOfRC0fb9wkbUbSJgSLqG94tYhBdtAYNVzUOFHA8qMTjA0OQ18IGac32VM9o85NYm2 WWohBYwf84YiNeSddTDuJ5IZd6M8WOUpa4Sz9Ikya9qfibHF+x7W/rDJOgx0D+g8hxjZ wZeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:message-id:date:to; bh=J7SAf6v1AijItIHHsueN5VTiQw1dfxRSgjsK/dOH8ww=; b=VTVGCbp9/Dj6/cEf1I6Y0Lw8c1g3VoDu55uUmTkgmdGYMy9b0PkYfZqkpze0OT1Cku NihzeIfDECn+e75sr1giwcaskhgxQAPNNb2PciC66JBwqdm/MiE6hbx4E6mTzHHUJSRh OW/UZ8lm3xeDnusLxwOeO/JYSZaE1Qz1pfNuBAG+MJjh8y8VkoCsTxKISqRDMv4QGx1t /aCib4clAHZpnmyS1pLicIAK8CT5vl+Ijse0yeVgP5kVwE4rFFF+VuqX6GZbSA/4BxBW rkjmt9qwJBMZd6sQqdlV8BrZTQNtFk9gtsXXD9sDlPHTveuyuXcbfbHoSD+ec/cvNtwp cC/Q== X-Gm-Message-State: APjAAAXsLXaF8t+DDRXgVA5526+1EDuga00vGLg8LDR4f59Z27prP2DE gfwMZ6gxVPKJ9S2rit7x5jorxSrKjfY= X-Google-Smtp-Source: APXvYqzk51ysHTHivSMPMgA8LdUuewtUY8DfOUCqU+WYsTBX4cNXc2OHsvFicZWuUKj9d4tQuFI8BA== X-Received: by 2002:a02:cc6c:: with SMTP id j12mr23517545jaq.102.1562631325604; Mon, 08 Jul 2019 17:15:25 -0700 (PDT) Received: from [192.168.7.230] ([104.218.188.91]) by smtp.gmail.com with ESMTPSA id c14sm17184299ioa.22.2019.07.08.17.15.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jul 2019 17:15:24 -0700 (PDT) From: Taylor Sarrafian Content-Type: multipart/alternative; boundary="Apple-Mail=_68245EA9-4FA8-48DF-A0DD-57194BCDF3EC" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Logical Replication for Very Large Databases Message-Id: <8B0D84B4-7A97-42E1-9E94-14E026244104@gmail.com> Date: Mon, 8 Jul 2019 17:15:23 -0700 To: pgsql-general@postgresql.org X-Mailer: Apple Mail (2.3445.104.11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_68245EA9-4FA8-48DF-A0DD-57194BCDF3EC Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi friends, We have a relatively large database (~5TB) receiving very frequent = INSERTs/UPDATEs, and we=E2=80=99d like to create a logical replica of = it. To put things in perspective, we often generate up to 10 = WAL-segments (16MB each) per second (wal_level=3Dreplica). We successfully set up logical replication in our smaller staging DB, = but the scale of production is making things difficult. --- Here are some approaches we considered: 1. `CREATE SUBSCRIPTION =E2=80=A6 WITH ( copy_data=3Dtrue )`=20 This would be ideal, except we=E2=80=99re afraid of accumulating too = much WAL on the publishing server while waiting for ~5TB to copy over. = We could theoretically increase the size of the drive to something like = 10TB, but that=E2=80=99s not currently an option for us. There=E2=80=99s also the issue of performance. It=E2=80=99s unclear what = impact `copy_data=3Dtrue` would have on our DB read/write throughput, = and we=E2=80=99re hesitant to try it. 2. Start from a base-backup and catch-up with `restore_command`: `SELECT pg_replication_slot_advance( pg_current_wal_lsn() )` could work = nicely with a matching `recovery_target_lsn` in `recovery.conf`. We already use `archive_command` with `wal-g` to store WAL and = base-backups to GCS. Unfortunately, by the time our base-backup is = downloaded onto the replica, it=E2=80=99s already at least 6 hours old. = And restoring with `restore_command` runs at a similar speed to = `archive_command`, so it remains ~5-8 hours behind as long as it=E2=80=99s= in standby. Our postgres process isn=E2=80=99t limited by CPU, memory, network, or = disk-speed on the replica. It doesn=E2=80=99t seem to be working at its = full capacity, which suggests a configuration issue. Please look at our configurations below and let us know if there are any = options we could tweak in `postgresql.conf` to speed up the WAL = ingestion for `restore_command`. 3. Start from a base-backup and catch-up with the `pg_wal` directory: We could write a script to grab WAL-segments from GCS and place them = into the `pg_wal` directory. This is what `restore_command` is = technically doing, but we might be able to squeeze some efficiency out = of a custom script. Maybe. =E2=80=94 Our server has 32 cores and 120GB of memory with the following selected = configs: ``` shared_buffers =3D 30GB huge_pages =3D try maintenance_work_mem =3D 1GB max_files_per_process =3D 2000 effective_io_concurrency =3D 100 max_worker_processes =3D 32 max_parallel_maintenance_workers =3D 2 max_parallel_workers_per_gather =3D 0 parallel_leader_participation =3D on max_parallel_workers =3D 32 wal_level =3D archive wal_buffers =3D 16MB checkpoint_timeout =3D 30min max_wal_size =3D 100GB min_wal_size =3D 1GB checkpoint_completion_target =3D 0.9 max_wal_senders =3D 20 wal_keep_segments =3D 10 effective_cache_size =3D 90GB ``` Thanks for all the help! ts <>= --Apple-Mail=_68245EA9-4FA8-48DF-A0DD-57194BCDF3EC Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Hi = friends,

We have a = relatively large database (~5TB) receiving very frequent = INSERTs/UPDATEs, and we=E2=80=99d like to create a logical replica of = it. To put things in perspective, we often generate up to 10 = WAL-segments (16MB each) per second (wal_level=3Dreplica).

We successfully set up = logical replication in our smaller staging DB, but the scale of = production is making things difficult.

---

Here are some approaches we = considered:

1. = `CREATE SUBSCRIPTION =E2=80=A6 WITH ( copy_data=3Dtrue = )` 

This = would be ideal, except we=E2=80=99re afraid of accumulating too much WAL = on the publishing server while waiting for ~5TB to copy over. We could = theoretically increase the size of the drive to something like 10TB, but = that=E2=80=99s not currently an option for us.

There=E2=80=99s also the issue of = performance. It=E2=80=99s unclear what impact `copy_data=3Dtrue` would = have on our DB read/write throughput, and we=E2=80=99re hesitant to try = it.

2. Start = from a base-backup and catch-up with `restore_command`:

`SELECT = pg_replication_slot_advance( pg_current_wal_lsn() )` could work nicely = with a matching `recovery_target_lsn` in `recovery.conf`.

We already use = `archive_command` with `wal-g` to store WAL and base-backups to GCS. = Unfortunately, by the time our base-backup is downloaded onto the = replica, it=E2=80=99s already at least 6 hours old. And restoring with = `restore_command` runs at a similar speed to `archive_command`, so it = remains ~5-8 hours behind as long as it=E2=80=99s in standby.

Our postgres process = isn=E2=80=99t limited by CPU, memory, network, or disk-speed on the = replica. It doesn=E2=80=99t seem to be working at its full capacity, = which suggests a configuration issue.

Please look at our configurations below = and let us know if there are any options we could tweak in = `postgresql.conf` to speed up the WAL ingestion for = `restore_command`.

3. Start from a base-backup and catch-up with = the `pg_wal` directory:

We could write a script to grab = WAL-segments from GCS and place them into the `pg_wal` directory. This = is what `restore_command` is technically doing, but we might be able to = squeeze some efficiency out of a custom script. Maybe.

=E2=80=94

Our server has 32 cores = and 120GB of memory with the following selected configs:
```
shared_buffers =3D = 30GB
huge_pages =3D try
maintenance_work_mem =3D 1GB
max_files_per_process =3D 2000
effective_io_concurrency =3D 100
max_worker_processes =3D 32
max_parallel_maintenance_workers =3D 2
max_parallel_workers_per_gather =3D 0
parallel_leader_participation =3D on
max_parallel_workers =3D 32
wal_level =3D = archive
wal_buffers =3D 16MB
checkpoint_timeout =3D 30min
max_wal_size = =3D 100GB
min_wal_size =3D 1GB
checkpoint_completion_target =3D 0.9
max_wal_senders =3D 20
wal_keep_segments = =3D 10
effective_cache_size =3D = 90GB
```

Thanks for all the help!

ts
= --Apple-Mail=_68245EA9-4FA8-48DF-A0DD-57194BCDF3EC--