2
0

README.services_extension 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. Services API enhancements in Firebird v2.
  2. -----------------------------------------
  3. 1) Services API extension for new shutdown modes.
  4. (Alex Peshkov, [email protected], 2008)
  5. New DB shutdown modes can now be set using services. A number of new
  6. isc_spb_prp_* constants should be used for it.
  7. isc_spb_prp_shutdown_mode and isc_spb_prp_online_mode are used to perform
  8. database shutdown/online operation. They have a single byte parameter,
  9. setting new shutdown mode: isc_spb_prp_sm_normal, isc_spb_prp_sm_multi,
  10. isc_spb_prp_sm_single and isc_spb_prp_sm_full. They exactly match gfix's
  11. shutdown modes. When performing shutdown operation, you must specify
  12. also type of shutdown: one of isc_spb_prp_force_shutdown,
  13. isc_spb_prp_attachments_shutdown or isc_spb_prp_transactions_shutdown.
  14. They have single int (4-byte) parameter, specifying timeout for desired
  15. operation.
  16. Please note that old-styled parameters are also supported and should be
  17. used to enter default shutdown (currently 'multi') and online ('normal')
  18. modes.
  19. Samples of use of new parameters in fbsvcmgr utility (supposing login and
  20. password are set using some other method):
  21. Shutdown database to single-user maintenance mode:
  22. fbsvcmgr service_mgr action_properties dbname employee prp_shutdown_mode prp_sm_single prp_force_shutdown 0
  23. After it enable multi-user maintenance:
  24. fbsvcmgr service_mgr action_properties dbname employee prp_online_mode prp_sm_multi
  25. After it go to full shutdown mode, disabling new attachments during 60 seconds:
  26. fbsvcmgr service_mgr action_properties dbname employee prp_shutdown_mode prp_sm_full prp_attachments_shutdown 60
  27. Return to normal state:
  28. fbsvcmgr service_mgr action_properties dbname employee prp_online_mode prp_sm_normal
  29. 2) Services API extension - nbackup support.
  30. (Alex Peshkov, [email protected], 2008)
  31. Nbackup performs two logical groups of operations - locking/unlocking database
  32. and backup/restore it. It doesn't make sense duplicating locking/unlocking in
  33. services, cause that functionality is present remotely in much better (from any
  34. point of view) in SQL language interface (ALTER DATABASE). But backup and restore
  35. must be run on localhost and the only way to access them is nbackup utility.
  36. Therefore expanding services API with this functionalty is very useful.
  37. The following actions were added:
  38. isc_action_svc_nbak - incremental nbackup,
  39. isc_action_svc_nrest - incremental database restore.
  40. The following parameters were added:
  41. isc_spb_nbk_level - backup level (integer),
  42. isc_spb_nbk_file - backup file name (string),
  43. isc_spb_nbk_no_triggers - do not run DB triggers (option).
  44. Samples of use of new parameters in fbsvcmgr utility (supposing login and
  45. password are set using some other method):
  46. Create backup level 0:
  47. fbsvcmgr service_mgr action_nbak dbname employee nbk_file e.nb0 nbk_level 0
  48. Create backup level 1:
  49. fbsvcmgr service_mgr action_nbak dbname employee nbk_file e.nb1 nbk_level 1
  50. Restore database from this files:
  51. fbsvcmgr service_mgr action_nrest dbname e.fdb nbk_file e.nb0 nbk_file e.nb1
  52. 3) Services API extension - trace support.
  53. (Khorsun Vlad, [email protected], 2009)
  54. There are five new services and corresponding actions to manage by user
  55. trace sessions :
  56. Start user trace session :
  57. action
  58. isc_action_svc_trace_start
  59. parameter(s)
  60. isc_spb_trc_name : trace session name, string, optional
  61. isc_spb_trc_cfg : trace session configuration, string, mandatory
  62. output
  63. text message with status of operation :
  64. - Trace session ID NNN started
  65. - Can not start trace session. There are no trace plugins loaded
  66. contents of trace session in text format
  67. Stop trace session
  68. action
  69. isc_action_svc_trace_stop
  70. parameter(s)
  71. isc_spb_trc_id : trace session ID, integer, mandatory
  72. output
  73. text message with status of operation :
  74. - Trace session ID NNN stopped
  75. - No permissions to stop other user trace session
  76. - Trace session ID NNN not found
  77. Suspend trace session
  78. action
  79. isc_action_svc_trace_suspend
  80. parameter(s)
  81. isc_spb_trc_id : trace session ID, integer, mandatory
  82. output
  83. text message with status of operation :
  84. - Trace session ID NNN paused
  85. - No permissions to change other user trace session
  86. - Trace session ID NNN not found
  87. Resume trace session
  88. action
  89. isc_action_svc_trace_resume
  90. parameter(s)
  91. isc_spb_trc_id : trace session ID, integer, mandatory
  92. output
  93. text message with status of operation :
  94. - Trace session ID NNN resumed
  95. - No permissions to change other user trace session
  96. - Trace session ID NNN not found
  97. List of existing trace sessions
  98. action
  99. isc_action_svc_trace_list
  100. parameter(s)
  101. none
  102. output
  103. text messages with list and state of trace sessions
  104. - Session ID: <number>
  105. - name: <string>
  106. - user: <string>
  107. - date: YYYY-MM-DD HH:NN:SS
  108. - flags: <string>
  109. "name" is trace session name and not printed if empty.
  110. "user" is creator user name
  111. "date" is session start date and time
  112. "flags" is comma delimited set of
  113. session's run state : "active" or "suspend"
  114. if creator user is administrator : "admin"
  115. if the session was created by the engine itself : "system"
  116. kind of session : "audit" or "trace"
  117. if user session log file is full : "log full"
  118. Output of every service is obtained as usually using isc_service_query call
  119. with isc_info_svc_line or isc_info_svc_to_eof information items.
  120. See also README.trace_services
  121. 4) Services API extension - running gbak at server side with .fbk at the client.
  122. (Alex Peshkov, [email protected], 2011-2012)
  123. This way of doing backups is specially efficient when one needs to perform
  124. backup/restore operation for database, located on a server accessed using
  125. internet, due to the great performance advantage.
  126. The simplest way to use this feature is fbsvcmgr. To backup database run
  127. approximately the following:
  128. fbsvcmgr remotehost:service_mgr -user sysdba -password XXX \
  129. action_backup -dbname some.fdb -bkp_file stdout >some.fbk
  130. and to restore it:
  131. fbsvcmgr remotehost:service_mgr -user sysdba -password XXX \
  132. action_restore -dbname some.fdb -bkp_file stdin <some.fbk
  133. Please notice - you can't use "verbose" switch when performing backup because
  134. data channel from server to client is used to deliver blocks of fbk files. You
  135. will get appropriate error message if you try to do it. When restoring database
  136. verbose mode may be used without limitations.
  137. If you want to perform backup/restore from your own program, you should use
  138. services API for it. Backup is very simple - just pass "stdout" as backup file
  139. name to server and use isc_info_svc_to_eof in isc_service_query() call. Data,
  140. returned by repeating calls to isc_service_query() (certainly with
  141. isc_info_svc_to_eof tag) is a stream, representing image of backup file. Restore
  142. is a bit more tricky. Client sends new spb parameter isc_info_svc_stdin to server
  143. in isc_service_query(). If service needs some data in stdin, it returns
  144. isc_info_svc_stdin in query results, followed by 4-bytes value - number of bytes
  145. server is ready to accept from client. (0 value means no more data is needed right
  146. now.) The main trick is that client should NOT send more data than requested by
  147. server - this causes an error "Size of data is more than requested". The data is
  148. sent in next isc_service_query() call in the send_items block, using
  149. isc_info_svc_line tag in tradition form: isc_info_svc_line, 2 bytes length, data.
  150. When server needs next portion, it once more returns non-zero isc_info_svc_stdin
  151. value from isc_service_query().
  152. A sample of how services API should be used for remote backup and restore can be
  153. found in source code of fbsvcmgr.
  154. 5) Services API extension - using services with non-default security database.
  155. (Alex Peshkov, [email protected], 2013)
  156. If one wants to use services API to access database which is configured to use
  157. non-default security database, new SPB item isc_spb_expected_db should be used
  158. when attaching to services manager. Value of this item is a database which is
  159. expected to be accessed.
  160. Formally this does not raise backward incompatibility - as long as one does not
  161. use new FB3 feature (multiple security databases) he has no problems with old
  162. programs using services API. In a case when one has really big need to use old
  163. program for a database with non-default configuration there is a workaround:
  164. setting environment variable FB_EXPECTED_DB which will be added to SPB
  165. automatically.
  166. Example. Imagine we have the following lines in databases.conf:
  167. employee = $(dir_sampledb)/employee.fdb
  168. {
  169. SecurityDatabase = employee
  170. }
  171. i.e. employee database is configured as security database for itself.
  172. To access it using fbsvcmgr one should use the following command line:
  173. fbsvcmgr host:service_mgr user sysdba password xxx expected_db employee action_db_stats dbname employee sts_data_pages
  174. or in advance set FB_EXPECTED_DB:
  175. export FB_EXPECTED_DB=employee
  176. fbsvcmgr host:service_mgr user sysdba password xxx action_db_stats dbname employee sts_data_pages
  177. Certainly any other database action can be used here.
  178. 6) Services API extension - using services to temporary turn off linger for database.
  179. (Alex Peshkov, [email protected], 2013)
  180. Linger is used to optimize performance in some cases (see also sql.extensions/README.linger).
  181. If you want to turn off linger temporary (for next database close) you may use gfix utility or
  182. services. New tag isc_spb_prp_nolinger is added for it (option). Setting isc_spb_prp_nolinger
  183. option turns off linger for the next database close operation and may be used to force closing
  184. database in linger state.
  185. Example:
  186. fbsvcmgr host:service_mgr user sysdba password xxx action_properties dbname employee prp_nolinger
  187. 7) Services API extension - passing SQL role to services manager.
  188. (Alex Peshkov, [email protected], 2014)
  189. Just a few actions (user-management related) were capable to pass SQL role to server in pre-3
  190. releases. With flexible access control in FB3 passing role to the services manager is sometimes
  191. useful and therefore possible. Services manager now accepts SPB item isc_spb_sql_role_name in
  192. start() call and passes it to invoked utilities.
  193. Example (assumimg user "leg" is granted admin rights):
  194. fbsvcmgr host:service_mgr user leg password leg action_restore dbname target.fdb bkp_file some.fbk
  195. (fails with "no permission for CREATE access to DATABASE" error)
  196. fbsvcmgr host:service_mgr user leg password leg role 'rdb$admin' action_restore dbname target.fdb bkp_file some.fbk
  197. (works as expected)
  198. 8) Services API extension - nbackup support (more).
  199. (Alex Peshkov, [email protected], 2020)
  200. Added support to fixup databases after file system copy.
  201. The following action was added:
  202. isc_action_svc_nfix - fixup database.
  203. Samples of use of new parameter in fbsvcmgr utility (supposing login and
  204. password are set using some other method):
  205. fbsvcmgr - action_nfix dbname /tmp/ecopy.fdb