Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ixpuL-0007pS-HW for pgsql-general@arkaria.postgresql.org; Sat, 01 Feb 2020 10:21:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ixpuK-0005eQ-8Q for pgsql-general@arkaria.postgresql.org; Sat, 01 Feb 2020 10:21:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ixpuJ-0005eH-Qe for pgsql-general@lists.postgresql.org; Sat, 01 Feb 2020 10:21:43 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ixpuF-0004rl-9J for pgsql-general@lists.postgresql.org; Sat, 01 Feb 2020 10:21:41 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 771D12206; Sat, 1 Feb 2020 11:21:33 +0100 (CET) Date: Sat, 1 Feb 2020 11:21:33 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Need support on tuning at the time of index creation Message-ID: <20200201102133.GA28560@hjp.at> References: <20200127224616.GA30598@hjp.at> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="LQksG6bCIzRHxTLp" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --LQksG6bCIzRHxTLp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2020-01-31 10:13:20 +0000, Sandip Pradhan wrote: > Thanks for your time. >=20 > Out Postgresql version: 9.5.9.14. >=20 > We are using COPY command to insert rows into the tables. While running C= OPY command, all indexes dropped. >=20 So I take it that the copy is fast, but the building of indexes is slow (actually I'm not sure whether less than 50 seconds per index is slow for tables of this size, but it's too slow for your application) > After successfully inserting all the rows, we are trying to create all th= ose indexes. >=20 > Example of index creation script: > CREATE INDEX cwt_sr_assocact_entityref > ON cwt_sr_associationact > USING btree > (entityapplicationcontext COLLATE pg_catalog."default", entitytype COLL= ATE pg_catalog."default", entitydn COLLATE pg_catalog."default"); >=20 > CREATE INDEX ix_sr_assoc_customerrelateddn > ON cwt_sr_associationact > USING btree > (customerrelateddn COLLATE pg_catalog."default"); >=20 > Running indexes in parallel. >=20 > Please find the hardware detail of the server: > OS: Red Hat Enterprise Linux 7.4 > RAM: 125 GB > CPU Core: 36 >=20 > Set maintenance_work_mem to 25GB Ideally, you would want to use all the cores and each process should use as much RAM as possible. However, if each process uses 25 GB, you can only fit 4 of them (not 5 because other stuff needs memory, too), in RAM at the same time, leaving 32 of your 36 cores idle. OTOH, for 36 processes, each would have to be restricted to about 3 GB, which doesn't sound ideal, either. So there's probably a sweet spot somewhere in the middle. What I would do: To save time, I would test only with a single table (there are 29 indexes on each table and that's almost certainly more than the optimal degree of parallelism, so we won't get anything from processing several tables at once). To establish a baseline, I'd look for the optimal parallelism with your current parameters: Build the indexes with 1, 2, 4, 8, 16, 29 processes in parallel. Stop if it gets noticably slower, especially if it starts to swap heavily. Then bisect between the two best ones. Note the results. Then reduce maintenance_work_mem to 50 % and repeat the experiment. Does it get better? If it gets better (or at least not much worse), reduce maintenance_work_mem again and repeat. Eventually you should find the optimal combination.=20 To reach your goal of 40 minutes for all 10 tables, your optimal run for a single table must be about 4 minutes. If you don't get close to that you will probably have to look for different solutions. As already mentioned, the speed of I/O makes a lot of difference. If you don't use SSDs yet, you should. If you do use SSDs, maybe you can get faster ones? You might also investigate putting pgsql_tmp on a RAM disk. You could also try changing synchronous_commit and/or fsync/full_page_writes (the latter only if you can tolerate losing your DB in a crash). hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --LQksG6bCIzRHxTLp Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAl41USgACgkQ8g5IURL+ KF3qoxAAmuG9/01pnwzhgbNYFiWKSp5hJ2YYMmxCU/WemNPAFOqqI3IRwVF0TXou sWWXelU9NYLVruFeZ2VeXwkStJtRtOSBOeY/+lcBAo7riV3wv9gCPjEwJAmd1TMy 2Tfry+/FwGsP7Iv2fUuSy8UasL6uPhW1nN2JAZCIYLEiM78xb58nUNUZnNeThsVD BwseRw4LQcxvB+DBpw/tEx9fMthgLfPXtooHqZgd7VC7gZrMWSsogLe1KHf2xJEs iwIJMDJ8ASH3RJIG5G0zgPQvEhhAjpqJQh1lXJUzioQ+BA36ftPjeR1Wxneffzn7 WknkBDTOdd5taymR4vD9rhkgYqOb9o6qiPXk3Z4H7Lal5AhKd38UNWITrCP7EH5r piSPdR9ZPG60kRDlVOThctoxJX9KvRTlPi284IMtDyO9cytZEvmWz5WSCnkGYQzK 72B/rUlJmZ1VYYLtk7H1xMa/BoqN0s1QKomsRgP1wJQjbEut4Gfle7vVhPFkKBPI /uR8vDHbiCYdCoWFYXax7MfCfXlSycFb9oeasnZQZoflrRcOkmcONDapn/EvEnTj U6Zut6LZfpRhJJYmPbFqSXY4d60/MCYAVPmI+15hYIQTwV4xaOhBgnA7DFYeG18l W94si6xIQSpTkFd6Zh7RvT/HSeCZ5gkSu1l1PSRquLElH/lwU/0= =/IB/ -----END PGP SIGNATURE----- --LQksG6bCIzRHxTLp--