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 1hiajb-00073e-Ri for pgsql-general@arkaria.postgresql.org; Wed, 03 Jul 2019 08:35:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hiajZ-0005cZ-QP for pgsql-general@arkaria.postgresql.org; Wed, 03 Jul 2019 08:35:21 +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 1hiajZ-0005Up-Aq for pgsql-general@lists.postgresql.org; Wed, 03 Jul 2019 08:35:21 +0000 Received: from hermes.gatewaynet.com ([193.92.121.98]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hiajO-0001mQ-4G for pgsql-general@lists.postgresql.org; Wed, 03 Jul 2019 08:35:20 +0000 Received: from smadev.internal.net (pc131.internal.net [10.9.200.131]) by hermes.gatewaynet.com (8.15.2/8.15.2/Debian-8) with ESMTPS id x638Z1Kq014478 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 3 Jul 2019 11:35:06 +0300 Received: from smadev.internal.net (smadev [10.9.200.131]) by smadev.internal.net (8.15.2/8.15.2) with ESMTP id x638Z1IO081200 for ; Wed, 3 Jul 2019 11:35:01 +0300 (EEST) (envelope-from achill@matrix.gatewaynet.com) Subject: Re: Partitioning an existing table - pg10.6 To: pgsql-general@lists.postgresql.org References: From: Achilleas Mantzios Message-ID: Date: Wed, 3 Jul 2019 11:35:01 +0300 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.3.2 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------BC710118B1D8282EC9B85FC7" Content-Language: en-US X-Virus-Scanned: clamav-milter 0.100.3 at hermes X-Virus-Status: Clean X-Spam-Status: No, score=-27.0 required=5.0 tests=ALL_TRUSTED,DYN_HAM_COORD, DYN_HAM_IT,DYN_HAM_NAUTICAL,DYN_HAM_SIGNAT1,HTML_MESSAGE autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on hermes.gatewaynet.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------BC710118B1D8282EC9B85FC7 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 3/7/19 10:01 π.μ., Ayub M wrote: > Hello, I am using postgres 10.6 and have a huge table with ~30m recs which needs to be partitioned. Whats the best strategy for it with minimal downtime? > > 1. Rename existing table and create new partitioned tables with orig name and keep inserting data from the old renamed to new table. This will incur downtime for the apps. > 2. Create partitioned table with new name and move the data from current table (move oldest to newest) and when moving current month paritition shutdown down the app and move the last set of data. > This will not incur downtime but if any data is changed which was already copied over then it might be lost. Regarding 2) you could setup a trigger on the original table which would also replicate INSERTS, DELETES and UPDATES to the new table. > > Any other approaches/alternatives? > > -- > Regards, > Ayub -- Achilleas Mantzios IT DEV Lead IT DEPT Dynacom Tankers Mgmt --------------BC710118B1D8282EC9B85FC7 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
On 3/7/19 10:01 π.μ., Ayub M wrote:
Hello, I am using postgres 10.6 and have a huge table with ~30m recs which needs to be partitioned. Whats the best strategy for it with minimal downtime?

1. Rename existing table and create new partitioned tables with orig name and keep inserting data from the old renamed to new table. This will incur downtime for the apps.
2. Create partitioned table with new name and move the data from current table (move oldest to newest) and when moving current month paritition shutdown down the app and move the last set of data. This will not incur downtime but if any data is changed which was already copied over then it might be lost.

Regarding 2) you could setup a trigger on the original table which would also replicate INSERTS, DELETES and UPDATES to the new table.


Any other approaches/alternatives?

--
Regards,
Ayub


-- 
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt
--------------BC710118B1D8282EC9B85FC7--