mirror of
https://github.com/postgres/postgres.git
synced 2025-07-11 10:01:57 +03:00
Logical decoding of TRUNCATE
Add a new WAL record type for TRUNCATE, which is only used when wal_level >= logical. (For physical replication, TRUNCATE is already replicated via SMGR records.) Add new callback for logical decoding output plugins to receive TRUNCATE actions. Author: Simon Riggs <simon@2ndquadrant.com> Author: Marco Nenciarini <marco.nenciarini@2ndquadrant.it> Author: Peter Eisentraut <peter.eisentraut@2ndquadrant.com> Reviewed-by: Petr Jelinek <petr.jelinek@2ndquadrant.com> Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
This commit is contained in:
@ -415,6 +415,7 @@ ReorderBufferReturnChange(ReorderBuffer *rb, ReorderBufferChange *change)
|
||||
case REORDER_BUFFER_CHANGE_INTERNAL_SPEC_CONFIRM:
|
||||
case REORDER_BUFFER_CHANGE_INTERNAL_COMMAND_ID:
|
||||
case REORDER_BUFFER_CHANGE_INTERNAL_TUPLECID:
|
||||
case REORDER_BUFFER_CHANGE_TRUNCATE:
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1491,6 +1492,38 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
|
||||
specinsert = change;
|
||||
break;
|
||||
|
||||
case REORDER_BUFFER_CHANGE_TRUNCATE:
|
||||
{
|
||||
int i;
|
||||
int nrelids = change->data.truncate.nrelids;
|
||||
int nrelations = 0;
|
||||
Relation *relations;
|
||||
|
||||
relations = palloc0(nrelids * sizeof(Relation));
|
||||
for (i = 0; i < nrelids; i++)
|
||||
{
|
||||
Oid relid = change->data.truncate.relids[i];
|
||||
Relation relation;
|
||||
|
||||
relation = RelationIdGetRelation(relid);
|
||||
|
||||
if (relation == NULL)
|
||||
elog(ERROR, "could not open relation with OID %u", relid);
|
||||
|
||||
if (!RelationIsLogicallyLogged(relation))
|
||||
continue;
|
||||
|
||||
relations[nrelations++] = relation;
|
||||
}
|
||||
|
||||
rb->apply_truncate(rb, txn, nrelations, relations, change);
|
||||
|
||||
for (i = 0; i < nrelations; i++)
|
||||
RelationClose(relations[i]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case REORDER_BUFFER_CHANGE_MESSAGE:
|
||||
rb->message(rb, txn, change->lsn, true,
|
||||
change->data.msg.prefix,
|
||||
@ -2255,6 +2288,7 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
|
||||
}
|
||||
break;
|
||||
}
|
||||
case REORDER_BUFFER_CHANGE_TRUNCATE:
|
||||
case REORDER_BUFFER_CHANGE_INTERNAL_SPEC_CONFIRM:
|
||||
case REORDER_BUFFER_CHANGE_INTERNAL_COMMAND_ID:
|
||||
case REORDER_BUFFER_CHANGE_INTERNAL_TUPLECID:
|
||||
@ -2534,6 +2568,7 @@ ReorderBufferRestoreChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
|
||||
break;
|
||||
}
|
||||
/* the base struct contains all the data, easy peasy */
|
||||
case REORDER_BUFFER_CHANGE_TRUNCATE:
|
||||
case REORDER_BUFFER_CHANGE_INTERNAL_SPEC_CONFIRM:
|
||||
case REORDER_BUFFER_CHANGE_INTERNAL_COMMAND_ID:
|
||||
case REORDER_BUFFER_CHANGE_INTERNAL_TUPLECID:
|
||||
|
Reference in New Issue
Block a user