I have to run a whole bunch of GIST index creation, on some tables containing lots of records (scale of many countries, OSM data):
CREATE INDEX CONCURRENTLY IF NOT EXISTS osm_footways_gist ON osm_footways USING GIST (geom);
....
(more info here: https://www.2ndquadrant.com/en/blog/create-index-concurrently/ )
The time needed to run them all is quite long, it can be up to several hours on a common desktop computer.
But I noticed that it uses only one single CPU core.
Would it be possible to run such index creation queries using all available CPU cores (or a predetermined number of them)?
202002192007 Edit
According to https://www.cybertec-postgresql.com/en/postgresql-parallel-create-index-for-better-performance/ I've tried this:
SET max_parallel_maintenance_workers TO 48;
SET maintenance_work_mem TO '128 GB';
ALTER TABLE osm_footways SET (parallel_workers = 48);
CREATE INDEX CONCURRENTLY IF NOT EXISTS osm_footways_gist ON osm_footways USING GIST (geom);
....
But still have 1 CPU core working.
Info:
>>> psql
# select Version();
version
---------------------------------------
PostgreSQL 11.10 (Debian 11.10-1.pgdg90+1) on x86_64-pc-linux-gnu,
compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit
(1 row)
# select postgis_version();
postgis_version
---------------------------------------
2.5 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
(1 row)
Dockerized.
SET
max_parallel_maintenance_workers
andmaintenance_work_mem
to high values before running the index creation but I always have only 1 CPU core working. :/ (hard drive setup doesn't allow to play much with tablespaces).