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

Lock table query does not escape table name #230

Closed
deric opened this issue Mar 17, 2020 · 3 comments
Closed

Lock table query does not escape table name #230

deric opened this issue Mar 17, 2020 · 3 comments

Comments

@deric
Copy link

deric commented Mar 17, 2020

Namespace containing e.g. dash - is not escaped properly in LOCK TABLE query, unlike CREATE INDEX queries.

running index repack only:

$ pg_repack -d my_db -x -t "app-production".ratings -e
LOG: (query) CREATE INDEX CONCURRENTLY index_477119363 ON "app-production".ratings USING btree ("!update_time") TABLESPACE pg_default
INFO: repacking index ""app-production".ratings_userid_index"
LOG: (query) SELECT pgc.relname, nsp.nspname FROM pg_class pgc INNER JOIN pg_namespace nsp ON nsp.oid = pgc.relnamespace WHERE pgc.relname = 'index_477119364' AND nsp.nspname = $1
LOG:    (param:0) = app-production
LOG: (query) SELECT repack.repack_indexdef($1, $2, $3, true)
LOG:    (param:0) = 477119364
LOG:    (param:1) = 475998744
LOG:    (param:2) = (null)
LOG: (query) CREATE INDEX CONCURRENTLY index_477119364 ON "app-production".ratings USING btree (userid) TABLESPACE pg_default
LOG: (query) BEGIN ISOLATION LEVEL READ COMMITTED
LOG: (query) SET LOCAL statement_timeout = 100
LOG: (query) LOCK TABLE app-production.ratings IN ACCESS EXCLUSIVE MODE
ERROR:  syntax error at or near "-"
LINE 1: LOCK TABLE app-production.ratings IN ACCESS EXCLUSIVE MODE
                        ^
LOG: (query) RESET statement_timeout
ERROR: query failed: ERROR:  current transaction is aborted, commands ignored until end of transaction block
DETAIL: query was: RESET statement_timeout
pg_repack 1.4.5
@deric
Copy link
Author

deric commented Mar 17, 2020

Seems to be related to #205. If this behavior is intentional, there should be some way how to override this. This way duplicate indexes are created and table is left broken state.

A workaround appears to be double quoting:

$ pg_repack -d my_db -x -t '"app-production".ratings'

@dvarrazzo
Copy link
Member

Yes, the behaviour is intentional and consistent with other Postgres tools. The correct solution is to pass the qualities to the command line, as in your second example. In the OP, the quotes are consumed by Bash and not passed to the command.

@deric
Copy link
Author

deric commented Mar 18, 2020

@dvarrazzo In that case pg_repack should stop before executing CREATE INDEX CONCURRENTLY in case an unescaped namespace is passed.

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