Skip to content

Commit 12a4828

Browse files
committed
Add API an ABI guidance to the C language docs
Includes guidance for major and minor version releases, and sets reasonable expectations for extension developers to follow. Author: David Wheeler, Peter Eisentraut Discussion: https://www.postgresql.org/message-id/flat/5DA9F9D2-B8B2-43DE-BD4D-53A4160F6E8D%40justatheory.com
1 parent d537b2e commit 12a4828

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed

doc/src/sgml/xfunc.sgml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,6 +2704,140 @@ CREATE FUNCTION concat_text(text, text) RETURNS text
27042704

27052705
&dfunc;
27062706

2707+
<sect2 id="xfunc-guidance">
2708+
<title>Server API and ABI Guidance</title>
2709+
2710+
<para>
2711+
This section contains guidance to authors of extensions and other server
2712+
plugins about ABI and API stability in the
2713+
<productname>PostgreSQL</productname> server.
2714+
</para>
2715+
2716+
<sect3 id="xfunc-guidance-general">
2717+
<title>General</title>
2718+
2719+
<para>
2720+
The <productname>PostgreSQL</productname> server contains several
2721+
well-delimited APIs for server plugins, such as the function manager
2722+
(<xref linkend="xfunc-c-polymorphic"><acronym>fmgr</acronym></xref>),
2723+
<xref linkend="spi"><acronym>SPI</acronym></xref>, and various hooks
2724+
specifically designed for extensions. These interfaces are carefully
2725+
managed for long-term stability and compatibility. However, the entire
2726+
set of global functions and variables in the server effectively
2727+
constitutes the publicly usable API, and most of it was not
2728+
designed with extensibility and long-term stability in mind.
2729+
</para>
2730+
2731+
<para>
2732+
Therefore, while taking advantage of these interfaces is valid, the
2733+
further one strays from the well-trodden path, the likelier it will be
2734+
that one might encounter ABI or API compatibility issues at some point.
2735+
Extension authors are encouraged to provide feedback about their
2736+
requirements, so that over time, as new use patterns arise, certain
2737+
interfaces can be considerd more stabilized or new, better-designed
2738+
interfaces can be added.
2739+
</para>
2740+
</sect3>
2741+
2742+
<sect3 id="xfunc-guidance-api-compatibility">
2743+
<title>API Compatibility</title>
2744+
<para>
2745+
The <acronym>API</acronym> or application programming interface, is the
2746+
interface used at compile time.
2747+
</para>
2748+
2749+
<sect4 id="xfunc-guidance-api-major-versions">
2750+
<title>Major Versions</title>
2751+
<para>
2752+
There is <emphasis>no</emphasis> promise of API compatibility between
2753+
<productname>PostgreSQL</productname> major versions. Extension code
2754+
therefore might require source code changes to work with multiple major
2755+
versions. These can usually be managed with preprocessor conditions
2756+
such as <literal>#if PG_VERSION_NUM &gt;= 160000</literal>.
2757+
Sophisticated extensions that use interfaces beyond the well-defined
2758+
ones usually require a few such changes for each major server version.
2759+
</para>
2760+
</sect4>
2761+
2762+
<sect4 id="xfunc-guidance-api-mninor-versions">
2763+
<title>Minor Versions</title>
2764+
<para>
2765+
<productname>PostgreSQL</productname> makes an effort to avoid server
2766+
API breaks in minor releases. In general, extension code that compiles
2767+
and works with a minor release should also compile and work with any
2768+
other minor release of the same major version, past or future.
2769+
</para>
2770+
2771+
<para>
2772+
When a change <emphasis>is</emphasis> required, it will be carefully
2773+
managed, taking the requirements of extensions into account. Such
2774+
changes will be communicated in the <xref linkend="release"/>.
2775+
</para>
2776+
</sect4>
2777+
</sect3>
2778+
2779+
<sect3 id="xfunc-guidance-abi-compatibility">
2780+
<title>ABI Compatibility</title>
2781+
<para>
2782+
The <acronym>ABI</acronym> or application binary interface, is the
2783+
interface used at run time.
2784+
</para>
2785+
2786+
<sect4 id="xfunc-guidance-abi-major-versions">
2787+
<title>Major Versions</title>
2788+
<para>
2789+
Servers of different major versions have intentionally incompatible
2790+
ABIs. Extensions that use server APIs must therefore be re-compiled for
2791+
each major release. The inclusion of <literal>PG_MODULE_MAGIC</literal>
2792+
ensures that code compiled for one major version will be rejected by
2793+
other major versions.
2794+
</para>
2795+
</sect4>
2796+
2797+
<sect4 id="xfunc-guidance-abi-mninor-versions">
2798+
<title>Minor Versions</title>
2799+
<para>
2800+
<productname>PostgreSQL</productname> makes an effort to avoid server
2801+
ABI breaks in minor releases. In general, an extension compiled against
2802+
any minor release should work with any other minor release of the same
2803+
major version, past or future.
2804+
</para>
2805+
2806+
<para>
2807+
When a change <emphasis>is</emphasis> required,
2808+
<productname>PostgreSQL</productname> will choose the least invasive
2809+
change possible, for example by squeezing a new field into padding
2810+
space or appending it to the end of a struct. These sorts of changes
2811+
should not impact extensions unless they use very unusual code
2812+
patterns.
2813+
</para>
2814+
2815+
<para>
2816+
In rare cases, however, even such non-invasive changes may be
2817+
impractical or impossible. In such an event, the change will be
2818+
carefully managed, taking the requirements of extensions into account.
2819+
Such changes will also be documented in the <xref linkend="release"/>.
2820+
</para>
2821+
2822+
<para>
2823+
Note, however, that many parts of the server are not designed or
2824+
maintained as publicly-consumable APIs (and that, in most cases, the
2825+
actual boundary is also not well-defined). If urgent needs arise,
2826+
changes in those parts will naturally be made with less consideration
2827+
for extension code than changes in well-defined and widely used
2828+
interfaces.
2829+
</para>
2830+
2831+
<para>
2832+
Also, in the absence of automated detection of such changes, this is
2833+
not a guarantee, but historically such breaking changes have been
2834+
extremely rare.
2835+
</para>
2836+
2837+
</sect4>
2838+
</sect3>
2839+
</sect2>
2840+
27072841
<sect2 id="xfunc-c-composite-type-args">
27082842
<title>Composite-Type Arguments</title>
27092843

0 commit comments

Comments
 (0)