Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qLRO5-0037Zi-N9 for pgsql-admin@arkaria.postgresql.org; Mon, 17 Jul 2023 16:47:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qLRO4-00CNn2-CJ for pgsql-admin@arkaria.postgresql.org; Mon, 17 Jul 2023 16:47:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qLRO3-00CNmu-UE for pgsql-admin@lists.postgresql.org; Mon, 17 Jul 2023 16:47:52 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qLRNy-00165M-Sp for pgsql-admin@postgresql.org; Mon, 17 Jul 2023 16:47:51 +0000 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-51f90f713b2so7212953a12.1 for ; Mon, 17 Jul 2023 09:47:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20221208.gappssmtp.com; s=20221208; t=1689612465; x=1692204465; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=IpZcqr2MarX4gfGPWnwEjMh82pjRxSzRuzi2WREq4eo=; b=PwFXQPzz1IsOOeezjnHZU2QJyFhCErkNHxL+L25+UJoLmaBjlKK1WT6Gf9N655Z5iT uX3RjhC1gjr9HinnZ7acwd6gLnMqhEsrtGZq6T6JMwqfpfXb0pZQ+G2zjICGcLU/CU7n D+Ynmno7neBzg1z0OzqZKrf+nNv/WJ626vzAcYKFSmA/4utDB6lkWP+ESeSaipP8FmVX Opgn1Agbxndfjm4eSrZ7oApyn9vhoIPspxXcruEQIa7E1XLpseBnrvSOzIDMkhFWgHIQ gGEqpQOivCt6NlALxPqpteHn68LUQp4JpXtoUVP+srSjNXhe3qQVKUvXc9Czp8D+QD6G N/tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689612465; x=1692204465; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=IpZcqr2MarX4gfGPWnwEjMh82pjRxSzRuzi2WREq4eo=; b=BGEj5y6KqC42X/aDBij3TSC8jIpJ9OOOAy6P3/Zjzt82IBzN5z6Ms/luwh2VvkLLOk Ckx83zlHSwwfdLS2Odln355gG7GxW99IZDgQLyanO75AcbnCuqgrVkIj0HpTs7K+f3NH Az/4jbbVOl1PVQcWVUKPvMa0A8i3M2qxsk/RkMI1o40VUVL/MD1+tVN5njU+krVmsWAo KH6GiA4fUG+XE09oFe1hJGy06PCzYxxaTOLH+d1X9yblMK9lPlJDYqF6Xk+CG3MO7Poy +PlrHbxIieBUbuWY3bi/hO1NB9UwijdoSw2XxR+97zkp23yyxGVOkqr4hmtnf+LzvuyG x/fw== X-Gm-Message-State: ABy/qLZ/KRH1KwQMPkY1JK8d6snzpBsFFoB2r1r3LbaXX7Jkq5m4lyrh uzdkQVOHfn/2OSbqvSEU0c+dTsRgR2hOcHo1Ldw= X-Google-Smtp-Source: APBJJlGDnbpn3xlspSlAgMt9u76H2sY5bHrlzQqP1yyupq80LnDtHsgeOQaddUaQL36cMZ2i3oTeGA== X-Received: by 2002:a05:6402:7c2:b0:51d:f589:9c7a with SMTP id u2-20020a05640207c200b0051df5899c7amr276171edy.17.1689612465086; Mon, 17 Jul 2023 09:47:45 -0700 (PDT) Received: from localhost.localdomain ([2001:871:5e:4fc2:f2f6:7179:233d:e889]) by smtp.gmail.com with ESMTPSA id m11-20020aa7c2cb000000b0051e2a5d9290sm10245135edp.77.2023.07.17.09.47.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jul 2023 09:47:44 -0700 (PDT) Message-ID: Subject: Re: Seeking Advice on Table Alterations without Downtime in PostgreSQL From: Laurenz Albe To: Veerendra Pulapa , "pgsql-admin@postgresql.org" Date: Mon, 17 Jul 2023 18:47:43 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 2023-07-17 at 16:31 +0000, Veerendra Pulapa wrote: > I am interested in techniques or approaches that allow for seamless alter= ations such > as adding/removing columns, modifying column data types, renaming columns= , and > altering constraints. Adding, dropping and renaming columns is always fast. Unless you have long running transactions, they will never give you trouble= . Changing the column data type is only fast if the types are binary compatib= le, for example varchar(20) -> varchar(100) or varchar(10) -> text. Other than that, the table has to be rewritten. To do that without down time, you could define an additional column with the new data type, fill ot with the value from the old column and then drop the old column. This will cause bloat if you do it in a single UPDATE, and constraints will require extra attention, but it is possible. You cannot alter constraints in PostgreSQL. You have to drop and re-create them. Yours, Laurenz Albe