I created an index in Postgres like this:
CREATE UNIQUE INDEX my_index_name
ON my_table USING btree (custid,
date_trunc('day'::text, timezone('UTC'::text, somedate)),
firstname,
middlename,
lastname);
I monitored the free disk space to get an estimate on the progress of the index creation, I expected to see the available space going down indicating the process was doing its job. The problem is that after 40 minutes of going down, it got stuck for 25 minutes, and then it started consuming disk space again:
When it seemed stuck, I checked the long running processes to see if something was blocking it (unlikely, this is a DB copy nobody else is using), and I saw there were 3 different identical "CREATE INDEX" processes.
That is what I want to ask about:
- Why does Postgres show 3 different processes?
- What was it doing during this period where it seemed stuck?
This is the command I issued to see the long running processes, after the process got unstuck, only the process 18511 continued running:
my_user => SELECT pid, now() - pg_stat_activity.query_start AS duration, query, state
FROM pg_stat_activity
WHERE (now() - query_start) > interval '5 minutes' AND state != 'idle'
ORDER by 2 DESC;
-[ RECORD 1 ]-------------------------------------------------------------------------------------------------------------------------------------------------------------
pid | 18511
duration | 01:04:37.969599
query | CREATE UNIQUE INDEX my_index_name ON my_table USING btree (custid, date_trunc('day'::text, timezone('UTC'::text, somedate)), firstname, middlename, lastname);
state | active
-[ RECORD 2 ]-------------------------------------------------------------------------------------------------------------------------------------------------------------
pid | 12712
duration | 01:04:37.969599
query | CREATE UNIQUE INDEX my_index_name ON my_table USING btree (custid, date_trunc('day'::text, timezone('UTC'::text, somedate)), firstname, middlename, lastname);
state | active
-[ RECORD 3 ]-------------------------------------------------------------------------------------------------------------------------------------------------------------
pid | 12713
duration | 01:04:37.969599
query | CREATE UNIQUE INDEX my_index_name ON my_table USING btree (custid, date_trunc('day'::text, timezone('UTC'::text, somedate)), firstname, middlename, lastname);
state | active
Some other information
- I'm running Postgres 11.5 in Amazon's RDS
- This table's size is 255 GiB
- In that graph, the Y axis is given in MiB, so at the top we have 800GiB