Giter Site home page Giter Site logo

Auto-Vacuum Isn't Re-enabled about pg-osc HOT 14 CLOSED

shayonj avatar shayonj commented on August 21, 2024
Auto-Vacuum Isn't Re-enabled

from pg-osc.

Comments (14)

jfrost avatar jfrost commented on August 21, 2024 1

I'm wrong about the table name:

az485-267","pid":2274,"level":30,"time":"2023-05-13T15:00:42.158+00:00","v":0,"msg":"Exception raised, rolling back query","rollback":true,"query":";\nALTER TABLE pgbench_accounts RENAME to pgosc_op_table_pgbench_accounts;\nALTER TABLE pgosc_st_pgbench_accounts_16727e RENAME to pgbench_accounts;\n\n\n\nALTER TABLE pgosc_st_pgbench_accounts_16727e SET (fillfactor=100);\nDROP TRIGGER IF EXISTS primary_to_audit_table_trigger ON pgbench_accounts;\n","version":"0.7.5"}
2023-05-13T15:00:42.4805123Z        +{"name":"pg-online-schema-change","hostname":"fv-az485-267","pid":2274,"level":60,"time":"2023-05-13T15:00:42.159+00:00","v":0,"msg":"Something went wrong: ERROR:  relation \"pgosc_st_pgbench_accounts_16727e\" does not exist\n","e":"ERROR:  relation \"pgosc_st_pgbench_accounts_16727e\" does not exist\n","version":"0.7.5"}

I'll fix that in my PR.

from pg-osc.

jfrost avatar jfrost commented on August 21, 2024 1

Confirmed working:

jefftest=# create table books (id serial primary key, email text);
CREATE TABLE
Time: 9.127 ms
jefftest=# alter table books SET (fillfactor=50, autovacuum_enabled=false);
ALTER TABLE
Time: 1.107 ms
MacBook-Pro :: ~/git/pg-osc β€Ήmain*β€Ί Β» bundle exec pg-online-schema-change perform \
  --alter-statement 'ALTER TABLE books RENAME COLUMN email TO new_email' \
  --dbname "jefftest" --host localhost --username jeff
<SNIP>
{"name":"pg-online-schema-change","hostname":"MacBook-Pro.attlocal.net","pid":7755,"level":30,"time":"2023-05-13T15:41:12.159-05:00","v":0,"msg":"Performing ANALYZE!","version":"0.8.1"}
INFO:  analyzing "public.books"
INFO:  "books": scanned 0 of 0 pages, containing 0 live rows and 0 dead rows; 0 rows in sample, 0 estimated total rows
{"name":"pg-online-schema-change","hostname":"MacBook-Pro.attlocal.net","pid":7755,"level":30,"time":"2023-05-13T15:41:12.160-05:00","v":0,"msg":"Validating constraints!","version":"0.8.1"}
{"name":"pg-online-schema-change","hostname":"MacBook-Pro.attlocal.net","pid":7755,"level":30,"time":"2023-05-13T15:41:12.161-05:00","v":0,"msg":"All tasks successfully completed","version":"0.8.1"}
jefftest=# SELECT array_to_string(reloptions, ',') as params FROM pg_class WHERE relname='books';
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 params                 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ fillfactor=50,autovacuum_enabled=false β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
(1 row)

from pg-osc.

shayonj avatar shayonj commented on August 21, 2024

That sounds like a bug! I have some time set out this weekend, so will get to it. Thanks for reporting πŸ™πŸΎ

from pg-osc.

jfrost avatar jfrost commented on August 21, 2024

Looks like it should probably. go right here. I guess we should store the state of whether vacuum is enabled/disabled so we only set it back to the previous setting after swap?

from pg-osc.

shayonj avatar shayonj commented on August 21, 2024

So, we do capture any primary_table_storage_parameters so we can re-add them later. We capture it here

result = Query.storage_parameters_for(client, client.table_name, true) || ""
Store.set(:primary_table_storage_parameters, result)

And then add it back here

puts primary_table_storage_parameters
storage_params_reset =
(
if primary_table_storage_parameters.empty?
""
else
"ALTER TABLE #{client.table_name} SET (#{primary_table_storage_parameters});"
end

This is how we fetch the table storage params

query = <<~SQL
SELECT array_to_string(reloptions, ',') as params FROM pg_class WHERE relname='#{table}';
SQL

So I think whats happening, the default autovacuum settings may not be getting returned and stored inside primary_table_storage_parameters. I think the storage params are only returned if its set manually. I will confirm and get back.

Otherwise we will basically need to find a way to "reset" the autovacuum settings.

from pg-osc.

jfrost avatar jfrost commented on August 21, 2024

I was thinking a simple MVP would be to just re-enable autovacuum blindly because that would cover most of the cases and add it to the caveats. I can probably whip up a quick PR for that. Then we can see about only restoring it when it was enabled to begin with.

from pg-osc.

jfrost avatar jfrost commented on August 21, 2024

Oh, actually, I think I might've found the problem.

from pg-osc.

jfrost avatar jfrost commented on August 21, 2024

So, @shayonj your suspicion is correct, this is how a table's storage params with autovacuum set to defaults looks:

jefftest=# SELECT array_to_string(reloptions, ',') as params FROM pg_class WHERE relname='a';
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ params β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ \N     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜
(1 row)

from pg-osc.

jfrost avatar jfrost commented on August 21, 2024

Also, shouldn't this:
https://github.com/shayonj/pg-osc/blob/main/lib/pg_online_schema_change/orchestrate.rb#L256
still be #{shadow_table} at this point in the process?

I think this gets us part of the way there:
#85

from pg-osc.

shayonj avatar shayonj commented on August 21, 2024

New release is out. Thanks for find and fix folks πŸ™ŒπŸΎ
https://github.com/shayonj/pg-osc/releases/tag/v0.8.0

from pg-osc.

jfrost avatar jfrost commented on August 21, 2024

Whoops, reopened it by targeting error!

from pg-osc.

shayonj avatar shayonj commented on August 21, 2024

woot!!

from pg-osc.

brycethornton avatar brycethornton commented on August 21, 2024

Thanks @jfrost and @shayonj! I appreciate your effort! I promise I'll contribute more in the future. I had hoped/planned to at least get a PR going for this but I just didn't make the time.

from pg-osc.

shayonj avatar shayonj commented on August 21, 2024

no worries at all! Thanks for the reporting. It all helps!

from pg-osc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.