# Create table and test

#  **Connect to PostgreSQL**

If your DB name is `mydb`:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-psql--u-postgres--w-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`psql -U postgres -W -d mydb`</div></div>OR using the Debezium user (read-only but good for testing SELECT):

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-psql--u-debezium--w-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`psql -U debezium -W -d mydb`</div></div>---

# ✅ **2. Create a table**

Inside psql:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-create-table-users-%28"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> users (    id SERIAL <span class="hljs-keyword">PRIMARY</span> KEY,    name <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">100</span>),    email <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">150</span>),    created_at <span class="hljs-type">TIMESTAMP</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-built_in">CURRENT_TIMESTAMP</span>);`</div></div>Debezium will track this table because:

- You created a publication with `FOR ALL TABLES`
- Debezium captures all changes in the `public` schema

---

# ✅ **3. Insert sample data**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-insert-into-users-%28n"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> users (name, email) <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">'Golam Kibria'</span>, <span class="hljs-string">'gkibria@example.com'</span>),(<span class="hljs-string">'John Doe'</span>, <span class="hljs-string">'john@example.com'</span>),(<span class="hljs-string">'Alice Rahman'</span>, <span class="hljs-string">'alice@example.com'</span>);`</div></div>---

# ✅ **4. Query table to confirm**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-%2A-from-users%3B"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">SELECT</span> <span class="hljs-operator">*</span> <span class="hljs-keyword">FROM</span> users;`</div></div>You should see:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-id-%7C-name-%7C-email-%7C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">` id <span class="hljs-operator">|</span>     name      <span class="hljs-operator">|</span>        email        <span class="hljs-operator">|</span>      created_at<span class="hljs-comment">----+---------------+----------------------+------------------------</span> <span class="hljs-number">1</span>  <span class="hljs-operator">|</span> Golam Kibria  <span class="hljs-operator">|</span> gkibria<span class="hljs-variable">@example</span>.com <span class="hljs-operator">|</span> <span class="hljs-number">2025</span><span class="hljs-number">-11</span><span class="hljs-number">-30</span> <span class="hljs-number">23</span>:<span class="hljs-number">50</span>:<span class="hljs-number">12</span> <span class="hljs-number">2</span>  <span class="hljs-operator">|</span> John Doe      <span class="hljs-operator">|</span> john<span class="hljs-variable">@example</span>.com    <span class="hljs-operator">|</span> <span class="hljs-number">2025</span><span class="hljs-number">-11</span><span class="hljs-number">-30</span> <span class="hljs-number">23</span>:<span class="hljs-number">50</span>:<span class="hljs-number">12</span> <span class="hljs-number">3</span>  <span class="hljs-operator">|</span> Alice Rahman  <span class="hljs-operator">|</span> alice<span class="hljs-variable">@example</span>.com   <span class="hljs-operator">|</span> <span class="hljs-number">2025</span><span class="hljs-number">-11</span><span class="hljs-number">-30</span> <span class="hljs-number">23</span>:<span class="hljs-number">50</span>:<span class="hljs-number">12</span>`</div></div>---

# 📡 **5. Verify Debezium CDC events (optional)**

In Kafka, list topics:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%2Fopt%2Fkafka%2Fbin%2Fkafka"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`/opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --list`</div></div>Expected:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-pg.public.users-pg.p"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`pg.<span class="hljs-keyword">public</span>.userspg.<span class="hljs-keyword">public</span>.users-valuepg.<span class="hljs-keyword">public</span>.users-<span class="hljs-keyword">key</span>`</div></div>Consume the topic:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%2Fopt%2Fkafka%2Fbin%2Fkafka-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`/opt/kafka/bin/kafka-console-consumer.sh \  --bootstrap-server localhost:9092 \  --topic pg.public.users \  --from-beginning`</div></div>