Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backupccl: allow table renames during restore #96830

Open
shermanCRL opened this issue Feb 8, 2023 · 4 comments
Open

backupccl: allow table renames during restore #96830

shermanCRL opened this issue Feb 8, 2023 · 4 comments
Labels
A-disaster-recovery C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-disaster-recovery

Comments

@shermanCRL
Copy link
Contributor

shermanCRL commented Feb 8, 2023

It is a requirement that, when restoring tables into a database, tables (and views) of those names must not exist in the target database. Besides being inconvenient, it can lead users down a surprisingly frustrating road.

Users would like to do these table restores “in place”, next to the existing tables. We should enable this by allowing renaming the incoming tables at restore time.

Possible syntax using a new AS clause:

RESTORE TABLE bank.customers AS customers2, bank.accounts AS accounts2 
FROM LATEST IN 's3://{bucket_name}?AWS_ACCESS_KEY_ID={key_id}&AWS_SECRET_ACCESS_KEY={access_key}';

After completion, users will end up with two tables. They then have the normal SQL primitives they need to merge (UPSERT etc).

While we are in the neighborhood, should we offer AS for restoring databases as well? This would be semantically equivalent to WITH new_db_name.

@dt Also mentions the idea of a “swap” option -- the existing identically-named table stays online during restore, which may take a while. Upon restore completion, the newly-restored table replaces the previous table, presumably atomically.

See also #55791

See also this Docs issue (internal) to be more prescriptive on when one should restore a table vs a database.

Jira issue: CRDB-24353

@shermanCRL shermanCRL added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-disaster-recovery labels Feb 8, 2023
@blathers-crl
Copy link

blathers-crl bot commented Feb 8, 2023

cc @cockroachdb/disaster-recovery

@shermanCRL shermanCRL added the T-sql-schema-deprecated Use T-sql-foundations instead label Feb 9, 2023
@shermanCRL
Copy link
Contributor Author

(Adding Schema as I am not sure who would need to implement this.)

@ajwerner
Copy link
Contributor

This is inside of restore planning. It uses schema APIs, but this is @cockroachdb/disaster-recovery's to implement.

@ajwerner
Copy link
Contributor

As a note, I am working on making it so that renaming or creating a table with a name that is actively being queried is possible (see #96840), but I imagine this issue remains useful in more contexts.

@exalate-issue-sync exalate-issue-sync bot removed the T-sql-schema-deprecated Use T-sql-foundations instead label Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-disaster-recovery C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-disaster-recovery
Projects
None yet
Development

No branches or pull requests

2 participants