Consider an authored staging scenario: CREATE TABLE ... LIKE ... INCLUDING ALL creates a new PostgreSQL table successfully, its primary key looks correct, and inserts with an omitted id work. The surprising result is that the new table can still obtain IDs from the original table's sequence. PostgreSQL documents why: LIKE INCLUDING DEFAULTS copies default expressions, and a copied expression containing nextval can create a functional linkage between the original and new tables; by contrast, INCLUDING IDENTITY creates a separate sequence for each copied identity column.
For this qualification, independence means something narrower than “the tables have different OIDs” or “their rows currently have different IDs.” The clone must have its own allocator, omitted-ID inserts into the clone must invoke that allocator, and those inserts must not advance the source allocator. Evidence therefore comes from three channels: the sequence associated with the column, the sequence referenced by the stored default dependency, and the IDs plus sequence states observed around controlled INSERT ... RETURNING statements.
The central counterexample is an ownership-only repair. Creating refonte_clone_lab.serial_clone_id_seq ... OWNED BY refonte_clone_lab.serial_clone.id can make pg_get_serial_sequence identify the new sequence even though the clone's copied default still invokes the source sequence. OWNED BY establishes lifecycle association; it does not rewrite another object's default expression.
Everything below is a proposed qualification protocol. Execution status: EXPECTED / NOT EXECUTED. Current decision: HOLD. No PostgreSQL server or psql execution is claimed. PostgreSQL 18.7, released November 12, 2026, is the proposed patch baseline; the PostgreSQL 18 manual is a major-version documentation family, not proof that an eventual test host runs that patch.
Define independence at the allocator boundary
The policy must precede the SQL: each cloned table in this exercise owns an independent identifier domain and must allocate automatically without consuming the source table's generator. A shared sequence could be a valid design under a different explicitly approved policy. It fails this policy.
That distinction prevents several weak signals from becoming false approvals. Different table OIDs prove that two relations are different objects, not that their defaults resolve to different sequences. A copied primary key proves uniqueness enforcement inside that table, not allocation isolation. Different current row values prove only that the stored values differ. Even pg_get_serial_sequence answers an association question, not necessarily the “what expression runs on this insert?” question: PostgreSQL defines it as returning the sequence associated with a serial or identity column, or NULL when none is associated.
The serial shorthand matters here. PostgreSQL documents bigserial as notation that creates a bigint column, a sequence, a nextval(...) default and an ownership association. Copying the resulting column is not a fresh invocation of the bigserial declaration. That is why a PostgreSQL CREATE TABLE LIKE sequence review must inspect the copied dependency instead of reasoning from the original declaration.
Treat this allocator test as adjacent to, not a substitute for, PostgreSQL schema compatibility checks. The existing Refonte workflow asks whether an already-present relation matches an intended schema signature; this protocol asks which allocator a newly cloned identifier column actually invokes.
The release record should therefore state one policy sentence before any observation: serial_clone and identity_clone must allocate independently from their respective sources; automatic clone inserts must not advance the source allocator. If the application actually requires a shared number space, stop and rewrite the requirement rather than coercing this test into approving it.
Freeze the schema and the expected state
The fixture contains exactly five data tables under refonte_clone_lab.
serial_source is declared as id bigserial PRIMARY KEY, payload text NOT NULL. serial_clone is created with LIKE refonte_clone_lab.serial_source INCLUDING ALL. Because INCLUDING ALL selects all available LIKE-copy options, that includes defaults and indexes; the documented default-copy contract warns that a copied nextval can retain a functional linkage.
bare_clone uses plain LIKE refonte_clone_lab.serial_source. PostgreSQL says default expressions are not copied unless INCLUDING DEFAULTS is selected, while not-null constraints are copied regardless. Indexes and primary keys require INCLUDING INDEXES; consequently this control is deliberately not treated as a copied-primary-key case.
identity_source uses:
id bigint GENERATED BY DEFAULT AS IDENTITY
(START WITH 1 INCREMENT BY 1 CACHE 1 NO CYCLE)
PRIMARY KEYand identity_clone uses LIKE identity_source INCLUDING ALL, created before either identity table allocates. PostgreSQL documents identity columns as using implicit sequences; INCLUDING IDENTITY creates a new sequence for each identity column in the new table, separate from the old table's sequence.
The manifest is authored before observations:
Case | Independently declared expected result |
P1 | Serial source and clone are distinct tables; both defaults depend on SOURCE_SEQ; source association is SOURCE_SEQ; clone association is NULL; both empty. |
P2 | Source s1 → 1, clone c1 → 2, source s2 → 3; SOURCE_SEQ = 3/true. |
P3 | Bare omitted-ID insert raises SQLSTATE 23502; explicit (9001,'manual') succeeds. |
P4 | Both identity columns are BY DEFAULT; associated OIDs differ: IDENTITY_SOURCE_SEQ versus IDENTITY_CLONE_SEQ. |
P5 | Identity source/clone allocations are 1/1/2/2, with each allocator advancing only for its table. |
P6 | Create CLONE_SEQ at 1001 and own it by clone.id; association becomes CLONE_SEQ, but default remains dependent on SOURCE_SEQ. |
P7 | Clone c2 returns 4; SOURCE_SEQ advances to 4/true; CLONE_SEQ stays 1001/false. |
P8 | Transactionally change clone default to CLONE_SEQ, verify, roll back; dependency returns to SOURCE_SEQ; allocate nothing. |
P9 | Repeat repair, verify, commit; association and default dependency both identify CLONE_SEQ. |
P10 | Clone c3 → 1001, source s3 → 5, clone c4 → 1002, source s4 → 6; exact final ledger matches. |
SOURCE_SEQ, CLONE_SEQ, IDENTITY_SOURCE_SEQ and IDENTITY_CLONE_SEQ are symbolic evidence identities. Numeric OIDs are database-local observations and must be resolved during the run, never embedded in a portable expected manifest.
Build and inventory the disposable fixture
The protocol must run only against an explicitly selected, owner-controlled disposable database. It refuses an existing refonte_clone_lab schema instead of dropping it, because cleanup-before-setup could erase evidence of an incorrect target. Setup commits before measured cases; later work uses autocommit except P8 and P9.
PostgreSQL's sequence options support explicit START, INCREMENT, CACHE, NO CYCLE and OWNED BY; pg_sequence exposes data type, start, increment, bounds, cache and cycle settings.
A complete qualification script can begin as follows:
\set ON_ERROR_STOP on
\set VERBOSITY verbose
\pset pager off
SET statement_timeout = '10s';
SET lock_timeout = '3s';
SET search_path = pg_catalog;
SELECT version() AS server_version,
current_setting('server_version_num') AS server_version_num,
current_database() AS database_name,
current_user AS role_name,
pg_backend_pid() AS backend_pid,
current_setting('search_path') AS inspection_search_path;
DO $$
BEGIN
IF EXISTS (
SELECT 1
FROM pg_catalog.pg_namespace
WHERE nspname = 'refonte_clone_lab'
) THEN
RAISE EXCEPTION 'refonte_clone_lab already exists: refuse non-fresh fixture';
END IF;
END
$$;
CREATE SCHEMA refonte_clone_lab;
CREATE TABLE refonte_clone_lab.serial_source (
id bigserial PRIMARY KEY,
payload text NOT NULL
);
CREATE TABLE refonte_clone_lab.serial_clone (
LIKE refonte_clone_lab.serial_source INCLUDING ALL
);
CREATE TABLE refonte_clone_lab.bare_clone (
LIKE refonte_clone_lab.serial_source
);
CREATE TABLE refonte_clone_lab.identity_source (
id bigint GENERATED BY DEFAULT AS IDENTITY
(START WITH 1 INCREMENT BY 1 CACHE 1 NO CYCLE)
PRIMARY KEY,
payload text NOT NULL
);
CREATE TABLE refonte_clone_lab.identity_clone (
LIKE refonte_clone_lab.identity_source INCLUDING ALL
);
CREATE FUNCTION refonte_clone_lab.assert_true(
p_label text,
p_value boolean
)
RETURNS void
LANGUAGE plpgsql
AS $$
BEGIN
IF p_value IS DISTINCT FROM true THEN
RAISE EXCEPTION 'assertion failed: %', p_label;
END IF;
END
$$;
CREATE FUNCTION refonte_clone_lab.default_sequence_oid(
p_table regclass,
p_column name
)
RETURNS oid
LANGUAGE plpgsql
STABLE
AS $$
DECLARE
v_oid oid;
v_count integer;
BEGIN
SELECT count(*), min(dep.refobjid)
INTO v_count, v_oid
FROM pg_catalog.pg_attribute a
JOIN pg_catalog.pg_attrdef ad
ON ad.adrelid = a.attrelid
AND ad.adnum = a.attnum
JOIN pg_catalog.pg_depend dep
ON dep.classid = 'pg_catalog.pg_attrdef'::regclass
AND dep.objid = ad.oid
AND dep.refclassid = 'pg_catalog.pg_class'::regclass
JOIN pg_catalog.pg_class seq
ON seq.oid = dep.refobjid
AND seq.relkind = 'S'
WHERE a.attrelid = p_table
AND a.attname = p_column
AND a.attnum > 0
AND NOT a.attisdropped;
IF v_count <> 1 THEN
RAISE EXCEPTION
'expected exactly one sequence dependency for %.%, found %',
p_table, p_column, v_count;
END IF;
RETURN v_oid;
END
$$;
CREATE FUNCTION refonte_clone_lab.sequence_state(p_seq oid)
RETURNS TABLE(last_value bigint, is_called boolean)
LANGUAGE plpgsql
STABLE
AS $$
BEGIN
RETURN QUERY EXECUTE
pg_catalog.format(
'SELECT last_value::bigint, is_called FROM %s',
p_seq::regclass
);
END
$$;
CREATE FUNCTION refonte_clone_lab.run_p3_negative()
RETURNS TABLE(
observed_sqlstate text,
observed_schema text,
observed_table text,
observed_column text
)
LANGUAGE plpgsql
AS $$
DECLARE
v_state text;
v_schema text;
v_table text;
v_column text;
BEGIN
BEGIN
INSERT INTO refonte_clone_lab.bare_clone(payload)
VALUES ('must_fail');
RAISE EXCEPTION 'P3 unexpected successful omitted-id insert';
EXCEPTION
WHEN not_null_violation THEN
GET STACKED DIAGNOSTICS
v_state = RETURNED_SQLSTATE,
v_schema = SCHEMA_NAME,
v_table = TABLE_NAME,
v_column = COLUMN_NAME;
IF v_state IS DISTINCT FROM '23502'
OR v_schema IS DISTINCT FROM 'refonte_clone_lab'
OR v_table IS DISTINCT FROM 'bare_clone'
OR v_column IS DISTINCT FROM 'id'
THEN
RAISE EXCEPTION
'P3 mismatched diagnostic: state=%, schema=%, table=%, column=%',
v_state, v_schema, v_table, v_column;
END IF;
RETURN QUERY SELECT v_state, v_schema, v_table, v_column;
END;
END
$$;
COMMIT;pg_attrdef stores default expressions and binds them to a relation through adrelid and a column number through adnum; pg_get_expr reconstructs their stored expression. The helper deliberately rejects zero or multiple sequence dependencies rather than converting missing evidence into a passing empty set.
Record the actual server and client identities
The future operator must record actual builds rather than replacing them with the planned baseline. psql -X suppresses startup files; -f executes a script file, and ON_ERROR_STOP makes noninteractive processing stop on an error and return a distinct error code.
A capture wrapper should preserve source bytes, digest, invocation, stdout, stderr and exit status in a new path:
set -u
RUN_ID="$(date -u +%Y%m%dT%H%M%SZ)-$$"
RUN_DIR="evidence-${RUN_ID}"
mkdir -m 700 "$RUN_DIR" || exit 70
cp qualification.sql "$RUN_DIR/source.sql" || exit 70
sha256sum "$RUN_DIR/source.sql" > "$RUN_DIR/source.sha256" || exit 70
psql --version > "$RUN_DIR/psql-version.txt" 2>&1 || exit 70
printf '%q ' psql -X -v ON_ERROR_STOP=1 \
-d "$PGDATABASE" -f "$RUN_DIR/source.sql" \
> "$RUN_DIR/invocation.txt"
printf '\n' >> "$RUN_DIR/invocation.txt"
psql -X -v ON_ERROR_STOP=1 \
-d "$PGDATABASE" \
-f "$RUN_DIR/source.sql" \
> "$RUN_DIR/stdout.txt" \
2> "$RUN_DIR/stderr.txt"
STATUS=$?
printf '%s\n' "$STATUS" > "$RUN_DIR/process-status.txt"
exit "$STATUS"No actual version string, PID, OID, digest or process result is supplied here. Expected evidence status: NOT EXECUTED. A client/server mismatch, capture failure, ambiguous database selection or partially missing output produces HOLD, not an inferred pass.
Trace copied defaults to their sequence objects
P1 asks what exists before any allocator is touched. PostgreSQL explicitly says copied default expressions can preserve nextval linkage. The inspection should bind the exact table OID and id attribute, locate its pg_attrdef row by adrelid/adnum, then follow dependencies from that default object to referenced pg_class objects whose relation kind is sequence.
pg_depend stores both sides using class-qualified identifiers: classid/objid identify the dependent object and refclassid/refobjid identify the referenced object, with deptype recording dependency semantics. For this admitted direct nextval('sequence'::regclass) shape, the test requires exactly one referenced sequence. It does not claim to be a semantic analyzer for arbitrary function-wrapped or dynamically resolved expressions.
Add these runtime captures after setup:
SELECT pg_catalog.pg_get_serial_sequence(
'refonte_clone_lab.serial_source', 'id'
)::regclass::oid AS source_seq_oid
\gset
SELECT pg_catalog.pg_get_serial_sequence(
'refonte_clone_lab.identity_source', 'id'
)::regclass::oid AS identity_source_seq_oid
\gset
SELECT pg_catalog.pg_get_serial_sequence(
'refonte_clone_lab.identity_clone', 'id'
)::regclass::oid AS identity_clone_seq_oid
\gset
\echo SOURCE_SEQ_OID=:source_seq_oid
\echo IDENTITY_SOURCE_SEQ_OID=:identity_source_seq_oid
\echo IDENTITY_CLONE_SEQ_OID=:identity_clone_seq_oid
SELECT c.oid AS table_oid,
n.nspname AS schema_name,
c.relname AS table_name
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.oid IN (
'refonte_clone_lab.serial_source'::regclass,
'refonte_clone_lab.serial_clone'::regclass
)
ORDER BY c.oid;
SELECT a.attrelid AS table_oid,
a.attnum,
ad.oid AS attrdef_oid,
pg_catalog.pg_get_expr(ad.adbin, ad.adrelid) AS default_expression,
dep.classid,
dep.objid,
dep.refclassid,
dep.refobjid AS referenced_sequence_oid,
dep.deptype
FROM pg_catalog.pg_attribute a
JOIN pg_catalog.pg_attrdef ad
ON ad.adrelid = a.attrelid
AND ad.adnum = a.attnum
JOIN pg_catalog.pg_depend dep
ON dep.classid = 'pg_catalog.pg_attrdef'::regclass
AND dep.objid = ad.oid
AND dep.refclassid = 'pg_catalog.pg_class'::regclass
JOIN pg_catalog.pg_class seq
ON seq.oid = dep.refobjid
AND seq.relkind = 'S'
WHERE a.attrelid IN (
'refonte_clone_lab.serial_source'::regclass,
'refonte_clone_lab.serial_clone'::regclass
)
AND a.attname = 'id'
ORDER BY a.attrelid, dep.refobjid;
SELECT refonte_clone_lab.assert_true(
'P1 source default uses SOURCE_SEQ',
refonte_clone_lab.default_sequence_oid(
'refonte_clone_lab.serial_source'::regclass, 'id'
) = :source_seq_oid
);
SELECT refonte_clone_lab.assert_true(
'P1 clone copied default uses SOURCE_SEQ',
refonte_clone_lab.default_sequence_oid(
'refonte_clone_lab.serial_clone'::regclass, 'id'
) = :source_seq_oid
);
SELECT refonte_clone_lab.assert_true(
'P1 clone initially has no associated sequence',
pg_catalog.pg_get_serial_sequence(
'refonte_clone_lab.serial_clone', 'id'
) IS NULL
);Read association and default dependency separately
The three fields should remain distinct in the evidence record:
Evidence field | P1 expected meaning |
Column association | Source → SOURCE_SEQ; clone → NULL |
Reconstructed clone default | Explanatory SQL showing a nextval of the source sequence |
Catalog dependency | Clone default object references SOURCE_SEQ |
A NULL result from pg_get_serial_sequence does not mean the clone cannot generate a value: it can still have a copied ordinary default. Conversely, a non-null association later will not prove that this ordinary default invokes that associated sequence. PostgreSQL's own wording separates sequence association from reconstructed expression text, and the dependency catalog gives a third object-level observation.
Prove that two serial tables consume one allocator
P2 supplies behavioral evidence without introducing concurrency. The only allocating statements are the three intended inserts, each executed once:
INSERT INTO refonte_clone_lab.serial_source(payload)
VALUES ('s1')
RETURNING id
\gset p2_s1_
\echo P2 source s1 RETURNING id=:p2_s1_id
INSERT INTO refonte_clone_lab.serial_clone(payload)
VALUES ('c1')
RETURNING id
\gset p2_c1_
\echo P2 clone c1 RETURNING id=:p2_c1_id
INSERT INTO refonte_clone_lab.serial_source(payload)
VALUES ('s2')
RETURNING id
\gset p2_s2_
\echo P2 source s2 RETURNING id=:p2_s2_id
SELECT *
FROM refonte_clone_lab.sequence_state(:source_seq_oid);
SELECT refonte_clone_lab.assert_true(
'P2 returned ids are 1,2,3',
:p2_s1_id::bigint = 1
AND :p2_c1_id::bigint = 2
AND :p2_s2_id::bigint = 3
);
SELECT refonte_clone_lab.assert_true(
'P2 exact source rows',
NOT EXISTS (
(SELECT id,payload FROM refonte_clone_lab.serial_source
EXCEPT
VALUES (1::bigint,'s1'::text),(3::bigint,'s2'::text))
UNION ALL
(VALUES (1::bigint,'s1'::text),(3::bigint,'s2'::text)
EXCEPT
SELECT id,payload FROM refonte_clone_lab.serial_source)
)
);
SELECT refonte_clone_lab.assert_true(
'P2 exact clone rows',
NOT EXISTS (
(SELECT id,payload FROM refonte_clone_lab.serial_clone
EXCEPT
VALUES (2::bigint,'c1'::text))
UNION ALL
(VALUES (2::bigint,'c1'::text)
EXCEPT
SELECT id,payload FROM refonte_clone_lab.serial_clone)
)
);With increment one, cache one and no other allocator calls, the expected outputs are 1, 2 and 3, and SOURCE_SEQ should report last_value=3, is_called=true. PostgreSQL documents last_value as the last value allocated and notes that cache one avoids preallocated blocks; those facts are useful precisely because this fixture excludes concurrent allocators.
Do not generalize “alternating numbers” into a dependency detector. Here the sequence of integers corroborates a catalog result under one owner, one session, CACHE 1 and a known statement order. The decisive structural evidence remains the clone default's dependency on SOURCE_SEQ.
Every insert can satisfy its local primary-key constraint and still violate the declared allocation policy. Likewise, this test says nothing about row visibility or checkpoint completeness; sequence allocation versus commit order is a separate problem involving concurrent transactions and commit visibility.
Test a clone that received no default
P3 demonstrates the opposite failure mode: removing copied defaults does not magically create an independent allocator.
Plain LIKE does not copy the source default, while the copied NOT NULL property leaves bare_clone.id requiring an explicit value. The negative helper catches only not_null_violation, records the diagnostic identity and rejects either an unexpected success or a mismatched target.
SELECT *
FROM refonte_clone_lab.run_p3_negative();
SELECT refonte_clone_lab.assert_true(
'P3 failed insert left no row',
NOT EXISTS (
SELECT 1
FROM refonte_clone_lab.bare_clone
)
);
INSERT INTO refonte_clone_lab.bare_clone(id,payload)
VALUES (9001,'manual');
SELECT refonte_clone_lab.assert_true(
'P3 explicit row is exactly 9001/manual',
NOT EXISTS (
(SELECT id,payload FROM refonte_clone_lab.bare_clone
EXCEPT VALUES (9001::bigint,'manual'::text))
UNION ALL
(VALUES (9001::bigint,'manual'::text)
EXCEPT SELECT id,payload FROM refonte_clone_lab.bare_clone)
)
);
SELECT refonte_clone_lab.assert_true(
'P3 bare clone has no associated sequence',
pg_catalog.pg_get_serial_sequence(
'refonte_clone_lab.bare_clone','id'
) IS NULL
);Expected diagnostic evidence is SQLSTATE 23502, schema refonte_clone_lab, table bare_clone, column id, and zero rows after the failed statement. The subsequent explicit (9001,'manual') row proves only that callers can supply an ID manually. It does not satisfy an automatic-ID requirement.
This control should not silently gain a primary key. INCLUDING INDEXES is the LIKE option that recreates indexes and primary-key, unique and exclusion constraints; the bare clone intentionally omits it.
Compare independently created identity sequences
P4 tests the documented contrast. Identity columns use an implicit sequence, and BY DEFAULT permits a caller-supplied value to override generated behavior. PostgreSQL separately notes that identity generation alone does not enforce uniqueness; a primary key or unique constraint is needed, which this fixture supplies explicitly.
SELECT a.attrelid,
a.attname,
a.attidentity,
pg_catalog.pg_get_serial_sequence(
a.attrelid::regclass::text, a.attname
) AS associated_sequence
FROM pg_catalog.pg_attribute a
WHERE a.attrelid IN (
'refonte_clone_lab.identity_source'::regclass,
'refonte_clone_lab.identity_clone'::regclass
)
AND a.attname = 'id';
SELECT refonte_clone_lab.assert_true(
'P4 identity sequence OIDs differ',
:identity_source_seq_oid::oid
IS DISTINCT FROM
:identity_clone_seq_oid::oid
);P5 then performs exactly four allocations:
INSERT INTO refonte_clone_lab.identity_source(payload)
VALUES ('is1') RETURNING id
\gset p5_is1_
SELECT FROM refonte_clone_lab.sequence_state(:identity_source_seq_oid);
SELECT FROM refonte_clone_lab.sequence_state(:identity_clone_seq_oid);
INSERT INTO refonte_clone_lab.identity_clone(payload)
VALUES ('ic1') RETURNING id
\gset p5_ic1_
SELECT FROM refonte_clone_lab.sequence_state(:identity_source_seq_oid);
SELECT FROM refonte_clone_lab.sequence_state(:identity_clone_seq_oid);
INSERT INTO refonte_clone_lab.identity_source(payload)
VALUES ('is2') RETURNING id
\gset p5_is2_
INSERT INTO refonte_clone_lab.identity_clone(payload)
VALUES ('ic2') RETURNING id
\gset p5_ic2_
SELECT refonte_clone_lab.assert_true(
'P5 identity ids are source 1,2 and clone 1,2',
:p5_is1_id::bigint = 1
AND :p5_ic1_id::bigint = 1
AND :p5_is2_id::bigint = 2
AND :p5_ic2_id::bigint = 2
);The intermediate observations matter. After is1, IDENTITY_SOURCE_SEQ should be 1/true while IDENTITY_CLONE_SEQ remains at its uncalled initial state. After ic1, both should be 1/true. That differentiates independent advancement from merely seeing equal resulting integers.
Separate equal ID values from shared sequence identity
Rows identity_source.id=1 and identity_clone.id=1 are fully compatible with independent allocators because the identifier domains are table-local. The evidence of independence is that the associated sequence OIDs differ and only the allocator belonging to the table advances when that table performs an omitted-ID insert. PostgreSQL expressly says INCLUDING IDENTITY creates a separate sequence for the copied identity column.
That is also why this protocol makes no claim of cross-table uniqueness. Identity generation and uniqueness are distinct properties. Reviewers dealing with the latter should treat database uniqueness policy as a separate integrity question.
Expose an ownership-only repair
P6 creates the intentionally incomplete repair:
CREATE SEQUENCE refonte_clone_lab.serial_clone_id_seq
AS bigint
START WITH 1001
INCREMENT BY 1
CACHE 1
NO CYCLE
OWNED BY refonte_clone_lab.serial_clone.id;
SELECT 'refonte_clone_lab.serial_clone_id_seq'::regclass::oid
AS clone_seq_oid
\gset
\echo CLONE_SEQ_OID=:clone_seq_oid
SELECT pg_catalog.pg_get_serial_sequence(
'refonte_clone_lab.serial_clone','id'
) AS clone_association,
refonte_clone_lab.default_sequence_oid(
'refonte_clone_lab.serial_clone'::regclass,'id'
) AS clone_default_sequence_oid;
SELECT FROM refonte_clone_lab.sequence_state(:source_seq_oid);
SELECT FROM refonte_clone_lab.sequence_state(:clone_seq_oid);
SELECT refonte_clone_lab.assert_true(
'P6 association is CLONE_SEQ',
pg_catalog.pg_get_serial_sequence(
'refonte_clone_lab.serial_clone','id'
)::regclass::oid = :clone_seq_oid
);
SELECT refonte_clone_lab.assert_true(
'P6 default still depends on SOURCE_SEQ',
refonte_clone_lab.default_sequence_oid(
'refonte_clone_lab.serial_clone'::regclass,'id'
) = :source_seq_oid
);OWNED BY associates a sequence with a column so that sequence lifecycle follows that column, subject to the documented same-owner and same-schema requirements. ALTER SEQUENCE ... OWNED BY changes that association; PostgreSQL does not describe it as an operation that rewrites the column's default expression.
The expected P6 record is therefore deliberately contradictory if someone treats all “sequence metadata” as interchangeable:
Field | Expected P6 |
Clone association | CLONE_SEQ |
Clone ordinary-default dependency | SOURCE_SEQ |
SOURCE_SEQ state | 3 / true |
CLONE_SEQ state | 1001 / false |
That is the distinctive PostgreSQL sequence ownership versus default failure. A plausible new sequence name and a valid ownership association are insufficient to approve allocator isolation.
|
Renaming either object would change labels, not the dependency edge being tested. Transferring SOURCE_SEQ ownership to the clone would be worse: it would detach a source resource from its original lifecycle rather than correcting the clone's invocation.
Observe the write that exposes the stale default
P7 converts that metadata mismatch into direct write evidence:
INSERT INTO refonte_clone_lab.serial_clone(payload)
VALUES ('c2')
RETURNING id
\gset p7_c2_
\echo P7 clone c2 RETURNING id=:p7_c2_id
SELECT FROM refonte_clone_lab.sequence_state(:source_seq_oid);
SELECT FROM refonte_clone_lab.sequence_state(:clone_seq_oid);
SELECT refonte_clone_lab.assert_true(
'P7 stale default returned 4',
:p7_c2_id::bigint = 4
);Expected result: c2 receives 4, SOURCE_SEQ becomes 4/true, and CLONE_SEQ remains 1001/false. This is exactly what should happen if the stored default still invokes SOURCE_SEQ: omission of the serial-style column causes its default to provide the value, and PostgreSQL's documented serial expansion is a nextval(...) default.
Expected row state at the end of P7 is:
Table | Exact expected rows |
serial_source | (1,s1), (3,s2) |
serial_clone | (2,c1), (4,c2) |
bare_clone | (9001,manual) |
The important operational result is not merely “4 appeared.” It is the reconciliation of three facts: pg_get_serial_sequence reports CLONE_SEQ; the default dependency still names SOURCE_SEQ; and the omitted-ID insert advances SOURCE_SEQ while CLONE_SEQ does not move.
An association-only reviewer would approve the wrong state. An expression-text-only reviewer has stronger evidence but could still be relying on string interpretation. The class-qualified pg_depend edge supplies object identity, while the actual insert establishes behavior in the bounded fixture.
Do not call nextval diagnostically to “double-check” either sequence. That would alter the experiment. Do not reset the source to 3 afterward. P7's unwanted allocation is evidence and must remain visible.
Rehearse and commit the default repair
The actual repair is a separate definition change:
ALTER TABLE refonte_clone_lab.serial_clone
ALTER COLUMN id
SET DEFAULT nextval(
'refonte_clone_lab.serial_clone_id_seq'::regclass
);PostgreSQL documents ALTER TABLE ... ALTER COLUMN ... SET DEFAULT expression as the operation that changes the default, and changes to defaults affect subsequent writes rather than renumbering existing rows. That is the operation required here; changing sequence ownership alone was insufficient.
Roll back the definition before allocating another ID
P8 rehearses transactional definition recovery and intentionally allocates nothing:
BEGIN;
ALTER TABLE refonte_clone_lab.serial_clone
ALTER COLUMN id
SET DEFAULT nextval(
'refonte_clone_lab.serial_clone_id_seq'::regclass
);
SELECT refonte_clone_lab.assert_true(
'P8 in-transaction default uses CLONE_SEQ',
refonte_clone_lab.default_sequence_oid(
'refonte_clone_lab.serial_clone'::regclass,'id'
) = :clone_seq_oid
);
SELECT refonte_clone_lab.assert_true(
'P8 association remains CLONE_SEQ',
pg_catalog.pg_get_serial_sequence(
'refonte_clone_lab.serial_clone','id'
)::regclass::oid = :clone_seq_oid
);
ROLLBACK;
SELECT refonte_clone_lab.assert_true(
'P8 rollback restored SOURCE_SEQ default',
refonte_clone_lab.default_sequence_oid(
'refonte_clone_lab.serial_clone'::regclass,'id'
) = :source_seq_oid
);
SELECT refonte_clone_lab.assert_true(
'P8 association still remains CLONE_SEQ',
pg_catalog.pg_get_serial_sequence(
'refonte_clone_lab.serial_clone','id'
)::regclass::oid = :clone_seq_oid
);
SELECT FROM refonte_clone_lab.sequence_state(:source_seq_oid);
SELECT FROM refonte_clone_lab.sequence_state(:clone_seq_oid);The expected states remain source 4/true and clone 1001/false because P8 contains no allocating operation. This is a DDL-definition rollback exercise, not a sequence reseed experiment.
P9 then commits the same definition:
BEGIN;
ALTER TABLE refonte_clone_lab.serial_clone
ALTER COLUMN id
SET DEFAULT nextval(
'refonte_clone_lab.serial_clone_id_seq'::regclass
);
SELECT refonte_clone_lab.assert_true(
'P9 precommit dependency is CLONE_SEQ',
refonte_clone_lab.default_sequence_oid(
'refonte_clone_lab.serial_clone'::regclass,'id'
) = :clone_seq_oid
);
COMMIT;
SELECT refonte_clone_lab.assert_true(
'P9 postcommit dependency is CLONE_SEQ',
refonte_clone_lab.default_sequence_oid(
'refonte_clone_lab.serial_clone'::regclass,'id'
) = :clone_seq_oid
);
SELECT refonte_clone_lab.assert_true(
'P9 association is CLONE_SEQ',
pg_catalog.pg_get_serial_sequence(
'refonte_clone_lab.serial_clone','id'
)::regclass::oid = :clone_seq_oid
);
SELECT refonte_clone_lab.assert_true(
'P9 source association retained',
pg_catalog.pg_get_serial_sequence(
'refonte_clone_lab.serial_source','id'
)::regclass::oid = :source_seq_oid
);Nothing in P8 or P9 authorizes transferring SOURCE_SEQ, changing source defaults or editing existing IDs.
Reconcile final rows and allocator state
P10 is the postrepair proof. It deliberately interleaves clone and source inserts so advancement of one sequence can be distinguished from advancement of the other.
INSERT INTO refonte_clone_lab.serial_clone(payload)
VALUES ('c3') RETURNING id
\gset p10_c3_
INSERT INTO refonte_clone_lab.serial_source(payload)
VALUES ('s3') RETURNING id
\gset p10_s3_
INSERT INTO refonte_clone_lab.serial_clone(payload)
VALUES ('c4') RETURNING id
\gset p10_c4_
INSERT INTO refonte_clone_lab.serial_source(payload)
VALUES ('s4') RETURNING id
\gset p10_s4_
\echo P10 c3=:p10_c3_id s3=:p10_s3_id c4=:p10_c4_id s4=:p10_s4_id
SELECT refonte_clone_lab.assert_true(
'P10 returned ids match manifest',
:p10_c3_id::bigint = 1001
AND :p10_s3_id::bigint = 5
AND :p10_c4_id::bigint = 1002
AND :p10_s4_id::bigint = 6
);
SELECT FROM refonte_clone_lab.sequence_state(:source_seq_oid);
SELECT FROM refonte_clone_lab.sequence_state(:clone_seq_oid);
SELECT FROM refonte_clone_lab.sequence_state(:identity_source_seq_oid);
SELECT FROM refonte_clone_lab.sequence_state(:identity_clone_seq_oid);The required final allocator state is SOURCE_SEQ 6/true, CLONE_SEQ 1002/true, and both identity sequences 2/true.
The row ledger is independently fixed:
Table | Exact expected final rows |
serial_source | (1,s1), (3,s2), (5,s3), (6,s4) |
serial_clone | (2,c1), (4,c2), (1001,c3), (1002,c4) |
bare_clone | (9001,manual) |
identity_source | (1,is1), (2,is2) |
identity_clone | (1,ic1), (2,ic2) |
The runnable script should finish with exact bidirectional comparisons, for example:
SELECT refonte_clone_lab.assert_true(
'P10 exact serial_source',
NOT EXISTS (
(SELECT id,payload FROM refonte_clone_lab.serial_source
EXCEPT VALUES
(1::bigint,'s1'::text),
(3::bigint,'s2'::text),
(5::bigint,'s3'::text),
(6::bigint,'s4'::text))
UNION ALL
(VALUES
(1::bigint,'s1'::text),
(3::bigint,'s2'::text),
(5::bigint,'s3'::text),
(6::bigint,'s4'::text)
EXCEPT SELECT id,payload FROM refonte_clone_lab.serial_source)
)
);
SELECT refonte_clone_lab.assert_true(
'P10 exact serial_clone',
NOT EXISTS (
(SELECT id,payload FROM refonte_clone_lab.serial_clone
EXCEPT VALUES
(2::bigint,'c1'::text),
(4::bigint,'c2'::text),
(1001::bigint,'c3'::text),
(1002::bigint,'c4'::text))
UNION ALL
(VALUES
(2::bigint,'c1'::text),
(4::bigint,'c2'::text),
(1001::bigint,'c3'::text),
(1002::bigint,'c4'::text)
EXCEPT SELECT id,payload FROM refonte_clone_lab.serial_clone)
)
);
SELECT refonte_clone_lab.assert_true(
'P10 exact identity_source',
NOT EXISTS (
(SELECT id,payload FROM refonte_clone_lab.identity_source
EXCEPT VALUES (1::bigint,'is1'::text),(2::bigint,'is2'::text))
UNION ALL
(VALUES (1::bigint,'is1'::text),(2::bigint,'is2'::text)
EXCEPT SELECT id,payload FROM refonte_clone_lab.identity_source)
)
);
SELECT refonte_clone_lab.assert_true(
'P10 exact identity_clone',
NOT EXISTS (
(SELECT id,payload FROM refonte_clone_lab.identity_clone
EXCEPT VALUES (1::bigint,'ic1'::text),(2::bigint,'ic2'::text))
UNION ALL
(VALUES (1::bigint,'ic1'::text),(2::bigint,'ic2'::text)
EXCEPT SELECT id,payload FROM refonte_clone_lab.identity_clone)
)
);Reject missing or misidentified evidence
The evidence package itself needs negative tests.
E1 removes P7 from a copy of the package. The reviewer must reject it because the most important counterexample (the state in which association says CLONE_SEQ while an actual omitted-ID write still consumes SOURCE_SEQ) is absent. Exit zero or later postrepair correctness cannot reconstruct that missing evidence.
E2 alters a copied postrepair evidence record so the association says CLONE_SEQ but the reported default dependency says SOURCE_SEQ. The package must be rejected as contradictory, even if the final row values happen to match. The correct response is investigation or rerun, not rewriting the expected manifest to fit the record.
Missing catalog rows similarly cannot count as success. Null-safe comparisons, cardinality checks and exact case membership are deliberate controls against “empty output looked green.”
Bound recovery before changing a live clone
The synthetic start value 1001 is an authored boundary chosen for this closed fixture. It is not a production recipe such as “use MAX(id)+1.” A populated live clone has additional questions: which IDs have been issued to external callers, whether the clone's existing rows overlap the intended local identifier domain, whether references exist outside this table, and which application paths may bypass the default. Those matters are outside this qualification and require their own approved scope.
The repair here changes future default-based writes. PostgreSQL documents SET DEFAULT as affecting subsequent inserts or updates, not rewriting existing rows. Accordingly, IDs 2 and 4 in serial_clone remain untouched after the repair. Preserving them is part of the expected ledger, not an anomaly to clean up.
Nor does an independent sequence create cross-table uniqueness. After repair, source values 5 and 6 and clone values 1001 and 1002 happen not to overlap because of the authored synthetic boundary, but no universal cross-table key guarantee is being claimed.
A rollback before allocation, as in P8, can restore the prior default definition. It does not establish that sequence values already handed out elsewhere could be recalled. PostgreSQL sequences have allocation semantics distinct from ordinary row rollback, and the separate Refonte article on sequence reseed and rollback behavior addresses that recovery class.
Operationally, preserve divergent observations. Do not “tidy” the fixture by resetting SOURCE_SEQ, deleting P7's row, or reseeding CLONE_SEQ. If an unexpected allocator call, retry or manual diagnostic nextval contaminates the statement schedule, mark the run RERUN and use a fresh identified fixture. Retain disposable objects until the evidence package has been reviewed; any cleanup afterward should explicitly target only the owned laboratory.
Decide which clone can be released
The qualification is a reconciliation problem, not a collection of green SQL statements.
Decision | Required interpretation |
ACCEPT_BOUNDED_INDEPENDENCE | Intended association and dependency agree; postrepair writes advance only the intended allocator; source binding is preserved; final rows and sequence states exactly match; evidence is complete. |
REPAIR_DEFAULT_BINDING | The documented shared-default violation is demonstrated and the candidate still requires the separately reviewed SET DEFAULT repair. |
HOLD | Policy is ambiguous, expression shape is outside the admitted direct-nextval form, environment or metadata is missing, records contradict each other, or live scope has not been reviewed. |
RERUN | A supposedly controlled run was contaminated by extra allocations, retries, wrong objects, incomplete capture or an untrusted fixture. |
For this article, the decision is HOLD, because no database execution has occurred. Documentation supports the expected behavior, but a proposed protocol is not an executed qualification.
A complete evidence record should contain case identity; source revision and cryptographic digest; psql build; server version() and server_version_num; database; role; backend PID; inspection search_path; table OIDs; attribute number and pg_attrdef OID where applicable; associated sequence identity; dependency sequence identity; pg_depend class IDs and dependency type; sequence OIDs and pg_sequence properties; exact statement order; transaction boundary and outcome; each RETURNING value; each sequence-state observation; row-set comparison; P3 SQLSTATE/schema/table/column diagnostics; stdout, stderr and process status.
pg_sequence is appropriate for static generator parameters such as start, increment, bounds, cache and cycle settings, while the sequence relation itself exposes current last_value and is_called. Keep those concepts separate as well.
Assign ownership of the allocator contract
The schema owner approves whether allocation is independent or intentionally shared. The DBA verifies catalog interpretation, DDL and operational boundaries. Application and data owners review identifier-domain assumptions and whether callers depend on existing IDs. The release reviewer reconciles the independent manifest against the captured evidence instead of treating successful script completion as the result.
That surrounding ownership fits into broader database integration and migration foundations, but this protocol deliberately excludes online migration scheduling, replication, dump/restore, trigger behavior and application cutover.
The distinction between “sound proposed protocol” and “qualified deployment” is important. PostgreSQL's documentation establishes command contracts: INCLUDING DEFAULTS can copy a functional sequence linkage, INCLUDING IDENTITY creates separate identity sequences, OWNED BY controls association, and SET DEFAULT changes the expression for future writes. Only an identified run can establish that a particular environment produced the expected catalog and behavioral evidence.
Develop database review practice with Database Administrator Essentials
This exercise is useful because it forces reviewers to distinguish three statements that sound deceptively similar: “the column has an associated sequence,” “the default depends on this sequence,” and “this insert actually consumed this sequence.” A competent PostgreSQL clone review should be able to explain why those statements can disagree during the ownership-only counterexample, and why the disagreement is operationally significant.
Refonte Learning's Database Administrator Essentials page describes a three-month program with an expected 12–14 hours per week. Its listed competencies include database design and architecture, SQL optimization, backup and recovery, security, monitoring, and data migration and integration; the page also describes hands-on projects and potential internship opportunities. The educational path names AWS RDS, Azure SQL and Google Cloud Spanner, while the current page also states that basic programming knowledge is recommended and that admission requires working toward a bachelor's or higher-level degree. Successful completion is associated on the page with a Training Certificate and Certificate of Internship.
The page should be checked for current details before enrollment. PostgreSQL-specific curriculum, a CREATE TABLE ... LIKE sequence-dependency laboratory, exact PostgreSQL or psql versions, internship assignment terms, and mentorship frequency are not established by the reviewed page and remain to be verified.
The concrete engineering handoff from this protocol is narrower: an approved allocator policy, a complete P1–P10 evidence package, explicit disposition of E1/E2-style defects, and a named owner for any remaining default-binding repair. Until an identified PostgreSQL 18.7/psql 18.7 run produces and reconciles that evidence, the qualification record remains EXPECTED / NOT EXECUTED; the decision remains HOLD.

