Prerequisites
Before you begin, ensure you have the following installed on your system:Bun Runtime
Install from bun.sh
Docker
Required for running PostgreSQL
Installation
Install dependencies
Use Bun to install all required dependencies:This will install the following key dependencies:
postgres- PostgreSQL client with logical replication supportreact&react-dom- Frontend UI frameworktypescript- Type-safe development
Start PostgreSQL with Docker
The project includes a pre-configured Docker setup for PostgreSQL:This command will:
- Pull the
postgres:16-alpineimage - Create a container named
postgres-realtime - Enable logical replication with the following settings:
wal_level=logicalmax_wal_senders=10max_replication_slots=10
- Expose PostgreSQL on port
5432 - Create the
alltablespublication for change tracking
The database credentials are:
- Database:
appdb - User:
appuser - Password:
secret
Start the application
Run the development server:This starts the Bun server on port
3000 with:- WebSocket server at
ws://localhost:3000/ws - HTTP server at
http://localhost:3000 - Hot Module Reloading (HMR) enabled
- PostgreSQL subscription active
Open in browser
Navigate to http://localhost:3000 to access the monitoring dashboard.
Docker Configuration
Thedocker-compose.yml file configures PostgreSQL with logical replication enabled:
docker-compose.yml
Understanding the Configuration
Logical Replication Settings
Logical Replication Settings
- wal_level=logical: Enables logical decoding required for change data capture
- max_wal_senders=10: Allows up to 10 concurrent replication connections
- max_replication_slots=10: Maximum number of replication slots
Initialization Script
Initialization Script
The This publication allows the application to subscribe to changes on all tables.
init.sql file runs on first startup and creates the publication:init.sql
Data Persistence
Data Persistence
The
db-data volume ensures your database persists between container restarts:Testing Your Setup
Verify that everything is working by creating a test table and inserting data:Troubleshooting
Port 5432 already in use
Port 5432 already in use
If you have another PostgreSQL instance running, either:Then update
- Stop the existing instance
- Modify the port mapping in
docker-compose.yml:
db.ts to match:WebSocket connection failed
WebSocket connection failed
Ensure the server is running on port 3000 and check the browser console for errors. The frontend automatically attempts to reconnect if the connection is lost.
No changes appearing
No changes appearing
Verify that:
- The
alltablespublication exists:\dRp+in psql - Logical replication is enabled:
SHOW wal_level;should returnlogical - The server console shows ”✅ Realtime subscription ready”
Next Steps
Configuration
Learn how to customize database settings and server options
Usage
Explore real-time monitoring features and workflows