Integrating large PostgreSQL table as partition for a new table I currently have a relatively large table containing timeseries data (628+ mil. live rows). The table definition (some names changed slightly) at the bottom of question.
I want to attach the existing table as a partition to a new (partitioned) table. However, the existing table has a singular id primary key (mainly used because Django requires it). Attaching the table would require me to update the primary key constraint to (id, timestamp) on the old table.
Because id is unique this isn't an issue, but given the size of the table I wonder if this constraint is checked upon creation (leading to quite the query) or whether only newly added/updated rows are checked. Stopping read/writes to the table for a few minutes is possible, but I can't wait for multiple hours.

Intended new table
Like the old table the id column is mainly required by our ORM sadly. A similar (prop_id, &quot;timestamp&quot;, value) index would be used on the partitioned table as well.
CREATE TABLE &quot;newtable&quot; (
    &quot;id&quot;            bigserial NOT NULL,
    &quot;timestamp&quot;     timestamp with time zone NOT NULL,
    &quot;prop_id&quot;       integer NOT NULL,
    &quot;value&quot;         double precision NOT NULL,
    PRIMARY KEY (&quot;id&quot;, &quot;timestamp&quot;)
) PARTITION BY RANGE (&quot;timestamp&quot;)
;


Old table definition
The &quot;id&quot; primary key is an artifact of our ORM (Django) and is inconsequential for any queries we do. We use the (prop_id, &quot;timestamp&quot;, value) index 99.9% of the time for index-only scans.
  Column   |           Type           | Collation | Nullable |                         Default                     | Storage | Stats target | Description
-----------+--------------------------+-----------+----------+----------------------------------------------------------+---------+--------------+-------------
 id        | bigint                   |           | not null | nextval('tablename_id_seq'::regclass) | plain   |              |
 timestamp | timestamp with time zone |           | not null |                     | plain   |              |
 value     | double precision         |           | not null |                     | plain   |              |
 prop_id   | integer                  |           | not null |                     | plain   |              |
Indexes:
    &quot;tablename_pkey&quot; PRIMARY KEY, btree (id)
    &quot;tablename_prop_id_timestamp_value_b9bc8326_idx&quot; btree (prop_id, &quot;timestamp&quot;, value)
Foreign-key constraints:
    &quot;tablename_prop_id_67f339b0_fk_othertable&quot; FOREIGN KEY (prop_id) REFERENCES othertable(id) DEFERRABLE INITIALLY DEFERRED
Proceed like this:

Don't create a primary key constraint on the partitioned table for now.
Rather, create unique indexes on the new partitions that will later become partitions of the primary key index.

As soon as the large table is old enough that you don't need the data any more, drop it.

Then you can create a primary key on the partitioned table that will use the already existing unique indexes as partitions.