I can reindex indexes one by one like this:
database=# REINDEX INDEX CONCURRENTLY indexname1;
...
database=# REINDEX INDEX CONCURRENTLY indexname2;
...
How could I run reindex of multiple indexes in one query?
Something like this:
database=# REINDEX INDEX CONCURRENTLY indexname1 indexname2;
ERROR: syntax error at or near "indexname2"
LINE 1: REINDEX INDEX CONCURRENTLY indexname1 indexname2;
^
Or this:
database=# REINDEX INDEX CONCURRENTLY indexname_*
ERROR: syntax error at or near "*"
LINE 1: REINDEX INDEX CONCURRENTLY indexname_*
^
As per the documentation, REINDEX cannot be executed inside a transaction block when used with a partitioned table, schema, or database. This means that you cannot use a single transaction to REINDEX multiple items concurrently.
You can execute multiple REINDEX CONCURRENTLY commands in a single script, through a python interface with PostgreSQL with psycopg2.