2010-09-20 22:08:53 +02:00
|
|
|
<!-- doc/src/sgml/bki.sgml -->
|
1998-08-15 08:49:33 +02:00
|
|
|
|
|
|
|
<chapter id="bki">
|
2000-12-23 17:24:29 +01:00
|
|
|
<title><acronym>BKI</acronym> Backend Interface</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Backend Interface (<acronym>BKI</acronym>) files are scripts in a
|
2005-01-06 00:42:03 +01:00
|
|
|
special language that is understood by the
|
|
|
|
<productname>PostgreSQL</productname> backend when running in the
|
|
|
|
<quote>bootstrap</quote> mode. The bootstrap mode allows system catalogs
|
|
|
|
to be created and filled from scratch, whereas ordinary SQL commands
|
|
|
|
require the catalogs to exist already.
|
2000-12-23 17:24:29 +01:00
|
|
|
<acronym>BKI</acronym> files can therefore be used to create the
|
|
|
|
database system in the first place. (And they are probably not
|
|
|
|
useful for anything else.)
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-06-12 07:55:50 +02:00
|
|
|
<application>initdb</application> uses a <acronym>BKI</acronym> file
|
2000-12-23 17:24:29 +01:00
|
|
|
to do part of its job when creating a new database cluster. The
|
2001-06-12 07:55:50 +02:00
|
|
|
input file used by <application>initdb</application> is created as
|
2001-11-21 06:53:41 +01:00
|
|
|
part of building and installing <productname>PostgreSQL</productname>
|
2010-01-05 02:06:57 +01:00
|
|
|
by a program named <filename>genbki.pl</filename>, which reads some
|
2005-01-06 00:42:03 +01:00
|
|
|
specially formatted C header files in the <filename>src/include/catalog/</>
|
2010-01-05 02:06:57 +01:00
|
|
|
directory of the source tree. The created <acronym>BKI</acronym> file
|
|
|
|
is called <filename>postgres.bki</filename> and is
|
2001-06-12 07:55:50 +02:00
|
|
|
normally installed in the
|
2000-12-23 17:24:29 +01:00
|
|
|
<filename>share</filename> subdirectory of the installation tree.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
Update documentation on may/can/might:
Standard English uses "may", "can", and "might" in different ways:
may - permission, "You may borrow my rake."
can - ability, "I can lift that log."
might - possibility, "It might rain today."
Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice. Similarly, "It may crash" is better stated, "It might crash".
Also update two error messages mentioned in the documenation to match.
2007-01-31 21:56:20 +01:00
|
|
|
Related information can be found in the documentation for
|
2000-12-23 17:24:29 +01:00
|
|
|
<application>initdb</application>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<sect1 id="bki-format">
|
|
|
|
<title><acronym>BKI</acronym> File Format</title>
|
|
|
|
|
|
|
|
<para>
|
2001-11-21 06:53:41 +01:00
|
|
|
This section describes how the <productname>PostgreSQL</productname>
|
2000-12-23 17:24:29 +01:00
|
|
|
backend interprets <acronym>BKI</acronym> files. This description
|
2001-06-12 07:55:50 +02:00
|
|
|
will be easier to understand if the <filename>postgres.bki</filename>
|
2005-01-06 00:42:03 +01:00
|
|
|
file is at hand as an example.
|
2000-12-23 17:24:29 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2002-03-22 20:20:45 +01:00
|
|
|
<acronym>BKI</acronym> input consists of a sequence of commands. Commands are made up
|
2000-12-23 17:24:29 +01:00
|
|
|
of a number of tokens, depending on the syntax of the command.
|
|
|
|
Tokens are usually separated by whitespace, but need not be if
|
2001-06-12 07:55:50 +02:00
|
|
|
there is no ambiguity. There is no special command separator; the
|
2001-11-21 23:57:01 +01:00
|
|
|
next token that syntactically cannot belong to the preceding
|
2000-12-23 17:24:29 +01:00
|
|
|
command starts a new one. (Usually you would put a new command on
|
|
|
|
a new line, for clarity.) Tokens can be certain key words, special
|
|
|
|
characters (parentheses, commas, etc.), numbers, or double-quoted
|
|
|
|
strings. Everything is case sensitive.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2005-04-14 03:38:22 +02:00
|
|
|
Lines starting with <literal>#</literal> are ignored.
|
2000-12-23 17:24:29 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
</sect1>
|
|
|
|
|
|
|
|
<sect1 id="bki-commands">
|
2002-03-22 20:20:45 +01:00
|
|
|
<title><acronym>BKI</acronym> Commands</title>
|
2000-12-23 17:24:29 +01:00
|
|
|
|
|
|
|
<variablelist>
|
2005-01-06 00:42:03 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term>
|
2009-09-27 00:42:03 +02:00
|
|
|
<literal>create</>
|
|
|
|
<replaceable class="parameter">tablename</replaceable>
|
|
|
|
<replaceable class="parameter">tableoid</replaceable>
|
2005-04-14 03:38:22 +02:00
|
|
|
<optional><literal>bootstrap</></optional>
|
|
|
|
<optional><literal>shared_relation</></optional>
|
|
|
|
<optional><literal>without_oids</></optional>
|
2009-09-27 00:42:03 +02:00
|
|
|
<optional><literal>rowtype_oid</> <replaceable>oid</></optional>
|
2005-01-06 00:42:03 +01:00
|
|
|
(<replaceable class="parameter">name1</replaceable> =
|
2015-02-21 22:25:49 +01:00
|
|
|
<replaceable class="parameter">type1</replaceable>
|
|
|
|
<optional>FORCE NOT NULL | FORCE NULL </optional> <optional>,
|
|
|
|
<replaceable class="parameter">name2</replaceable> =
|
|
|
|
<replaceable class="parameter">type2</replaceable>
|
|
|
|
<optional>FORCE NOT NULL | FORCE NULL </optional>,
|
|
|
|
...</optional>)
|
2005-01-06 00:42:03 +01:00
|
|
|
</term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Create a table named <replaceable
|
2005-04-14 03:38:22 +02:00
|
|
|
class="parameter">tablename</replaceable>, and having the OID
|
|
|
|
<replaceable class="parameter">tableoid</replaceable>,
|
|
|
|
with the columns given in parentheses.
|
2005-01-06 00:42:03 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The following column types are supported directly by
|
|
|
|
<filename>bootstrap.c</>: <type>bool</type>,
|
|
|
|
<type>bytea</type>, <type>char</type> (1 byte),
|
|
|
|
<type>name</type>, <type>int2</type>,
|
|
|
|
<type>int4</type>, <type>regproc</type>, <type>regclass</type>,
|
|
|
|
<type>regtype</type>, <type>text</type>,
|
|
|
|
<type>oid</type>, <type>tid</type>, <type>xid</type>,
|
|
|
|
<type>cid</type>, <type>int2vector</type>, <type>oidvector</type>,
|
|
|
|
<type>_int4</type> (array), <type>_text</type> (array),
|
2005-03-29 21:44:23 +02:00
|
|
|
<type>_oid</type> (array), <type>_char</type> (array),
|
2005-01-06 00:42:03 +01:00
|
|
|
<type>_aclitem</type> (array). Although it is possible to create
|
|
|
|
tables containing columns of other types, this cannot be done until
|
|
|
|
after <structname>pg_type</> has been created and filled with
|
2005-04-14 03:38:22 +02:00
|
|
|
appropriate entries. (That effectively means that only these
|
|
|
|
column types can be used in bootstrapped tables, but non-bootstrap
|
|
|
|
catalogs can contain any built-in type.)
|
2005-01-06 00:42:03 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
When <literal>bootstrap</> is specified,
|
|
|
|
the table will only be created on disk; nothing is entered into
|
|
|
|
<structname>pg_class</structname>,
|
|
|
|
<structname>pg_attribute</structname>, etc, for it. Thus the
|
|
|
|
table will not be accessible by ordinary SQL operations until
|
|
|
|
such entries are made the hard way (with <literal>insert</>
|
|
|
|
commands). This option is used for creating
|
|
|
|
<structname>pg_class</structname> etc themselves.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The table is created as shared if <literal>shared_relation</> is
|
|
|
|
specified.
|
|
|
|
It will have OIDs unless <literal>without_oids</> is specified.
|
2010-08-17 06:37:21 +02:00
|
|
|
The table's row type OID (<structname>pg_type</> OID) can optionally
|
2009-09-27 00:42:03 +02:00
|
|
|
be specified via the <literal>rowtype_oid</> clause; if not specified,
|
|
|
|
an OID is automatically generated for it. (The <literal>rowtype_oid</>
|
|
|
|
clause is useless if <literal>bootstrap</> is specified, but it can be
|
|
|
|
provided anyway for documentation.)
|
2005-01-06 00:42:03 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2000-12-23 17:24:29 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term>
|
2005-04-14 03:38:22 +02:00
|
|
|
<literal>open</> <replaceable class="parameter">tablename</replaceable>
|
2000-12-23 17:24:29 +01:00
|
|
|
</term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2005-04-14 03:38:22 +02:00
|
|
|
Open the table named
|
2000-12-23 17:24:29 +01:00
|
|
|
<replaceable class="parameter">tablename</replaceable>
|
2005-04-14 03:38:22 +02:00
|
|
|
for insertion of data. Any currently open table is closed.
|
2000-12-23 17:24:29 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term>
|
2005-04-14 03:38:22 +02:00
|
|
|
<literal>close</> <optional><replaceable class="parameter">tablename</replaceable></optional>
|
2000-12-23 17:24:29 +01:00
|
|
|
</term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2005-04-14 03:38:22 +02:00
|
|
|
Close the open table. The name of the table can be given as a
|
|
|
|
cross-check, but this is not required.
|
2000-12-23 17:24:29 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term>
|
2005-04-14 03:38:22 +02:00
|
|
|
<literal>insert</> <optional><literal>OID =</> <replaceable class="parameter">oid_value</replaceable></optional> <literal>(</> <replaceable class="parameter">value1</replaceable> <replaceable class="parameter">value2</replaceable> ... <literal>)</>
|
2000-12-23 17:24:29 +01:00
|
|
|
</term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Insert a new row into the open table using <replaceable
|
|
|
|
class="parameter">value1</replaceable>, <replaceable
|
|
|
|
class="parameter">value2</replaceable>, etc., for its column
|
|
|
|
values and <replaceable
|
|
|
|
class="parameter">oid_value</replaceable> for its OID. If
|
|
|
|
<replaceable class="parameter">oid_value</replaceable> is zero
|
2005-04-13 20:54:57 +02:00
|
|
|
(0) or the clause is omitted, and the table has OIDs, then the
|
|
|
|
next available OID is assigned.
|
2000-12-23 17:24:29 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
NULL values can be specified using the special key word
|
2001-06-12 07:55:50 +02:00
|
|
|
<literal>_null_</literal>. Values containing spaces must be
|
2000-12-23 17:24:29 +01:00
|
|
|
double quoted.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term>
|
2005-04-14 03:38:22 +02:00
|
|
|
<literal>declare</> <optional><literal>unique</></optional>
|
|
|
|
<literal>index</> <replaceable class="parameter">indexname</replaceable>
|
|
|
|
<replaceable class="parameter">indexoid</replaceable>
|
|
|
|
<literal>on</> <replaceable class="parameter">tablename</replaceable>
|
|
|
|
<literal>using</> <replaceable class="parameter">amname</replaceable>
|
|
|
|
<literal>(</> <replaceable class="parameter">opclass1</replaceable>
|
|
|
|
<replaceable class="parameter">name1</replaceable>
|
|
|
|
<optional>, ...</optional> <literal>)</>
|
2000-12-23 17:24:29 +01:00
|
|
|
</term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Create an index named <replaceable
|
2005-04-14 03:38:22 +02:00
|
|
|
class="parameter">indexname</replaceable>, having OID
|
|
|
|
<replaceable class="parameter">indexoid</replaceable>,
|
|
|
|
on the table named
|
|
|
|
<replaceable class="parameter">tablename</replaceable>, using the
|
2000-12-23 17:24:29 +01:00
|
|
|
<replaceable class="parameter">amname</replaceable> access
|
|
|
|
method. The fields to index are called <replaceable
|
|
|
|
class="parameter">name1</replaceable>, <replaceable
|
|
|
|
class="parameter">name2</replaceable> etc., and the operator
|
|
|
|
classes to use are <replaceable
|
|
|
|
class="parameter">opclass1</replaceable>, <replaceable
|
|
|
|
class="parameter">opclass2</replaceable> etc., respectively.
|
2005-01-06 00:42:03 +01:00
|
|
|
The index file is created and appropriate catalog entries are
|
|
|
|
made for it, but the index contents are not initialized by this command.
|
2000-12-23 17:24:29 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2006-07-31 03:16:38 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term>
|
|
|
|
<literal>declare toast</>
|
|
|
|
<replaceable class="parameter">toasttableoid</replaceable>
|
|
|
|
<replaceable class="parameter">toastindexoid</replaceable>
|
|
|
|
<literal>on</> <replaceable class="parameter">tablename</replaceable>
|
|
|
|
</term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Create a TOAST table for the table named
|
|
|
|
<replaceable class="parameter">tablename</replaceable>.
|
|
|
|
The TOAST table is assigned OID
|
|
|
|
<replaceable class="parameter">toasttableoid</replaceable>
|
|
|
|
and its index is assigned OID
|
|
|
|
<replaceable class="parameter">toastindexoid</replaceable>.
|
|
|
|
As with <literal>declare index</>, filling of the index
|
|
|
|
is postponed.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2000-12-23 17:24:29 +01:00
|
|
|
<varlistentry>
|
2005-04-14 03:38:22 +02:00
|
|
|
<term><literal>build indices</></term>
|
2000-12-23 17:24:29 +01:00
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2005-01-06 00:42:03 +01:00
|
|
|
Fill in the indices that have previously been declared.
|
2000-12-23 17:24:29 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
|
|
|
|
</sect1>
|
|
|
|
|
2005-04-14 03:38:22 +02:00
|
|
|
<sect1 id="bki-structure">
|
|
|
|
<title>Structure of the Bootstrap <acronym>BKI</acronym> File</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The <literal>open</> command cannot be used until the tables it uses
|
|
|
|
exist and have entries for the table that is to be opened.
|
|
|
|
(These minimum tables are <structname>pg_class</>,
|
|
|
|
<structname>pg_attribute</>, <structname>pg_proc</>, and
|
|
|
|
<structname>pg_type</>.) To allow those tables themselves to be filled,
|
|
|
|
<literal>create</> with the <literal>bootstrap</> option implicitly opens
|
|
|
|
the created table for data insertion.
|
|
|
|
</para>
|
|
|
|
|
2006-07-31 03:16:38 +02:00
|
|
|
<para>
|
|
|
|
Also, the <literal>declare index</> and <literal>declare toast</>
|
|
|
|
commands cannot be used until the system catalogs they need have been
|
|
|
|
created and filled in.
|
|
|
|
</para>
|
|
|
|
|
2005-04-14 03:38:22 +02:00
|
|
|
<para>
|
|
|
|
Thus, the structure of the <filename>postgres.bki</filename> file has to
|
|
|
|
be:
|
|
|
|
<orderedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<literal>create bootstrap</> one of the critical tables
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<literal>insert</> data describing at least the critical tables
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<literal>close</>
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Repeat for the other critical tables.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<literal>create</> (without <literal>bootstrap</>) a noncritical table
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<literal>open</>
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<literal>insert</> desired data
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<literal>close</>
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Repeat for the other noncritical tables.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2006-07-31 03:16:38 +02:00
|
|
|
Define indexes and toast tables.
|
2005-04-14 03:38:22 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<literal>build indices</>
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</orderedlist>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
There are doubtless other, undocumented ordering dependencies.
|
|
|
|
</para>
|
|
|
|
</sect1>
|
|
|
|
|
2000-12-23 17:24:29 +01:00
|
|
|
<sect1 id="bki-example">
|
|
|
|
<title>Example</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The following sequence of commands will create the
|
2005-04-14 03:38:22 +02:00
|
|
|
table <literal>test_table</literal> with OID 420, having two columns
|
2000-12-23 17:24:29 +01:00
|
|
|
<literal>cola</literal> and <literal>colb</literal> of type
|
|
|
|
<type>int4</type> and <type>text</type>, respectively, and insert
|
2007-02-01 01:28:19 +01:00
|
|
|
two rows into the table:
|
1998-08-15 08:49:33 +02:00
|
|
|
<programlisting>
|
2005-04-14 03:38:22 +02:00
|
|
|
create test_table 420 (cola = int4, colb = text)
|
2000-12-23 17:24:29 +01:00
|
|
|
open test_table
|
|
|
|
insert OID=421 ( 1 "value1" )
|
|
|
|
insert OID=422 ( 2 _null_ )
|
|
|
|
close test_table
|
1998-08-15 08:49:33 +02:00
|
|
|
</programlisting>
|
2000-12-23 17:24:29 +01:00
|
|
|
</para>
|
|
|
|
</sect1>
|
1998-08-15 08:49:33 +02:00
|
|
|
</chapter>
|