1. May 26, 2023
  2. May 25, 2023
  3. May 22, 2023
  4. May 15, 2023
  5. May 11, 2023
    • Dimitri Fontaine's avatar
      Fix how snapshot are exported when using CDC. (#279) · 19f72f6a
      Dimitri Fontaine authored
      It turns out that we can't just call pg_create_logical_replication_slot() in
      a transaction that uses a snapshot to sync the initial copy of the data with
      the change data capture. We need to use the CREATE_REPLICATION_SLOT logical
      replication command with the RESERVE_WAL true SNAPSHOT 'export' options.
      
      * Add a new test case that fails because of missing data around replication slot creation.
      
      * Implement tracking of --plugin, --origin, and --slot-name options.
      
      We already tracked --snapshot so that we can --resume and continue operating
      with the same snapshot as before, and we should really have the same
      facility for the rest of the replication based options.
      
      * In --follow mode, export the snapshot via CREATE_REPLICATION_SLOT.
      
      The previous code would set transaction snapshot to a previously exported
      snapshot and then create the logical replication slot, but that creates a
      replication gap. Postgres supports only one way to avoid that gap, which
      consists of exporting the snapshot used to create the replication slot.
      
      In passing, register the full information we get from creating the
      replication slot to file, in such a way that we can re-use that file and
      information later, including the consistent_point LSN that is associated
      with the replication slot... and the snapshot.
      
      As a result, the following commands have been removed from the CLI:
      
          pgcopydb stream create slot
          pgcopydb stream create origin
          pgcopydb stream drop slot
          pgcopydb stream drop origin
      
      The only way to create a replication slot with pgcopydb is now the command
      `pgcopydb snapshot --follow`, and the replication origin on the target must
      be created with the consistent_point LSN returned by the same command.
      
      * Fix unit tests to adjust to the new API/CLI.
      
      The creation of a replication slot is not done in the pgcopydb steam setup
      command anymore, the command pgcopydb snapshot --follow must be used now.
      
      * Fix installing default values for --plugin and --slot-name.
      
      In particular the option --plugin also is supported via the environment
      variable PGCOPYDB_OUTPUT_PLUGIN and we must refrain from overwritting the
      value we might have read from there.
      
      Then we need to adjust the tests to wait until the coproc snapshot command
      has created its snapshot and files on-disk to be able to properly read the
      values from there (snapshot, replication slot name and lsn, etc).
      19f72f6a
    • Dimitri Fontaine's avatar
    • Dimitri Fontaine's avatar
      Fix pgsql is_response_ok to accept also PGRES_COPY_BOTH. (#284) · 59ec46dd
      Dimitri Fontaine authored
      That result status comes from our implementation of a logical decoding
      client, where COPY BOTH protocol is used.
      59ec46dd
    • Dimitri Fontaine's avatar
    • Shubham Dhama's avatar
      Fix double precision out of range during COPY. (#281) · d8075076
      Shubham Dhama authored
      We have identified the root cause of the issue where double precision values were going out of range during the COPY operation. It turns out that we were missing the extra_float_digits GUC (grand unified configuration) while copying the float8 data. As a result, when extreme values like '1.7976931348623157E+308' were copied from the source, an overflow occurred.
      d8075076
  6. May 05, 2023
    • Dimitri Fontaine's avatar
      Fix the transition between replay operating modes. (#277) · dd1744fd
      Dimitri Fontaine authored
      When switching replay operating modes we want to replay all the changes that
      has been streamed locally but have not been caught-up yet. This includes
      some JSON to SQL transformation work that was missed before.
      
      To be able to receive from the transform queue after having received a
      signal to stop, we need to also reset the signals control flags, otherwise
      all we get is an early exit in queue_receive.
      dd1744fd
  7. May 02, 2023
  8. Apr 28, 2023
    • Dimitri Fontaine's avatar
      53e85804
    • Dimitri Fontaine's avatar
      Update pgcopydb sentinel's replay_lsn asynchronously. (#267) · 18ff38ab
      Dimitri Fontaine authored
      * Update pgcopydb sentinel's replay_lsn asynchronously.
      
      When in follow replay mode, the pgcopydb sentinel is updated quite
      frequently so that we can see progress being made and be reactive about when
      to implement the migration cutover.
      
      Now, we might have to consider some latency with the source database system
      where the replay_lsn is published, so rate-limiting those sentinel updates
      is important. Also, rate limiting alone might not be enough to prevent
      slowing down the replay process, so switch to using libpq async API.
      
      * Make sure to update replay_lsn before sub-process exit.
      18ff38ab
  9. Apr 27, 2023
  10. Apr 25, 2023
  11. Apr 20, 2023
    • Dimitri Fontaine's avatar
      Fix the previous commit to switch to dynamic memory for schema parts. (#260) · c3ce5f40
      Dimitri Fontaine authored
      The summary commands were also statically allocated with BUFSIZE bytes,
      which is not always enough to fit the index definitions etc. Apply same
      approach as in commit f05d75b6.
      
      Also add unit test coverage this time.
      c3ce5f40
    • Dimitri Fontaine's avatar
      Assorted streaming fixes, including skipping of empty transactions. (#257) · 0c4e4334
      Dimitri Fontaine authored
      * Assorted streaming fixes, including skipping of empty transactions.
      
      * Fix memory management of JSON buffers when parsing Logical Messages.
      
      Now that we need to keep around the previous LogicalMessageMetadata, we also
      need to keep around its JSON buffer. This means we can't re-use the pointer
      to the current context buffer, and we need to duplicate memory even when
      using wal2json and keeping the same JSON buffer as received.
      
      In passing, adjust the JSON files in the test suite according to the new
      empty transactions filtering and synthetic KEEPALIVE situation.
      
      * Atttempt to fix CI errors (exit code 141).
      
      The exit code 141 is 128 + 13, and 13 is SIGPIPE. It means that in our
      cdc-low-level test case when doing receive | transform | apply, one of the
      processes is trying to write to its output pipe when the next process has
      already exited, or at least closed its pipe input file descriptor.
      
      By ignoring SIGPIPE we ask the system to return EPIPE at write time. Let's
      now see how our code handles that.
      0c4e4334
  12. Apr 17, 2023
  13. Apr 14, 2023
    • Dimitri Fontaine's avatar
      Use dynamic memory for variable length schema parts. (#249) · f05d75b6
      Dimitri Fontaine authored
      Rather than using a static BUFSIZE string buffer we call calloc() to
      allocate memory dynamically for index columns, index definitions, constraint
      definition, and collation descriptions.
      
      The allocated memory is used throughout the pgcopydb program execution, and
      at the moment the memory is not de-allocated by a call to free(). Instead,
      we rely on the OS to take care of that for us when exiting pgcopydb.
      f05d75b6
    • Dimitri Fontaine's avatar
      Fix special characters in SQL queries. (#248) · 04ebb02b
      Dimitri Fontaine authored
      Instead of escaping the characters at the C code level only, issuing queries
      with actual newlines in the query text, arrange to embed escaped characters
      in the SQL query text (\n and \r).
      04ebb02b
    • Dimitri Fontaine's avatar
      Fix exclude-schema filtering to apply to pg_dump and pg_restore. (#247) · f280da00
      Dimitri Fontaine authored
      It could be that the role used to connect to the source and target databases
      lacks privileges to access some Postgres schema and/or objects within that
      schema, which means using --exclude-schema on the command line is the right
      approach.
      f280da00
    • Dimitri Fontaine's avatar
      Fix Postgres catalog queries that implement sequences filtering. (#246) · 012bd2ae
      Dimitri Fontaine authored
      We need to find sequences that are associated with table columns either as
      default values (through pg_depend entry between the sequence and pg_attrdef)
      or as an identity column (through a pg_depend entry between the sequence and
      the table column directly).
      
      Also, when a sequence is filtered-out from our pg_restore activity, then we
      need to also filter-out the archive TOC entry for the default value that
      uses the sequence, in addition to filtering out the table and the sequence
      themselves.
      
        ALTER TABLE ONLY public.bar ALTER COLUMN id SET DEFAULT nextval(...)
      
      Otherwise we get ERROR: relation does not exist in pg_restore.
      012bd2ae
    • Dimitri Fontaine's avatar
      187a89fc
  14. Apr 13, 2023
  15. Apr 07, 2023
  16. Apr 06, 2023
  17. Apr 05, 2023
    • Dimitri Fontaine's avatar
      Implement the feature to log to file, with support for JSON. (#234) · 0ab7a11d
      Dimitri Fontaine authored
      This allows pgcopydb to log both to the terminal and also to a file, where
      the format is not adjusted for terminal width (long time format, source file
      and line always included).
      
      Also implements logging in JSON, using a JSON object per line with a static
      set of attributes that includes all the metadata we have about the log
      message.
      
      The control of this feature set is entirely based on using environment
      variables, no new command line switch has been introduced. It is possible to
      log both in plain text with colors on the terminal and to a JSON file at the
      same time.
      0ab7a11d
  18. Apr 04, 2023
  19. Apr 03, 2023
    • Dimitri Fontaine's avatar
      Introduce new option --skip-vacuum. (#230) · b27f0fa7
      Dimitri Fontaine authored
      This allows postponing the first round of VACUUM ANALYZE on the target
      tables after enabling the production workload again.
      b27f0fa7
    • Dimitri Fontaine's avatar
      Refactor copydb_init_specs to use a CopyDBOptions struct. (#229) · 02b3d8bb
      Dimitri Fontaine authored
      Rather than having to add so many parameters just re-use the options struct
      as a parameter there.
      
      We still want to have a separate command line option structure rather than
      use the internal tracking CopyDataSpec structure at command line parsing
      time, but we can still simplify the code a good deal.
      
      This allows easier adding of new command line options in the future.
      02b3d8bb
    • Dimitri Fontaine's avatar
      Fix when we VACUUM ANALYZE. (#228) · d3f2fbb4
      Dimitri Fontaine authored
      Careful reading of the Explicit Locking chapter of Postgres documentation
      shows that VACUUM and ANALYZE take a SHARE UPDATE EXCLUSIVE lock against the
      target table, and CREATE INDEX take a SHARE lock, which conflicts with the
      former one.
      
        https://www.postgresql.org/docs/current/explicit-locking.html
      
      So we can't actually VACUUM ANALYZE a table while building the indexes and
      then constraints on top of that. The queueing of the VACUUM operations is
      now done after the indexes and constraints are built.
      d3f2fbb4
  20. Mar 31, 2023
    • Dimitri Fontaine's avatar
      Refrain from logging user data. (#227) · 39bf9825
      Dimitri Fontaine authored
      In the apply process logging the SQL statements opens the door to logging
      user data. For privacy concerns, reduce the apply module logging.
      
      Also reduce the amount of logs sent by the receive and apply processes in
      general, as this can lead to a very large volume of data and we do not
      anciticape needing that level of details to be able to debug operations.
      39bf9825