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 1tVvLc-00CfqN-PV for pgsql-general@arkaria.postgresql.org; Thu, 09 Jan 2025 16:25:29 +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 1tVvLc-003zp6-8x for pgsql-general@arkaria.postgresql.org; Thu, 09 Jan 2025 16:25:27 +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 1tVvLb-003zma-T3 for pgsql-general@lists.postgresql.org; Thu, 09 Jan 2025 16:25:27 +0000 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tVvLY-000lEi-2G for pgsql-general@lists.postgresql.org; Thu, 09 Jan 2025 16:25:27 +0000 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-aaec111762bso227389866b.2 for ; Thu, 09 Jan 2025 08:25:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736439924; x=1737044724; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=/0YdHJtOzLDtCgFWNdSbKFhL8TFq5eMgRBepAzSg5RU=; b=ZlQGPMBXxnily22CKuGyMrjR/yZwWUr3fmWLtnLat5VWi4kRjSlMkotBwhxHEMEcVO mGjPe6oXJx0qULvx2YY2+pFxQP56nx7DMoaZ61C/tXyzM8kNDJevOdPYBc1euPo3CiS9 /F6kfOe0EHcqSvkEdNTgFBrZYaiM36By903xDcHFcqODn1yWsJIEmOrvFgQ0fVKPfNZe MHvTIMW3FPODi10xrUrCn5WGp7xvHOmmobtASuTdTRTeC/vak36dE72GblY9A8e43pbp F9tTLD/z1UTaEsuz1kN+wHHCGA3lqlcbW/UEBAzdTAPhGU/4nobJ3g9toBxBArLpXXVe Y+yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736439924; x=1737044724; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=/0YdHJtOzLDtCgFWNdSbKFhL8TFq5eMgRBepAzSg5RU=; b=KDUU1V/nSkNUfZj4d0N1R605hV3jDFHITKNJdSP2/5GDu28zDwhXuEeslEiWtNChTg M4le0rcfxG3cEcrm0t0bQKqGmTeLMo8tYjppCiemRXUtb63yMX1GXTKO39chzukkwa7U nqex7KPtN8mhbolSIZ2vgbLFtOIQRoE+G3cgJydX11BHWwuRVSXAsBlucMyXb0gh3sx2 g1p98ofPQIF2zbfezgvsPJjAcLlkHk6f0yE21UYsdyLrsOgtRrALHzRmXb3jrijSINgh D6rllKu7+4G6pExbvoCuhyj+9HwHL20LaL18Luu2C979nlKwjr/uYyOVQK/oaTsN7Hok tuBw== X-Gm-Message-State: AOJu0Yz7bD7VosWFsgSAA1BunYaH8Jxf+yPg2KW53vQyo78r3b0aZUH0 Lywhp7bjaTEHdC0F+tgwqZzcnd77nSk4Vpu/GkCeYx3Q3WwFybqvDIaF0j/AbgMZ+4mur0qHMjo T3Tc7fFx90bK9je3l6H0Bj8CDwo8culj2 X-Gm-Gg: ASbGnctpwGb9SAB47hmbT+eFvzhD4ZuzOgyJblHwGeGwEokuAeCxmFxNraSIcfjkxmA jJb1y3p8p1T+AlVZlsVic++cEFFOp45LUBqNJe/PLX+wuJGzPSbfAtlk4dqgAP9Y5SA2HFtmF X-Google-Smtp-Source: AGHT+IF4kHfGMA7nViclYrezoaHbI5s56t59ZynwCXZb3ZO+Bq3x2J+tabCJQgT5Xdh6f9AI60vy0HzINz/3xuKw5Oo= X-Received: by 2002:a17:907:3f09:b0:aae:fb7c:50df with SMTP id a640c23a62f3a-ab2ab748e82mr614126566b.36.1736439923782; Thu, 09 Jan 2025 08:25:23 -0800 (PST) MIME-Version: 1.0 From: veem v Date: Thu, 9 Jan 2025 21:55:09 +0530 X-Gm-Features: AbW1kvYwipYcf6C8ZxlQunHB6EhJM10E-KDS98PC5t3UHnWbc5PF9Vdv0rXzYr8 Message-ID: Subject: Alter table fast To: pgsql-general Content-Type: multipart/alternative; boundary="000000000000d4bcd5062b486ced" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000d4bcd5062b486ced Content-Type: text/plain; charset="UTF-8" Hello, It's postgres version 16.1, we want to convert an existing column data type from integer to numeric and it's taking a long time. The size of the table is ~50GB and the table has ~150million rows in it and it's not partitioned. We tried running the direct alter and it's going beyond hours, so wanted to understand from experts what is the best way to achieve this? 1)Should we go with below Alter table alter column type numeric(15,0) USING ::NUMERIC(15,0); OR We should add a new not null column. update the data in that column from the existing column. drop the old column rename the new column to the old column. Regards Veem --000000000000d4bcd5062b486ced Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello,
It's postgres version 16.1, we want to conv= ert an existing column data type from integer to numeric and it's takin= g a long time. The size of the table is ~50GB and the table has ~150million= rows in it and it's not partitioned. We tried running the direct alter= and it's going beyond hours, so wanted to understand from experts what= is the best way to achieve this?

1)Should we go with below
Alte= r table <table_name> alter column <column_name> type numeric(15= ,0) USING <column_name>::NUMERIC(15,0);
OR
We should add a new = not null column.
update the data in that column from the existing column= .
drop the old column
rename the new column to the old column.

Regards
Veem
--000000000000d4bcd5062b486ced--