1. Jul 22, 2022
  2. Jul 20, 2022
  3. Jul 19, 2022
    • Dimitri Fontaine's avatar
      Implement pgcopydb clone --follow. (#72) · fa728933
      Dimitri Fontaine authored
      * Implement pgcopydb clone --follow.
      
      * Review and improve some replay LSN log messages.
      
      * Review process organisation for pgcopydb clone --follow.
      
      We need to separate the clone process tree (with its calls to waipid()
      blocking until all the sub-processes are done) and the follow process tree
      that creates two extra sub-processes (prefetch and catchup).
      
      As a result `pgcopydb clone` process tree is impacted too, and the main
      process only exports a snapshot now. The rest of the top-level processing is
      actually implemented in the "main" (or "clone") sub-process, even when a
      "follow" sub-process is not started.
      
      * Improve docs for pgcopydb clone --follow.
      fa728933
  4. Jul 18, 2022
    • Dimitri Fontaine's avatar
      944885cf
    • Dimitri Fontaine's avatar
      Implement a sentinel. (#69) · 974972e8
      Dimitri Fontaine authored
      * Implement a sentinel.
      
      The sentinel is a table on the source database with 3 columns to share the
      LSN start position for the logical decoding receiver, the LSN end position
      where to stop receiving and applying logical decoding changes, and finally
      the apply boolean which can be set to true when the catching-up process is
      allowed to start processing pre-fetched events.
      
      The idea is to set the sentinel apply boolean as soon as the base copy
      finishes, and to allow pgcopydb users and test suite to set and endpos after
      the start of the follow processes.
      
      * Assorted fixes.
      
        - review the test files to use the new commands facilities
        - only use the sentinel in the catchup command, not the apply command
        - filter out CDC for pgcopydb.* tables (sentinel)
        - allow retrying until the streaming context files have been created
      
      * Use the pgcopydb sentinel table startpos and endpos in follow command.
      
      Rather than manually fetching the current LSN on the source database and
      then passing that as an argument to pgcopydb follow --endpos, we can now use
      the pgcopydb stream sentinel set endpos --current command.
      
      * Use the pgcopydb sentinel to track progress, and sync as we go.
      
      We need to sync with the sentinel changes in case an endpos has been set
      concurrently to the pgcopydb follow processing. We can also use the sentinel
      shared table as a way to exchange information between the replay process and
      the receive process, such as the replay_lsn.
      
      * Publish replay_lsn feedback to the replication stream.
      
      * Implement support for early WAL file switching, improve tests.
      
      Now the tests are running a separate instance for the injection of SQL
      commands, and the sentinel endpos is driven from outside the pgcopydb follow
      process and command.
      
      * Review and adjust documentation for pgcopydb follow etc.
      
      This PR introduces a bunch of new commands and also changes in how some
      commands are made available. Finally edit the docs to reflect the new CLI.
      974972e8
  5. Jul 11, 2022
  6. Jul 08, 2022
    • Dimitri Fontaine's avatar
      Implement pgcopydb stream catchup. (#66) · c9b8ab6d
      Dimitri Fontaine authored
      This command knows how to catch-up from the current tracked position found
      at the target database. This position should be created from the LSN
      returned by the creation of the logical replication slot, which the other
      command `pgcopydb stream setup` already does.
      c9b8ab6d
  7. Jul 07, 2022
    • Dimitri Fontaine's avatar
      Implement pgcopydb stream prefetch. (#65) · 4c31c50d
      Dimitri Fontaine authored
      * Implement pgcopydb stream prefetch.
      
      The prefetch command setup the logical decoding operations in a way that
      allows transforming each JSON file received into an SQL file. It's a kind of
      integration of the two following commands:
      
          $ pgcopydb stream receive
          $ pgcopydb stream transform
      
      Where the transform process is started in the background as soon as needed.
      
      * Implement pgcopydb stream setup.
      
      Also implement two other new commands to create and drop a replication
      origin, so that the command
      
          $ pgcopydb stream setup
      
      is equivalent to the commands
      
          $ pgcopydb create slot
          $ pgcopydb create origin --startpos <slot creation lsn>
      4c31c50d
  8. Jul 05, 2022
    • Dimitri Fontaine's avatar
      Implement support for copying roles. (#64) · e8b47745
      Dimitri Fontaine authored
      * Implement support for copying roles.
      
      Postgres roles are global objects, which means they do not belong to any
      specific database in an instance. To be able to dump and restore the roles,
      we need to use pg_dumpall --roles-only.
      
      * Manually send SQL commands from the pg_dumpall --roles-only script.
      
      This allows to implement "create role if not exists" our own way, accepting
      roles that already exists as they are.
      
      * Have tests/pagila use a non-postgres role.
      
      We now create a "pagila" role and make it owner of the database and its
      objects, and then run the pgcopydb commands using that new non-superuser
      role.
      
      The creation of the new role on the target system is made by calling into
      pgcopydb dump roles and pgcopydb restore roles.
      
      * Skip ALTER ROLE commands too when skipping CREATE ROLE.
      
      * Imnplement pgcopydb copy roles.
      
      * Implement pgcopydb clone --roles.
      
      This includes a STEP 0 that copies the roles from the source instance to the
      target instance.
      e8b47745
  9. Jul 04, 2022
  10. Jul 02, 2022
  11. Jul 01, 2022
  12. Jun 30, 2022
  13. Jun 27, 2022
  14. Jun 13, 2022
    • Dimitri Fontaine's avatar
      Set tcp_keepalives_idle to 60s on the source database. · 5d29736e
      Dimitri Fontaine authored
      Because we might keep open a long-running transaction on the source
      database, the one that keeps a snapshot open for the whole duration of the
      migration, then it's probably best to set the tcp_keepalives_idle to
      something short.
      
      This should help avoid some problems with firewalls shutting down long
      running (idle) Postgres connections or transactions.
      5d29736e
  15. Jun 08, 2022
  16. Jun 02, 2022
    • Dimitri Fontaine's avatar
      WIP: add support for logical decoding (receiver) (#12) · 718e3177
      Dimitri Fontaine authored
      * First batch of work to implement support for logical decoding.
      
      The idea is to enable Change data capture while the initial copy of the
      source database is happening, in a way that we can then later catch-up with
      the changes and reduce the maintenance window for the migration.
      
      The trouble with using Logical Replication directly is that:
      
        - logical replication has no support for DDLs, so the schema parts needs a
          separate handling anyways
      
        - during the initial copy of the data the logical replication subscriber
          does not consume from the replication slot, meaning that a high traffic
      	source system might end-up filling up the WAL disk entirely when the
      	initial copy takes too long
      
        - using logical replication requires creating new SQL objects in both the
          source and the target database, and the subscription on the target
      	database requires superuser access.
      
      All in all there is a strong case to be made for writing a client-side
      logical decoding client that replays the changes from the source system into
      the target system.
      
      * Improve logical decoding support, refactor code.
      
      * Add a quick metadata parsing stage to the receiver.
      
      This provides some stats and a better output, but that's about it really.
      
      * Fix compilation with gcc.
      
      * Create WAL.json files in XDG_DATA_HOME (~/.local/share).
      
      * Implement fsync() on a regular basis and report flush_lsn accordingly.
      
      * Install the Unix signal handlers.
      
      * Fix the logical decoding write/flush/close callbacks.
      
      Include calling the flush callback when a signal has been received, and the
      close callback before exiting the pgsql_stream_logical function.
      
      * Implement resuming operations from the latest LSN.
      
      * Error handling enhancements.
      
      This includes a retry policy for streaming changes, and also better logging
      of error messages.
      
      * Move signal handlers init to logical streaming only at the moment.
      
      Checking that the rest of the code is ready to handle interrupts is not
      within the realm of this PR. Let's just install the signal handlers for the
      logical streaming command and review the general case separately.
      
      * Add some docs for the new commands.
      
      Just a skeleton of the needed documentation, will be improved on later.
      
      * Refactor StreamDBoptions to re-use the common CopyDBOptions.
      
      * Clean-up inter-modules dependencies.
      
      * Implement pgcopydb stream receive --endpos.
      
      * Implement a new test suite for Change Data Capture.
      
      * Review docs.
      
      * Improve docs.
      
      * Typo fix the github workflow branch names (master/main)
      
      * Add tests/cdc to our test matrix.
      
      * Patch review.
      718e3177
    • Dimitri Fontaine's avatar
      8ab548cb
  17. May 24, 2022
  18. May 23, 2022
    • Dimitri Fontaine's avatar
      Skip long-running transactions when --not-consistent is used. (#45) · 9a524b2b
      Dimitri Fontaine authored
      To prevent limitations around lock management when running pgcopydb on a
      source database with lots of objects, we now benefit from --not-consistent
      as an opportunity to reduce long-running transactions.
      
      It was already the case that --not-consistent wouldn't require exporting or
      setting a snapshot, but the opportunity was not yet implemented fully.
      9a524b2b
  19. May 20, 2022
    • Dimitri Fontaine's avatar
      Fix filtering of the pre-data section of the dump. (#44) · 19db6b62
      Dimitri Fontaine authored
      * Implement filtering the pre-data section.
      
      When installing the schema on the target database, we want to already filter
      out the SQL objects that are filtered-out in the filtering setup. The
      previous coding forgot about that parts.
      
      See #43.
      
      * Implement support for exclude-schemas.
      
      The parsing was implemented already, but the filtering itself was shy of a
      brick load. We need to both filter tables that belong to the schema (we did)
      and also the schema object itself (we didn't).
      
      * Add missed SQL objects types to parse from pg_restore archive list.
      
      * Add ACL as a pg_restore archive catalog description entry.
      19db6b62
  20. May 16, 2022