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

Using pg-osc only for backfilling data #89

Closed
ahilmer opened this issue Jun 5, 2023 · 4 comments
Closed

Using pg-osc only for backfilling data #89

ahilmer opened this issue Jun 5, 2023 · 4 comments

Comments

@ahilmer
Copy link
Contributor

ahilmer commented Jun 5, 2023

Hi,

I would be interested in using pg-osc but without using any alter statement. My use case would be to get rid of a bloated table by creating a new table and filling it with (a delta) of the original table.

E.g. like this:

pg-online-schema-change perform \
  --dbname "postgres" \
  --host "localhost" \
  --username "jamesbond" \

Would be adding a "fake" alter statement be a workaround or do you have any other ideas?

  --alter-statement 'ALTER TABLE books ADD COLUMN email IF NOT EXISTS new_email varchar' 
@jfrost
Copy link
Collaborator

jfrost commented Jun 5, 2023

Did you already review https://github.com/shayonj/pg-osc#backfill-data ? Sounds like that is what you're looking for.

@ahilmer
Copy link
Contributor Author

ahilmer commented Jun 6, 2023

Hi @jfrost thanks for your quick reply!

Sorry, I think my question was not correctly formulated.

Actually I want to use the backfill feature (--copy-statement) but without altering my table.

But I have to specify an alter statement.

I would like to just give the table name which should get backfilled without an alter statement.

Would be adding this "fake" statement be enough?

--alter-statement 'ALTER TABLE books ADD COLUMN email IF NOT EXISTS new_email varchar'

@jfrost
Copy link
Collaborator

jfrost commented Jun 6, 2023

I see what you're asking now. Yes, you can use any valid alter table. Here's a simple example using our sample books table that has an id column that is of type int:

  --alter-statement "ALTER TABLE books ALTER COLUMN id TYPE int"

Since it is already of type int, this is basically a no-op. It might be nice to allow skipping the alter-statement, but then we would need to pass in the tablename. PRs welcome!

@ahilmer
Copy link
Contributor Author

ahilmer commented Jun 24, 2023

Great, thanks!

@ahilmer ahilmer closed this as completed Jun 24, 2023
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

No branches or pull requests

2 participants