1OVSDB(7)                         Open vSwitch                         OVSDB(7)
2
3
4

NAME

6       ovsdb - Open vSwitch Database (Overview)
7

DESCRIPTION

9       OVSDB, the Open vSwitch Database, is a network-accessible database sys‐
10       tem.  Schemas in OVSDB specify the tables in a database and their  col‐
11       umns’ types and can include data, uniqueness, and referential integrity
12       constraints.  OVSDB offers atomic, consistent, isolated, durable trans‐
13       actions.   RFC  7047  specifies  the JSON-RPC based protocol that OVSDB
14       clients and servers use to communicate.
15
16       The OVSDB protocol is well suited for state synchronization because  it
17       allows  each  client  to  monitor the contents of a whole database or a
18       subset of it.  Whenever a monitored portion of  the  database  changes,
19       the server tells the client what rows were added or modified (including
20       the new contents) or deleted.  Thus,  OVSDB  clients  can  easily  keep
21       track of the newest contents of any part of the database.
22
23       While OVSDB is general-purpose and not particularly specialized for use
24       with Open vSwitch, Open vSwitch does use it for multiple purposes.  The
25       leading use of OVSDB is for configuring and monitoring ovs-vswitchd(8),
26       the  Open  vSwitch  switch  daemon,  using  the  schema  documented  in
27       ovs-vswitchd.conf.db(5).   The  Open Virtual Network (OVN) project uses
28       two OVSDB schemas, documented as part of that project.   Finally,  Open
29       vSwitch  includes  the  “VTEP”  schema, documented in vtep(5) that many
30       third-party hardware switches support for configuring  VXLAN,  although
31       OVS itself does not directly use this schema.
32
33       The  OVSDB  protocol  specification  allows  independent, interoperable
34       implementations of OVSDB to be developed.   Open  vSwitch  includes  an
35       OVSDB  server implementation named ovsdb-server(1), which supports sev‐
36       eral protocol extensions documented in its manpage, and  a  basic  com‐
37       mand-line  OVSDB  client named ovsdb-client(1), as well as OVSDB client
38       libraries for C and  for  Python.   Open  vSwitch  documentation  often
39       speaks  of  these  OVSDB  implementations  in  Open  vSwitch  as simply
40       “OVSDB,” even though that is distinct from the OVSDB protocol; we  make
41       the  distinction  explicit only when it might otherwise be unclear from
42       the context.
43
44       In addition to these  generic  OVSDB  server  and  client  tools,  Open
45       vSwitch  includes  tools  for working with databases that have specific
46       schemas: ovs-vsctl works with the ovs-vswitchd  configuration  database
47       and vtep-ctl works with the VTEP database.
48
49       RFC  7047  specifies  the  OVSDB  protocol  but  it does not specify an
50       on-disk storage format.  Open vSwitch includes ovsdb-tool(1) for  work‐
51       ing with its own on-disk database formats.  The most notable feature of
52       this format is that ovsdb-tool(1) makes it easy for users to print  the
53       transactions  that  have  changed a database since the last time it was
54       compacted.  This feature is often useful for troubleshooting.
55

SCHEMAS

57       Schemas in OVSDB have a JSON format that  is  specified  in  RFC  7047.
58       They  are  often  stored  in  files  with  an extension .ovsschema.  An
59       on-disk database in OVSDB includes a schema and  data,  embedding  both
60       into  a  single file.  The Open vSwitch utility ovsdb-tool has commands
61       that work with schema files and with the schemas embedded  in  database
62       files.
63
64       An  Open  vSwitch schema has three important identifiers.  The first is
65       its name, which is also the name used in JSON-RPC calls to  identify  a
66       database based on that schema.  For example, the schema used to config‐
67       ure Open vSwitch has the name Open_vSwitch.  Schema names begin with  a
68       letter  or  an  underscore,  followed  by any number of letters, under‐
69       scores, or digits.  The ovsdb-tool  commands  schema-name  and  db-name
70       extract the schema name from a schema or database file, respectively.
71
72       An  OVSDB  schema  also  has  a  version  of the form x.y.z e.g. 1.2.3.
73       Schemas managed within the Open vSwitch project manage version  number‐
74       ing  in  the  following way (but OVSDB does not mandate this approach).
75       Whenever we change the database schema in a non-backward compatible way
76       (e.g. when we delete a column or a table), we increment <x> and set <y>
77       and <z> to 0.  When we change the database schema in a backward compat‐
78       ible  way (e.g. when we add a new column), we increment <y> and set <z>
79       to 0.  When we change the database schema cosmetically (e.g.  we  rein‐
80       dent   its   syntax),   we  increment  <z>.   The  ovsdb-tool  commands
81       schema-version and db-version extract the schema version from a  schema
82       or database file, respectively.
83
84       Very old OVSDB schemas do not have a version, but RFC 7047 mandates it.
85
86       An OVSDB schema optionally has a “checksum.”  RFC 7047 does not specify
87       the use of the checksum and recommends that clients  ignore  it.   Open
88       vSwitch  uses  the checksum to remind developers to update the version:
89       at build time, if the schema’s embedded checksum, ignoring the checksum
90       field  itself,  does  not match the schema’s content, then it fails the
91       build with a recommendation to update the  version  and  the  checksum.
92       Thus,  a developer who changes the schema, but does not update the ver‐
93       sion, receives an automatic reminder.  In practice  this  has  been  an
94       effective way to ensure compliance with the version number policy.  The
95       ovsdb-tool commands schema-cksum and db-cksum extract the schema check‐
96       sum from a schema or database file, respectively.
97

