bki.sgml
上传用户:blenddy
上传日期:2007-01-07
资源大小:6495k
文件大小:11k
源码类别:

数据库系统

开发平台:

Unix_Linux

  1. <!--
  2. $Header: /usr/local/cvsroot/pgsql/doc/src/sgml/bki.sgml,v 1.2 1998/12/29 02:24:13 thomas Exp $
  3. Transcribed from the original bki.man.5 documentation
  4. - Thomas Lockhart 1998-08-03
  5. -->
  6. <chapter id="bki">
  7. <title>Backend Interface</title>
  8. <para>
  9. Backend Interface (<acronym>BKI</acronym>) files are scripts that are input 
  10. to the <productname>Postgres</productname>
  11. backend running in the special "bootstrap" mode that allows it to perform
  12. database functions without a database system already existing.  <acronym>BKI</acronym> files
  13. can therefore be used to create the database system in the first place.
  14. <application>initdb</application>
  15. uses <acronym>BKI</acronym> files to do just that: to create a database system.  However,
  16. <application>initdb</application>'s
  17. <acronym>BKI</acronym> files are generated internally.  It generates them using the files
  18. <filename>global1.bki.source</filename> and <filename>local1.template1.bki.source</filename>, which it finds in the
  19. <productname>Postgres</productname> "library" directory.  They get installed there as part of installing
  20. <productname>Postgres</productname>.  These .source files get build as part of the <productname>Postgres</productname> build
  21. process, by a build program called 
  22.   <application>genbki</application>.
  23.   <application>genbki</application>
  24. takes as input <productname>Postgres</productname> source files that double as
  25.   <application>genbki</application>
  26. input that builds tables and C header files that describe those
  27. tables.
  28. </para>
  29. <para>
  30. Related information may be found in documentation for 
  31. <application>initdb</application>,
  32. <application>createdb</application>,
  33. and the <acronym>SQL</acronym> command <command>CREATE DATABASE</command>.
  34. </para>
  35. <sect1>
  36. <title><acronym>BKI</acronym> File Format</title>
  37. <para>
  38. The <productname>Postgres</productname> backend interprets <acronym>BKI</acronym> files as described below.  This
  39. description will be easier to understand if the <filename>global1.bki.source</filename> file is
  40. at hand as an example.  (As explained above, this .source file isn't quite
  41. a <acronym>BKI</acronym> file, but you'll be able to guess what the resulting <acronym>BKI</acronym> file would be
  42. anyway).
  43. </para>
  44. <para>
  45. Commands are composed of a command name followed by space separated
  46. arguments.  Arguments to a command which begin with a <quote>$</quote> are
  47. treated specially.  If <quote>$$</quote> are the first two characters, then
  48. the first <quote>$</quote> is ignored and the argument is then processed
  49. normally.  If the <quote>$</quote> is followed by space, then it is treated
  50. as a NULL
  51. value.  Otherwise, the characters following the <quote>$</quote> are
  52. interpreted as the name of a macro causing the argument to be replaced
  53. with the macro's value.  It is an error for this macro to be
  54. undefined.
  55. </para>
  56. <para>
  57. Macros are defined using
  58. <programlisting>
  59. define macro macro_name = macro_value
  60. </programlisting>
  61. and are undefined using 
  62. <programlisting>
  63. undefine macro macro_name
  64. </programlisting>
  65. and redefined using the same syntax as define.
  66. </para>
  67. <para>
  68. Lists of general commands and macro commands
  69. follow.
  70. </para>
  71. </sect1>
  72. <sect1>
  73. <title>General Commands</title>
  74. <variablelist>
  75. <varlistentry>
  76. <term>
  77. OPEN <replaceable class="parameter">classname</replaceable>
  78. </term>
  79. <listitem>
  80. <para>
  81. Open the class called
  82. <replaceable class="parameter">classname</replaceable>
  83. for further manipulation.
  84. </para>
  85. </listitem>
  86. </varlistentry>
  87. <varlistentry>
  88. <term>
  89. CLOSE [<replaceable class="parameter">classname</replaceable>]
  90. </term>
  91. <listitem>
  92. <para>
  93. Close the open class called
  94. <replaceable class="parameter">classname</replaceable>.
  95. It is an error if 
  96. <replaceable class="parameter">classname</replaceable>
  97. is not already opened.   If no
  98. <replaceable class="parameter">classname</replaceable>
  99. is given, then the currently open class is closed.
  100. </para>
  101. </listitem>
  102. </varlistentry>
  103. <varlistentry>
  104. <term>
  105. PRINT
  106. </term>
  107. <listitem>
  108. <para>
  109. Print the currently open class.
  110. </para>
  111. </listitem>
  112. </varlistentry>
  113. <varlistentry>
  114. <term>
  115. INSERT [OID=<replaceable class="parameter">oid_value</replaceable>] (<replaceable class="parameter">value1</replaceable> <replaceable class="parameter">value2</replaceable> ...)
  116. </term>
  117. <listitem>
  118. <para>
  119. Insert a new instance to the open class using
  120. <replaceable class="parameter">value1</replaceable>,
  121. <replaceable class="parameter">value2</replaceable>,
  122. etc., for its attribute values and 
  123. <replaceable class="parameter">oid_value</replaceable>
  124. for its OID.  If
  125. <replaceable class="parameter">oid_value</replaceable>
  126. is not <quote>0</quote>, then this value will be used as the instance's
  127. object identifier.  Otherwise, it is an error.
  128. </para>
  129. </listitem>
  130. </varlistentry>
  131. <varlistentry>
  132. <term>
  133. INSERT (<replaceable class="parameter">value1</replaceable> <replaceable class="parameter">value2</replaceable> ...)
  134. </term>
  135. <listitem>
  136. <para>
  137. As above, but the system generates a unique object identifier.
  138. </para>
  139. </listitem>
  140. </varlistentry>
  141. <varlistentry>
  142. <term>
  143. CREATE <replaceable class="parameter">classname</replaceable> (<replaceable class="parameter">name1</replaceable> = <replaceable class="parameter">type1</replaceable> [,<replaceable class="parameter">name2</replaceable> = <replaceable class="parameter">type2</replaceable>[,...]])
  144. </term>
  145. <listitem>
  146. <para>
  147. Create a class named
  148. <replaceable class="parameter">classname</replaceable>
  149. with the attributes given in parentheses.
  150. </para>
  151. </listitem>
  152. </varlistentry>
  153. <varlistentry>
  154. <term>
  155. OPEN (<replaceable class="parameter">name1</replaceable> = <replaceable class="parameter">type1</replaceable> [,<replaceable class="parameter">name2</replaceable> = <replaceable class="parameter">type2</replaceable>[,...]]) AS <replaceable class="parameter">classname</replaceable>
  156. </term>
  157. <listitem>
  158. <para>
  159. Open a class named
  160. <replaceable class="parameter">classname</replaceable>
  161. for writing but do not record its existence in the system catalogs.
  162. (This is primarily to aid in bootstrapping.)
  163. </para>
  164. </listitem>
  165. </varlistentry>
  166. <varlistentry>
  167. <term>
  168. DESTROY <replaceable class="parameter">classname</replaceable>
  169. </term>
  170. <listitem>
  171. <para>
  172. Destroy the class named
  173. <replaceable class="parameter">classname</replaceable>.
  174. </para>
  175. </listitem>
  176. </varlistentry>
  177. <varlistentry>
  178. <term>
  179. DEFINE INDEX <replaceable class="parameter">indexname</replaceable> ON <replaceable class="parameter">class_name</replaceable> USING <replaceable class="parameter">amname</replaceable>
  180.   (<replaceable class="parameter">opclass</replaceable> <replaceable class="parameter">attr</replaceable> | (<replaceable class="parameter">function</replaceable>(<replaceable class="parameter">attr</replaceable>))
  181. </term>
  182. <listitem>
  183. <para>
  184. Create an index named
  185. <replaceable class="parameter">indexname</replaceable>
  186. on the class named
  187. <replaceable class="parameter">classname</replaceable>
  188. using the
  189. <replaceable class="parameter">amname</replaceable>
  190. access method.  The fields to index are called
  191. <replaceable class="parameter">name1</replaceable>,
  192. <replaceable class="parameter">name2</replaceable>
  193. etc., and the operator collections to use are
  194. <replaceable class="parameter">collection_1</replaceable>,
  195. <replaceable class="parameter">collection_2</replaceable>
  196. etc., respectively.
  197. </para>
  198. </listitem>
  199. </varlistentry>
  200. </variablelist>
  201. <note>
  202. <para>
  203. This last sentence doesn't reference anything in the example. Should be changed to make sense. - Thomas 1998-08-04
  204. </para>
  205. </note>
  206. </sect1>
  207. <sect1>
  208. <title>Macro Commands</title>
  209. <para>
  210. <variablelist>
  211. <varlistentry>
  212. <term>
  213. DEFINE FUNCTION <replaceable class="parameter">macro_name</replaceable> AS <replaceable class="parameter">rettype</replaceable> <replaceable class="parameter">function_name</replaceable>(<replaceable class="parameter">args</replaceable>)
  214. </term>
  215. <listitem>
  216. <para>
  217. Define a function prototype for a function named
  218. <replaceable class="parameter">macro_name</replaceable>
  219. which has its value of type
  220. <replaceable class="parameter">rettype</replaceable>
  221. computed from the execution
  222. <replaceable class="parameter">function_name</replaceable>
  223. with the arguments
  224. <replaceable class="parameter">args</replaceable>
  225. declared in a C-like manner.
  226. </para>
  227. </listitem>
  228. </varlistentry>
  229. <varlistentry>
  230. <term>
  231. DEFINE MACRO <replaceable class="parameter">macro_name</replaceable> FROM FILE <replaceable class="parameter">filename</replaceable>
  232. </term>
  233. <listitem>
  234. <para>
  235. Define a macro named
  236. <replaceable class="parameter">macro_name</replaceable>
  237. which has its value 
  238. read from the file called
  239. <replaceable class="parameter">filename</replaceable>.
  240. </para>
  241. </listitem>
  242. </varlistentry>
  243. </variablelist>
  244. </para>
  245. </sect1>
  246. <sect1>
  247. <title>Debugging Commands</title>
  248. <para>
  249. <note>
  250. <para>
  251. This section on debugging commands was commented-out in the original documentation. Thomas 1998-08-05
  252. </para>
  253. </note>
  254. <variablelist>
  255. <varlistentry>
  256. <term>
  257. r
  258. </term>
  259. <listitem>
  260. <para>
  261. Randomly print the open class.
  262. </para>
  263. </listitem>
  264. </varlistentry>
  265. <varlistentry>
  266. <term>
  267. m -1
  268. </term>
  269. <listitem>
  270. <para>
  271. Toggle display of time information.
  272. </para>
  273. </listitem>
  274. </varlistentry>
  275. <varlistentry>
  276. <term>
  277. m 0
  278. </term>
  279. <listitem>
  280. <para>
  281. Set retrievals to now.
  282. </para>
  283. </listitem>
  284. </varlistentry>
  285. <varlistentry>
  286. <term>
  287. m 1 Jan 1 01:00:00 1988
  288. </term>
  289. <listitem>
  290. <para>
  291. Set retrievals to snapshots of the specfied time.
  292. </para>
  293. </listitem>
  294. </varlistentry>
  295. <varlistentry>
  296. <term>
  297. m 2 Jan 1 01:00:00 1988, Feb 1 01:00:00 1988
  298. </term>
  299. <listitem>
  300. <para>
  301. Set retrievals to ranges of the specified times.
  302. Either time may be replaced with space
  303. if an unbounded time range is desired.
  304. </para>
  305. </listitem>
  306. </varlistentry>
  307. <varlistentry>
  308. <term>
  309. &amp;A <replaceable class="parameter">classname</replaceable> <replaceable class="parameter">natts</replaceable> <replaceable class="parameter">name1</replaceable> <replaceable class="parameter">type1</replaceable> <replaceable class="parameter">name2</replaceable> <replaceable class="parameter">type2</replaceable> <replaceable class="parameter">...</replaceable>
  310. </term>
  311. <listitem>
  312. <para>
  313. Add 
  314. <replaceable class="parameter">natts</replaceable>
  315. attributes named
  316. <replaceable class="parameter">name1</replaceable>,
  317. <replaceable class="parameter">name2</replaceable>,
  318. etc. of
  319. types
  320. <replaceable class="parameter">type1</replaceable>,
  321. <replaceable class="parameter">type2</replaceable>,
  322. etc. to the class
  323. <replaceable class="parameter">classname</replaceable>.
  324. </para>
  325. </listitem>
  326. </varlistentry>
  327. <varlistentry>
  328. <term>
  329. &amp;RR <replaceable class="parameter">oldclassname</replaceable> <replaceable class="parameter">newclassname</replaceable>
  330. </term>
  331. <listitem>
  332. <para>
  333. Rename the
  334. <replaceable class="parameter">oldclassname</replaceable>
  335. class to
  336. <replaceable class="parameter">newclassname</replaceable>.
  337. </para>
  338. </listitem>
  339. </varlistentry>
  340. <varlistentry>
  341. <term>
  342. &amp;RA classname oldattname newattname
  343. <replaceable class="parameter">classname</replaceable>
  344. <replaceable class="parameter">oldattname</replaceable>
  345. <replaceable class="parameter">newattname</replaceable>
  346. </term>
  347. <listitem>
  348. <para>
  349. Rename the
  350. <replaceable class="parameter">oldattname</replaceable>
  351. attribute in the class named
  352. <replaceable class="parameter">classname</replaceable>
  353. to
  354. <replaceable class="parameter">newattname</replaceable>.
  355. </para>
  356. </listitem>
  357. </varlistentry>
  358. </variablelist>
  359. </para>
  360. </sect1>
  361. <sect1>
  362. <title>Example</title>
  363. <para>
  364. The following set of commands will create the <quote>pg_opclass</quote>
  365. class containing the
  366. <parameter>int_ops</parameter>
  367. collection as an object with an OID of
  368. <parameter>421</parameter>,
  369. print out the class, and then close it.
  370. <programlisting>
  371. create pg_opclass (opcname=name)
  372. open pg_opclass
  373. insert oid=421 (int_ops)
  374. print
  375. close pg_opclass
  376. </programlisting>
  377. </para>
  378. </sect1>
  379. </chapter>