1. Nov 22, 2022
  2. Nov 21, 2022
    • Dimitri Fontaine's avatar
      Refrain from using wal2json computed column "nextlsn". · 2de9c9d6
      Dimitri Fontaine authored
      This column isn't part of Postgres Logical Decoding API and relying on it
      would prevent pgcopydb from being compatible with other output plugins in
      the future.
      
      Also, our internal tracking of the LSN position was pretty confused at
      times, using a single LSN value makes it simpler to follow our logic.
      
      To still be able to follow WAL filename changes we introduce the SWITCH WAL
      statement in our SQL files too, not just the JSON files anymore. The replay
      process knows how to parse those SWITCH WAL statements.
      
      To still be able to match our endpos with the actual LSN position in the
      WAL, we introduce a new KEEPALIVE statement in our SQL and JSON files too.
      The replay process knows how to parse those KEEPALIVE statements and mark
      the progress on the replication origin tracking on the target database.
      2de9c9d6
    • Shubham Dhama's avatar
      Fix migration failure of an empty database with --drop-if-exists. (#152) · 8cc18823
      Shubham Dhama authored
      It fixes a corner case when --drop-if-exists is used to migrate a database that
      contains no tables. Before this change, `copydb_target_drop_tables` generates an
      invalid SQL query`DROP TABLE IF EXISTSCASCADE`.
      8cc18823
    • Dimitri Fontaine's avatar
      Implement pgcopydb list tables --drop-cache. (#150) · 301c8a3e
      Dimitri Fontaine authored
      This allows to manually drop the cache created with --cache option.
      301c8a3e
    • Dimitri Fontaine's avatar
      Fix the Dockerfile for wal2json support with older Postgres versions. (#153) · ec7ae12b
      Dimitri Fontaine authored
      The apt.postgresql.org debian repository has archived its support for debian
      stretch release, in a way that we need to now use
      apt-archive.postgresql.org.
      
      We could switch to using a bare debian system as the base for our docker
      image here, but we would then have to provide and maintain the entry points
      scripting that the official docker image is providing.
      ec7ae12b
  3. Nov 07, 2022
    • Dimitri Fontaine's avatar
      Implement an option to cache pg_table_size() results. (#146) · ae74b739
      Dimitri Fontaine authored
      * Implement an option to cache pg_table_size() results.
      
      In some environments computing the pg_table_size() can be quite slow, so we
      might benefit from managing a cache of the table sizes that we can re-use.
      This cache is implemented as the pgcopydb.table_size table on the source
      database, which is created with the command pgcopydb list tables --cache.
      
      * Filter out pgcopydb schema when listing sequences, indexes.
      
      * Avoid using pgcopydb list tables in tests.
      
      Because we now create a schema (and leave it behind) when running the
      pgcopydb list tables command, avoid using it in the tests, specifically when
      targetting the target database.
      
      Instead, use pgcopydb list extensions, which doesn't leave objects behind.
      
      * Update tests/cdc JSON file with the new extra transaction.
      
      * Fix tests/follow with new pgcopydb list table skipping pgcopydb schema.
      
      We can't use `pgcopydb list table | grep sentinel` anymore, because we
      excluded the pgcopydb schema from the list commands now that we have both
      the sentinel table and the table_size tables in there.
      ae74b739
    • nakatlam's avatar
      3bdf701d
  4. Nov 03, 2022
  5. Nov 01, 2022
  6. Oct 18, 2022
  7. Oct 17, 2022
  8. Oct 13, 2022
  9. Oct 12, 2022
    • Dimitri Fontaine's avatar
      Implement Logical Decoding compatibility with Postgres 9.6. (#124) · 6bcf3f26
      Dimitri Fontaine authored
      * Implement Logical Decoding compatibility with Postgres 9.6.
      
      Several function and column names have changed (xlog to wal) between
      Postgres major versions 9.6 and 10, and also in Postgres 9.6 creating a
      logical replication slot seems to always export a (new) snapshot.
      
      In this PR we adjust pgcopydb behavior to rely on the logical replication
      protocol CREATE_REPLICATION_SLOT command to export our snapshot when the
      option --follow is used and the source server is Postgres 9.6.
      
      * Add tests/follow-9.6 to the CI.
      
      * Add support for Postgres 9.5 and 10.
      
      Both needed special attention, in particular in the test suite.
      6bcf3f26
  10. Oct 05, 2022
    • Dimitri Fontaine's avatar
      Make it easier to navigate the source code. (#121) · 4731fadd
      Dimitri Fontaine authored
      - split files into smaller specialised units,
      
        - rename "stream.c" to "ld_stream.c" to share the Logical Decoding prefix
          with other modules "ld_apply.c" and "ld_transform.c",
      
        - create blobs.c and extensions.c units,
      
        - split "table-data.c" schema preparation function into new module
          "copydb_schema.c",
      
        - rename utility files with the _utils prefix, like others in the same
          category.
      4731fadd
    • Dimitri Fontaine's avatar
      Also install tcp_keepalives_idle timeout on the target connection. (#120) · 84113512
      Dimitri Fontaine authored
      While a CREATE INDEX command or an ALTER TABLE command is running, at the
      tcp level we're entirely quiet. When that command runs for more than 2
      hours, with the default Linux settings, our connection might get
      interrupted. Prevent against that.
      84113512
  11. Sep 30, 2022
  12. Sep 29, 2022
    • Dimitri Fontaine's avatar
    • Dimitri Fontaine's avatar
      Set idle_in_transaction_session_timeout to zero. (#116) · 91c812ac
      Dimitri Fontaine authored
      In the context of the main session that holds onto the snapshot and does
      nothing, we really want to avoid that session getting killed by Postgres
      because of the idle_in_transaction_session_timeout.
      91c812ac
    • Dimitri Fontaine's avatar
      Make sure to transform JSON files in all cases. (#115) · 637a5e41
      Dimitri Fontaine authored
      There is a case when we reach the endpos at startup (or restart), and we
      have a JSON file around that was not transformed yet: the current LSN is not
      past this file yet, and the previous time when streaming we didn't reach to
      the endpos yet.
      
      Now we need to transform that JSON file into SQL, even though we don't have
      an open file pointer to call fclose() on.
      637a5e41
    • Dimitri Fontaine's avatar
      Bug fixes for the transform process. (#114) · 5d3b78db
      Dimitri Fontaine authored
      - make sure to reset the FILE * pointer to NULL after closing the file.
       - use a stable sub-process to transform JSON files into SQL.
      
      For the second point, we re-use the queuing infrastructure introduced in a
      recent patch. This allows to have a single sub-process started that will
      handle all the JSON to SQL transformations during replay.
      5d3b78db
    • Dimitri Fontaine's avatar
      Use docker-compose run in tests, instead of docker-compose up. (#113) · a147c085
      Dimitri Fontaine authored
      * Use docker-compose run in tests, instead of docker-compose up.
      
      In passing, also change the test build dependencies in a way that
      docker-compose knows about our usage of the common pagila container. This
      allows skipping useless builds of that intermediate container.
      
      The docker-compose run command also is a better UI for our testing when
      compared to using docker-compose up and then waiting until the main
      container stops.
      
      * Separate our build pgcopydb service and the test service.
      
      * Attempt to fix GitHub worklow for tests: compute version string first.
      
      * Review and simplify docker-compose build dependencies.
      
      In short docker-compose does not know how to handle build time dependencies
      between different containers. I suppose we would need a place to push the
      intermediate images and pull them later, and we're now using the local
      docker daemon for that by building the pre-requisites manually before
      invoking the docker-compose build and run commands.
      a147c085
  13. Sep 28, 2022
    • Dimitri Fontaine's avatar
      From the lab: we could have more lines in a WAL.json file. (#112) · 913594dd
      Dimitri Fontaine authored
      Change the static memory allocation to a dynamic one for the array of line
      pointers. Even if we only require a sizeof(char *) (a single pointer) per
      line to allocate, we might need a lot of them.
      913594dd
    • Dimitri Fontaine's avatar
    • Dimitri Fontaine's avatar
      Add support for Extension Configuration Tables (#101) · 2bc7e28a
      Dimitri Fontaine authored
      * Implement pgcopydb list extensions.
      
      * Implement pgcopydb copy extensions.
      
      * Add support for extension configuration in pgcopydb copy extensions.
      
      * Fix extension listing query.
      
      * Add a unit test covering extensions, and fix some bugs.
      
      * Fix schema queries for sequences when filtering is involved.
      
      * Add schema/data that requires Postgis in the extensions unit test.
      
      * Remove extra logging that's not necessary anymore.
      
      * Implement pgcopydb clone --skip-extensions.
      
      This allows to skip creating extensions on the target database, which
      requires superuser privileges. This could now be implemented with another
      command such as pgcopydb copy extensions.
      
      * Fix connection management for pgcopydb copy extensions.
      
      * Logs and comments clean-up.
      
      * Make sure we can --skip-extensions and use a non-superuser role.
      
      The test case now uses non-superuser for the pgcopydb clone operation, and
      deals with roles and extensions separately, with superuser privileges. For
      that to work, we need to skip restoring the ACL and COMMENT entries for the
      extensions and the schema they depend on, as that's superuser territory.
      
      * Copy extension configuration table user-data in pgcopydb clone.
      
      * Add a documentation section about Postgres superuser.
      2bc7e28a
  14. Sep 22, 2022
  15. Sep 21, 2022