Stream change events

tobira watch streams a connection’s change events to stdout, one line per event, until Ctrl-C, --max or --timeout. It works with PostgreSQL, Greenplum, MongoDB, Redis, Amazon DynamoDB, Cloud Firestore and Azure Cosmos DB: see targets by driver. Watching never writes, so it works on read-only connections. The terminal UI has the same feature as the live tail.

tobira watch local-pg orders_changed                  # a PostgreSQL LISTEN channel
tobira watch mongo shop.orders --max 10               # a MongoDB collection
tobira watch cache 'session:*' --format table         # a Redis key pattern
tobira watch dynamo orders                            # a DynamoDB table with a stream
tobira watch fs users/ada/orders                      # a Firestore collection path

Targets by driver

DriverWhat it watchesTargetop values
PostgreSQL, GreenplumA LISTEN channel. There are no change streams, so give a channel.The channel name, such as orders_changednotify
MongoDBChange streams, on a replica set or a sharded clusterdb.collection, or a database name for all of its changesMongoDB’s operation type: insert, update, replace, delete and so on
RedisKeyspace notifications, when the server has them enabledA key pattern such as session:*, or a key prefix as db0.userinsert (new key), update, delete (also expired and evicted keys)
Amazon DynamoDBDynamoDB Streams. The table needs a stream enabled.The table nameinsert, update, delete
Cloud FirestoreA snapshot listenerA collection path (users, users/ada/orders) or a document path (users/ada)insert, update, delete
Azure Cosmos DBThe change feed, checked every secondA container name in the connection’s database, or database.containerupsert for a created or replaced item. Deletes do not appear.

tobira watch

tobira watch <connection|dsn> <namespace.collection|target> [--format jsonl|table] [--max N] [--timeout D] [--channel]

Arguments

  • <connection|dsn>: a connection name or a DSN, as for tobira query.
  • <namespace.collection|target>: a collection as namespace.collection, or a driver-specific target: see targets by driver. A target without a dot, or with a glob character (*, ?, [), is a target. One with a dot is a collection unless --channel is given.

Flags

FlagDefaultMeaning
--format <name>jsonljsonl: one JSON object per event, {"time", "op", "channel", "key", "payload"}. table: a header, then one aligned line per event (the time in UTC, the payload cut to 120 columns).
--max <n>0Stop after this many events and exit 0; 0 is no limit. A negative value is a usage error.
--timeout <duration>0Stop after this long and exit 0. Connecting counts, and a timeout before the watch starts exits 3. 0 is none. A negative value is a usage error.
--channeloffRead the target as a channel, database or key pattern even when it has a dot.

Output

Each line is written as soon as its event arrives. The op values of each driver are in targets by driver.

  • Values are redacted like errors are: the DSN, the resolved password and password= values, so a password that also occurs in a channel name or a payload is masked there too.
  • A payload field named password (or pwd, pass) is masked. Fields named token, secret, api_key and the like are treated as data and printed as they are.
  • jsonl escapes control characters as JSON does, and table shows them as escapes (\x1b).

Ctrl-C exits 3 with canceled. A stream that breaks exits with the code of its error (2 for a lost connection).

The AI assistant and the MCP server have no watch tool: a stream that runs until stopped does not fit a tool call that returns one answer.