SERVICE MODELS

99       OVSDB   supports   three  service  models  for  databases:  standalone,
100       active-backup, and clustered.  The  service  models  provide  different
101       compromises  among  consistency, availability, and partition tolerance.
102       They also differ in the number of servers required and in terms of per‐
103       formance.   The  standalone  and  active-backup database service models
104       share one on-disk format, and clustered databases use a different  for‐
105       mat, but the OVSDB programs work with both formats.  ovsdb(5) documents
106       these file formats.
107
108       RFC 7047, which specifies the OVSDB protocol, does not mandate or spec‐
109       ify any particular service model.
110
111       The following sections describe the individual service models.
112
113   Standalone Database Service Model
114       A  standalone  database runs a single server.  If the server stops run‐
115       ning, the database becomes inaccessible, and if the server’s storage is
116       lost  or corrupted, the database’s content is lost.  This service model
117       is appropriate when the database controls  a  process  or  activity  to
118       which  it is linked via “fate-sharing.”  For example, an OVSDB instance
119       that controls an Open vSwitch virtual switch daemon, ovs-vswitchd, is a
120       standalone  database  because  a server failure would take out both the
121       database and the virtual switch.
122
123       To set up a standalone database, use  ovsdb-tool  create  to  create  a
124       database file, then run ovsdb-server to start the database service.
125
126       To  configure  a  client,  such  as ovs-vswitchd or ovs-vsctl, to use a
127       standalone database, configure the server to listen  on  a  “connection
128       method”  that  the client can reach, then point the client to that con‐
129       nection method.  See Connection Methods  below  for  information  about
130       connection methods.
131
132   Active-Backup Database Service Model
133       An  active-backup  database  runs two servers (on different hosts).  At
134       any given time, one of the servers is designated with the  active  role
135       and  the  other  the backup role.  An active server behaves just like a
136       standalone server.  A backup server makes an OVSDB  connection  to  the
137       active  server  and uses it to continuously replicate its content as it
138       changes in real time.  OVSDB clients can connect to either  server  but
139       only the active server allows data modification or lock transactions.
140
141       Setup  for  an  active-backup database starts from a working standalone
142       database service, which is initially the  active  server.   On  another
143       node,  to  set up a backup server, create a database file with the same
144       schema as the active server.  The initial contents of the database file
145       do  not  matter, as long as the schema is correct, so ovsdb-tool create
146       will work, as will copying the database file from  the  active  server.
147       Then  use ovsdb-server --sync-from=<active> to start the backup server,
148       where <active> is an OVSDB connection method  (see  Connection  Methods
149       below)  that  connects to the active server.  At that point, the backup
150       server will fetch a copy of the active database and keep it  up-to-date
151       until it is killed.
152
153       When the active server in an active-backup server pair fails, an admin‐
154       istrator can switch the backup  server  to  an  active  role  with  the
155       ovs-appctl     command     ovsdb-server/disconnect-active-ovsdb-server.
156       Clients then have read/write  access  to  the  now-active  server.   Of
157       course,  administrators are slow to respond compared to software, so in
158       practice external management software detects the active server’s fail‐
159       ure  and  changes the backup server’s role.  For example, the “Integra‐
160       tion Guide for Centralized Control” in the OVN documentation  describes
161       how to use Pacemaker for this purpose in OVN.
162
163       Suppose  an  active  server fails and its backup is promoted to active.
164       If the failed server is revived, it must be started as a backup server.
165       Otherwise, if both servers are active, then they may start out of sync,
166       if the database changed while the server was down, and they  will  con‐
167       tinue to diverge over time.  This also happens if the software managing
168       the database servers cannot  reach  the  active  server  and  therefore
169       switches  the backup to active, but other hosts can reach both servers.
170       These “split-brain” problems  are  unsolvable  in  general  for  server
171       pairs.
172
173       Compared  to a standalone server, the active-backup service model some‐
174       what increases availability, at a risk of split-brain.  It adds  gener‐
175       ally  insignificant performance overhead.  On the other hand, the clus‐
176       tered service model, discussed below, requires at least 3  servers  and
177       has  greater  performance overhead, but it avoids the need for external
178       management software and eliminates the possibility of split-brain.
179
180       Open vSwitch 2.6  introduced  support  for  the  active-backup  service
181       model.
182
183       IMPORTANT:
184          There  was  a  change of a database file format in version 2.15.  To
185          upgrade/downgrade the ovsdb-server  processes  across  this  version
186          follow  the instructions described under Upgrading from version 2.14
187          and earlier to 2.15 and later and Downgrading from version 2.15  and
188          later to 2.14 and earlier.
189
190   Clustered Database Service Model
191       A  clustered  database runs across 3 or 5 or more database servers (the
192       cluster) on different hosts.  Servers in a cluster  automatically  syn‐
193       chronize  writes  within  the  cluster.   A 3-server cluster can remain
194       available in the face of at most 1 server failure; a  5-server  cluster
195       tolerates  up  to 2 failures.  Clusters larger than 5 servers will also
196       work, with every 2 added servers allowing the  cluster  to  tolerate  1
197       more  failure,  but write performance decreases.  The number of servers
198       should be odd: a 4- or 6-server cluster cannot tolerate  more  failures
199       than a 3- or 5-server cluster, respectively.
200
201       To set up a clustered database, first initialize it on a single node by
202       running ovsdb-tool create-cluster, then start ovsdb-server.   Depending
203       on  its arguments, the create-cluster command can create an empty data‐
204       base or copy a standalone database’s contents into the new database.
205
206       To configure a client to use a clustered database, first configure  all
207       of  the  servers  to  listen on a connection method that the client can
208       reach, then point the client to all of the servers’ connection methods,
209       comma-separated.  See Connection Methods, below, for more detail.
210
211       Open vSwitch 2.9 introduced support for the clustered service model.
212
213   How to Maintain a Clustered Database
214       To  add  a  server to a cluster, run ovsdb-tool join-cluster on the new
215       server and start ovsdb-server.  To remove a running server from a clus‐
216       ter, use ovs-appctl to invoke the cluster/leave command.  When a server
217       fails and cannot be recovered, e.g. because its hard disk  crashed,  or
218       to  otherwise  remove  a  server  that  is  down  from  a  cluster, use
219       ovs-appctl to invoke cluster/kick to make the remaining servers kick it
220       out of the cluster.
221
222       The above methods for adding and removing servers only work for healthy
223       clusters, that is, for clusters with no more failures than their  maxi‐
224       mum  tolerance.   For  example, in a 3-server cluster, the failure of 2
225       servers prevents servers joining or leaving the  cluster  (as  well  as
226       database access).  To prevent data loss or inconsistency, the preferred
227       solution to this problem is to bring up enough of the failed servers to
228       make  the cluster healthy again, then if necessary remove any remaining
229       failed servers and add new ones.  If this cannot be done,  though,  use
230       ovs-appctl  to  invoke cluster/leave --force on a running server.  This
231       command forces the server to which it is directed to leave its  cluster
232       and form a new single-node cluster that contains only itself.  The data
233       in the new cluster may be inconsistent with the former cluster:  trans‐
234       actions not yet replicated to the server will be lost, and transactions
235       not yet applied to  the  cluster  may  be  committed.   Afterward,  any
236       servers in its former cluster will regard the server to have failed.
237
238       Once  a server leaves a cluster, it may never rejoin it.  Instead, cre‐
239       ate a new server and join it to the cluster.
240
241       The servers in a cluster synchronize data  over  a  cluster  management
242       protocol  that  is  specific to Open vSwitch; it is not the same as the
243       OVSDB protocol specified in RFC 7047.  For this purpose, a server in  a
244       cluster is tied to a particular IP address and TCP port, which is spec‐
245       ified in the ovsdb-tool command that creates or joins the cluster.  The
246       TCP port used for clustering must be different from that used for OVSDB
247       clients.  To change the port or address of a server in a cluster, first
248       remove it from the cluster, then add it back with the new address.
249
250       To  upgrade the ovsdb-server processes in a cluster from one version of
251       Open vSwitch to another, upgrading them one at a  time  will  keep  the
252       cluster  healthy  during  the upgrade process.  (This is different from
253       upgrading a database schema, which is covered later under Upgrading  or
254       Downgrading a Database.)
255
256       IMPORTANT:
257          There  was  a  change of a database file format in version 2.15.  To
258          upgrade/downgrade the ovsdb-server  processes  across  this  version
259          follow  the instructions described under Upgrading from version 2.14
260          and earlier to 2.15 and later and Downgrading from version 2.15  and
261          later to 2.14 and earlier.
262
263       Clustered OVSDB does not support the OVSDB “ephemeral columns” feature.
264       ovsdb-tool and ovsdb-client change ephemeral  columns  into  persistent
265       ones  when they work with schemas for clustered databases.  Future ver‐
266       sions of OVSDB might add support for this feature.
267
268   Upgrading from version 2.14 and earlier to 2.15 and later
269       There is a change of a  database  file  format  in  version  2.15  that
270       doesn’t  allow older versions of ovsdb-server to read the database file
271       modified by the ovsdb-server version 2.15 or later.  This also  affects
272       runtime  communications  between  servers  in active-backup and cluster
273       service models. To upgrade the ovsdb-server processes from one  version
274       of  Open vSwitch (2.14 or earlier) to another (2.15 or higher) instruc‐
275       tions below should be followed. (This is  different  from  upgrading  a
276       database  schema, which is covered later under Upgrading or Downgrading
277       a Database.)
278
279       In case of standalone service model no special handling during  upgrade
280       is required.
281
282       For  the  active-backup  service  model,  administrator needs to update
283       backup ovsdb-server first and the active one after that, or  shut  down
284       both servers and upgrade at the same time.
285
286       For  the  cluster service model recommended upgrade strategy is follow‐
287       ing:
288
289       1. Upgrade processes one at a time.  Each  ovsdb-server  process  after
290          upgrade  should  be  started with --disable-file-column-diff command
291          line argument.
292
293       2. When all ovsdb-server processes upgraded, use ovs-appctl  to  invoke
294          ovsdb/file/column-diff-enable command on each of them or restart all
295          ovsdb-server processes one at  a  time  without  --disable-file-col‐
296          umn-diff command line option.
297
298   Downgrading from version 2.15 and later to 2.14 and earlier
299       Similar to upgrading covered under Upgrading from version 2.14 and ear‐
300       lier to 2.15 and later, downgrading from the ovsdb-server version  2.15
301       and  later to 2.14 and earlier requires additional steps. (This is dif‐
302       ferent from upgrading a database schema, which is covered  later  under
303       Upgrading or Downgrading a Database.)
304
305       For all service models it’s required to:
306
307       1. Stop  all ovsdb-server processes (single process for standalone ser‐
308          vice model, all involved processes  for  active-backup  and  cluster
309          service models).
310
311       2. Compact all database files with ovsdb-tool compact command.
312
313       3. Downgrade and restart ovsdb-server processes.
314
315   Understanding Cluster Consistency
316       To   ensure  consistency,  clustered  OVSDB  uses  the  Raft  algorithm
317       described in Diego Ongaro’s Ph.D. thesis, “Consensus:  Bridging  Theory
318       and  Practice”.   In  an  operational Raft cluster, at any given time a
319       single server is the “leader” and  the  other  nodes  are  “followers”.
320       Only  the leader processes transactions, but a transaction is only com‐
321       mitted when a majority of the servers confirm to the leader  that  they
322       have written it to persistent storage.
323
324       In most database systems, read and write access to the database happens
325       through transactions.  In such a  system,  Raft  allows  a  cluster  to
326       present a strongly consistent transactional interface.  OVSDB uses con‐
327       ventional transactions for writes, but  clients  often  effectively  do
328       reads  a different way, by asking the server to “monitor” a database or
329       a subset of one  on  the  client’s  behalf.   Whenever  monitored  data
330       changes,  the server automatically tells the client what changed, which
331       allows the client to maintain an accurate snapshot of the  database  in
332       its memory.  Of course, at any given time, the snapshot may be somewhat
333       dated since some of it could have changed without the change  notifica‐
334       tion yet being received and processed by the client.
335
336       Given  this  unconventional usage model, OVSDB also adopts an unconven‐
337       tional clustering model.  Each server in a cluster  acts  independently
338       for the purpose of monitors and read-only transactions, without verify‐
339       ing that data is up-to-date with the leader.  Servers forward  transac‐
340       tions  that write to the database to the leader for execution, ensuring
341       consistency.  This has the following consequences:
342
343       · Transactions that involve writes, against any server in the  cluster,
344         are  linearizable  if clients take care to use correct prerequisites,
345         which is the same condition required for linearizability in a  stand‐
346         alone  OVSDB.   (Actually, “at-least-once” consistency, because OVSDB
347         does not have a session mechanism to drop duplicate transactions if a
348         connection  drops  after  the server commits it but before the client
349         receives the result.)
350
351       · Read-only transactions can yield results based on a stale version  of
352         the  database, if they are executed against a follower.  Transactions
353         on the  leader  always  yield  fresh  results.   (With  monitors,  as
354         explained  above,  a  client  can  always see stale data even without
355         clustering, so clustering does not change the consistency  model  for
356         monitors.)
357
358       · Monitor-based  (or read-heavy) workloads scale well across a cluster,
359         because clustering OVSDB adds no additional work or communication for
360         reads and monitors.
361
362       · A write-heavy client should connect to the leader, to avoid the over‐
363         head of followers forwarding transactions to the leader.
364
365       · When a client conducts a mix of read and  write  transactions  across
366         more  than  one  server in a cluster, it can see inconsistent results
367         because a read transaction might read stale data whose  updates  have
368         not  yet  propagated  from the leader.  By default, utilities such as
369         ovn-sbctl (in OVN) connect to the cluster leader to avoid this issue.
370
371         The same might occur  for  transactions  against  a  single  follower
372         except that the OVSDB server ensures that the results of a write for‐
373         warded to the leader by a given server are  visible  at  that  server
374         before it replies to the requesting client.
375
376       · If  a client uses a database on one server in a cluster, then another
377         server in the cluster (perhaps because the first server failed),  the
378         client  could  observe stale data.  Clustered OVSDB clients, however,
379         can use a column in the _Server database to detect  that  data  on  a
380         server is older than data that the client previously read.  The OVSDB
381         client library in Open vSwitch uses this  feature  to  avoid  servers
382         with stale data.
383

