pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rich Shepard <rshepard@appl-ecosys.com>
To: PostgreSQL General <pgsql-general@lists.postgresql.org>
Subject: Re: Alter the column data type of the large data volume table.
Date: Thu, 3 Dec 2020 09:18:05 -0800 (PST)
Message-ID: <alpine.LNX.2.20.2012030915280.29996@salmo.appl-ecosys.com> (raw)
In-Reply-To: <CAHOFxGpqi_=T2JQf+eNef3A5XR-Z9FeSB-hpZkG5aOr0PPvi0g@mail.gmail.com>
References: <CAD5cqMJT9Q=U3EkpgjsL5QcHNXfwvHVHe+RBabZBXh4OW9n8AA@mail.gmail.com>
	<CAHOFxGpqi_=T2JQf+eNef3A5XR-Z9FeSB-hpZkG5aOr0PPvi0g@mail.gmail.com>

On Thu, 3 Dec 2020, Michael Lewis wrote:

> On Wed, Dec 2, 2020 at 11:53 PM charles meng <xlyybz@gmail.com> wrote:

>> I have a table with 1.6 billion records. The data type of the primary key
>> column is incorrectly used as integer. I need to replace the type of the
>> column with bigint. Is there any ideas for this?

> You can add a new column with NO default value and null as default and have
> it be very fast. Then you can gradually update rows in batches (if on
> PG11+, perhaps use do script with a loop to commit after X rows) to set the
> new column the same as the primary key. Lastly, in a transaction, update
> any new rows where the bigint column is null, and change which column is
> the primary key & drop the old one. This should keep each transaction
> reasonably sized to not hold up other processes.

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.

Regards,

Rich





view thread (16+ messages)  latest in thread

Message-ID: <alpine.LNX.2.20.2012030915280.29996@salmo.appl-ecosys.com>
Permalink:  ../alpine.LNX.2.20.2012030915280.29996@salmo.appl-ecosys.com/
Also on:    postgresql.org/message-id/alpine.LNX.2.20.2012030915280.29996@salmo.appl-ecosys.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: rshepard@appl-ecosys.com
  Subject: Re: Alter the column data type of the large data volume table.
  In-Reply-To: <alpine.LNX.2.20.2012030915280.29996@salmo.appl-ecosys.com>
  References: <CAD5cqMJT9Q=U3EkpgjsL5QcHNXfwvHVHe+RBabZBXh4OW9n8AA@mail.gmail.com> <CAHOFxGpqi_=T2JQf+eNef3A5XR-Z9FeSB-hpZkG5aOr0PPvi0g@mail.gmail.com> <alpine.LNX.2.20.2012030915280.29996@salmo.appl-ecosys.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox