Short answer: there is no single "undo" command for a table that vanished somewhere in a data pipeline. You get a SQL table "back from the communication" by identifying which layer lost or altered it — database, replication feed, message queue, API, or log payload — then restoring from the authoritative source and verifying against a checksum or row count.

That answer needs a caveat, because "the communication" is ambiguous. It could mean a message queue (Kafka, RabbitMQ, Azure Service Bus) carrying change events, a REST or gRPC API response that reported table data, a database replication or CDC stream, a log export, or a network conversation captured in pcap. Each has a different recovery path. The steps below cover the common ones and tell you how to tell them apart.

For the practical case most people mean — a table whose rows exist in a stream or export but no longer exist in a queryable database — the recovery has three phases: locate the payload, reconstruct rows into a real table, and reconcile against a known baseline.

First, decide which "communication" you actually have

Before touching anything, classify the medium. The label on the tool matters less than what it guarantees.

A message queue holds events, not a snapshot. A Kafka topic with cleanup.policy=compact keeps the latest value per key, so you can rebuild current state but not full history. A non-compacted topic keeps everything only until retention expires (retention.ms, often 7 days by default). RabbitMQ deletes a message once it's acknowledged and has no built-in replay for classic queues without a retained store.

An API response is a point-in-time projection. If the endpoint returned JSON rows, you have those rows and nothing else — no deleted rows, no columns the endpoint didn't expose.

A replication or CDC stream (Debezium, Postgres logical replication, SQL Server CDC) carries before/after images if configured, which makes point-in-time reconstruction feasible.

A log or pcap dump is raw text or bytes. You can extract SQL statements or payloads from it, but ordering and completeness are usually uncertain.

Write down which one you have and what its retention window is. That single fact determines whether recovery means replay or reconstruction.

Prerequisites before you start

You need four things in place, and skipping any of them is how recovery turns into guessing:

1: Read access to the source system — the topic, the queue, the API credentials, or the log store. 2: A target database where you can create a scratch schema. Never restore directly over production. 3: A baseline to compare against: a known row count, a checksum, a primary key range, or a prior backup. 4: The schema definition — column names, types, nullability, and constraints. A payload without its schema is a pile of strings.

If you're missing the baseline, create one now from any surviving copy: a replica, a backup, a BI extract. Without it you can rebuild rows but can't prove completeness.

Step 1: Find the authoritative payload

Start at the layer closest to the source of truth. For a CDC stream that's the connector's topic or slot; for an API it's the endpoint's own logs; for a queue it's the consumer group's committed offsets.

Check the retention and offset range first. In Kafka:

This shows committed offsets and lag. If the earliest available offset (--offsets with --time -2) is newer than where your data lived, replay won't recover it. Note that fact immediately — it changes the plan from "replay" to "restore from backup plus patch from downstream."

For an API, look for the request/response log or an audit trail. If the service exposes pagination, re-fetch the same query with the same parameters and cursor if the API supports historical reads. Most don't, so capture what the logs already contain.

For a database's own communication — the connection that ran the destructive statement — check pg_stat_activity history, pg_stat_statements, audit logs (pgaudit, SQL Server's default trace or extended events), or the binary log if MySQL was involved.

At the end of this step you should have a concrete file, topic partition range, or query result set, and a documented retention boundary. That's your success check: you can name the exact bytes you'll work from.

Step 2: Extract and normalize the payloads

Raw event payloads are rarely directly insertable. CDC events often carry an envelope: an operation type (c, u, d, r), a before and after object, and metadata like timestamps and transaction IDs.

The rule is: replay ordered events, apply the operation type, and stop at your target timestamp. A simplified rebuild loop:

1: Filter to the key or table you need. 2: Drop events with op = 'd' if you want the state before deletion, or keep them if you're rebuilding history. 3: For u, take the after image; if you need the pre-update state, take before. 4: Order by the log's own sequence (LSN, binlog position, or the event's offset and timestamp) — never by wall-clock time alone, because clock skew reorders transactions. 5: Apply to a scratch table with the real primary key.

If the payload is JSON from an API, define the column mapping explicitly, including null handling. A missing field and a null field are different, and collapsing them silently corrupts aggregates later.

A worked check: suppose a baseline says the table had 1,240,000 rows at the cutoff. You extract 1,240,000 distinct primary keys and the max key matches. That's plausible but not proof — an update to a non-key column could still be wrong. Add a checksum over the key columns and at least one measure column.

For checksums across systems, md5 over a canonical concatenation works in Postgres and MySQL; SQL Server has HASHBYTES. Compute it the same way on both sides, including type casting and null substitution, or the comparison is meaningless.

Step 3: Rebuild into a real table

Now materialize. Create the scratch table with the original schema, load the reconstructed rows in key order, and apply constraints only after load — this surfaces duplicates and orphaned foreign keys as load errors rather than silent corruption.

Loading order matters if foreign keys exist. Parents before children. If you're rebuilding a transaction table, load the header rows, then detail rows, then any child lookups.

Then reconcile, and be specific about what you're comparing:

Row count against the baseline, by key range, not just total. Checksum on key plus one or two measure columns. Null density per column versus baseline — a currency column that's now 100% null is a mapping failure, not a data problem. Max/min timestamps to confirm the cutoff was honored.

State the check and the expected result before you run it. "Row count within the range 2025-01-01 to cutoff should equal 1,240,000; checksum should match the replica" is checkable. "Looks right" is not.

The most common failure: the queue never held the rows

The single most frequent reason this recovery fails is a mistaken belief that a message broker stores a table. It stores events or messages, and its retention is a policy, not a guarantee.

Three typical cases:

Compacted topics. With log compaction, Kafka keeps only the last value per key. If a row was inserted and then deleted, the deletion tombstone may be the only event left, and the insert is gone. Rebuilding current state works; rebuilding a specific past state does not.

Acknowledged and deleted messages. RabbitMQ, SQS, and most work queues remove messages once consumed. Unless you set up a separate archive consumer writing to durable storage, there is nothing to replay. The fix is architectural — add an archive sink before you need it.

Outbox and transactional boundaries. Some systems publish after commit but lose events on failure; others publish before commit and leak phantom rows. If you can't tell which, compare the rebuilt table's row count against the source database's own count at the same cutoff. A shortfall concentrated in one time window points to a publish gap, not a bad join.

In all three, the honest recovery is a database backup or replica, with the stream used only to patch forward from the backup's timestamp to the incident.

What if "the communication" means a live connection or protocol capture?

A different interpretation: you have a pcap, an ODBC/JDBC trace, or a database proxy log, and you want the table's data that passed over the wire.

This is feasible but limited. You can parse the SQL statements and result sets if the protocol is unencrypted or you have the TLS keys. Tools like tshark with the Postgres or MySQL dissectors can extract query text and row data; TDS (SQL Server) has weaker dissector support, so expect manual parsing.

Limits you should state up front: encryption removes visibility entirely without keys; large result sets may have been paged or compressed (Postgres' extended protocol can compress, and TDS has its own encoding); and if the connection used prepared statements, the actual values may be bound separately from the text. Treat any extraction as partial until a row count and a key checksum prove otherwise.

Success check: the extracted row count matches the result set size recorded in the trace, and the key range is contiguous with no gaps.

Restoring from backup when the stream can't cover it

If the retention boundary has passed, stop trying to replay and go to backups. The general order is: point-in-time recovery of the database to just before the incident, then apply any surviving events after that timestamp.

For Postgres, continuous archiving plus WAL gives PITR to an arbitrary timestamp. For MySQL, binlogs give the same if log_bin was on. SQL Server uses transaction log backups and STOPAT. In every case the recovery point is bounded by your backup cadence — you can't recover to a moment between backups if WAL or binlogs weren't retained.

Verify by repeating the same row count and checksum checks from Step 3. Then patch forward using whatever events remain, and re-run the checks. If the patched result diverges from the baseline, the patch events are incomplete — that's your stop condition, and it means the remaining gap needs a source-system owner, not more scripting.

A concrete worked estimate

Suppose you have a Kafka topic with 3 partitions, events averaging 2 KB, and a compaction policy. You need to know whether the topic can hold the rows you're missing.

Total bytes retained = partition count × average segment size retained × number of segments retained per partition. With a 1 GB segment size and a 7-day retention policy, each partition holds roughly whatever fits in 7 days at your throughput. At 500 events/second and 2 KB each, that's about 1 MB/s, or roughly 600 GB over 7 days across the topic, about 200 GB per partition. If your missing window is 2 days and the row volume is below that, replay is viable; if it's above, it isn't.

Those inputs are illustrative, not measured — substitute your own broker metrics or Prometheus kafka_log_log_size values.

The arithmetic matters because it turns "maybe the topic has it" into a checkable number. Compute it before you write the replay job.

Keeping it recoverable next time

The durable fix is not a faster restore; it's making the communication layer retain what you need.

Set cleanup.policy=delete with an explicit retention long enough for your worst-case recovery window, and document that number. For event streams, use a delete policy with a documented replay window rather than compaction alone, or dual-write to a durable archive (object storage, a cold table). Keep an archive consumer or sink for every queue whose messages you might need. Acknowledged-and-gone is a design choice, not a law. Record the communication layer's retention in your runbook next to the backup cadence, because the effective recovery point is the earlier of the two.

Most teams discover their stream retention only during an incident. Writing it down beforehand is cheap.

When to stop and escalate

Stop scripted recovery and hand off when: the stream retention has passed and no backup covers the window; the payload schema doesn't match the table and the mismatch is unexplained; checksums diverge after a verified replay and continue to diverge after re-running; or the incident involves a destructive statement in a regulated data set where reconstruction without an audit trail may itself be a compliance problem. At that point the source-system owner and, where relevant, legal or compliance need to be in the loop — more ad hoc extraction increases the chance of an irreconcilable copy.

The core habit worth keeping: classify the medium, find the retention boundary, rebuild into a scratch table, and prove the result with a count and a checksum. Everything else is specific to which queue, database, or API you're standing in front of.