Question

An application needs to have data as more freshly updated from a database as possible. In such a case, is there any other way for getting the data, besides of a timer based requesting (polling) the database?

I work with a MS SQL Server 2008 (and .NET applications + Entity Framework), but I'd like to get knowing about other types of databases as well.

Was it helpful?

Solution

Service Broker for SQL Server 2005+ can do this.

Sorry, I'm not sure of other RDBMS

OTHER TIPS

In Oracle you can use the built in DBMS_ALERT package to facilitate this.

DBMS_ALERT supports asynchronous notification of database events (alerts). By appropriate use of this package and database triggers, an application can notify itself whenever values of interest in the database are changed.

Suppose a graphics tool is displaying a graph of some data from a database table. The graphics tool can, after reading and graphing the data, wait on a database alert (WAITONE) covering the data just read. The tool automatically wakes up when the data is changed by any other user. All that is required is that a trigger be placed on the database table, which performs a signal (SIGNAL) whenever the trigger is fired.

Certain database vendors also provide integrated message buses that your app can simply subscribe to:

An alternative would be to route the data into the database in the first place via a message bus like Tibco/RV and simply "branch" it, on stream going into the DB and one going to your application, or use a caching layer like Coherence between your app and the DB.

LISTEN / NOTIFY for PostgreSQL

http://www.postgresql.org/docs/current/static/sql-notify.html

in the database...

NOTIFY static_channel_name, 'static-message';

or in a function/trigger:

perform pg_notify('dynamic-channel-name', 'dynamic-message');

in the database client:

LISTEN some_channel_name; --note the lack of quotes

The LISTEN client will receive the PostgreSQL process ID, channel name, and message value.

The standard JDBC driver for PostgreSQL doesn't like notifications, however you can use the https://github.com/impossibl/pgjdbc-ng driver for this purpose

Another Oracle solution: We've developed applications using the dotnet framework from Microsoft that take advantage of Database Change Notification feature of Oracle in conjunction with ODP.Net (the Oracle data provider for dotnet). Using this, the database actually notifies the dotnet application when new data has arrived allowing us to avoid constant polling. The link I reference above is an Oracle tutorial for doing just that. Hope this helps you out.

Don't know about any other RDBMS's.

For one of our applications (accessed trough Chrome and ONLY Chrome), we're using MySQL with sys_exec UDF. Basically, why Chrome - due to WebSocket support.

Once a critical update / insert / delete occurs, an external program is invoked trough newly added sys_exec functionality embedded in certain triggers. At that point, we've got all we need to relay the message to every connected client without any need for polling or multiple queries as everything happens real-time.

We use a combination of Oracle GoldenGate and the Java Persistence API (JPA) to do this with Oracle database, but also with DB2, Sybase, Microsoft SQL Server, MySQL, Teradata, etc. The feature is described here: http://docs.oracle.com/middleware/1212/coherence/COHIG/golden_g.htm

What GoldenGate does is turn the database transaction log into a filterable event stream that can be consumed anywhere across the network. We use it to turn relevant transactions into either cache updates or cache invalidations, both of which can trigger application-level events, e.g. pushing the data all the way out to desktop or HTML5 websocket applications.

(For full disclosure, I work at Oracle on one of the products using GoldenGate.)

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top