DATABASE REPLICATION

385       OVSDB  can  layer  replication  on  top  of  any of its service models.
386       Replication, in this context, means to make,  and  keep  up-to-date,  a
387       read-only copy of the contents of a database (the replica).  One use of
388       replication is to keep an up-to-date backup of a database.   A  replica
389       used solely for backup would not need to support clients of its own.  A
390       set of replicas that do serve clients could be used to scale  out  read
391       access to the primary database.
392
393       A  database  replica is set up in the same way as a backup server in an
394       active-backup pair, with the difference that the replica is never  pro‐
395       moted to an active role.
396
397       A database can have multiple replicas.
398
399       Open vSwitch 2.6 introduced support for database replication.
400

CONNECTION METHODS

402       An  OVSDB  connection  method  is a string that specifies how to make a
403       JSON-RPC connection between an OVSDB  client  and  server.   Connection
404       methods  are  part  of the Open vSwitch implementation of OVSDB and not
405       specified by RFC 7047.  ovsdb-server uses connection methods to specify
406       how it should listen for connections from clients and ovsdb-client uses
407       them to specify how it should connect to a server.  Connections in  the
408       opposite  direction,  where  ovsdb-server  connects to a client that is
409       configured to listen for an incoming connection, are also possible.
410
411       Connection methods are classified as active or passive.  An active con‐
412       nection method makes an outgoing connection to a remote host; a passive
413       connection method listens for connections from remote hosts.  The  most
414       common arrangement is to configure an OVSDB server with passive connec‐
415       tion methods and clients with active ones, but the OVSDB implementation
416       in Open vSwitch supports the opposite arrangement as well.
417
418       OVSDB supports the following active connection methods:
419
420       ssl:<host>:<port>
421              The specified SSL or TLS <port> on the given <host>.
422
423       tcp:<host>:<port>
424              The specified TCP <port> on the given <host>.
425
426       unix:<file>
427              On  Unix-like  systems, connect to the Unix domain server socket
428              named <file>.
429
430              On Windows, connect to a local named pipe that is represented by
431              a  file  created  in  the path <file> to mimic the behavior of a
432              Unix domain socket.
433
434       <method1>,<method2>,…,<methodN>
435              For a clustered database  service  to  be  highly  available,  a
436              client  must  be  able  to  connect to any of the servers in the
437              cluster.  To do so, specify connection methods for each  of  the
438              servers separated by commas (and optional spaces).
439
440              In theory, if machines go up and down and IP addresses change in
441              the right way, a client could talk to the wrong  instance  of  a
442              database.  To avoid this possibility, add cid:<uuid> to the list
443              of methods, where <uuid> is the cluster ID of the desired  data‐
444              base  cluster, as printed by ovsdb-tool db-cid.  This feature is
445              optional.
446
447       OVSDB supports the following passive connection methods:
448
449       pssl:<port>[:<ip>]
450              Listen on the given TCP <port> for SSL or TLS  connections.   By
451              default,  connections  are  not  bound  to a particular local IP
452              address.  Specifying <ip> limits connections to those  from  the
453              given IP.
454
455       ptcp:<port>[:<ip>]
456              Listen on the given TCP <port>.  By default, connections are not
457              bound to a particular local IP address.  Specifying <ip>  limits
458              connections to those from the given IP.
459
460       punix:<file>
461              On Unix-like systems, listens for connections on the Unix domain
462              socket named <file>.
463
464              On Windows, listens on a local named pipe, creating a named pipe
465              <file>  to  mimic the behavior of a Unix domain socket. The ACLs
466              of the named pipe include LocalSystem, Administrators, and  Cre‐
467              ator Owner.
468
469       All  IP-based  connection  methods  accept IPv4 and IPv6 addresses.  To
470       specify  an  IPv6  address,  wrap   it   in   square   brackets,   e.g.
471       ssl:[::1]:6640.   Passive IP-based connection methods by default listen
472       for IPv4 connections only; use [::] as the address to accept both  IPv4
473       and IPv6 connections, e.g. pssl:6640:[::].  DNS names are also accepted
474       if built with unbound library.  On Linux, use %<device> to designate  a
475       scope for IPv6 link-level addresses, e.g. ssl:[fe80::1234%eth0]:6653.
476
477       The  <port> may be omitted from connection methods that use a port num‐
478       ber.  The default <port> for TCP-based connection methods is 6640, e.g.
479       pssl:  is  equivalent  to  pssl:6640.  In Open vSwitch prior to version
480       2.4.0, the default port was 6632.   To  avoid  incompatibility  between
481       older and newer versions, we encourage users to specify a port number.
482
483       The  ssl  and pssl connection methods requires additional configuration
484       through  --private-key,  --certificate,  and  --ca-cert  command   line
485       options.   Open vSwitch can be built without SSL support, in which case
486       these connection methods are not supported.
487

