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 1kl86v-0006Uf-O3 for pgsql-general@arkaria.postgresql.org; Fri, 04 Dec 2020 10:14: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 1kl86t-0006x4-PM for pgsql-general@arkaria.postgresql.org; Fri, 04 Dec 2020 10:14:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kl86t-0006vT-EW for pgsql-general@lists.postgresql.org; Fri, 04 Dec 2020 10:14:43 +0000 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kl86r-0000Bx-8h for pgsql-general@lists.postgresql.org; Fri, 04 Dec 2020 10:14:42 +0000 Received: by mail-wr1-x42f.google.com with SMTP id g14so4724804wrm.13 for ; Fri, 04 Dec 2020 02:14:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gautherot.net; s=google; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=MYjt2fIqPtty5AIN1PTBjGtar2SPVGHm3EVuGXue1uw=; b=XSP9G4oUDmcdMW2JRgMLEFiL8iz33q9yoS2+nz2HBm6aA8uRsomKMgK0yHmFlTyuo7 WZa65FdQuP0ItPP+lKO7gTfltHCHXEF8RZFizQC6dR0tsvscWLsQBjCtgTxJKor8FQMn h3f7jR0Sfrso17u9FjK+gTGHOi+c7GfVpejpTcfD0rB7lUVeEFc3b5g+TcUsP/+kTbdp 07Z9NstAH3AF7maWRsq8z7OaYD96ApPNFTGl+icOG6i94bsWJoMxVF+fq9ys7GXbK4SW 9ze+0U9LqtDoy4q9Ds/dRxV7YKSZw9DSwUVmvXL9qwMfcnqm94xRvwSRtsvkQaSqZkpg RRnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=MYjt2fIqPtty5AIN1PTBjGtar2SPVGHm3EVuGXue1uw=; b=GGea6mPj5J/w7Fj65meh8nelD780Frt+VYsq3TCjGZQQuRkFrRVRDypWAyk2XdKzZ6 R2LxN1FsWStO4Oz/Tq/GLgOl32h2qf65uqopoCNtuY2wTT8O/RmXVLZuyWcncIeMI9vF SpHwb1b6Q/5GV5k+WO8wxShZchUSBX66ubcOQcympUN9QIPNBDVjvUtu/tt/2M+4MKES XbSjHhoeZcYeZ8H9yGt/aF3JVUSXfYrP+kNh9mDqjyrYdOU2uqrbQuLXUDiqR4vvT4bc mDT/jHU4RCjr8TZP3UMISjuSKeLODi18DtTK8vwrgUrq3K53DFwxFUjXPP0Ew+3EYSBZ nLQA== X-Gm-Message-State: AOAM530sDyzakGatKw5DGWRbiuK+b07Dj1a5/WgQ6GP+7ucIxT6dC3T8 Ph/RoMOcG10YqjOWRQO2Wm3B1MQ/zSFY3w== X-Google-Smtp-Source: ABdhPJwiPhyQbHA8v3gTQxu2ySQ6HGFTDWteAQes/o4uqL5YHqzkVwmvfmcZFAYxDTFzkHyDOAIpUA== X-Received: by 2002:adf:8169:: with SMTP id 96mr4052567wrm.418.1607076879941; Fri, 04 Dec 2020 02:14:39 -0800 (PST) Received: from ?IPv6:::1? (2a01cb0404c4380080dc6925ea05ccea.ipv6.abo.wanadoo.fr. [2a01:cb04:4c4:3800:80dc:6925:ea05:ccea]) by smtp.gmail.com with ESMTPSA id m2sm2432982wml.34.2020.12.04.02.14.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Dec 2020 02:14:39 -0800 (PST) Subject: Re: Alter the column data type of the large data volume table. From: Olivier Gautherot To: charles meng Cc: PostgreSQL General References: Message-ID: <7ea796d5-197f-d617-0a0d-33cd7f14b190@gautherot.net> Date: Fri, 4 Dec 2020 11:14:37 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------04539537AB32C955546A0643" Content-Language: en-US X-Antivirus: Avast (VPS 201202-6, 02-12-2020), Outbound message X-Antivirus-Status: Clean List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------04539537AB32C955546A0643 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Hi Charles, On 04-12-2020 9:44, Olivier Gautherot wrote: > Hi Charles, > > On Fri, Dec 4, 2020 at 9:12 AM charles meng > wrote: > > What I mean is that it will take a lot of time to complete all > data processing.I have to say that it is a good solution to adjust > the column type without affecting online users. > > I found a tool on github, see the link below, unfortunately, this > is for MySQL... > > https://github.com/github/gh-ost > > > MySQL has its own strategy with regard to column handling so what > works there does not necessarily fit here. > > There are some good ideas in this thread but I would start with a few > checks: > > 1) What version of PG are you using ? > > 2) If you can try on your current setup (not necessarily in > Production) to add a column typed bigint - if it is recent enough it > will be a simple catalog update. Michael's suggestion is viable > > 3) Given the massive number of rows, I would update as suggested, > progressively in batches of a few tens of thousands. Make sure you > commit and vacuum after each to retrieve the space (or you may end up > with a storage space issue in addition to all the rest). In the > meantime, add a trigger to set the new column to the index value. Once > the new column is complete, drop the old column and set the new one as > primary key (it may take a while to recalculate the index). > > 4) If your table is still growing, I would definitely look into > partitioning as it can hardly make things worse. > > 5) If you're brave enough, convert your current table as a partition > (rename it to something like table_hist), duplicate the table model > under the same name as now (adjusting the primary key type) and set > the INHERITS on the primary key range. The inheritance should take > care of the type conversion (haven't tried it but it's worth a try). > If it works, you will reach your goal without downtime or significant > overhead. Sorry, just tried this one and it failed: type mismatch. Cheers -- Olivier Gautherot -- El software de antivirus Avast ha analizado este correo electr=C3=B3nico en= busca de virus. https://www.avast.com/antivirus --------------04539537AB32C955546A0643 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Hi Charles,

On 04-12-2020 9:44, Olivier Gautherot wrote:
Hi Charles,

On Fri, Dec 4, 2020 at 9:12 AM charles meng <xlyybz@gmail.com> wrote:
What I mean is that it will take a lot of time to complete all data processing.I have to say that it is a good solution to adjust the column type without affecting online users.

I found a tool on github, see the link below, unfortunately, this is for MySQL...


MySQL has its own strategy with regard to column handling so what works there does not necessarily fit here. 

There are some good ideas in this thread but I would start with a few checks:

1) What version of PG are you using ?

2) If you can try on your current setup (not necessarily in Production) to add a column typed bigint - if it is recent enough it will be a simple catalog update. Michael's suggestion is viable

3) Given the massive number of rows, I would update as suggested, progressively in batches of a few tens of thousands. Make sure you commit and vacuum after each to retrieve the space (or you may end up with a storage space issue in addition to all the rest). In the meantime, add a trigger to set the new column to the index value. Once the new column is complete, drop the old column and set the new one as primary key (it may take a while to recalculate the index).

4) If your table is still growing, I would definitely look into partitioning as it can hardly make things worse.

5) If you're brave enough, convert your current table as a partition (rename it to something like table_hist), duplicate the table model under the same name as now (adjusting the primary key type) and set the INHERITS on the primary key range. The inheritance should take care of the type conversion (haven't tried it but it's worth a try). If it works, you will reach your goal without downtime or significant overhead.

Sorry, just tried this one and it failed: type mismatch.


Cheers
--
Olivier Gautherot

--------------04539537AB32C955546A0643--