Skip to content

feat: export via COPY TO STDOUT instead of temporary view (SUPPORT-17025)#171

Draft
terezaskalova wants to merge 1 commit into
masterfrom
devin/1784192911-pgsql-copy-no-temp-view
Draft

feat: export via COPY TO STDOUT instead of temporary view (SUPPORT-17025)#171
terezaskalova wants to merge 1 commit into
masterfrom
devin/1784192911-pgsql-copy-no-temp-view

Conversation

@terezaskalova

Copy link
Copy Markdown

Summary

The Copy export adapter no longer creates a temporary view on the source database. Previously, when the DB user could create a view, each export ran DDL against the source:

CREATE TEMP VIEW "<uid>" AS <query>;
\COPY (SELECT * FROM "<uid>") TO '<file>' WITH CSV ...;
DROP VIEW "<uid>";

The temp view existed only to work around a psql limitation: the client-side \copy meta-command must fit on a single line, so multi-line queries fail unless wrapped in a view.

This PR switches to the server-side COPY (...) TO STDOUT SQL statement, redirecting its output to the target file with psql's \o meta-command:

\encoding UTF8
<initQueries>
\o '<file>'
COPY (<query>) TO STDOUT WITH CSV DELIMITER ',' FORCE QUOTE *;
\o

COPY ... TO STDOUT is a regular SQL statement, so it handles multi-line queries without any DDL and requires no special privileges (any user that can SELECT can run it). Output CSV is byte-for-byte the same as before.

Because no view is created anymore, the pre-flight canUserCreateView() (has_schema_privilege(...)) and isTransactionReadOnly() (SHOW transaction_read_only) probe queries — and the whole view/non-view branch — are removed. This also drops two round-trip queries per export.

This directly addresses the customer request in SUPPORT-17025 (replication with no DDL updates on the source).

Testing

  • composer ci passes (phpcs, phpstan, unit + functional).
  • Updated expected output for run-action-row-debug-logging (logged SQL) and error-invalid-query (error now references COPY (...) TO STDOUT instead of CREATE TEMP VIEW).
  • run-action-with-read-only-user still passes, confirming read-only users export correctly via the new path.

Release Notes

Justification, description

Customer (SUPPORT-17025) requires DB replication with no DDL changes on the source. The Postgres extractor's Copy adapter created/dropped a temporary view per export; it now uses COPY (...) TO STDOUT redirected to the output file, avoiding all DDL while producing identical output.

Plans for Customer Communication

Provide the customer with a testing image tag to validate against their source before release.

Impact Analysis

Applies to all Postgres extractor exports using the Copy (psql) adapter. Output CSV is unchanged. Multi-line queries continue to work (previously handled via the temp view). Read-only users and users without CREATE privilege are unaffected (already used a direct COPY path).

Deployment Plan

Standard component release after review + CI.

Rollback Plan

Revert this PR / redeploy the previous image tag.

Post-Release Support Plan

Monitor extractor job error rates in Datadog for the Copy adapter.

Link to Devin session: https://app.devin.ai/sessions/66131de271cc4c3f98cda8411b9c4602
Requested by: @terezaskalova

Co-Authored-By: tereza.skalova <tereza.skalova@keboola.com>
@devin-ai-integration

Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant