|
| 1 | +<!-- doc/src/sgml/sequenceam.sgml --> |
| 2 | + |
| 3 | +<chapter id="sequenceam"> |
| 4 | + <title>Sequence Access Method Interface Definition</title> |
| 5 | + |
| 6 | + <indexterm> |
| 7 | + <primary>Sequence Access Method</primary> |
| 8 | + </indexterm> |
| 9 | + <indexterm> |
| 10 | + <primary>sequenceam</primary> |
| 11 | + <secondary>Sequence Access Method</secondary> |
| 12 | + </indexterm> |
| 13 | + |
| 14 | + <para> |
| 15 | + This chapter explains the interface between the core |
| 16 | + <productname>PostgreSQL</productname> system and <firstterm>sequence access |
| 17 | + methods</firstterm>, which manage the operations around sequences . The core |
| 18 | + system knows little about these access methods beyond what is specified here, |
| 19 | + so it is possible to develop entirely new access method types by writing |
| 20 | + add-on code. |
| 21 | + </para> |
| 22 | + |
| 23 | + <para> |
| 24 | + Each sequence access method is described by a row in the |
| 25 | + <link linkend="catalog-pg-am"><structname>pg_am</structname></link> system |
| 26 | + catalog. The <structname>pg_am</structname> entry specifies a name and a |
| 27 | + <firstterm>handler function</firstterm> for the sequence access method. These |
| 28 | + entries can be created and deleted using the |
| 29 | + <xref linkend="sql-create-access-method"/> and |
| 30 | + <xref linkend="sql-drop-access-method"/> SQL commands. |
| 31 | + </para> |
| 32 | + |
| 33 | + <para> |
| 34 | + A sequence access method handler function must be declared to accept a single |
| 35 | + argument of type <type>internal</type> and to return the pseudo-type |
| 36 | + <type>sequence_am_handler</type>. The argument is a dummy value that simply |
| 37 | + serves to prevent handler functions from being called directly from SQL commands. |
| 38 | + |
| 39 | + The result of the function must be a pointer to a struct of type |
| 40 | + <structname>SequenceAmRoutine</structname>, which contains everything that the |
| 41 | + core code needs to know to make use of the sequence access method. The return |
| 42 | + value needs to be of server lifetime, which is typically achieved by |
| 43 | + defining it as a <literal>static const</literal> variable in global |
| 44 | + scope. The <structname>SequenceAmRoutine</structname> struct, also called the |
| 45 | + access method's <firstterm>API struct</firstterm>, defines the behavior of |
| 46 | + the access method using callbacks. These callbacks are pointers to plain C |
| 47 | + functions and are not visible or callable at the SQL level. All the |
| 48 | + callbacks and their behavior is defined in the |
| 49 | + <structname>SequenceAmRoutine</structname> structure (with comments inside |
| 50 | + the struct defining the requirements for callbacks). Most callbacks have |
| 51 | + wrapper functions, which are documented from the point of view of a user |
| 52 | + (rather than an implementor) of the sequence access method. For details, |
| 53 | + please refer to the <ulink url="https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/include/access/sequenceam.h;hb=HEAD"> |
| 54 | + <filename>src/include/access/sequenceam.h</filename></ulink> file. |
| 55 | + </para> |
| 56 | + |
| 57 | + <para> |
| 58 | + Currently, the way a sequence access method stores data is fairly |
| 59 | + unconstrained, and it is possible to use a predefined |
| 60 | + <link linkend="tableam">Table Access Method</link> to store sequence |
| 61 | + data. |
| 62 | + </para> |
| 63 | + |
| 64 | + <para> |
| 65 | + For crash safety, a sequence access method can use |
| 66 | + <link linkend="wal"><acronym>WAL</acronym></link>, or a custom |
| 67 | + implementation. |
| 68 | + If <acronym>WAL</acronym> is chosen, either |
| 69 | + <link linkend="generic-wal">Generic WAL Records</link> can be used, or a |
| 70 | + <link linkend="custom-rmgr">Custom WAL Resource Manager</link> can be |
| 71 | + implemented. |
| 72 | + </para> |
| 73 | + |
| 74 | + <para> |
| 75 | + Any developer of a new <literal>sequence access method</literal> can refer to |
| 76 | + the existing <literal>local</literal> implementation present in |
| 77 | + <filename>src/backend/access/sequence/local.c</filename> for details of |
| 78 | + its implementation. |
| 79 | + </para> |
| 80 | +</chapter> |
0 commit comments