Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lAPBJ-0004z3-W7 for pgsql-general@arkaria.postgresql.org; Fri, 12 Feb 2021 03:31:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lAPBI-0006ky-VB for pgsql-general@arkaria.postgresql.org; Fri, 12 Feb 2021 03:31:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lAPBI-0006kr-Nv for pgsql-general@lists.postgresql.org; Fri, 12 Feb 2021 03:31:44 +0000 Received: from mail-ot1-x336.google.com ([2607:f8b0:4864:20::336]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lAPBG-0001ZJ-Nw for pgsql-general@lists.postgresql.org; Fri, 12 Feb 2021 03:31:43 +0000 Received: by mail-ot1-x336.google.com with SMTP id c16so7270239otp.0 for ; Thu, 11 Feb 2021 19:31:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=7PmKknPFyuvKKEhGwjF5Kv6aVj2EIGQVl5wS4MMfey4=; b=N6PAGzhVtHxjTifLGq7PlpFKG4yYco+uzYnGM4jh7/B7HTa70g40PvtaPmWw5KYXxF ERpxGQWwQOieEaM+GordCWcjnBR3Dn37tlMIGefOf7ZSDY86mI5x3hGYa95ipZ+bPItY C9M5nugUMmLOKSN0l1hM8v+Nu0kdCEF/EknDhnCJGuMRzW7BJTAuYCH7zcQ682zhTkJ8 1N7r7WXRCI4H1bsQC4VqS/0oyGrKH1McrAEEfAaZ3hDWzpO7zjC7W5pZUdU65Jk4X3ai XVUyCHGDTJZq/Q9jgf80P3TDDCIUUKCW/gH/0TsVsjniTQeZDr0Jrv7UKQ09oTQrFaFz mb6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=7PmKknPFyuvKKEhGwjF5Kv6aVj2EIGQVl5wS4MMfey4=; b=KgLsYPFbL1sfLCFzHE6plfLKaAAGLqDZG4Lei5i3nPZhoim4POQX2wiR+m4XK/+m/2 Q+ruLdnIc/D9dk2GXxPO1m/qBIt641C460/Ff7jeMm0KKpaNG1s+uOY/5LWTcvRiTqR9 vKdkMDtDIRa4dXOF3iB/DDwrXFJfwghlzUs+yZKJUQ2+NfnsDbAiWYeotRUnrqUtF8yU imkFcM6kYxnscbCt8SDCWcq5O1cfWJrlyD9qMWmiFWWYuDbXBb7MOTf6wK6u11KwfBla s9zzVZheaidNbPrhosJyjWX/kJ9zOFE53Jfm9f6Ys0dP9t8C2xnD9/dGfq84CexsmMFp iDIg== X-Gm-Message-State: AOAM532bUBwiaUzExqu5+sjfBMuEGTthq0AmbKIFMUPalBsxLeCMiSu7 lyIS9kXjphacFU+G0GMDFjY077wANbwmzw== X-Google-Smtp-Source: ABdhPJwqSUs/8rDtZ77tzz+ypM5gDK2pzcdBaDh4ZeasgGo8PDvkx3C21DNaJwVrhQPC7vxH8Z42cQ== X-Received: by 2002:a9d:426:: with SMTP id 35mr783311otc.8.1613100701860; Thu, 11 Feb 2021 19:31:41 -0800 (PST) Received: from [192.168.88.10] (ip174-67-141-204.no.no.cox.net. [174.67.141.204]) by smtp.googlemail.com with ESMTPSA id h24sm1379191otl.50.2021.02.11.19.31.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Feb 2021 19:31:41 -0800 (PST) To: "pgsql-generallists.postgresql.org" From: Ron Subject: Building lots of indices in parallel Message-ID: <7fa62c6a-dfab-4d0e-17cc-e4030f83fcc9@gmail.com> Date: Thu, 11 Feb 2021 21:31:40 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk We're migrating a big database (200ish tables 30 of which have bytea or xml fields; the Oracle size is 10TB) to Postgresql 12.5 (RDS, if it matters), and after the loads are completed, it will be time to create the secondary indices (tables currently only have PK constraints), and they of course need to be built as fast as possible. The first things to do are based in Postgres itself: ALTER TABLE foo SET (parallel_workers = 4); SET max_parallel_maintenance_workers TO 4; CREATE INDEX foo_ind2 ON foo (f1); That creates one index very quickly, but only one index at a time, wasting the other CPUs (there are 48 in the VM, and 384GB RAM). What is the impact on locking/contention of using something like GNU Parallel (especially when it tries to create multiple indices on the same table in parallel)? Is there a better way to quickly create lots of indices? -- Angular momentum makes the world go 'round.