1. Aug 08, 2023
    • Dimitri Fontaine's avatar
      Fix ci/banned.h.sh. · cf054e35
      Dimitri Fontaine authored
      Avoid using sscand(), use strtoull with a base 16 instead. In passing
      clean-up some extra logging.
      cf054e35
    • Dimitri Fontaine's avatar
      Use PREPARE/EXECUTE statements for applying DML in follow mode. · 0769a783
      Dimitri Fontaine authored
      When replaying INSERT/UPDATE/DELETE statements, switch to using PREPARE and
      EXECUTE at the protocol level (using the libpq functions PQprepare and
      PQexecPrepared). When a statement has already been prepared previously in
      our session, we then only send the EXECUTE statement.
      
      This shoud provide nice performance improvements.
      0769a783
  2. Aug 07, 2023
  3. Aug 04, 2023
  4. Aug 03, 2023
    • Dimitri Fontaine's avatar
      Refactor the cli_compare code. (#418) · 70741cdc
      Dimitri Fontaine authored
      Introduce a new C module "compare.c" and implement the work there, leaving
      the "cli_compare.c" module with command line and output handling.
      
      In passing, add the checksum information to the schema.json file at the end
      of the pgcopydb compare data command, that might be useful.
      70741cdc
    • Dimitri Fontaine's avatar
      Use Postgres async queries to compute checksums. (#416) · 452ce599
      Dimitri Fontaine authored
      That way pgcopydb compare data waits for as long as the slowest query that
      are running concurrently on source and target instances, which is better
      than serial execution on two different servers.
      
      This changes the JSON format output, because we also now skip fetching the
      target database catalogs.
      452ce599
  5. Aug 02, 2023
    • Dimitri Fontaine's avatar
      Fix filtering on schema names. (#415) · 2da78407
      Dimitri Fontaine authored
      First, the parsing of the schema and table names from the INI file was done
      wrong, in a way that shows with long schema and table names.
      
      Then, I just learned we can't use pg_restore --schema in our context,
      because it would then skip the CREATE SCHEMA statement and pgcopydb relies
      on pg_restore to create the schema on the target database,
      2da78407
  6. Aug 01, 2023
    • Dimitri Fontaine's avatar
      Implement concurrent workers for Large Objects data copy. (#411) · 913e78e9
      Dimitri Fontaine authored
      * Implement concurrent workers for Large Objects data copy.
      
      The default is 4 workers for Large Object data, and another process is
      created to queue the Large Object metadata (oid) and allow workers to share
      the workload. New option available: --large-objects-jobs.
      
      * Fix blob summary.
      
      Reinstall a blob summary file and change its format to JSON.
      913e78e9
  7. Jul 28, 2023
    • Dimitri Fontaine's avatar
      Improve pgcopydb compare data checksum computation. (#407) · 82600afc
      Dimitri Fontaine authored
      Use an output format that is stable in number of digits and can deal with a
      bigint overflow (in Postgres a sum(bigint) is numeric): use an MD5 sum and
      represent it as an UUID.
      
      Also, include the row count in the MD5 computation to better protect against
      collisions.
      
      Finally, add support for pgcopydb compare data --json.
      82600afc
  8. Jul 27, 2023
  9. Jul 26, 2023
  10. Jul 24, 2023
    • Dimitri Fontaine's avatar
    • Dimitri Fontaine's avatar
      Implement extension requirements support. (#400) · 2a8e01f3
      Dimitri Fontaine authored
      This option allows specifying which version of an extension to install on
      the target database. The version might be different from the version on the
      source, and in some cases installing the default version of an extension is
      not desired. Examples are PostGIS v2 and v3 series, for instance.
      
      A requirement file in JSON can be given to pgcopydb commands. The JSON file
      should be an array of objects with the "name" and "version" keys, and can be
      given to either of these commands:
      
          pgcopydb copy extensions --requirements requirements.json
          pgcopydb clone ... --requirements requirements.json
      
      To list the available extension versions on the target database use the
      following commands:
      
          pgcopydb list extension --available-versions
          pgcopydb list extension --available-versions --json
      
          pgcopydb list extension --requirements
          pgcopydb list extension --requirements --json
      
      The last command will output all the extensions available on the target
      database with their default version. It's then possible to edit the output
      file and change the version numbers before giving it back to the copy and
      clone commands.
      2a8e01f3
  11. Jul 20, 2023
  12. Jul 19, 2023
    • Shubham Dhama's avatar
      Fix issue with resuming streaming of interleaved transactions. (#394) · 4d2691e5
      Shubham Dhama authored
      This resolves a problem encountered during the transition from prefetch to
      replay mode, where the transform process identifies some incomplete
      transactions. This issue also arises when we interrupt 'follow' and execute
      a 'follow --resume'.
      
      The root cause is upon resumption of streaming, we may encounter a
      transaction where the initial messages have LSNs less than the startpos
      calculated from the latest json file.
      
      The implemented fix involves comparing the LSNs with 'startpos' only when
      resuming streaming of partially complete transactions. Once 'startpos' is
      reached, comparison of LSNs for subsequent messages is discontinued.
      
      Fixes: #373
      4d2691e5
  13. Jul 17, 2023
  14. Jul 12, 2023
  15. Jul 11, 2023
    • Dimitri Fontaine's avatar
      Assorted fixes for the test_decoding parser. (#380) · 0011c31d
      Dimitri Fontaine authored
      First, Postgres type names might contain square brackets (arrays), which are
      used as a delimited in the test_decoding format for typenames. Fix the code
      to handle the following properly:
      
          f2[text[]]:'{incididunt,ut,labore,et,dolore,magna}'
      
      Then, it turns out that test_decoding emits text in standard SQL form, which
      is to say in single-quotes and with single-quotes doubled, but with the \n
      and other characters not-escaped. We need to edit the representation a
      little so that the ld_transform module processes the text correctly.
      0011c31d
    • Dimitri Fontaine's avatar
      The cli_stream module didn't get the pg_strdup() memo for DSNs. (#379) · d7641331
      Dimitri Fontaine authored
      See #323.
      Fixes #377.
      d7641331
    • Dimitri Fontaine's avatar
      Add facilities to list extension versions. (#378) · 8343be67
      Dimitri Fontaine authored
      The new commands allow listing extension versions in different ways and
      formats (human-friendly table, JSON):
      
        $ pgcopydb list extensions --available-versions
        $ pgcopydb list extensions --requirements
      
      The idea is to prepare for a feature where the extension versions to install
      on the target database can be provided by the user. To prepare for that, the
      new commands allow listing available extension versions on the target
      database and preparing the current requirements file from the extensions
      available on the target and their default version.
      8343be67
  16. Jul 07, 2023
  17. Jul 06, 2023
    • Dimitri Fontaine's avatar
      The cli_stream module didn't get the pg_strdup() memo for DSNs. (#371) · 0d300744
      Dimitri Fontaine authored
      The connection strings are now dynamically allocated but cli_stream somehow
      didn't get the memo so far.
      0d300744
    • Dimitri Fontaine's avatar
      Implement multi-parts read from Unix PIPE. (#370) · c19d3f5d
      Dimitri Fontaine authored
      * Implement multi-parts read from Unix PIPE.
      
      A Unix PIPE is typically 64kB large and we might have JSON messages that
      won't fit in that. The size of the buffer filled by the read() call used to
      be fixed at 128MB, but that doesn't have an impact on how much data we can
      receive in a single read() call actually.
      
      Fix that properly and allocate the size of the PIPE buffer thanks to a call
      to fnctl(fd, FIONREAD) which seems to be well supported. Then use the libpq
      string buffer facility to build the messages in memory when receiving them a
      piece at a time from the Unix PIPE buffer, in multiple read() calls.
      
      * Ensure our read_from_stream buffer terminates properly.
      
      C-string must be terminated by '\0' and the read() call is not ensuring
      that.
      c19d3f5d
    • Dimitri Fontaine's avatar
      Fix NULL connection string in: pgcopydb list schema. (#369) · 2949803e
      Dimitri Fontaine authored
      The list command does not use a --target connection string, so we skip
      preparing the target catalogs in that case. In passing, also fix a strange
      way that PQgetisnull() was done for sequences, as the misleading error meant
      this code got a free round of review.
      2949803e
    • Dimitri Fontaine's avatar
      Review double-precision format string from %g to %f. (#368) · 9cade472
      Dimitri Fontaine authored
      * Review double-precision format string from %g to %f.
      
      That's apparently how to write double-precision integer values without
      loosing precision.
      
      * Use fmod() to determine if the float value is an integer.
      9cade472
    • Dimitri Fontaine's avatar
      Refactor how ld_stream writes to PIPE stdout. (#367) · d81144db
      Dimitri Fontaine authored
      Implement a retry loop in case the PIPE buffer is full or something else
      requires several write attempts before succeeding to write the whole buffer
      there.
      d81144db
  18. Jul 04, 2023
    • Dimitri Fontaine's avatar
      Fix skipping streaming messages when resuming from latest JSON file. (#359) · ba7df802
      Dimitri Fontaine authored
      * Fix skipping streaming messages when resuming from latest JSON file.
      
      It might happen that several JSON messages have the same LSN in our stream,
      usually that concerns KEEPALIVE and BEGIN and COMMIT message. Unless paying
      attention to the latest message action, we could skip a BEGIN message that
      has the same LSN as the latest message even if that message was a KEEPALIVE.
      
      Fix this by keeping around the latest message action. It should be all we
      need to distinguish a new message from the latest one.
      
      * Registering latest message at resume properly.
      
      It could be that we have several messages with the same LSN: I, L, E, for
      instance. Take that into account in streamCheckResumePosition.
      
      * Code review.
      ba7df802
  19. Jun 30, 2023
  20. Jun 29, 2023
    • Dimitri Fontaine's avatar
      Implement --skip-extension-comments. (#356) · 173130dc
      Dimitri Fontaine authored
      On Azure Flexible Server for Postgres the COMMENT ON EXTENSION command is
      not supported as a non-superuser and could cause migrations to fail. Waiting
      for a fix in Azure, allow skipping that part of the pg_dump and restore
      activity.
      173130dc
    • Dimitri Fontaine's avatar
      Fix stream_transform_resume to share context with stream_transform_file. (#355) · 1c306533
      Dimitri Fontaine authored
      When resuming operations from pre-existing files on-disk, we implement some
      cache invalidation by transforming the JSON file again from scratch, and
      tracking progress in our internal data structures.
      
      That's needed in case the previous version of the file terminates in the
      middle of a transaction rather than at a clean transaction boundary.
      
      The previous approach missed that the internal tracking state kept in the
      StreamContext instance was not shared. Now it is.
      1c306533
  21. Jun 28, 2023
    • Dimitri Fontaine's avatar
      Fix our PG_VERSION_STRING_MAX_LENGTH to host more. (#353) · f4b73c9f
      Dimitri Fontaine authored
      The current debian Postgres version string is longer than we anticipated:
      
          "16beta1 (Debian 16~beta1-2.pgdg+~20230605.2256.g3f1aaaa)"
      
      In passing, also make sure that `pgcopydb ping` sets the right GUCs even
      when using Postgres 9.5, and allow more GUCs for that version too.
      f4b73c9f