- Notifications
You must be signed in to change notification settings - Fork10
The Socket.IO Postgres adapter, allowing to broadcast events between several Socket.IO servers
License
NotificationsYou must be signed in to change notification settings
socketio/socket.io-postgres-adapter
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
The@socket.io/postgres-adapter package allows broadcasting packets between multiple Socket.IO servers.

Table of contents
| Feature | socket.io version | Support |
|---|---|---|
| Socket management | 4.0.0 | ✅ YES (since version0.1.0) |
| Inter-server communication | 4.1.0 | ✅ YES (since version0.1.0) |
| Broadcast with acknowledgements | 4.5.0 | ✅ YES (since version0.3.0) |
| Connection state recovery | 4.6.0 | ❌ NO |
npm install @socket.io/postgres-adapterimport{Server}from"socket.io";import{createAdapter}from"@socket.io/postgres-adapter";importpgfrom"pg";constio=newServer();constpool=newpg.Pool({user:"postgres",host:"localhost",database:"postgres",password:"changeit",port:5432,});pool.query(` CREATE TABLE IF NOT EXISTS socket_io_attachments ( id bigserial UNIQUE, created_at timestamptz DEFAULT NOW(), payload bytea );`);pool.on("error",(err)=>{console.error("Postgres error",err);});io.adapter(createAdapter(pool));io.listen(3000);
importclusterfrom"node:cluster";import{createServer}from"node:http";import{availableParallelism}from"node:os";import{Server}from"socket.io";import{setupPrimary}from"@socket.io/postgres-adapter"import{createAdapter}from"@socket.io/cluster-adapter";importpgfrom"pg";if(cluster.isPrimary){constpool=newpg.Pool({user:"postgres",password:"changeit",});awaitpool.query(` CREATE TABLE IF NOT EXISTS socket_io_attachments ( id bigserial UNIQUE, created_at timestamptz DEFAULT NOW(), payload bytea ); `);setupPrimary(pool);for(leti=0;i<availableParallelism();i++){cluster.fork();}}else{constio=newServer({adapter:createAdapter(),});io.on("connection",(socket)=>{/* ... */});io.listen(3000);}
| Name | Description | Default value |
|---|---|---|
channelPrefix | The prefix of the notification channel. | socket.io |
tableName | The name of the table for payloads over the 8000 bytes limit or containing binary data. | socket_io_attachments |
payloadThreshold | The threshold for the payload size in bytes (seehttps://www.postgresql.org/docs/current/sql-notify.html). | 8_000 |
cleanupInterval | Number of ms between two cleanup queries. | 30_000 |
heartbeatInterval | The number of ms between two heartbeats. | 5_000 |
heartbeatTimeout | The number of ms without heartbeat before we consider a node down. | 10_000 |
About
The Socket.IO Postgres adapter, allowing to broadcast events between several Socket.IO servers
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.