Overview
This guide will help you set up PostgreSQL Realtime Monitor from scratch. You’ll have a working real-time database monitor with a React frontend in just a few steps.Installation
Install Dependencies
Install all required packages using Bun:This installs:
postgres- PostgreSQL client with logical replication supportreact&react-dom- UI framework (v19.2.0)typescript- Type safety and developer experience
Start PostgreSQL
Launch PostgreSQL with Docker Compose. This starts a PostgreSQL 16 instance with logical replication enabled:The database starts with:
- Host:
localhost:5432 - Database:
appdb - User:
appuser - Password:
secret - Logical Replication: Enabled (
wal_level=logical) - Publication:
alltables(created automatically viainit.sql)
View Docker Compose Configuration
View Docker Compose Configuration
docker-compose.yml
Start the Application
Run the Bun development server:This starts:
- HTTP Server on
http://localhost:3000 - WebSocket Server on
ws://localhost:3000/ws - Hot Module Reloading for React components
Open in Browser
Navigate to http://localhost:3000You’ll see:
- A connection status indicator (should show “Connected”)
- An empty table waiting for database changes
- Total changes counter at 0
Testing Real-time Updates
Now let’s see the real-time monitoring in action by making database changes.Connect to PostgreSQL
Open a new terminal and connect to the running PostgreSQL container:You should see the PostgreSQL prompt:
Create a Test Table
Create a simple todos table:
Watch your browser - the table columns will automatically appear once you insert data!
Insert Data
Add some todo items and watch them appear instantly in the browser:Each INSERT operation will:
- Appear in the browser immediately
- Show operation type as INSERT (green badge)
- Display all column values including auto-generated
idandcreated_at - Increment the total changes counter
Understanding the Architecture
Here’s how the system captures and streams changes:Interactive Features
The React frontend includes powerful table features:Column Sorting
Column Sorting
Click any column header to sort:
- First click: Sort ascending ↑
- Second click: Sort descending ↓
- Third click: Remove sorting
- Numbers (numeric comparison)
- Dates (timestamp comparison)
- Strings (alphabetical)
Column Filtering
Column Filtering
Each column has a filter input below the header:
- Type to filter rows matching that column
- Multiple filters work together (AND logic)
- Case-insensitive matching
- Active filters show count and clear button
Dynamic Columns
Dynamic Columns
The table automatically detects columns from your data:
- No configuration needed
- Works with any table structure
- Columns appear as data arrives
Operation Colors
Operation Colors
Operations are color-coded for quick identification:
- INSERT: Green (#10b981)
- UPDATE: Blue (#3b82f6)
- DELETE: Red (#ef4444)
API Endpoints
The server exposes two endpoints:Configuration
To connect to a different PostgreSQL instance, editdb.ts:
db.ts
Troubleshooting
WebSocket shows 'Disconnected'
WebSocket shows 'Disconnected'
Check that the Bun server is running:Verify the server started successfully and shows:
No changes appearing
No changes appearing
Ensure PostgreSQL is configured correctly:If the publication is missing:
Port 3000 already in use
Port 3000 already in use
Change the port in Update the WebSocket URL in
src/index.ts:src/App.tsx to match:Docker container won't start
Docker container won't start
Check if port 5432 is already in use:To use a different port, edit Then update
docker-compose.yml:db.ts accordingly:Next Steps
Architecture Deep Dive
Learn how the real-time system works under the hood
API Reference
Explore WebSocket messages and REST endpoints
Configuration Guide
Customize database connections and server settings
Usage Examples
Learn common workflows and usage patterns