Skip to content

Commit e54a42a

Browse files
committed
Add API and ABI stability 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 4f29394 commit e54a42a

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

doc/src/sgml/xfunc.sgml

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

27052705
&dfunc;
27062706

2707+
<sect2 id="xfunc-api-abi-stability-guidance">
2708+
<title>Server API and ABI Stability Guidance</title>
2709+
2710+
<para>
2711+
This section contains guidance to authors of extensions and other server
2712+
plugins about API and ABI 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-demarcated APIs for server plugins, such as the function manager
2722+
(<acronym>fmgr</acronym>, described in this chapter),
2723+
<acronym>SPI</acronym> (<xref linkend="spi"/>), 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 designed
2728+
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 API or ABI 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 considered 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-demarcated
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 release notes (<xref
2775+
linkend="release"/>).
2776+
</para>
2777+
</sect4>
2778+
</sect3>
2779+
2780+
<sect3 id="xfunc-guidance-abi-compatibility">
2781+
<title>ABI Compatibility</title>
2782+
<para>
2783+
The <acronym>ABI</acronym>, or application binary interface, is the
2784+
interface used at run time.
2785+
</para>
2786+
2787+
<sect4 id="xfunc-guidance-abi-major-versions">
2788+
<title>Major Versions</title>
2789+
<para>
2790+
Servers of different major versions have intentionally incompatible
2791+
ABIs. Extensions that use server APIs must therefore be re-compiled for
2792+
each major release. The inclusion of <literal>PG_MODULE_MAGIC</literal>
2793+
(see <xref linkend="xfunc-c-dynload"/>) ensures that code compiled for
2794+
one major version will be rejected by other major versions.
2795+
</para>
2796+
</sect4>
2797+
2798+
<sect4 id="xfunc-guidance-abi-mninor-versions">
2799+
<title>Minor Versions</title>
2800+
<para>
2801+
<productname>PostgreSQL</productname> makes an effort to avoid server
2802+
ABI breaks in minor releases. In general, an extension compiled against
2803+
any minor release should work with any other minor release of the same
2804+
major version, past or future.
2805+
</para>
2806+
2807+
<para>
2808+
When a change <emphasis>is</emphasis> required,
2809+
<productname>PostgreSQL</productname> will choose the least invasive
2810+
change possible, for example by squeezing a new field into padding
2811+
space or appending it to the end of a struct. These sorts of changes
2812+
should not impact extensions unless they use very unusual code
2813+
patterns.
2814+
</para>
2815+
2816+
<para>
2817+
In rare cases, however, even such non-invasive changes may be
2818+
impractical or impossible. In such an event, the change will be
2819+
carefully managed, taking the requirements of extensions into account.
2820+
Such changes will also be documented in the release notes (<xref
2821+
linkend="release"/>).
2822+
</para>
2823+
2824+
<para>
2825+
Note, however, that many parts of the server are not designed or
2826+
maintained as publicly-consumable APIs (and that, in most cases, the
2827+
actual boundary is also not well-defined). If urgent needs arise,
2828+
changes in those parts will naturally be made with less consideration
2829+
for extension code than changes in well-defined and widely used
2830+
interfaces.
2831+
</para>
2832+
2833+
<para>
2834+
Also, in the absence of automated detection of such changes, this is
2835+
not a guarantee, but historically such breaking changes have been
2836+
extremely rare.
2837+
</para>
2838+
2839+
</sect4>
2840+
</sect3>
2841+
</sect2>
2842+
27072843
<sect2 id="xfunc-c-composite-type-args">
27082844
<title>Composite-Type Arguments</title>
27092845

0 commit comments

Comments
 (0)