6

Im trying to create index on large table:

 datid  |       datname        |  pid  | usesysid |         usename         |       application_name       | client_addr  | client_hostname | client_port |          backend_start         |          xact_start           |          query_start           |         state_change          | waiting | state  | backend_xid | backend_xmin  |                                           query                                           
 -------+----------------------+-------+----------+-------------------------+---  --------------------------+--------------+-----------------+-------------+------ -------------------------+-------------------------------+---------------------- ---------+-------------------------------+---------+--------+-------------+----- ---------+---------------------------------------------------------------------- ---------------------
  25439 | messengerdb          | 30692 |    25438 | messengerdb_rw          |  pgAdmin III - Przegl??darka | 10.167.12.52 |                 |       50593 | 2016-08-11 05:27:12.101452+02  | 2016-08-11 05:28:01.535943+02 | 2016-08-11 05:28:01.535943+02 | 2016-08-11 05:28:01.535958+02 | t       | active  |             |   1173740991 | CREATE INDEX CONCURRENTLY user_time_idx                                                   +
        |                      |       |          |                         |                              |              |                 |             |                               |                                |                               |                               |         |         |             |              |    ON core.conversations (user_id ASC NULLS LAST,  last_message_timestamp ASC NULLS LAST);+

Is this query working? I'm worried about 'waiting' column === 't' does it mean that it is waiting for lock or sth?

3
  • format please. thank you Commented Aug 11, 2016 at 7:11
  • 2
    format what? it looks ok here ;/ Commented Aug 11, 2016 at 7:12
  • Really dont know how to do it better :( sorry for the inconvenience Commented Aug 11, 2016 at 7:54

1 Answer 1

14

Creating an index concurrently may take a long time since it does not lock the table from writes and it waits until other transactions are finished. However, it may wait forever if you have connections that stay idle in transactions (for example when a client or application keeps an open connection without rollback/commit).

Check if there are some idle connections in transactions (you should be able to see them in the processes list). You can also check PostgreSQL logs.

Section about creating index concurrently in PostgreSQL documentation can be helpful. There is also a nice article about concurrent indexes under this link.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot. Is there a way to find out what is the current state (how big it is) of this index creating? I do not see any 'idle connections in transaction' ;/
@DreamCatch afaik there is no possibility to check the current state of the whole process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.