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

Escape table names for --only-indexes #205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

panga
Copy link

@panga panga commented Mar 11, 2019

Currently, the --only-indexes option doesn't escape table names given in the command line and causes the following error:

LOG: (query) LOCK TABLE table-name IN ACCESS EXCLUSIVE MODE
ERROR:  syntax error at or near "-"
LINE 1: LOCK TABLE table-name IN ACCESS ...
                                            ^
ERROR: query failed: ERROR:  current transaction is aborted, commands ignored until end of transaction block

Example:

pg_repack -h SERVER -U USER -d DATABASE --echo --table='table-name' --only-indexes

Note: There's a workaround, you can add double quotes to the table name, however, this is something very easy to miss and cause the database become in an invalid state with a lot of indexes uncomplete rebuilt.

This PR change the SQL query used in bin/pg_repack and fix the issue.

@schmiddy
Copy link
Member

Thanks for the proposed fix - but this sounds like a duplicate of #177. Although the behavior is ugly it is intentional.

@panga
Copy link
Author

panga commented Mar 11, 2019

@schmiddy I understand. In this case, extra validation would be helpful to avoid issues and also some mention in the docs. Thank you

Copy link
Collaborator

@za-arthur za-arthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. It looks good to me.

Thanks for the proposed fix - but this sounds like a duplicate of #177. Although the behavior is ugly it is intentional.

I think that #177 solves the issue in a different way by enforcing quotes. On the other hand this PR changes internal behavior of how table name is retrieved which is used later:

appendStringInfo(&sql, "LOCK TABLE %s IN ACCESS EXCLUSIVE MODE",

On the other hand it is probably worth to add new tests.

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

Successfully merging this pull request may close these issues.

4 participants