Execute SQL only with option --live #50
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The reason behind this change:
I have several databases with pretty big numbers of users, schemas and tables.
At first, I've run pgbedrock with option 'generate' to generate configuration files. Then I've run pgbedrock with 'configure --check' parameter with output redirected to file. Practically all Postgres session hanged up. When I killed such sessions (using pg_terminate_backend), I found file generated by pgbedrock with pretty big number of SQL commands (up to 300.000 lines).
It were commands like
grant REFERENCES/TRIGGER/TRUNCATE ...
and
alter DEFAULTE PRIVILEGE ... TO <superuser_name>
I supposed that the problem was in 'rollback' all these command.
To fix this, I tried to skip execution of these commands if parameter 'live' set to 'False'.
My tests showed that this really fix the problem, and all output files were generated as expected.
This change also make pgbedrock run faster with '--check' option because we do not need to execute generated SQL statements and then roll them back.
I hope this change will make pgbedrock a little bit better.