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 1kkt9d-0006Jk-C9 for pgsql-general@arkaria.postgresql.org; Thu, 03 Dec 2020 18:16:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kkt9c-0007BN-Ah for pgsql-general@arkaria.postgresql.org; Thu, 03 Dec 2020 18:16:32 +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 1kkt9c-0007BG-0i for pgsql-general@lists.postgresql.org; Thu, 03 Dec 2020 18:16:32 +0000 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kkt9Z-0000Sx-MR for pgsql-general@lists.postgresql.org; Thu, 03 Dec 2020 18:16:31 +0000 Received: by mail-oi1-x236.google.com with SMTP id k2so3121643oic.13 for ; Thu, 03 Dec 2020 10:16:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=c+BHgYhHN9s/AOwBztx3vxr0Btlkjv//evWtRhbmVBU=; b=kqtXk6igL+9eZ48b6uOrq18y68JFsrSYUXuwG7NDXO/nfJgbE8jcU077T2vw3C49za PUgOVySgj9XkgPNuidfPtZJphYp1PTvTiKOG9n0rv2oT2Ok+M0iNlbOqHAgHFvqranha yJZh58XzXXGzkZXqN+ptwSxG6RWpVrpTEdxt46eaM4hxPvgzqbGq++kYzNztUrlpexGe tXpyZ4pR5AwS9N6yH1GQhnSqZuhQGEyizrZezgysYdtCE8FZOmx3P+IFLji6uV+SqzbI EcEStWgjO1+Ctp5VgyDx8i7bTnYYeOwi2SQ2qVU3kegUG/w5WSjPy6tEfFwrjnHBwIoQ Qe6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=c+BHgYhHN9s/AOwBztx3vxr0Btlkjv//evWtRhbmVBU=; b=twDVAuZ+7EbcWD/ql3OvjTFgDQTLGuvPs3ySJAI4h3PEmwG+m5lORjLveQA9+Xj6O6 qEdCIv38eUgAo6wU1jWV8pP8GmCEFoPYxHXFotdEjpJwtfVgmC1riFnhlZe6/muGGpwb y6VcThXrUOEV1jV5eglheN+Z63HYht7HYhpqPaRm6qmqlx0/X0diwlMaAmEUwG8/b5Uf wIwZw78HRjfsw4//5H19auWj5arab0z5bwLj8TSFwEQFkDAABYrrmbjy7/WMorG8Jt9t nACE8vDcTj9IPUBohWrzK2flNOP2dYeeMyv2kCcf0m1pFubOtylkO/g3YXQSMK5xecPY dI8Q== X-Gm-Message-State: AOAM533dBmJWAz1BGABuVcb7RwX67wWnvLJlGu7QBzCQ6IVtGwp7RN8X l6C7zZnyEX4KPfV7FeSLXbvxrFqzxCHQKQ== X-Google-Smtp-Source: ABdhPJwTKXL1CFB+G1ELCSpQKvqunodUGJ+6nNvW1eHRu+e2X1Hs8AAVWtWn91cIbhrocWCgiF7vQg== X-Received: by 2002:a54:4d8f:: with SMTP id y15mr175868oix.150.1607019387338; Thu, 03 Dec 2020 10:16:27 -0800 (PST) Received: from [192.168.1.10] (ip174-67-141-204.no.no.cox.net. [174.67.141.204]) by smtp.googlemail.com with ESMTPSA id t5sm32763oth.16.2020.12.03.10.16.26 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Dec 2020 10:16:26 -0800 (PST) Subject: Re: Alter the column data type of the large data volume table. To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: Date: Thu, 3 Dec 2020 12:16:25 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------4AE2FB4453FA26CD83D3DBA1" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------4AE2FB4453FA26CD83D3DBA1 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 12/3/20 11:53 AM, Michael Lewis wrote: > > > On Thu, Dec 3, 2020 at 10:18 AM Rich Shepard > wrote: > > Tell me, please, why > > ALTER TABLE ALTER COLUMN SET DATA TYPE BIGINT > > will not do the job? > > I've found some varchar columns in a couple of tables too small and > used the > above to increase their size. Worked perfectly. > > > > Something else noteworthy is that with varchar, there is no rewrite of the > table. You are just removing or loosening the length restriction on a > variable width column type. I believe you could change all columns from > VARCHAR(n) to TEXT or VARCHAR(n+X) and have it take almost no time at all > since you are only impacting the catalog tables (pretty sure about that at > least). With a fixed width column like int4 to int8, all the rows need to > be actually re-written. And in this case it's the PK, so indexed and thus even slower.  Lots slowe. -- Angular momentum makes the world go 'round. --------------4AE2FB4453FA26CD83D3DBA1 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit On 12/3/20 11:53 AM, Michael Lewis wrote:


On Thu, Dec 3, 2020 at 10:18 AM Rich Shepard <rshepard@appl-ecosys.com> wrote:
Tell me, please, why

ALTER TABLE <tablename> ALTER COLUMN <columnname> SET DATA TYPE BIGINT

will not do the job?

I've found some varchar columns in a couple of tables too small and used the
above to increase their size. Worked perfectly.


Something else noteworthy is that with varchar, there is no rewrite of the table. You are just removing or loosening the length restriction on a variable width column type. I believe you could change all columns from VARCHAR(n) to TEXT or VARCHAR(n+X) and have it take almost no time at all since you are only impacting the catalog tables (pretty sure about that at least). With a fixed width column like int4 to int8, all the rows need to be actually re-written.

And in this case it's the PK, so indexed and thus even slower.  Lots slowe.

--
Angular momentum makes the world go 'round.
--------------4AE2FB4453FA26CD83D3DBA1--