Skip to content

VIRTUAL_DB module

A virtual db will expose the same front db api however, it will backed by many real db. This means that a virtual db url translates to many real db urls. This virtual layer also enables us to use the real dbs in multiple ways such as: parallel, failover(hotswap), round-robin.

Therefore: each virtual db url with associated real dbs and a way to use(mode) it’s real dbs must be specified.

The implemented modes are:

  • FAILOVER - Use the first URL; if it fails, take the next URL and redo the operation.
  • PARALLEL - Use all the URLs in the virtual DB URL set. Fails if all the URLs fail.
  • ROUND (round-robin) - Use the next URL each time; if it fails, use the next one, redo operation.

There are conceptual limitations to the above modes with respect to the operation. For example in parallel mode it is ok to insert into multiple dbs the same value but it is bad to query multiple dbs into the same result. This implementation threats such operation as it would be in failover mode.

Conceptual allowed(1) and not allowed(0) operations
parallel round
dbb->use_table
dbb->init
dbb->close
dbb->query 0 1
dbb->fetch_result 0 0
dbb->raw_query 0 1
dbb->free_result 0 0
dbb->insert 1 1
dbb->delete 1 0
dbb->update 1 0
dbb->replace 1 0
dbb->last_inserted_id 0 0
dbb->insert_update 1 1
When an operation from a process on a real DB fails:
it is marked (global and local CAN flag down)
its connection closed
Later a timer process (probe):
foreach virtual db_url
foreach real db_url
if global CAN down
try to connect
if ok
global CAN up
close connection
Later each process:
if local CAN down and global CAN up
if db_max_consec_retrys *
try to connect
if ok
local CAN up

The timer process(probe) is a process that tries to reconnect to failed dbs from time to time. It is a separate process so that when it blocks (for a timeout on the connection) it doesnt matter.

The following modules must be loaded before this module:

  • At least one real db module.

The following libraries or applications must be installed before running OpenSIPS with this module loaded:

  • None.

Multiple value parameter used for virtual db urls declaration.

Set db_urls parameter
...
modparam("group","db_url","virtual://set1")
modparam("presence|presence_xml", "db_url","virtual://set2")
modparam("db_virtual", "db_urls", "define set1 PARALLEL")
modparam("db_virtual", "db_urls", "mysql://opensips:opensipsrw@localhost/testa")
modparam("db_virtual", "db_urls", "postgres://opensips:opensipsrw@localhost/opensips")
modparam("db_virtual", "db_urls", "define set2 FAILOVER")
modparam("db_virtual", "db_urls", "mysql://opensips:opensipsrw@localhost/testa")
...

Time interval after which a registered timer process attempts to check failed(as reported by other processes) connections to real dbs. The probe will connect and disconnect to the failed real db and announce others.

Default value is 10 (10 sec).

Set db_probe_time parameter
...
modparam("db_virtual", "db_probe_time", 20)
...

After the timer process has reported that it can connect to the real db, other processes will try to reconnect to it. There are cases where although the probe could connect some might fail. This parameter represents the number of consecutive failed retries that a process will do before it gives up. This value is reset and suppressed by a MI function(db_set).

Default value is 10 (10 consecutive times).

Set db_max_consec_retrys parameter
...
modparam("db_virtual", "db_max_consec_retrys", 20)
...

Return information about global state of the real dbs.

Name: db_get

Parameters:

  • None.

MI FIFO Command Format:

Terminal window
db_get
_empty_line_

Sets the permissions for real dbs access per set per db.

Sets the reconnect reset flag.

Name: db_set

Parameters:

  • set_index [int]
  • db_url_index [int]
  • may_use_db_flag [boolean]
  • ignore db_max_consec_retrysboolean

db_set 3 2 0 1 means:

  • 3 - the fourth set (must exist)
  • 2 - the third url in the fourth set(must exist)
  • 0 - processes are not allowed to use that url
  • 1 - reset and suppress db_max_consec_retrys

MI FIFO Command Format:

Terminal window
db_set 3 2 0 1
_empty_line_

Top contributors by DevScore(1), authored commits(2) and lines added/removed(3)

#NameDevScoreCommitsLines++Lines—
1.Razvan Pistolea3272258311
2.Stefan Darius (@dariusstefan)10533776
3.Bogdan-Andrei Iancu (@bogdan-iancu)6464
4.Anca Vamanu3133
5.Razvan Crainea (@razvancrainea)3122

(1) DevScore = author_commits + author_lines_added / (project_lines_added / project_commits) + author_lines_deleted / (project_lines_deleted / project_commits)

(2) including any documentation-related commits, excluding merge commits

(3) ignoring whitespace edits, renamed files and auto-generated files

#NameCommit Activity
1.Stefan Darius (@dariusstefan)Jun 2026 - Jul 2026
2.Razvan Crainea (@razvancrainea)Jun 2026 - Jun 2026
3.Anca VamanuJan 2011 - Jan 2011
4.Bogdan-Andrei Iancu (@bogdan-iancu)Aug 2009 - Dec 2009
5.Razvan PistoleaJul 2009 - Aug 2009

(1) including any documentation-related commits, excluding merge commits

Last edited by: Razvan Crainea (@razvancrainea), Razvan Pistolea.

All documentation files (i.e. .md extension) are licensed under the Creative Common License 4.0