DATABASE LIFE CYCLE

489       This section describes how to handle various events in the  life  cycle
490       of a database using the Open vSwitch implementation of OVSDB.
491
492   Creating a Database
493       Creating  and  starting  up  the service for a new database was covered
494       separately for each database service model in the Service  Models  sec‐
495       tion, above.
496
497   Backing Up and Restoring a Database
498       OVSDB  is  often  used  in contexts where the database contents are not
499       particularly valuable.  For example, in many systems, the database  for
500       configuring  ovs-vswitchd  is  essentially rebuilt from scratch at boot
501       time.  It is not worthwhile to back up these databases.
502
503       When OVSDB is used for valuable data, a backup strategy is  worth  con‐
504       sidering.   One  way is to use database replication, discussed above in
505       Database Replication which keeps an online, up-to-date copy of a  data‐
506       base,  possibly  on a remote system.  This works with all OVSDB service
507       models.
508
509       A more common backup strategy is to periodically take and store a snap‐
510       shot.   For  the  standalone and active-backup service models, making a
511       copy of the database file, e.g. using cp, effectively makes a snapshot,
512       and  because OVSDB database files are append-only, it works even if the
513       database is  being  modified  when  the  snapshot  takes  place.   This
514       approach does not work for clustered databases.
515
516       Another  way  to make a backup, which works with all OVSDB service mod‐
517       els, is to use ovsdb-client backup, which connects to a  running  data‐
518       base  server  and outputs an atomic snapshot of its schema and content,
519       in the same format used for standalone and active-backup databases.
520
521       Multiple options are also available when the time comes  to  restore  a
522       database  from  a backup.  For the standalone and active-backup service
523       models, one option is to stop the database server or servers, overwrite
524       the  database file with the backup (e.g. with cp), and then restart the
525       servers.  Another way, which works with any service model,  is  to  use
526       ovsdb-client  restore,  which connects to a running database server and
527       replaces the data in one of its databases by a provided snapshot.   The
528       advantage  of  ovsdb-client restore is that it causes zero downtime for
529       the database and its server.  It has the downside that UUIDs of rows in
530       the  restored  database will differ from those in the snapshot, because
531       the OVSDB protocol does not allow clients to specify row UUIDs.
532
533       None of these approaches saves and restores data in  columns  that  the
534       schema  designates  as ephemeral.  This is by design: the designer of a
535       schema only marks a column as ephemeral if it  is  acceptable  for  its
536       data to be lost when a database server restarts.
537
538       Clustering  and  backup serve different purposes.  Clustering increases
539       availability, but it does not protect against data loss if,  for  exam‐
540       ple, a malicious or malfunctioning OVSDB client deletes or tampers with
541       data.
542
543   Changing Database Service Model
544       Use ovsdb-tool create-cluster to create a clustered database  from  the
545       contents of a standalone database.  Use ovsdb-client backup to create a
546       standalone database from the contents of a running clustered  database.
547       When  the  cluster  is  down and cannot be revived, ovsdb-client backup
548       will not work.
549
550       Use ovsdb-tool cluster-to-standalone to convert clustered  database  to
551       standalone database when the cluster is down and cannot be revived.
552
553   Upgrading or Downgrading a Database
554       The evolution of a piece of software can require changes to the schemas
555       of the databases that it uses.  For example, new features might require
556       new  tables  or  new  columns in existing tables, or conceptual changes
557       might require a database to be reorganized  in  other  ways.   In  some
558       cases, the easiest way to deal with a change in a database schema is to
559       delete the existing database and start fresh with the new schema, espe‐
560       cially if the data in the database is easy to reconstruct.  But in many
561       other cases, it is better to convert the database from  one  schema  to
562       another.
563
564       The  OVSDB implementation in Open vSwitch has built-in support for some
565       simple cases of converting a database from one schema to another.  This
566       support  can  handle  changes  that  add  or remove database columns or
567       tables or that eliminate constraints (for example,  changing  a  column
568       that must have exactly one value into one that has one or more values).
569       It can also handle changes that add constraints or make them  stricter,
570       but  only  if  the existing data in the database satisfies the new con‐
571       straints (for example, changing a column that has one  or  more  values
572       into  a  column  with exactly one value, if every row in the column has
573       exactly one value).  The built-in conversion can  cause  data  loss  in
574       obvious  ways, for example if the new schema removes tables or columns,
575       or indirectly, for example by deleting unreferenced rows in tables that
576       the new schema marks for garbage collection.
577
578       Converting  a  database  can  lose data, so it is wise to make a backup
579       beforehand.
580
581       To use OVSDB’s built-in support for schema conversion with a standalone
582       or  active-backup  database, first stop the database server or servers,
583       then use ovsdb-tool convert to convert it to the new schema,  and  then
584       restart the database server.
585
586       OVSDB  also  supports  online database schema conversion for any of its
587       database  service  models.   To  convert   a   database   online,   use
588       ovsdb-client  convert.  The conversion is atomic, consistent, isolated,
589       and durable.  ovsdb-server disconnects any clients connected  when  the
590       conversion takes place (except clients that use the set_db_change_aware
591       Open vSwitch extension RPC).  Upon reconnection, clients will  discover
592       that the schema has changed.
593
594       Schema  versions and checksums (see Schemas above) can give hints about
595       whether a database needs to be converted to a new schema.  If there  is
596       any  question,  though,  the needs-conversion command on ovsdb-tool and
597       ovsdb-client can provide a definitive answer.
598
599   Working with Database History
600       Both on-disk database formats that OVSDB supports are  organized  as  a
601       stream  of  transaction records.  Each record describes a change to the
602       database as a list of rows that were inserted or deleted  or  modified,
603       along  with  the  details.   Therefore, in normal operation, a database
604       file only grows, as each change causes another record to be appended at
605       the  end.   Usually,  a user has no need to understand this file struc‐
606       ture.  This section covers some exceptions.
607
608   Compacting Databases
609       If OVSDB database files were truly append-only,  then  over  time  they
610       would  grow  without bound.  To avoid this problem, OVSDB can compact a
611       database file, that is, replace it by a new version that contains  only
612       the  current  database contents, as if it had been inserted by a single
613       transaction.  From time to time, ovsdb-server automatically compacts  a
614       database that grows much larger than its minimum size.
615
616       Because  ovsdb-server  automatically  compacts databases, it is usually
617       not necessary to compact them manually, but OVSDB still  offers  a  few
618       ways  to  do it.  First, ovsdb-tool compact can compact a standalone or
619       active-backup  database  that  is  not  currently   being   served   by
620       ovsdb-server  (or otherwise locked for writing by another process).  To
621       compact any database that is currently being  served  by  ovsdb-server,
622       use  ovs-appctl  to send the ovsdb-server/compact command.  Each server
623       in an active-backup or clustered database maintains its  database  file
624       independently, so to compact all of them, issue this command separately
625       on each server.
626
627   Viewing History
628       The ovsdb-tool utility’s  show-log  command  displays  the  transaction
629       records  in  an  OVSDB  database  file  in a human-readable format.  By
630       default, it shows minimal detail, but adding  the  option  -m  once  or
631       twice  increases  the  level of detail.  In addition to the transaction
632       data, it shows the time and date of each transaction and any  “comment”
633       added  to  the  transaction by the client.  The comments can be helpful
634       for quickly understanding a transaction; for  example,  ovs-vsctl  adds
635       its command line to the transactions that it makes.
636
637       The  show-log  command  works  with  both  OVSDB  file formats, but the
638       details of the output format differ.  For active-backup  and  clustered
639       databases,  the sequence of transactions in each server’s log will dif‐
640       fer, even at points when they reflect the same data.
641
642   Truncating History
643       It may occasionally be useful to “roll back” a database file to an ear‐
644       lier point.  Because of the organization of OVSDB records, this is easy
645       to do.  Start by noting the record number <i> of the  first  record  to
646       delete  in  ovsdb-tool  show-log  output.   Each record is two lines of
647       plain text, so trimming the log is as simple as running  head  -n  <j>,
648       where <j> = 2 * <i>.
649
650   Corruption
651       When  ovsdb-server  opens an OVSDB database file, of any kind, it reads
652       as many transaction records as it can from the file  until  it  reaches
653       the end of the file or it encounters a corrupted record.  At that point
654       it stops reading and regards the data that it has read to this point as
655       the  full  contents of the database file, effectively rolling the data‐
656       base back to an earlier point.
657
658       Each transaction record contains an embedded SHA-1 checksum, which  the
659       server  verifies  as  it  reads a database file.  It detects corruption
660       when a checksum fails to verify.  Even though SHA-1 is no  longer  con‐
661       sidered  secure for use in cryptography, it is acceptable for this pur‐
662       pose because it is not used to defend against malicious attackers.
663
664       The first record in a standalone or active-backup database file  speci‐
665       fies  the  schema.   ovsdb-server  will  refuse to work with a database
666       where this record is corrupted, or with a clustered database file  with
667       corruption  in the first few records.  Delete and recreate such a data‐
668       base, or restore it from a backup.
669
670       When ovsdb-server adds records to a database file in which it  detected
671       corruption,  it  first  truncates  the  file  just  after the last good
672       record.
673

SEE ALSO

675       RFC 7047, “The Open vSwitch Database Management Protocol.”
676
677       Open  vSwitch   implementations   of   generic   OVSDB   functionality:
678       ovsdb-server(1), ovsdb-client(1), ovsdb-tool(1).
679
680       Tools  for  working  with  databases  that have specific OVSDB schemas:
681       ovs-vsctl(8), vtep-ctl(8), and (in OVN) ovn-nbctl(8), ovn-sbctl(8).
682
683       OVSDB   schemas   for   Open   vSwitch   and   related   functionality:
684       ovs-vswitchd.conf.db(5), vtep(5), and (in OVN) ovn-nb(5), ovn-sb(5).
685

AUTHOR

687       The Open vSwitch Development Community
688
690       2021, The Open vSwitch Development Community
691
692
693
694
6952.15                             Feb 17, 2021                         OVSDB(7)
Impressum