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 1oH7WE-0001Dh-VW for pgsql-admin@arkaria.postgresql.org; Thu, 28 Jul 2022 17:41:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oH7WC-00084b-Sd for pgsql-admin@arkaria.postgresql.org; Thu, 28 Jul 2022 17:41:52 +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 1oH7WC-00084S-G2 for pgsql-admin@lists.postgresql.org; Thu, 28 Jul 2022 17:41:52 +0000 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oH7W5-0008N4-Lc for pgsql-admin@lists.postgresql.org; Thu, 28 Jul 2022 17:41:52 +0000 Received: by mail-oi1-x231.google.com with SMTP id s204so3186628oif.5 for ; Thu, 28 Jul 2022 10:41:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=qFgNrTKvWgWnw/LkeXbKa8jFTTyr9WBmEod9mQR4Cb8=; b=UlG+nLzRAj8QmjD/PGOwSSJRakf+0oPkQJDaEPcaxIg3sUs+OkE5wA7AJBWniOYag8 6DKlKe5Nwy9HvQQzqc7mxmCPjxBM2tpwKj65v5pWBMd32jiN2H3iO5JbVm6bjXU+YOqk 6tJ5odyUzgA0yd5o5I+ynWm2ZlM/nTkbm3XEmsvBl10k1gwZbR9EPwimfgnrucvDiqX6 QJX/ekmTMsdEKfoSHw7f+W5WHxfmtUEbOQ3mH25hmsI6flpkg8A+WaiKf6POQBgE9Glz knOvY2LjEs5Q4+KIsprde7676fpgobJw6rtn0jExJ1+yHnEt4yXPpv4sVLgcF6PY4V/V +HTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=qFgNrTKvWgWnw/LkeXbKa8jFTTyr9WBmEod9mQR4Cb8=; b=rjS31EUqIhBHvE43M3IJZXzGPkRZhuoBkPXGjjNPf5U4PHLIYHma66lrdYraZU8FwW n0vKJ2vgKa0nSld4LXOXQsampcHnGCqxIHImA7dBqbFga2fYHqlAsJCeGWCBIJVXn5QX TIHO86T0F6z7UlqXc07AgJ6PqA1qGiJoPmU5DHKQf9xzTnnAkfGXUFwAAHKQF5PzOrRP zN5KHsN1GhB7VZ1X2AzcGd8ESCHecI4ZtbxzPcClwbyjYN9FSARCTLurt7/EUDKSKcPZ JeGbO+VUOedj2UdyiX2bW/oK4VEJvZh9en67/XxBCAw91BPMJVjpeY7LlXedH2XoEUUn 3g5g== X-Gm-Message-State: AJIora9XNJMJLKOyA2C7fO3gLmeKua9NjvkgGBuWKiSWhTiYY8zQt1iS Dnd27TJomva4pV09ts25ELXUWzzTQ5I= X-Google-Smtp-Source: AGRyM1vVv9A77fb8BFPPD+tVjrsOwADtVxX7WIirLcuYJDmLxfubno5Gs2UwCwyY9QaedkF/4KYJUw== X-Received: by 2002:aca:1e05:0:b0:33a:afcd:9bf0 with SMTP id m5-20020aca1e05000000b0033aafcd9bf0mr217614oic.213.1659030103008; Thu, 28 Jul 2022 10:41:43 -0700 (PDT) Received: from [192.168.88.10] (ip68-11-68-85.no.no.cox.net. [68.11.68.85]) by smtp.googlemail.com with ESMTPSA id k29-20020a4a851d000000b0043548e83486sm544067ooh.35.2022.07.28.10.41.42 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 28 Jul 2022 10:41:42 -0700 (PDT) Message-ID: <5a747f00-02dc-3922-6506-fef8ccd701bf@gmail.com> Date: Thu, 28 Jul 2022 12:41:41 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: What to watch out for when ALTERing NUMERIC(38,0) to BIGINT? Content-Language: en-US To: pgsql-admin References: <3421791.1659021999@sss.pgh.pa.us> From: Ron In-Reply-To: <3421791.1659021999@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/28/22 10:26, Tom Lane wrote: > "David G. Johnston" writes: >> On Thu, Jul 28, 2022 at 8:13 AM Ron wrote: >>> Besides what's mentioned in >>> https://www.postgresql.org/docs/12/ddl-alter.html#id-1.5.4.8.10, what >>> happens *internally* when I run: >>> ALTER TABLE foo ALTER COLUMN bar TYPE BIGINT; >> IIUC, that would be the silver lining in all of this - the rewritten table >> would have zero fragmentation and bloat. > Yeah. What happens internally is a table rewrite: the entire content > of the table (and its indexes) is written into a new set of files. > At commit, the old files are deleted. The main gotchas, for a large > table, are the transient disk space consumption and the fact that the > table stays exclusively locked the whole time. Rewriting a 3TB table doesn't seem appetizing.  Fortunately, there's only one table like that... -- Angular momentum makes the world go 'round.