public inbox for [email protected]  
help / color / mirror / Atom feed
RE: AIX support
47+ messages / 14 participants
[nested] [flat]

* RE: AIX support
@ 2025-02-07 16:50  Srirama Kucherlapati <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: Srirama Kucherlapati @ 2025-02-07 16:50 UTC (permalink / raw)
  To: Heikki Linnakangas <[email protected]>; pgsql-hackers; [email protected] <[email protected]>; +Cc: Bruce Momjian <[email protected]>; Robert Haas <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; [email protected] <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>

Hi Team,
A few updates regarding the meson build.

We have successfully resolved issues with the meson build on AIX, allowing the meson configure and build to succeed.
A problem was addressed in the meson script wrt AIX (to build a nested shared libraries), specifically in the symbolextractor.py file. The fix has been implemented and will be submitted to the meson community.

https://github.com/mesonbuild/meson/blob/07f595fa98087352940121c87ba9aca0ebc95996/mesonbuild/scripts...

Currently, we are verifying the test results.


Warm regards,
Sriram.



^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* RE: AIX support
@ 2025-03-07 14:11  Srirama Kucherlapati <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: Srirama Kucherlapati @ 2025-03-07 14:11 UTC (permalink / raw)
  To: Heikki Linnakangas <[email protected]>; pgsql-hackers; [email protected] <[email protected]>; +Cc: Bruce Momjian <[email protected]>; Robert Haas <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; [email protected] <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>

Hi Team,
Our team has identified couple of issues with the meson build on AIX, primarily focusing on the following areas:

  1.  Symbol extraction and resolution in object files during binary creation.
  2.  Dynamic runtime library path resolution in shared libraries.
We have resolved them and we plan to submit these fixes to the meson community shortly.

In addition, we are actively working on resolving other test issues. I will provide you with updates once these problems have been resolved.

92/301 postgresql:regress / regress/regress
    # 4 of 223 tests failed.


Warm regards,
Sriram.



^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-03-07 16:20  Robert Haas <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: Robert Haas @ 2025-03-07 16:20 UTC (permalink / raw)
  To: Srirama Kucherlapati <[email protected]>; +Cc: Heikki Linnakangas <[email protected]>; pgsql-hackers; [email protected] <[email protected]>; Bruce Momjian <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; [email protected] <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>

On Fri, Mar 7, 2025 at 9:11 AM Srirama Kucherlapati
<[email protected]> wrote:
> Our team has identified couple of issues with the meson build on AIX, primarily focusing on the following areas:
>
> Symbol extraction and resolution in object files during binary creation.
> Dynamic runtime library path resolution in shared libraries.
>
> We have resolved them and we plan to submit these fixes to the meson community shortly.

Nice!

-- 
Robert Haas
EDB: http://www.enterprisedb.com





^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* RE: AIX support
@ 2025-03-17 16:58  Srirama Kucherlapati <[email protected]>
  parent: Robert Haas <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: Srirama Kucherlapati @ 2025-03-17 16:58 UTC (permalink / raw)
  To: Robert Haas <[email protected]>; pgsql-hackers; Heikki Linnakangas <[email protected]>; [email protected] <[email protected]>; +Cc: Bruce Momjian <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; [email protected] <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>

Hi Team,
Here are the updates on the meson on AIX.  Our team had pushed the fixes meson github here …

https://github.com/mesonbuild/meson/pull/14335

#14335 Enhance AIX shared library build to use an export List.<https://github.com/mesonbuild/meson/pull/14335;





^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-04-03 08:25  wenhui qiu <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: wenhui qiu @ 2025-04-03 08:25 UTC (permalink / raw)
  To: Srirama Kucherlapati <[email protected]>; +Cc: Robert Haas <[email protected]>; pgsql-hackers; Heikki Linnakangas <[email protected]>; [email protected] <[email protected]>; Bruce Momjian <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; [email protected] <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>

HI Srirama
     It's getting close to  code freeze. Any updates from your end?


Thanks

On Tue, Mar 18, 2025 at 12:58 AM Srirama Kucherlapati <[email protected]>
wrote:

> Hi Team,
>
> Here are the updates on the meson on AIX.  Our team had pushed the fixes
> meson github here …
>
>
>
> https://github.com/mesonbuild/meson/pull/14335
>
>
>
> #14335 Enhance AIX shared library build to use an export List.
> <https://github.com/mesonbuild/meson/pull/14335;
>
>
>
>
>
>
>
>


^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* RE: AIX support
@ 2025-04-03 13:45  Srirama Kucherlapati <[email protected]>
  parent: wenhui qiu <[email protected]>
  0 siblings, 2 replies; 47+ messages in thread

From: Srirama Kucherlapati @ 2025-04-03 13:45 UTC (permalink / raw)
  To: wenhui qiu <[email protected]>; Heikki Linnakangas <[email protected]>; [email protected] <[email protected]>; pgsql-hackers; +Cc: Robert Haas <[email protected]>; Bruce Momjian <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; [email protected] <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>

Hi Wenhui Qiu,

May I know the freeze dates.

We are nearly ready to deliver the patch. Currently, we have compiled the
source using Meson and are investigating one test case issue. Once we pinpoint
the cause, we will send you the patch. Notably, this test case behaves
differently on AIX, opting for a Bitmap Index Scan instead of an Index Scan.
Not sure if this is really specific to AIX?

                >> meson test

396 Ok:                 81
397 Expected Fail:      0
398 Fail:               1  (regex)
399 Unexpected Pass:    0
400 Skipped:            219
401 Timeout:            0


>>
  7  explain (costs off) select * from pg_proc where proname ~ '^abc';
  8 -                              QUERY PLAN
  9 -----------------------------------------------------------------------
10 - Index Scan using pg_proc_proname_args_nsp_index on pg_proc
11 -   Index Cond: ((proname >= 'abc'::text) AND (proname < 'abd'::text))
12 +                                 QUERY PLAN
13 +----------------------------------------------------------------------------
14 + Bitmap Heap Scan on pg_proc
15     Filter: (proname ~ '^abc'::text)
16 -(3 rows)
17 +   ->  Bitmap Index Scan on pg_proc_proname_args_nsp_index
18 +         Index Cond: ((proname >= 'abc'::text) AND (proname < 'abd'::text))
19 +(4 rows)

As of now below are the changes wrt to meson.

        modified:   meson.build
        modified:   src/backend/meson.build
        modified:   src/bin/initdb/initdb.c
        modified:   src/include/c.h
        modified:   src/include/port/aix.h
        modified:   src/include/utils/float.h
        modified:   src/interfaces/ecpg/compatlib/meson.build
        modified:   src/interfaces/ecpg/ecpglib/meson.build
        modified:   src/interfaces/ecpg/pgtypeslib/meson.build
        modified:   src/interfaces/libpq/meson.build
        modified:   src/test/regress/expected/txid.out
        modified:   src/test/regress/expected/xid.out
        modified:   src/test/regress/sql/sanity_check.sql



Warm regards,
Sriram.


^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-04-03 13:49  Heikki Linnakangas <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  1 sibling, 1 reply; 47+ messages in thread

From: Heikki Linnakangas @ 2025-04-03 13:49 UTC (permalink / raw)
  To: Srirama Kucherlapati <[email protected]>; wenhui qiu <[email protected]>; [email protected] <[email protected]>; pgsql-hackers; +Cc: Robert Haas <[email protected]>; Bruce Momjian <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; [email protected] <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>

On 03/04/2025 16:45, Srirama Kucherlapati wrote:
> Hi Wenhui Qiu,
> 
> May I know the freeze dates.

April 8th is the feature freeze. Any new features must be *committed* by 
then. We are already very close to that, and given that there's no 
concrete patch for committer to review yet, I think it's safe to say 
that you missed it already.

-- 
Heikki Linnakangas
Neon (https://neon.tech)







^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-04-03 13:54  Andres Freund <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  1 sibling, 0 replies; 47+ messages in thread

From: Andres Freund @ 2025-04-03 13:54 UTC (permalink / raw)
  To: Srirama Kucherlapati <[email protected]>; +Cc: wenhui qiu <[email protected]>; Heikki Linnakangas <[email protected]>; [email protected] <[email protected]>; pgsql-hackers; Robert Haas <[email protected]>; Bruce Momjian <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Thomas Munro <[email protected]>; [email protected] <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>

Hi,

On 2025-04-03 13:45:01 +0000, Srirama Kucherlapati wrote:
> We are nearly ready to deliver the patch. Currently, we have compiled the
> source using Meson and are investigating one test case issue. Once we pinpoint
> the cause, we will send you the patch. Notably, this test case behaves
> differently on AIX, opting for a Bitmap Index Scan instead of an Index Scan.
> Not sure if this is really specific to AIX?
> 
>                 >> meson test
> 
> 396 Ok:                 81
> 397 Expected Fail:      0
> 398 Fail:               1  (regex)
> 399 Unexpected Pass:    0
> 400 Skipped:            219

FWIW, the skipped tests indicate that you are building without tap tests or
such - that means most of the testsuite is not run. That certainly is not good
enough.

Greetings,

Andres Freund






^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* RE: AIX support
@ 2025-04-04 19:31  Srirama Kucherlapati <[email protected]>
  parent: Heikki Linnakangas <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: Srirama Kucherlapati @ 2025-04-04 19:31 UTC (permalink / raw)
  To: Heikki Linnakangas <[email protected]>; wenhui qiu <[email protected]>; [email protected] <[email protected]>; pgsql-hackers; +Cc: Robert Haas <[email protected]>; Bruce Momjian <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; [email protected] <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>


Hi Heikki and team,

Thank you for considering our request. As discussed, we have revised the patch
to incorporate all the review comments provided.
Please find the attached patch, which focuses solely on the gmake changes.
As discussed the meson specific changes would be provided as different patch.

We have taken into account and resolved the earlier comments within this patch.
https://www.postgresql.org/message-id/e0dc2bff-300b-4edd-912b-b6c52274bdc5%40iki.fi


- Build using latest master. (used commit 898c131b58a0b)
   - We have merged our changes to this latest level.
- configure.ac
   - Updated the changes aligning to configure file.
- configure
   - Updated the comments wrt to the alignment details. Updated with
     the gcc specific fix which talks about the alignment.
  - updated the int64_t specific changes.
- doc/src/sgml/dfunc.sgml
  - This is removed as it is not relevant.
- src/backend/port/aix/mkldexport.sh
  - When building shared libraries from various archives on AIX, we encounter a
     situation where symbols are not exported. To resolve this, we require an export
     file. For instance, the command is used to export symbols.
     gcc -shared libtest.so libtest.a -Wl,-bE:test.exp

     However, if we directly provide object files in the command line instead of an
     archive, the symbols will be exported automatically, as demonstrated by the command
     gcc -shared libtest.so test1.o test2.o test3.o.
   - We will update the description with additional details in the later point of time. (Considering the time lines)

- src/makefiles/Makefile.aix
   - The changes in this file are required
   - This change is not required “+LDFLAGS_SL += -Wl,-bnoentry -Wl,-H512 -Wl,-bM:SRE”
- src/template/aix
   - WRT to the MEMSET_LOOP_LIMIT flag, this is set to “0”, which would internally use
     The system call memset() as mentioned in the below link as well

     https://www.postgresql.org/message-id/20060203135315.E08B09DC816%40postgresql.org

I Kindly request you to review the changes and provide your feedback.


With all the above changes we have built and ran the tests. As of now we see
there is only one test case that is failing, which seems to have been
introduced recently. And this might not be related to the above changes as
earlier there were no test cases failing.

64 not ok 12    + float8                   235 ms

297 # 1 of 226 tests failed.


20 +ERROR:  value out of range: overflow
21  -- test overflow/underflow handling
22  SELECT gamma(float8 '-infinity');
23  ERROR:  value out of range: overflow


Warm regards,
Sriram.



Attachments:

  [application/octet-stream] 0001-AIX-support.v7.patch (14.4K, 3-0001-AIX-support.v7.patch)
  download | inline diff:
From 614cd077da0de9ca92c4e4fb300c39f73ab5ad10 Mon Sep 17 00:00:00 2001
From: Sriram RK <[email protected]>
Date: Fri, 4 Apr 2025 13:16:21 -0500
Subject: [PATCH] AIX support.

---
 Makefile                           |  2 -
 configure                          | 34 ++++++++++++++---
 configure.ac                       | 34 ++++++++++++++---
 src/Makefile.shlib                 | 29 ++++++++++++++
 src/backend/Makefile               | 20 ++++++++++
 src/backend/port/aix/mkldexport.sh | 61 ++++++++++++++++++++++++++++++
 src/backend/utils/error/elog.c     |  2 +
 src/include/port/aix.h             |  4 ++
 src/include/storage/s_lock.h       | 10 ++---
 src/makefiles/Makefile.aix         | 39 +++++++++++++++++++
 src/port/strerror.c                |  2 +
 src/template/aix                   |  7 ++++
 12 files changed, 224 insertions(+), 20 deletions(-)
 create mode 100755 src/backend/port/aix/mkldexport.sh
 create mode 100644 src/include/port/aix.h
 create mode 100644 src/makefiles/Makefile.aix
 create mode 100644 src/template/aix

diff --git a/Makefile b/Makefile
index 8a2ec9396b6..9bc1a4ec17b 100644
--- a/Makefile
+++ b/Makefile
@@ -13,8 +13,6 @@
 
 # AIX make defaults to building *every* target of the first rule.  Start with
 # a single-target, empty rule to make the other targets non-default.
-# (We don't support AIX anymore, but if someone tries to build on AIX anyway,
-# at least they'll get the instructions to run 'configure' first.)
 all:
 
 all check install installdirs installcheck installcheck-parallel uninstall clean distclean maintainer-clean dist distcheck world check-world install-world installcheck-world:
diff --git a/configure b/configure
index 11615d1122d..6088fa26679 100755
--- a/configure
+++ b/configure
@@ -3008,6 +3008,7 @@ else
 # --with-template not given
 
 case $host_os in
+  aix*) template=aix ;;
   cygwin*|msys*) template=cygwin ;;
   darwin*) template=darwin ;;
 dragonfly*) template=netbsd ;;
@@ -16953,13 +16954,34 @@ _ACEOF
 # wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
 # much of a penalty for disk and memory space.
 
-MAX_ALIGNOF=$ac_cv_alignof_double
+if test "$PORTNAME" != "aix"; then
+    MAX_ALIGNOF=$ac_cv_alignof_double
+
+    if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
+      as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+    if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
+      as_fn_error $? "alignment of 'long long int' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+else
+# The AIX 'power' alignment rules apply the natural alignment of the "first
+# member" if it is of a floating-point data type (or is an aggregate whose
+# recursively "first" member or element is such a type). The alignment
+# associated with these types for subsequent members use an alignment value
+# where the floating-point data type is considered to have 4-byte alignment.
+# More info
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99557
+#
+# The double is aligned to 4-bytes on AIX in aggregates. But to maintain
+# alignement across platforms the max alignment of long should be considered.
+    MAX_ALIGNOF=$ac_cv_alignof_long
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_double ; then
+      MAX_ALIGNOF=$ac_cv_alignof_double
+    fi
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_int64_t; then
+      MAX_ALIGNOF="$ac_cv_alignof_int64_t"
+    fi
 
-if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
-  as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
-fi
-if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
-  as_fn_error $? "alignment of 'int64_t' is greater than the alignment of 'double'" "$LINENO" 5
 fi
 
 cat >>confdefs.h <<_ACEOF
diff --git a/configure.ac b/configure.ac
index debdf165044..c21aaa52064 100644
--- a/configure.ac
+++ b/configure.ac
@@ -62,6 +62,7 @@ PGAC_ARG_REQ(with, template, [NAME], [override operating system template],
 # --with-template not given
 
 case $host_os in
+  aix*) template=aix ;;
   cygwin*|msys*) template=cygwin ;;
   darwin*) template=darwin ;;
 dragonfly*) template=netbsd ;;
@@ -1987,13 +1988,34 @@ AC_CHECK_ALIGNOF(double)
 # wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
 # much of a penalty for disk and memory space.
 
-MAX_ALIGNOF=$ac_cv_alignof_double
+if test "$PORTNAME" != "aix"; then
+    MAX_ALIGNOF=$ac_cv_alignof_double
+
+    if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
+      as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+    if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF; then
+      as_fn_error $? "alignment of 'long long int' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+else
+# The AIX 'power' alignment rules apply the natural alignment of the "first
+# member" if it is of a floating-point data type (or is an aggregate whose
+# recursively "first" member or element is such a type). The alignment
+# associated with these types for subsequent members use an alignment value
+# where the floating-point data type is considered to have 4-byte alignment.
+# More info
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99557
+# 
+# The double is aligned to 4-bytes on AIX in aggregates. But to maintain
+# alignement across platforms the max alignment of long should be considered.
+    MAX_ALIGNOF=$ac_cv_alignof_long
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_double ; then
+      MAX_ALIGNOF=$ac_cv_alignof_double
+    fi
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_int64_t ; then
+      MAX_ALIGNOF="$ac_cv_alignof_int64_t"
+    fi
 
-if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
-  AC_MSG_ERROR([alignment of 'long' is greater than the alignment of 'double'])
-fi
-if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
-  AC_MSG_ERROR([alignment of 'int64_t' is greater than the alignment of 'double'])
 fi
 AC_DEFINE_UNQUOTED(MAXIMUM_ALIGNOF, $MAX_ALIGNOF, [Define as the maximum alignment requirement of any C data type.])
 
diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index fa81f6ffdd6..13ea84ac185 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -106,6 +106,20 @@ ifdef SO_MAJOR_VERSION
 override CPPFLAGS += -DSO_MAJOR_VERSION=$(SO_MAJOR_VERSION)
 endif
 
+ifeq ($(PORTNAME), aix)
+  LINK.shared		= $(COMPILER)
+  ifdef SO_MAJOR_VERSION
+    shlib		= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
+  endif
+  haslibarule   = yes
+  # $(exports_file) is also usable as an import file
+  exports_file		= lib$(NAME).exp
+  BUILD.exports		= ( echo '\#! $(shlib)'; $(AWK) '/^[^\#]/ {printf "%s\n",$$1}' $< ) > $@
+  ifneq (,$(SHLIB_EXPORTS))
+    LINK.shared		+= -Wl,-bE:$(exports_file)
+  endif
+endif
+
 ifeq ($(PORTNAME), darwin)
   ifdef soname
     # linkable library
@@ -254,6 +268,14 @@ $(stlib): $(OBJS) | $(SHLIB_PREREQS)
 	touch $@
 endif #haslibarule
 
+# AIX wraps both shared libraries and static library, which can be used both
+# for static and shared linking
+ifeq ($(PORTNAME), aix)
+$(stlib): $(shlib)
+	rm -f $(stlib)
+	$(AR) $(AROPT) $(stlib) $(shlib)
+endif # aix
+
 ifeq (,$(filter cygwin win32,$(PORTNAME)))
 
 # Normal case
@@ -267,8 +289,11 @@ ifneq ($(shlib), $(shlib_major))
 endif
 # Make sure we have a link to a name without any version numbers
 ifneq ($(shlib), $(shlib_bare))
+# except on AIX, where that's not a thing
+ifneq ($(PORTNAME), aix)
 	rm -f $(shlib_bare)
 	$(LN_S) $(shlib) $(shlib_bare)
+endif # aix
 endif # shlib_bare
 endif # shlib_major
 
@@ -376,6 +401,9 @@ install-lib-static: $(stlib) installdirs-lib
 
 install-lib-shared: $(shlib) installdirs-lib
 ifdef soname
+# we don't install $(shlib) on AIX
+# (see http://archives.postgresql.org/message-id/52EF20B2E3209443BC37736D00C3C1380A6E79FE@EXADV1.host.magwien.gv.at)
+ifneq ($(PORTNAME), aix)
 	$(INSTALL_SHLIB) $< '$(DESTDIR)$(libdir)/$(shlib)'
 ifneq ($(PORTNAME), cygwin)
 ifneq ($(PORTNAME), win32)
@@ -391,6 +419,7 @@ ifneq ($(shlib), $(shlib_bare))
 endif
 endif # not win32
 endif # not cygwin
+endif # not aix
 ifneq (,$(findstring $(PORTNAME),win32 cygwin))
 	$(INSTALL_SHLIB) $< '$(DESTDIR)$(bindir)/$(shlib)'
 endif
diff --git a/src/backend/Makefile b/src/backend/Makefile
index 7344c8c7f5c..572f5430a60 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -63,12 +63,14 @@ all: submake-libpgport submake-catalog-headers submake-utils-headers postgres $(
 
 ifneq ($(PORTNAME), cygwin)
 ifneq ($(PORTNAME), win32)
+ifneq ($(PORTNAME), aix)
 
 postgres: $(OBJS)
 	$(CC) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LIBS) -o $@
 
 endif
 endif
+endif
 
 ifeq ($(PORTNAME), cygwin)
 
@@ -95,6 +97,24 @@ libpostgres.a: postgres
 
 endif # win32
 
+ifeq ($(PORTNAME), aix)
+
+postgres: $(POSTGRES_IMP)
+	$(CC) $(CFLAGS) $(call expand_subsys,$(OBJS)) $(LDFLAGS) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -Wl,-brtllib -o $@
+
+# Linking to a single .o with -r is a lot faster than building a .a or passing
+# all objects to MKLDEXPORT.
+#
+# It looks alluring to use $(CC) -r instead of ld -r, but that doesn't
+# trivially work with gcc, due to gcc specific static libraries linked in with
+# -r.
+$(POSTGRES_IMP): $(OBJS)
+	ld -r -o SUBSYS.o $(call expand_subsys,$^)
+	$(MKLDEXPORT) SUBSYS.o . > $@
+	@rm -f SUBSYS.o
+
+endif # aix
+
 $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
 
 
diff --git a/src/backend/port/aix/mkldexport.sh b/src/backend/port/aix/mkldexport.sh
new file mode 100755
index 00000000000..adf3793e868
--- /dev/null
+++ b/src/backend/port/aix/mkldexport.sh
@@ -0,0 +1,61 @@
+#!/bin/sh
+#
+# mkldexport
+#	create an AIX exports file from an object file
+#
+# src/backend/port/aix/mkldexport.sh
+#
+# Usage:
+#	mkldexport objectfile [location]
+# where
+#	objectfile is the current location of the object file.
+#	location is the eventual (installed) location of the
+#		object file (if different from the current
+#		working directory).
+#
+# [This file comes from the Postgres 4.2 distribution. - ay 7/95]
+#
+# Header: /usr/local/devel/postgres/src/tools/mkldexport/RCS/mkldexport.sh,v 1.2 1994/03/13 04:59:12 aoki Exp
+#
+
+# setting this to nm -B might be better
+# ... due to changes in AIX 4.x ...
+# ... let us search in different directories - Gerhard Reithofer
+if [ -x /usr/ucb/nm ]
+then NM=/usr/ucb/nm
+elif [ -x /usr/bin/nm ]
+then NM=/usr/bin/nm
+elif [ -x /usr/ccs/bin/nm ]
+then NM=/usr/ccs/bin/nm
+elif [ -x /usr/usg/bin/nm ]
+then NM=/usr/usg/bin/nm
+else echo "Fatal error: cannot find `nm' ... please check your installation."
+     exit 1
+fi
+
+CMDNAME=`basename $0`
+if [ -z "$1" ]; then
+	echo "Usage: $CMDNAME object [location]"
+	exit 1
+fi
+OBJNAME=`basename $1`
+if [ "`basename $OBJNAME`" != "`basename $OBJNAME .o`" ]; then
+	OBJNAME=`basename $OBJNAME .o`.so
+fi
+if [ -z "$2" ]; then
+	echo '#!'
+else
+	if [ "$2" = "." ]; then
+		# for the base executable (AIX 4.2 and up)
+		echo '#! .'
+	else
+		echo '#!' $2
+	fi
+fi
+$NM -BCg $1 | \
+	egrep ' [TDB] ' | \
+	sed -e 's/.* //' | \
+	egrep -v '\$' | \
+	sed -e 's/^[.]//' | \
+	sort | \
+	uniq
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 8a6b6905079..3a8e9dc30b0 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -904,7 +904,9 @@ errcode_for_file_access(void)
 			/* Wrong object type or state */
 		case ENOTDIR:			/* Not a directory */
 		case EISDIR:			/* Is a directory */
+#if defined(ENOTEMPTY) && (ENOTEMPTY != EEXIST) /* same code on AIX */
 		case ENOTEMPTY:			/* Directory not empty */
+#endif
 			edata->sqlerrcode = ERRCODE_WRONG_OBJECT_TYPE;
 			break;
 
diff --git a/src/include/port/aix.h b/src/include/port/aix.h
new file mode 100644
index 00000000000..7d08480c8c0
--- /dev/null
+++ b/src/include/port/aix.h
@@ -0,0 +1,4 @@
+/*
+ * src/include/port/aix.h
+ */
+
diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
index 2f73f9fcf57..5da9b3acda4 100644
--- a/src/include/storage/s_lock.h
+++ b/src/include/storage/s_lock.h
@@ -421,17 +421,15 @@ tas(volatile slock_t *lock)
 	__asm__ __volatile__(
 "	lwarx   %0,0,%3,1	\n"
 "	cmpwi   %0,0		\n"
-"	bne     1f			\n"
+"	bne     $+16		\n"		/* branch to li %1,1 */
 "	addi    %0,%0,1		\n"
 "	stwcx.  %0,0,%3		\n"
-"	beq     2f			\n"
-"1: \n"
+"	beq     $+12		\n"		/* branch to lwsync */
 "	li      %1,1		\n"
-"	b       3f			\n"
-"2: \n"
+"	b       $+12		\n"		/* branch to end of asm sequence */
 "	lwsync				\n"
 "	li      %1,0		\n"
-"3: \n"
+
 :	"=&b"(_t), "=r"(_res), "+m"(*lock)
 :	"r"(lock)
 :	"memory", "cc");
diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix
new file mode 100644
index 00000000000..d33918f91b9
--- /dev/null
+++ b/src/makefiles/Makefile.aix
@@ -0,0 +1,39 @@
+# MAKE_EXPORTS is required for svr4 loaders that want a file of
+# symbol names to tell them what to export/import.
+MAKE_EXPORTS= true
+
+# -blibpath must contain ALL directories where we should look for libraries
+libpath := $(shell echo $(subst -L,:,$(filter -L/%,$(LDFLAGS))) | sed -e's/ //g'):/usr/lib:/lib
+
+# when building with gcc, need to make sure that libgcc can be found
+ifeq ($(GCC), yes)
+libpath := $(libpath):$(dir $(shell gcc -print-libgcc-file-name))
+endif
+
+rpath = -Wl,-blibpath:'$(rpathdir)$(libpath)'
+
+#LDFLAGS_SL += -Wl,-bnoentry -Wl,-H512 -Wl,-bM:SRE
+
+# gcc needs to know it's building a shared lib, otherwise it'll not emit
+# correct code / link to the right support libraries
+ifeq ($(GCC), yes)
+LDFLAGS_SL += -shared
+endif
+
+# env var name to use in place of LD_LIBRARY_PATH
+ld_library_path_var = LIBPATH
+
+
+POSTGRES_IMP= postgres.imp
+
+ifdef PGXS
+BE_DLLLIBS= -Wl,-bI:$(pkglibdir)/$(POSTGRES_IMP)
+else
+BE_DLLLIBS= -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP)
+endif
+
+MKLDEXPORT_DIR=src/backend/port/aix
+MKLDEXPORT=$(top_srcdir)/$(MKLDEXPORT_DIR)/mkldexport.sh
+
+%$(DLSUFFIX): %.o
+	$(CC) $(CFLAGS) $*.o $(LDFLAGS) $(LDFLAGS_SL) -o $@ $(BE_DLLLIBS)
diff --git a/src/port/strerror.c b/src/port/strerror.c
index f0746517770..c46b9dc91fc 100644
--- a/src/port/strerror.c
+++ b/src/port/strerror.c
@@ -214,8 +214,10 @@ get_errno_symbol(int errnum)
 			return "ENOTCONN";
 		case ENOTDIR:
 			return "ENOTDIR";
+#if defined(ENOTEMPTY) && (ENOTEMPTY != EEXIST) /* same code on AIX */
 		case ENOTEMPTY:
 			return "ENOTEMPTY";
+#endif
 		case ENOTSOCK:
 			return "ENOTSOCK";
 #ifdef ENOTSUP
diff --git a/src/template/aix b/src/template/aix
new file mode 100644
index 00000000000..48a3ce55cf7
--- /dev/null
+++ b/src/template/aix
@@ -0,0 +1,7 @@
+# src/template/aix
+
+# Extra CFLAGS for code that will go into a shared library
+CFLAGS_SL=""
+
+# Native memset() is faster.
+MEMSET_LOOP_LIMIT=0
-- 
2.41.0



^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-04-04 20:44  Heikki Linnakangas <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: Heikki Linnakangas @ 2025-04-04 20:44 UTC (permalink / raw)
  To: Srirama Kucherlapati <[email protected]>; wenhui qiu <[email protected]>; [email protected] <[email protected]>; pgsql-hackers; +Cc: Robert Haas <[email protected]>; Bruce Momjian <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; [email protected] <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>

On 04/04/2025 22:31, Srirama Kucherlapati wrote:
 > - src/backend/port/aix/mkldexport.sh>
>    - When building shared libraries from various archives on AIX, we encounter a
>       situation where symbols are not exported. To resolve this, we require an export
>       file. For instance, the command is used to export symbols.
> 
>       gcc -shared libtest.so libtest.a -Wl,-bE:test.exp
> 
>       However, if we directly provide object files in the command line instead of an
>       archive, the symbols will be exported automatically, as demonstrated by the command
> 
>       gcc -shared libtest.so test1.o test2.o test3.o.

Oh, that's interesting. So if we do that, we don't need mkldepxort.sh 
anymore?

>     - WRT to the MEMSET_LOOP_LIMIT flag, this is set to “0”, which would 
> internally use
> 
>       The system call memset() as mentioned in the below link as well
> 
> https://www.postgresql.org/message- 
> id/20060203135315.E08B09DC816%40postgresql.org <https:// 
> www.postgresql.org/message-id/20060203135315.E08B09DC816%40postgresql.org>

Yes, I understand what it does. But why? Whatever benchmarking was done 
back in 2006 by is no longer relevant.

> With all the above changes we have built and ran the tests. As of now we see
> 
> there is only one test case that is failing, which seems to have been
> 
> introduced recently. And this might not be related to the above changes as
> 
> earlier there were no test cases failing.
> 
> 64 not ok 12    + float8                   235 ms
> 
> 297 # 1 of 226 tests failed.
> 
> 20 +ERROR:  value out of range: overflow
> 
> 21  -- test overflow/underflow handling
> 
> 22  SELECT gamma(float8 '-infinity');
> 
> 23  ERROR:  value out of range: overflow

Yeah, that function is new. I don't know if it's a pre-existing problem 
or something specific to AIX. Please check the archives for prior 
discussion on that; if you can reproduce it, maybe you can help to fix it?

>  12 files changed, 224 insertions(+), 20 deletions(-)

I'm glad to see this patch shrinking :-)

> diff --git a/src/include/port/aix.h b/src/include/port/aix.h
> new file mode 100644
> index 00000000000..7d08480c8c0
> --- /dev/null
> +++ b/src/include/port/aix.h
> @@ -0,0 +1,4 @@
> +/*
> + * src/include/port/aix.h
> + */
> +

Useless.

> diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
> index 2f73f9fcf57..5da9b3acda4 100644
> --- a/src/include/storage/s_lock.h
> +++ b/src/include/storage/s_lock.h
> @@ -421,17 +421,15 @@ tas(volatile slock_t *lock)
>  	__asm__ __volatile__(
>  "	lwarx   %0,0,%3,1	\n"
>  "	cmpwi   %0,0		\n"
> -"	bne     1f			\n"
> +"	bne     $+16		\n"		/* branch to li %1,1 */
>  "	addi    %0,%0,1		\n"
>  "	stwcx.  %0,0,%3		\n"
> -"	beq     2f			\n"
> -"1: \n"
> +"	beq     $+12		\n"		/* branch to lwsync */
>  "	li      %1,1		\n"
> -"	b       3f			\n"
> -"2: \n"
> +"	b       $+12		\n"		/* branch to end of asm sequence */
>  "	lwsync				\n"
>  "	li      %1,0		\n"
> -"3: \n"
> +
>  :	"=&b"(_t), "=r"(_res), "+m"(*lock)
>  :	"r"(lock)
>  :	"memory", "cc");

Why is this change needed?

Yes, I know we've been over this many times already. I still don't 
understand why it's needed. The onus is on you to explain it adequately, 
in comments in the patch, so that I and others understand it. Or even 
better, remove it if it's not necessary.

> diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix
> new file mode 100644
> index 00000000000..d33918f91b9
> --- /dev/null
> +++ b/src/makefiles/Makefile.aix
> @@ -0,0 +1,39 @@
> +# MAKE_EXPORTS is required for svr4 loaders that want a file of
> +# symbol names to tell them what to export/import.
> +MAKE_EXPORTS= true

Oh this is interesting. I think MAKE_EXPORTS is actually a leftover that 
I failed to remove when I removed the AIX support; it's not used on any 
currently-supported platform.

> +# -blibpath must contain ALL directories where we should look for libraries
> +libpath := $(shell echo $(subst -L,:,$(filter -L/%,$(LDFLAGS))) | sed -e's/ //g'):/usr/lib:/lib

Is this still sensible on modern AIX systems? What happens if you leave 
it out?

> +# when building with gcc, need to make sure that libgcc can be found
> +ifeq ($(GCC), yes)
> +libpath := $(libpath):$(dir $(shell gcc -print-libgcc-file-name))
> +endif

Same here. Still relevant? What happens if you leave it out?

> +# gcc needs to know it's building a shared lib, otherwise it'll not emit
> +# correct code / link to the right support libraries
> +ifeq ($(GCC), yes)
> +LDFLAGS_SL += -shared
> +endif

On other platforms, we have this in LINK.shared, see src/Makefile.shlib. 
Should we do the same on AIX; if not, why not?

> +# env var name to use in place of LD_LIBRARY_PATH
> +ld_library_path_var = LIBPATH

Does AIX have LD_LIBRARY_PATH? This suggests that it does:

https://www.ibm.com/support/pages/aix-libpath-recommendations

What's the difference between LIBPATH and LD_LIBRARY_PATH? Why prefer 
LIBPATH?


Separately from the remaining issues with this patch, I still feel 
pretty reluctant with accepting this, because if I commit this patch, 
I'm on the hook to keep it working. I do regularly commit stuff that I'm 
not personally that interested in, but a new port is different:

If something breaks on AIX, I have no means (or interest!) in debugging 
it. That means that I need to be pretty confident that there are others 
who are interested and invested in keeping working, take ownership, will 
help to debug problems in a timely fashion, and can submit high-quality 
fixes. I am not seeing that.

I also notice that all the AIX systems we have in the buildfarm are still:

- maintained by Noah, who - correct me if I'm wrong - is not 
particularly interested in AIX or keen on maintaining them
- are on AIX 7.1.5, which I believe is already end-of-line
- running on power7 hardware which is 15 years old.

That's not very reassuring.

-- 
Heikki Linnakangas
Neon (https://neon.tech)






^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* RE: AIX support
@ 2025-04-05 18:29  Srirama Kucherlapati <[email protected]>
  parent: Heikki Linnakangas <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: Srirama Kucherlapati @ 2025-04-05 18:29 UTC (permalink / raw)
  To: Heikki Linnakangas <[email protected]>; pgsql-hackers; +Cc: Robert Haas <[email protected]>; Bruce Momjian <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; [email protected] <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>; wenhui qiu <[email protected]>; [email protected] <[email protected]>

--_004_CY8PR15MB5602EADE20375FB66090B61BDBA82CY8PR15MB5602namp_
Content-Type: multipart/alternative;
	boundary="_000_CY8PR15MB5602EADE20375FB66090B61BDBA82CY8PR15MB5602namp_"

--_000_CY8PR15MB5602EADE20375FB66090B61BDBA82CY8PR15MB5602namp_
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

Hi Heikki,
Please find the attached patch addressing the provided comments. Our respon=
ses are outlined below.
>> - src/backend/port/aix/mkldexport.sh>

> Oh, that's interesting. So if we do that, we don't need mkldepxort.sh
> anymore?

Here the better approach still would be to use the script to extract the
symbols build the corresponding shared libraries.  As we see there are
lot of extensions that are getting built using the symbols exported from
"postges" binary, we need to definitely  use the script to extract the symb=
ols
and import them while building the library extensions.


>> - WRT to the MEMSET_LOOP_LIMIT flag, this is set to =930=94, which would
>> internally use

> Yes, I understand what it does. But why? Whatever benchmarking was done
> back in 2006 by is no longer relevant.


We ran the program , mentioned in the below link and collected the

benchmark stats on our node (POWER_10).

    https://postgrespro.com/list/thread-id/1673194



The native AIX memset() seems to performs better. The benchmark seems to be=
 still

relevant, so I think we should continue to use the existing optimization fo=
r

AIX. Below are the stats (64bit Object mode).





>> ./memset-aix



        sizeof(int)  =3D 4

        sizeof(long) =3D 8

        Loop by int (size=3D8) : 0.238024

        memset by int (size=3D8) : 0.280301

        Loop by long (size=3D8) : 0.202650

        Loop by int (size=3D16) : 0.389846

        memset by int (size=3D16) : 0.280979

        Loop by long (size=3D16) : 0.246879

        Loop by int (size=3D32) : 0.773478

        memset by int (size=3D32) : 0.331691

        Loop by long (size=3D32) : 0.422261

        Loop by int (size=3D64) : 1.945150

        memset by int (size=3D64) : 0.319117

        Loop by long (size=3D64) : 0.769770

        Loop by int (size=3D128) : 4.517186

        memset by int (size=3D128) : 0.398292

        Loop by long (size=3D128) : 1.982307

        Loop by int (size=3D256) : 12.486661

        memset by int (size=3D256) : 0.463115

        Loop by long (size=3D256) : 4.526272

        Loop by int (size=3D512) : 24.433075

        memset by int (size=3D512) : 0.681426

        Loop by long (size=3D512) : 12.564701

        Loop by int (size=3D1024) : 48.060486

        memset by int (size=3D1024) : 0.904048

        Loop by long (size=3D1024) : 24.149871

        Loop by int (size=3D2048) : 96.288018

        memset by int (size=3D2048) : 1.509465

        Loop by long (size=3D2048) : 48.216079

        Loop by int (size=3D4096) : 191.847177

        memset by int (size=3D4096) : 1.435403

        Loop by long (size=3D4096) : 96.433072


>>  12 files changed, 224 insertions(+), 20 deletions(-)
> I'm glad to see this patch shrinking :-)

Thanks for your suggestions, yes it further shrinked.


> > diff --git a/src/include/port/aix.h b/src/include/port/aix.h

> Useless.


I too initially felt this was not needed, This file is still required as th=
e below file is

getting auto generated. I attempted to remove it; the below error is hit.

so this is still required.



     64 ../../src/include/c.h:59:10: fatal error: pg_config_os.h: No such f=
ile or directory

     65    59 | #include "pg_config_os.h"               /* config from incl=
ude/port/PORTNAME.h */

     66       |          ^~~~~~~~~~~~~~~~



> diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h

> Why is this change needed?

> Yes, I know we've been over this many times already. I still don't
> understand why it's needed. The onus is on you to explain it adequately,
> in comments in the patch, so that I and others understand it. Or even
> better, remove it if it's not necessary.

If you recall, we previously considered replacing this assembly code with
__sync_lock_test_and_set(). However, as you mentioned earlier, this should =
be
handled in a separate patch. For now, I'll make a note and submit a separat=
e
patch for this later, as originally planned. Below is the reference to olde=
r
discussion.
https://www.postgresql.org/message-id/7751f9c5-e2e6-4252-a9fa-14b3e78ddec9%=
40iki.fi


>> diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix
>> +MAKE_EXPORTS=3D true

>Oh this is interesting. I think MAKE_EXPORTS is actually a leftover that
>I failed to remove when I removed the AIX support; it's not used on any
>currently-supported platform.

Removed it and its working fine.


>> +# -blibpath must contain ALL directories where we should look for libra=
ries
>> +libpath :=3D $(shell echo $(subst -L,:,$(filter -L/%,$(LDFLAGS))) | sed=
 -e's/ //g'):/usr/lib:/lib

> Is this still sensible on modern AIX systems? What happens if you leave
> it out?


This is required as it is looking for the possible non-default directories =
for the linker

at the runtime. This is used along with rpath. As suggested, I tested this =
by removing

the libpath, but at run time the linker is not able to find the dependent l=
ibraries path

as a result, the binaries are not getting loaded. After doing some research=
, AIX uses a stricter,

more explicit approach. The runtime linker expects to tell it exactly where=
 to look using -blibpath.



>> +# when building with gcc, need to make sure that libgcc can be found
>> +ifeq ($(GCC), yes)
>> +libpath :=3D $(libpath):$(dir $(shell gcc -print-libgcc-file-name))
>> +endif

> Same here. Still relevant? What happens if you leave it out?

Removed it and it is working fine.


>> +# gcc needs to know it's building a shared lib, otherwise it'll not emi=
t
>> +# correct code / link to the right support libraries
>> +ifeq ($(GCC), yes)
>> +LDFLAGS_SL +=3D -shared
>> +endif

>On other platforms, we have this in LINK.shared, see src/Makefile.shlib.
>Should we do the same on AIX; if not, why not?



I tried your suggestion to move the gcc "LDFLAGS_SL +=3D -shared" flag to M=
akefile.shlib,

"LINK.shared       =3D $(COMPILER) -shared", but there are some extensions =
dependent

on this in "contrib" which are not building with =93-shared=94 flag, as a r=
esult a testcase

is failing to load this library "contrib/spi/autoinc.so" . Below is the err=
or.



not ok 78    + triggers                                 2443 ms

31 +ERROR:  incompatible library "/home/pgdev/pgdb/postgres/src/test/regres=
s/autoinc.so": missing magic block

32 +HINT:  Extension libraries are required to use the PG_MODULE_MAGIC macr=
o.



I noticed that the =93-shared=94 flag was missing while building the contri=
b/spi/autoinc.so library.

I tried to add the =93include $(top_builddir)/src/Makefile.shlib=94 in the

contrib/spi/Makefile, but still the =93-shared=94 flag is not getting inclu=
ded while building

the library.
So we will continue to use the earlier change.


> Does AIX have LD_LIBRARY_PATH? This suggests that it does:
> https://www.ibm.com/support/pages/aix-libpath-recommendations
> What's the difference between LIBPATH and LD_LIBRARY_PATH? Why prefer
LIBPATH?

AIX uses only LIBPATH and  LD_LIBRARY_PATH is specific to Linux.




> Separately from the remaining issues with this patch, I still feel
> pretty reluctant with accepting this, because if I commit this patch,
> I'm on the hook to keep it working. I do regularly commit stuff that I'm
> not personally that interested in, but a new port is different:

> If something breaks on AIX, I have no means (or interest!) in debugging
> it. That means that I need to be pretty confident that there are others
> who are interested and invested in keeping working, take ownership, will
> help to debug problems in a timely fashion, and can submit high-quality
> fixes. I am not seeing that.

I completely understand your concerns about committing to a new port and
ensuring its long-term maintenance.
Our team would like to extend the support to maintain PostgreSQL on AIX.
We would like to assist by timely debugging and resolving any issues on AIX=
.
We=92re also keen to actively contribute to this effort.


> I also notice that all the AIX systems we have in the buildfarm are still=
:

> - maintained by Noah, who - correct me if I'm wrong - is not
> particularly interested in AIX or keen on maintaining them
> - are on AIX 7.1.5, which I believe is already end-of-line
> - running on power7 hardware which is 15 years old.

> That's not very reassuring.



^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-04-07 10:04  Heikki Linnakangas <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  0 siblings, 2 replies; 47+ messages in thread

From: Heikki Linnakangas @ 2025-04-07 10:04 UTC (permalink / raw)
  To: Srirama Kucherlapati <[email protected]>; pgsql-hackers; +Cc: Robert Haas <[email protected]>; Bruce Momjian <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; [email protected] <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>; wenhui qiu <[email protected]>; [email protected] <[email protected]>

On 05/04/2025 21:29, Srirama Kucherlapati wrote:
>>> - WRT to the MEMSET_LOOP_LIMIT flag, this is set to “0”, which would 
>>> internally use
> 
>> Yes, I understand what it does. But why? Whatever benchmarking was done 
>> back in 2006 by is no longer relevant.
> 
> We ran the program , mentioned in the below link and collected the
> benchmark stats on our node (POWER_10).
> 
> https://postgrespro.com/list/thread-id/1673194 <https://postgrespro.com/ 
> list/thread-id/1673194>
> 
> The native AIX memset() seems to performs better. The benchmark seems to 
> be still relevant, so I think we should continue to use the existing optimization for
> AIX.

At least it needs to be updated to match what MemSet() looks like 
nowadays. The changes may be just cosmetic, but better check. Should 
also check the effect on MemSetAligned(). That might matter more for 
performance in practice.

A third thing to check is the performance of MemSet() when the pointer 
is, in fact, aligned.

The other question is what do the results look like on other platforms? 
How much difference does the libc implementation make, vs. the compiler 
and CPU architecture? If the difference is related to compiler or CPU 
architecture, then this doesn't belong in the AIX template, but 
somewhere else.

> Below are the stats (64bit Object mode).
> 
>>> ./memset-aix
> 
>          sizeof(int)  = 4
>          sizeof(long) = 8

MemSet() uses 'long', so the int tests are not relevant. I have omitted 
them below.

>          memset by int (size=8) : 0.280301
>          Loop by long (size=8) : 0.202650
> 
>          memset by int (size=16) : 0.280979
>          Loop by long (size=16) : 0.246879
> 
>          memset by int (size=32) : 0.331691
>          Loop by long (size=32) : 0.422261

Ok, MemSet() is faster with very small sizes, the crossover is somewhere 
between 16 and 32 bytes.

I'm actually surprised the compiler doesn't replace the memset() call 
with a few store instructions with these sizes.

>          memset by int (size=1024) : 0.904048
>          Loop by long (size=1024) : 24.149871

So with larger sizes, memset() wins hands down.

I'm surprised how big the difference is, because I actually expected the 
compiler to detect the memory-zeroing loop and replace it with some 
fancy vector instructions (does powerpc have any?). Or a call to 
memset(); I've seen compilers convert loops to memset() and vice versa.

My gut feeling is actually that we should remove the MemSet() macro 
altogether and just use memset() everywhere. The compilers are much 
better at optimizing it in year 2025 than they were back in 2002. I'd 
love to see some rigorous benchmarks across different platforms and 
compilers to demonstrate that, and then just get rid of MemSet().

MemSetAligned() might still be worth keeping. Sometimes we know that a 
piece of memory is aligned, but the compiler does not. But maybe even 
that should just assert and hint the compiler that the input is aligned, 
and then call memset().

If you'd like to help the community in general, if you could do some 
more rigorous benchmarking along those lines, not just for AIX, and 
start a new thread to discuss that, that'd be much appreciated. That 
would be the best way to resolve this.

For the more narrow question of what should the AIX template do, that 
comes down to whether there's some *AIX-specific* performance 
difference. The generated powerpc assembly code is presumably the same 
on AIX and other operating systems, so it comes down to whether there's 
some big difference in AIX's memset() implementation vs. glibc's.

>> diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
> 
>> Why is this change needed?
> 
>> Yes, I know we've been over this many times already. I still don't 
>> understand why it's needed. The onus is on you to explain it adequately, 
>> in comments in the patch, so that I and others understand it. Or even 
>> better, remove it if it's not necessary.
> 
> If you recall, we previously considered replacing this assembly code 
> with __sync_lock_test_and_set(). However, as you mentioned earlier, 
> this should be handled in a separate patch. For now, I'll make a 
> note and submit a separate patch for this later, as originally
> planned. Below is the reference to older discussion.

Yes, I do recall. Please read again my comment above: this all needs to 
be explained in comments in the code.

To be precise, I have these questions:

- Does GCC on AIX (still) use the IBM assembler?
- Does the IBM assembler still not understand the label syntax?
- Is there some other label syntax that would work on the IBM assembler?
- Is it possible to use the GNU assembler instead?

>>> +# -blibpath must contain ALL directories where we should look for libraries
>>> +libpath := $(shell echo $(subst -L,:,$(filter -L/%,$(LDFLAGS))) | sed -e's/ //g'):/usr/lib:/lib
> 
>> Is this still sensible on modern AIX systems? What happens if you leave 
>> it out?
> 
> This is required as it is looking for the possible non-default 
> directories for the linker at the runtime. This is used along with
> rpath. As suggested, I tested this by removing the libpath, but at
> run time the linker is not able to find the dependent libraries path 
> as a result, the binaries are not getting loaded. After doing some 
> research, AIX uses a stricter, more*explicit* approach. The runtime
> linker expects to tell it exactly where to look using -blibpath.

Ok, some comments would be in order to explain that, maybe with links to 
the relevant AIX documentation.

-- 
Heikki Linnakangas
Neon (https://neon.tech)






^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* RE: AIX support
@ 2025-04-12 16:41  Srirama Kucherlapati <[email protected]>
  parent: Heikki Linnakangas <[email protected]>
  1 sibling, 2 replies; 47+ messages in thread

From: Srirama Kucherlapati @ 2025-04-12 16:41 UTC (permalink / raw)
  To: Heikki Linnakangas <[email protected]>; pgsql-hackers; +Cc: Robert Haas <[email protected]>; Bruce Momjian <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; [email protected] <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>; wenhui qiu <[email protected]>; [email protected] <[email protected]>

Here are some stats wrt to loop and native memset after enabling optimization with the same test tool(tested for long and long align using MemSetAligned). Corresponding glibc is linked on PPcle and AIX libc is linked on AIX.

https://postgrespro.com/list/thread-id/1673194


                                        AIX loop-1  PPCle - loop1   AIX loop-2  PPCle - loop2
    Loop by long (size=8)           :   0           0               0.000001    0
    Loop Align by long (size=8)     :   0           0               0           0
    memset by long (size=8)         :   0.00999     0.010229        0.00994     0.010211
    Loop by long (size=16)          :   0           0               0           0
    Loop Align by long (size=16)    :   0           0               0           0
    memset by long (size=16)        :   0.010082    0.010036        0.010094    0.01003
    Loop by long (size=32)          :   0.32903     0.227726        0.329027    0.227707
    Loop Align by long (size=32)    :   0.329486    0.227705        0.328932    0.227712
    memset by long (size=32)        :   0.021061    0.01064         0.021115    0.01064
    Loop by long (size=64)          :   0.334761    0.227714        0.34326     0.227688
    Loop Align by long (size=64)    :   0.329005    0.236937        0.329084    0.236906
    memset by long (size=64)        :   0.059559    0.025612        0.053004    0.029589
    Loop by long (size=128)         :   0.420381    0.329634        0.420332    0.329524
    Loop Align by long (size=128)   :   0.420376    0.337169        0.42022     0.337162
    memset by long (size=128)       :   0.420153    0.098774        0.420312    0.101888
    Loop by long (size=256)         :   0.472187    0.428049        0.472774    0.429217
    Loop Align by long (size=256)   :   0.472586    0.438316        0.472447    0.438325
    memset by long (size=256)       :   0.473731    0.428013        0.473864    0.42759
    Loop by long (size=512)         :   0.676089    0.435649        0.632774    0.43574
    Loop Align by long (size=512)   :   0.66702     0.428013        0.630751    0.427319
    memset by long (size=512)       :   0.666619    0.427989        0.691485    0.427263
    Loop by long (size=1024)        :   1.00773     0.45079         0.925212    0.452131
    Loop Align by long (size=1024)  :   0.92114     0.45084         0.920574    0.452994
    memset by long (size=1024)      :   0.935062    0.450821        0.917       0.452396
    Loop by long (size=2048)        :   1.52585     0.702127        1.265107    0.701822
    Loop Align by long (size=2048)  :   1.57524     0.702158        1.439109    0.702651
    memset by long (size=2048)      :   1.614771    0.702247        1.384672    0.701857
    Loop by long (size=4096)        :   1.418133    1.37568         1.325803    1.376005
    Loop Align by long (size=4096)  :   1.421619    1.375741        1.325743    1.376071
    memset by long (size=4096)      :   1.423404    1.375716        1.325666    1.376091

After enabling optimization levels, both are performing similar.
As both are performing similar we have removed the MEMSET_LOOP in the AIX template and tried the below benchmark after running pgbench.

    Run#1
    >> pgbench -c 50 -p 5678 -d postgres -T 180 -r -P 10  -L 10 -j 20
    pgbench (18devel)
    starting vacuum...end.
    progress: 10.0 s, 2603.2 tps, lat 18.692 ms stddev 61.947, 0 failed
    progress: 20.0 s, 3373.2 tps, lat 14.841 ms stddev 17.724, 0 failed
    progress: 30.0 s, 2599.6 tps, lat 19.222 ms stddev 99.307, 0 failed
    progress: 40.0 s, 3531.3 tps, lat 14.159 ms stddev 14.786, 0 failed
    progress: 50.0 s, 2561.3 tps, lat 15.180 ms stddev 33.532, 0 failed
    progress: 60.0 s, 3315.4 tps, lat 18.421 ms stddev 111.988, 0 failed
    progress: 70.0 s, 3517.4 tps, lat 14.203 ms stddev 14.931, 0 failed
    progress: 80.0 s, 2023.4 tps, lat 21.858 ms stddev 125.718, 0 failed
    progress: 90.0 s, 3472.1 tps, lat 16.049 ms stddev 55.152, 0 failed
    progress: 100.0 s, 3580.5 tps, lat 13.966 ms stddev 14.636, 0 failed
    progress: 110.0 s, 2823.4 tps, lat 14.572 ms stddev 20.433, 0 failed
    progress: 120.0 s, 3140.3 tps, lat 18.717 ms stddev 120.447, 0 failed
    progress: 130.0 s, 3488.4 tps, lat 14.329 ms stddev 15.057, 0 failed
    progress: 140.0 s, 2503.7 tps, lat 19.966 ms stddev 125.551, 0 failed
    progress: 150.0 s, 3083.3 tps, lat 16.212 ms stddev 56.652, 0 failed
    progress: 160.0 s, 3572.0 tps, lat 13.991 ms stddev 14.660, 0 failed
    progress: 170.0 s, 3642.2 tps, lat 13.722 ms stddev 14.507, 0 failed
    progress: 180.0 s, 2453.6 tps, lat 20.364 ms stddev 133.126, 0 failed
    transaction type: <builtin: TPC-B (sort of)>
    scaling factor: 50
    query mode: simple
    number of clients: 50
    number of threads: 20
    maximum number of tries: 1
    duration: 180 s
    number of transactions actually processed: 552889
    number of failed transactions: 0 (0.000%)
    number of transactions above the 10.0 ms latency limit: 227816/552889 (41.205%)
    latency average = 16.252 ms
    latency stddev = 69.656 ms
    initial connection time = 237.245 ms
    tps = 3074.421213 (without initial connection time)
    statement latencies in milliseconds and failures:
             0.002           0 \set aid random(1, 100000 * :scale)
             0.001           0 \set bid random(1, 1 * :scale)
             0.001           0 \set tid random(1, 10 * :scale)
             0.001           0 \set delta random(-5000, 5000)
             1.090           0 BEGIN;
             3.153           0 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
             1.462           0 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
             2.012           0 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
             4.060           0 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
             1.224           0 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_T
             3.246           0 END;


    Run#2
    >> pgbench -c 50 -p 5678 -d postgres -T 180 -r -P 10  -L 10 -j 20
    pgbench (18devel)
    starting vacuum...end.

    transaction type: <builtin: TPC-B (sort of)>
    scaling factor: 50
    query mode: simple
    number of clients: 50
    number of threads: 20
    maximum number of tries: 1
    duration: 180 s
    number of transactions actually processed: 577290
    number of failed transactions: 0 (0.000%)
    number of transactions above the 10.0 ms latency limit: 234815/577290 (40.675%)
    latency average = 15.558 ms
    latency stddev = 65.428 ms
    initial connection time = 314.109 ms
    tps = 3211.642930 (without initial connection time)
    statement latencies in milliseconds and failures:
             0.002           0 \set aid random(1, 100000 * :scale)
             0.001           0 \set bid random(1, 1 * :scale)
             0.001           0 \set tid random(1, 10 * :scale)
             0.001           0 \set delta random(-5000, 5000)
             1.084           0 BEGIN;
             2.761           0 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
             1.371           0 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
             2.000           0 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
             4.014           0 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
             1.229           0 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_T
             3.093           0 END;



>> diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h

> - Does GCC on AIX (still) use the IBM assembler?
> - Does the IBM assembler still not understand the label syntax?
> - Is there some other label syntax that would work on the IBM assembler?
> - Is it possible to use the GNU assembler instead?

GCC on AIX still uses the AIX native assembler only. The GNU assembler has some level of support in AIX through some of the patches. But still GCC/gnu assembler combination is not very much tested.

We removed AIX specific changes for TAS(), which would now use the __sync_lock_test_and_set() routines directly instead, and we ran pgbench on it.

    + pgbench -c 50 -p 5678 -d postgres -T 180 -r -P 10 -L 10 -j 20
    pgbench (18devel)
    starting vacuum...end.

    scaling factor: 50
    query mode: simple
    number of clients: 50
    number of threads: 20
    maximum number of tries: 1
    duration: 180 s
    number of transactions actually processed: 550838
    number of failed transactions: 0 (0.000%)
    number of transactions above the 10.0 ms latency limit: 227805/550838 (41.356%)
    latency average = 16.323 ms
    latency stddev = 68.404 ms
    initial connection time = 235.449 ms
    tps = 3061.041640 (without initial connection time)
    statement latencies in milliseconds and failures:
             0.002           0 \set aid random(1, 100000 * :scale)
             0.001           0 \set bid random(1, 1 * :scale)
             0.001           0 \set tid random(1, 10 * :scale)
             0.001           0 \set delta random(-5000, 5000)
             1.098           0 BEGIN;
             2.993           0 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
             1.501           0 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
             2.004           0 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
             4.127           0 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
             1.238           0 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
             3.356           0 END;



> 21  -- test overflow/underflow handling
>
> 22  SELECT gamma(float8 '-infinity');
>
> 23  ERROR:  value out of range: overflow

WRT failure in lgamma(), we worked with the libm team to resolve it. It’s an issue with the errno that is being set. I’ll work on the testcase.

   >> ./gamma-test NaN

    Gamma and natural logarithm of gamma for the input values:
    Gamma(NaNS) = NaNQ errno: 34
    lgamma(NaNS) = NaNQ errno: 34


   With fixed libm

    + ./gamma-test NaN

    Gamma and natural logarithm of gamma for the input values:
    Gamma(NaNS) = NaNQ errno: 0
    lgamma(NaNS) = NaNQ errno: 0



Warm Regards,
Sriram








^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* RE: AIX support
@ 2025-04-12 17:09  Srirama Kucherlapati <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  1 sibling, 0 replies; 47+ messages in thread

From: Srirama Kucherlapati @ 2025-04-12 17:09 UTC (permalink / raw)
  To: Heikki Linnakangas <[email protected]>; pgsql-hackers; +Cc: Robert Haas <[email protected]>; Bruce Momjian <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; [email protected] <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>; wenhui qiu <[email protected]>; [email protected] <[email protected]>

Working on the patch. I will update you.

-Sriram.


^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* RE: AIX support
@ 2025-04-15 16:20  Srirama Kucherlapati <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  1 sibling, 1 reply; 47+ messages in thread

From: Srirama Kucherlapati @ 2025-04-15 16:20 UTC (permalink / raw)
  To: Heikki Linnakangas <[email protected]>; pgsql-hackers; +Cc: Robert Haas <[email protected]>; Bruce Momjian <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; [email protected] <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>; wenhui qiu <[email protected]>; [email protected] <[email protected]>

Hi Team, Please find the attached diff with the latest changes.

The diff file changes that were done for memset and spinlock, are modified
on top of the previous patch.

New changes for review: 0001-AIX-support.tas.memset.diffs
Previous patch: 0001-AIX-support.v8.patch


>> diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
>
We have replaced the asm code with the gcc specific routines __sync_lock_test_and_set ()
and ran the pgbench. On AIX both have the similar performance, On PPcle we see a slight
variation in the performance. It seems the asm code is performing better on PPCle. Please
let us know, would it be better to continue to use the PPC assemble code over gcc routines.

Attached are the complete stats. (spinlock.stats.log)
Below is the summary…

                        AIX With asm    AIX With __sync   PPCle With asm  PPCle With __sync
number of transactions "226554/         "230810/          "356945/        "364346/
above the 10.0 ms       556329          567936            918647          863937
latency limit           (40.723%)"      (40.640%)"       (38.856%)"       (42.173%)"

latency average         16.160 ms       15.821 ms         9.796 ms        10.416 ms
initial connection time 230.786 ms      249.668 ms        19.606 ms       20.090 ms
tps                     3086.209412     3158.14915        5103.024267     4799.621896


> diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix
>
> At least it needs to be updated to match what MemSet() looks like
> nowadays. The changes may be just cosmetic, but better check. Should
> also check the effect on MemSetAligned(). That might matter more for
> performance in practice.

As per the stats in the previous mail wrt to memset, both the loop and the native
memset are performing similar after optimization “-O2”. So for now we removed the
native memset changes.
We will setup the memset performance on different platforms and will post the
details in a different thread.


>>> +# -blibpath must contain ALL directories where we should look for libraries
>>> +libpath := $(shell echo $(subst -L,:,$(filter -L/%,$(LDFLAGS))) | sed -e's/ //g'):/usr/lib:/lib
>

Added additional details about the -blibpath usage. These details are available in the below link
https://download.boulder.ibm.com/ibmdl/pub/software/dw/aix/es-aix_ll.pdf



> 21  -- test overflow/underflow handling
>
> 22  SELECT gamma(float8 '-infinity');
>
> 23  ERROR:  value out of range: overflow

This testcase is resolved from AIX libm side. Below is the result.


postgres=#
SELECT x, gamma(x),lgamma(x)
FROM (VALUES (0.5), (1), (2), (3), (4), (5),
(float8 'infinity'), (float8 'nan')) AS t(x);

      0.5 | 1.772453850905516 | 0.5723649429247001
        1 |                 1 |                  0
        2 |                 1 |                  0
        3 |                 2 | 0.6931471805599453
        4 |                 6 |  1.791759469228055
        5 |                24 | 3.1780538303479458
Infinity |          Infinity |           Infinity
      NaN |               NaN |                NaN


Kindly let us know your feedback on the diffs.
I will commit the diffs to the patch(0001-AIX-support.v8.patch) once you are fine.



Warm regards,
Sriram.



------------------------------------------
AIX with asm spin lock


>> pgbench -c 50 -p 5678 -d postgres -T 180 -r -P 10  -L 10 -j 20
pgbench (18devel)
starting vacuum...end.
progress: 10.0 s, 3181.5 tps, lat 15.331 ms stddev 17.867, 0 failed
progress: 20.0 s, 3277.2 tps, lat 14.730 ms stddev 18.792, 0 failed
progress: 30.0 s, 2642.9 tps, lat 19.556 ms stddev 106.940, 0 failed
progress: 40.0 s, 3614.3 tps, lat 13.830 ms stddev 14.673, 0 failed
progress: 50.0 s, 2355.4 tps, lat 21.208 ms stddev 132.907, 0 failed
progress: 60.0 s, 3046.8 tps, lat 16.407 ms stddev 53.507, 0 failed
progress: 70.0 s, 3640.1 tps, lat 13.734 ms stddev 14.549, 0 failed
progress: 80.0 s, 2435.2 tps, lat 20.518 ms stddev 125.603, 0 failed
progress: 90.0 s, 3576.3 tps, lat 13.977 ms stddev 14.341, 0 failed
progress: 100.0 s, 3653.9 tps, lat 13.681 ms stddev 14.554, 0 failed
progress: 110.0 s, 2414.6 tps, lat 20.684 ms stddev 134.585, 0 failed
progress: 120.0 s, 3051.6 tps, lat 16.383 ms stddev 63.253, 0 failed
progress: 130.0 s, 3657.2 tps, lat 13.667 ms stddev 14.375, 0 failed
progress: 140.0 s, 3159.0 tps, lat 14.259 ms stddev 18.915, 0 failed
progress: 150.0 s, 2889.8 tps, lat 19.006 ms stddev 121.852, 0 failed
progress: 160.0 s, 3649.0 tps, lat 13.693 ms stddev 14.288, 0 failed
progress: 170.0 s, 2799.8 tps, lat 14.552 ms stddev 17.307, 0 failed
progress: 180.0 s, 2582.9 tps, lat 22.914 ms stddev 121.785, 0 failed
transaction type: <builtin: TPC-B (sort of)>
scaling factor: 50
query mode: simple
number of clients: 50
number of threads: 20
maximum number of tries: 1
duration: 180 s
number of transactions actually processed: 556329
number of failed transactions: 0 (0.000%)
number of transactions above the 10.0 ms latency limit: 226554/556329 (40.723%)
latency average = 16.160 ms
latency stddev = 69.085 ms
initial connection time = 230.786 ms
tps = 3086.209412 (without initial connection time)
statement latencies in milliseconds and failures:
         0.002           0 \set aid random(1, 100000 * :scale)
         0.001           0 \set bid random(1, 1 * :scale)
         0.001           0 \set tid random(1, 10 * :scale)
         0.001           0 \set delta random(-5000, 5000)
         1.084           0 BEGIN;
         2.997           0 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
         1.400           0 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
         2.014           0 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
         4.094           0 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
         1.217           0 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
         3.346           0 END;




------------------------------------------
AIX with  __sync_lock_test_and_set

pgdev@roxxpg2:~/pgdb/postgres/install]
>> pgbench -c 50 -p 5678 -d postgres -T 180 -r -P 10  -L 10 -j 20
pgbench (18devel)
starting vacuum...end.
progress: 10.0 s, 3391.8 tps, lat 14.339 ms stddev 13.922, 0 failed
progress: 20.0 s, 2724.0 tps, lat 18.350 ms stddev 96.241, 0 failed
progress: 30.0 s, 3571.4 tps, lat 14.001 ms stddev 14.957, 0 failed
progress: 40.0 s, 2630.9 tps, lat 18.993 ms stddev 115.583, 0 failed
progress: 50.0 s, 3574.5 tps, lat 13.984 ms stddev 14.838, 0 failed
progress: 60.0 s, 3577.0 tps, lat 13.973 ms stddev 15.055, 0 failed
progress: 70.0 s, 2401.7 tps, lat 20.810 ms stddev 149.104, 0 failed
progress: 80.0 s, 2891.0 tps, lat 17.291 ms stddev 73.637, 0 failed
progress: 90.0 s, 3529.0 tps, lat 14.160 ms stddev 15.212, 0 failed
progress: 100.0 s, 2637.2 tps, lat 18.951 ms stddev 111.379, 0 failed
progress: 110.0 s, 3593.1 tps, lat 13.903 ms stddev 14.604, 0 failed
progress: 120.0 s, 3560.3 tps, lat 14.048 ms stddev 14.926, 0 failed
progress: 130.0 s, 3230.5 tps, lat 13.796 ms stddev 15.330, 0 failed
progress: 140.0 s, 2293.2 tps, lat 24.154 ms stddev 163.908, 0 failed
progress: 150.0 s, 3511.8 tps, lat 14.219 ms stddev 15.367, 0 failed
progress: 160.0 s, 3612.9 tps, lat 13.836 ms stddev 14.839, 0 failed
progress: 170.0 s, 2523.9 tps, lat 19.811 ms stddev 129.520, 0 failed
progress: 180.0 s, 3533.7 tps, lat 14.136 ms stddev 14.988, 0 failed
transaction type: <builtin: TPC-B (sort of)>
scaling factor: 50
query mode: simple
number of clients: 50
number of threads: 20
maximum number of tries: 1
duration: 180 s
number of transactions actually processed: 567936
number of failed transactions: 0 (0.000%)
number of transactions above the 10.0 ms latency limit: 230810/567936 (40.640%)
latency average = 15.821 ms
latency stddev = 69.610 ms
initial connection time = 249.668 ms
tps = 3158.149150 (without initial connection time)
statement latencies in milliseconds and failures:
         0.002           0 \set aid random(1, 100000 * :scale)
         0.001           0 \set bid random(1, 1 * :scale)
         0.001           0 \set tid random(1, 10 * :scale)
         0.001           0 \set delta random(-5000, 5000)
         1.092           0 BEGIN;
         2.794           0 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
         1.472           0 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
         2.040           0 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
         4.062           0 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
         1.225           0 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
         3.117           0 END;



------------------------------------------
PPCle with asm code


Pple - with asm
[pgdev@roxxpg3 install]$ pgbench -c 50 -p 5678 -d postgres -T 180 -r -P 10  -L 10 -j 20
pgbench (18devel)
starting vacuum...end.
progress: 10.0 s, 4932.9 tps, lat 10.110 ms stddev 7.215, 0 failed
progress: 20.0 s, 5041.2 tps, lat 9.916 ms stddev 6.794, 0 failed
progress: 30.0 s, 5135.3 tps, lat 9.737 ms stddev 6.572, 0 failed
progress: 40.0 s, 5085.2 tps, lat 9.830 ms stddev 6.556, 0 failed
progress: 50.0 s, 5199.0 tps, lat 9.616 ms stddev 6.579, 0 failed
progress: 60.0 s, 5173.5 tps, lat 9.663 ms stddev 6.536, 0 failed
progress: 70.0 s, 5184.9 tps, lat 9.643 ms stddev 6.796, 0 failed
progress: 80.0 s, 5205.1 tps, lat 9.605 ms stddev 6.639, 0 failed
progress: 90.0 s, 5209.5 tps, lat 9.598 ms stddev 6.636, 0 failed
progress: 100.0 s, 5141.9 tps, lat 9.723 ms stddev 6.631, 0 failed
progress: 110.0 s, 5204.0 tps, lat 9.607 ms stddev 6.494, 0 failed
progress: 120.0 s, 5187.3 tps, lat 9.638 ms stddev 6.683, 0 failed
progress: 130.0 s, 5046.7 tps, lat 9.904 ms stddev 6.820, 0 failed
progress: 140.0 s, 4643.9 tps, lat 10.768 ms stddev 7.380, 0 failed
progress: 150.0 s, 5080.3 tps, lat 9.840 ms stddev 6.681, 0 failed
progress: 160.0 s, 5152.3 tps, lat 9.705 ms stddev 6.669, 0 failed
progress: 170.0 s, 5106.7 tps, lat 9.790 ms stddev 6.518, 0 failed
progress: 180.0 s, 5130.0 tps, lat 9.743 ms stddev 6.651, 0 failed
transaction type: <builtin: TPC-B (sort of)>
scaling factor: 50
query mode: simple
number of clients: 50
number of threads: 20
maximum number of tries: 1
duration: 180 s
number of transactions actually processed: 918647
number of failed transactions: 0 (0.000%)
number of transactions above the 10.0 ms latency limit: 356945/918647 (38.856%)
latency average = 9.796 ms
latency stddev = 6.718 ms
initial connection time = 19.606 ms
tps = 5103.024267 (without initial connection time)
statement latencies in milliseconds and failures:
         0.001           0 \set aid random(1, 100000 * :scale)
         0.001           0 \set bid random(1, 1 * :scale)
         0.001           0 \set tid random(1, 10 * :scale)
         0.001           0 \set delta random(-5000, 5000)
         0.578           0 BEGIN;
         1.764           0 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
         0.595           0 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
         0.922           0 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
         2.504           0 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
         0.499           0 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
         2.956           0 END;




------------------------------------------
PPCle with __sync_lock_test_and_set


PPCle - with __sync



[pgdev@roxxpg3 install]$ pgbench -c 50 -p 5678 -d postgres -T 180 -r -P 10  -L 10 -j 20
pgbench (18devel)
starting vacuum...end.
progress: 10.0 s, 4817.2 tps, lat 10.353 ms stddev 7.367, 0 failed
progress: 20.0 s, 4737.2 tps, lat 10.552 ms stddev 7.232, 0 failed
progress: 30.0 s, 4774.7 tps, lat 10.470 ms stddev 7.186, 0 failed
progress: 40.0 s, 4892.3 tps, lat 10.219 ms stddev 7.072, 0 failed
progress: 50.0 s, 4811.5 tps, lat 10.391 ms stddev 7.123, 0 failed
progress: 60.0 s, 4883.1 tps, lat 10.242 ms stddev 6.962, 0 failed
progress: 70.0 s, 4867.8 tps, lat 10.269 ms stddev 7.049, 0 failed
progress: 80.0 s, 4886.6 tps, lat 10.228 ms stddev 7.037, 0 failed
progress: 90.0 s, 4765.9 tps, lat 10.494 ms stddev 7.149, 0 failed
progress: 100.0 s, 4902.0 tps, lat 10.198 ms stddev 7.030, 0 failed
progress: 110.0 s, 4815.3 tps, lat 10.381 ms stddev 7.208, 0 failed
progress: 120.0 s, 4807.1 tps, lat 10.400 ms stddev 7.059, 0 failed
progress: 130.0 s, 4932.0 tps, lat 10.137 ms stddev 6.973, 0 failed
progress: 140.0 s, 4880.6 tps, lat 10.244 ms stddev 7.009, 0 failed
progress: 150.0 s, 4613.2 tps, lat 10.837 ms stddev 7.594, 0 failed
progress: 160.0 s, 4335.8 tps, lat 11.533 ms stddev 7.776, 0 failed
progress: 170.0 s, 4904.0 tps, lat 10.194 ms stddev 6.935, 0 failed
progress: 180.0 s, 4762.6 tps, lat 10.501 ms stddev 7.194, 0 failed
transaction type: <builtin: TPC-B (sort of)>
scaling factor: 50
query mode: simple
number of clients: 50
number of threads: 20
maximum number of tries: 1
duration: 180 s
number of transactions actually processed: 863937
number of failed transactions: 0 (0.000%)
number of transactions above the 10.0 ms latency limit: 364346/863937 (42.173%)
latency average = 10.416 ms
latency stddev = 7.168 ms
initial connection time = 20.090 ms
tps = 4799.621896 (without initial connection time)
statement latencies in milliseconds and failures:
         0.001           0 \set aid random(1, 100000 * :scale)
         0.001           0 \set bid random(1, 1 * :scale)
         0.001           0 \set tid random(1, 10 * :scale)
         0.001           0 \set delta random(-5000, 5000)
         0.628           0 BEGIN;
         1.793           0 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
         0.627           0 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
         0.977           0 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
         2.694           0 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
         0.525           0 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
         3.194           0 END;




------------------------------------------


Attachments:

  [application/octet-stream] 0001-AIX-support.tas.memset.diffs (3.2K, 3-0001-AIX-support.tas.memset.diffs)
  download

  [text/plain] spinlock.stats.log (11.0K, 4-spinlock.stats.log)
  download | inline:
------------------------------------------
AIX with asm spin lock


>> pgbench -c 50 -p 5678 -d postgres -T 180 -r -P 10  -L 10 -j 20
pgbench (18devel)
starting vacuum...end.
progress: 10.0 s, 3181.5 tps, lat 15.331 ms stddev 17.867, 0 failed
progress: 20.0 s, 3277.2 tps, lat 14.730 ms stddev 18.792, 0 failed
progress: 30.0 s, 2642.9 tps, lat 19.556 ms stddev 106.940, 0 failed
progress: 40.0 s, 3614.3 tps, lat 13.830 ms stddev 14.673, 0 failed
progress: 50.0 s, 2355.4 tps, lat 21.208 ms stddev 132.907, 0 failed
progress: 60.0 s, 3046.8 tps, lat 16.407 ms stddev 53.507, 0 failed
progress: 70.0 s, 3640.1 tps, lat 13.734 ms stddev 14.549, 0 failed
progress: 80.0 s, 2435.2 tps, lat 20.518 ms stddev 125.603, 0 failed
progress: 90.0 s, 3576.3 tps, lat 13.977 ms stddev 14.341, 0 failed
progress: 100.0 s, 3653.9 tps, lat 13.681 ms stddev 14.554, 0 failed
progress: 110.0 s, 2414.6 tps, lat 20.684 ms stddev 134.585, 0 failed
progress: 120.0 s, 3051.6 tps, lat 16.383 ms stddev 63.253, 0 failed
progress: 130.0 s, 3657.2 tps, lat 13.667 ms stddev 14.375, 0 failed
progress: 140.0 s, 3159.0 tps, lat 14.259 ms stddev 18.915, 0 failed
progress: 150.0 s, 2889.8 tps, lat 19.006 ms stddev 121.852, 0 failed
progress: 160.0 s, 3649.0 tps, lat 13.693 ms stddev 14.288, 0 failed
progress: 170.0 s, 2799.8 tps, lat 14.552 ms stddev 17.307, 0 failed
progress: 180.0 s, 2582.9 tps, lat 22.914 ms stddev 121.785, 0 failed
transaction type: <builtin: TPC-B (sort of)>
scaling factor: 50
query mode: simple
number of clients: 50
number of threads: 20
maximum number of tries: 1
duration: 180 s
number of transactions actually processed: 556329
number of failed transactions: 0 (0.000%)
number of transactions above the 10.0 ms latency limit: 226554/556329 (40.723%)
latency average = 16.160 ms
latency stddev = 69.085 ms
initial connection time = 230.786 ms
tps = 3086.209412 (without initial connection time)
statement latencies in milliseconds and failures:
         0.002           0 \set aid random(1, 100000 * :scale)
         0.001           0 \set bid random(1, 1 * :scale)
         0.001           0 \set tid random(1, 10 * :scale)
         0.001           0 \set delta random(-5000, 5000)
         1.084           0 BEGIN;
         2.997           0 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
         1.400           0 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
         2.014           0 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
         4.094           0 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
         1.217           0 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
         3.346           0 END;




------------------------------------------
AIX with  __sync_lock_test_and_set

pgdev@roxxpg2:~/pgdb/postgres/install]
>> pgbench -c 50 -p 5678 -d postgres -T 180 -r -P 10  -L 10 -j 20
pgbench (18devel)
starting vacuum...end.
progress: 10.0 s, 3391.8 tps, lat 14.339 ms stddev 13.922, 0 failed
progress: 20.0 s, 2724.0 tps, lat 18.350 ms stddev 96.241, 0 failed
progress: 30.0 s, 3571.4 tps, lat 14.001 ms stddev 14.957, 0 failed
progress: 40.0 s, 2630.9 tps, lat 18.993 ms stddev 115.583, 0 failed
progress: 50.0 s, 3574.5 tps, lat 13.984 ms stddev 14.838, 0 failed
progress: 60.0 s, 3577.0 tps, lat 13.973 ms stddev 15.055, 0 failed
progress: 70.0 s, 2401.7 tps, lat 20.810 ms stddev 149.104, 0 failed
progress: 80.0 s, 2891.0 tps, lat 17.291 ms stddev 73.637, 0 failed
progress: 90.0 s, 3529.0 tps, lat 14.160 ms stddev 15.212, 0 failed
progress: 100.0 s, 2637.2 tps, lat 18.951 ms stddev 111.379, 0 failed
progress: 110.0 s, 3593.1 tps, lat 13.903 ms stddev 14.604, 0 failed
progress: 120.0 s, 3560.3 tps, lat 14.048 ms stddev 14.926, 0 failed
progress: 130.0 s, 3230.5 tps, lat 13.796 ms stddev 15.330, 0 failed
progress: 140.0 s, 2293.2 tps, lat 24.154 ms stddev 163.908, 0 failed
progress: 150.0 s, 3511.8 tps, lat 14.219 ms stddev 15.367, 0 failed
progress: 160.0 s, 3612.9 tps, lat 13.836 ms stddev 14.839, 0 failed
progress: 170.0 s, 2523.9 tps, lat 19.811 ms stddev 129.520, 0 failed
progress: 180.0 s, 3533.7 tps, lat 14.136 ms stddev 14.988, 0 failed
transaction type: <builtin: TPC-B (sort of)>
scaling factor: 50
query mode: simple
number of clients: 50
number of threads: 20
maximum number of tries: 1
duration: 180 s
number of transactions actually processed: 567936
number of failed transactions: 0 (0.000%)
number of transactions above the 10.0 ms latency limit: 230810/567936 (40.640%)
latency average = 15.821 ms
latency stddev = 69.610 ms
initial connection time = 249.668 ms
tps = 3158.149150 (without initial connection time)
statement latencies in milliseconds and failures:
         0.002           0 \set aid random(1, 100000 * :scale)
         0.001           0 \set bid random(1, 1 * :scale)
         0.001           0 \set tid random(1, 10 * :scale)
         0.001           0 \set delta random(-5000, 5000)
         1.092           0 BEGIN;
         2.794           0 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
         1.472           0 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
         2.040           0 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
         4.062           0 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
         1.225           0 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
         3.117           0 END;



------------------------------------------
PPCle with asm code


Pple - with asm
[pgdev@roxxpg3 install]$ pgbench -c 50 -p 5678 -d postgres -T 180 -r -P 10  -L 10 -j 20
pgbench (18devel)
starting vacuum...end.
progress: 10.0 s, 4932.9 tps, lat 10.110 ms stddev 7.215, 0 failed
progress: 20.0 s, 5041.2 tps, lat 9.916 ms stddev 6.794, 0 failed
progress: 30.0 s, 5135.3 tps, lat 9.737 ms stddev 6.572, 0 failed
progress: 40.0 s, 5085.2 tps, lat 9.830 ms stddev 6.556, 0 failed
progress: 50.0 s, 5199.0 tps, lat 9.616 ms stddev 6.579, 0 failed
progress: 60.0 s, 5173.5 tps, lat 9.663 ms stddev 6.536, 0 failed
progress: 70.0 s, 5184.9 tps, lat 9.643 ms stddev 6.796, 0 failed
progress: 80.0 s, 5205.1 tps, lat 9.605 ms stddev 6.639, 0 failed
progress: 90.0 s, 5209.5 tps, lat 9.598 ms stddev 6.636, 0 failed
progress: 100.0 s, 5141.9 tps, lat 9.723 ms stddev 6.631, 0 failed
progress: 110.0 s, 5204.0 tps, lat 9.607 ms stddev 6.494, 0 failed
progress: 120.0 s, 5187.3 tps, lat 9.638 ms stddev 6.683, 0 failed
progress: 130.0 s, 5046.7 tps, lat 9.904 ms stddev 6.820, 0 failed
progress: 140.0 s, 4643.9 tps, lat 10.768 ms stddev 7.380, 0 failed
progress: 150.0 s, 5080.3 tps, lat 9.840 ms stddev 6.681, 0 failed
progress: 160.0 s, 5152.3 tps, lat 9.705 ms stddev 6.669, 0 failed
progress: 170.0 s, 5106.7 tps, lat 9.790 ms stddev 6.518, 0 failed
progress: 180.0 s, 5130.0 tps, lat 9.743 ms stddev 6.651, 0 failed
transaction type: <builtin: TPC-B (sort of)>
scaling factor: 50
query mode: simple
number of clients: 50
number of threads: 20
maximum number of tries: 1
duration: 180 s
number of transactions actually processed: 918647
number of failed transactions: 0 (0.000%)
number of transactions above the 10.0 ms latency limit: 356945/918647 (38.856%)
latency average = 9.796 ms
latency stddev = 6.718 ms
initial connection time = 19.606 ms
tps = 5103.024267 (without initial connection time)
statement latencies in milliseconds and failures:
         0.001           0 \set aid random(1, 100000 * :scale)
         0.001           0 \set bid random(1, 1 * :scale)
         0.001           0 \set tid random(1, 10 * :scale)
         0.001           0 \set delta random(-5000, 5000)
         0.578           0 BEGIN;
         1.764           0 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
         0.595           0 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
         0.922           0 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
         2.504           0 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
         0.499           0 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
         2.956           0 END;




------------------------------------------
PPCle with __sync_lock_test_and_set


PPCle - with __sync



[pgdev@roxxpg3 install]$ pgbench -c 50 -p 5678 -d postgres -T 180 -r -P 10  -L 10 -j 20
pgbench (18devel)
starting vacuum...end.
progress: 10.0 s, 4817.2 tps, lat 10.353 ms stddev 7.367, 0 failed
progress: 20.0 s, 4737.2 tps, lat 10.552 ms stddev 7.232, 0 failed
progress: 30.0 s, 4774.7 tps, lat 10.470 ms stddev 7.186, 0 failed
progress: 40.0 s, 4892.3 tps, lat 10.219 ms stddev 7.072, 0 failed
progress: 50.0 s, 4811.5 tps, lat 10.391 ms stddev 7.123, 0 failed
progress: 60.0 s, 4883.1 tps, lat 10.242 ms stddev 6.962, 0 failed
progress: 70.0 s, 4867.8 tps, lat 10.269 ms stddev 7.049, 0 failed
progress: 80.0 s, 4886.6 tps, lat 10.228 ms stddev 7.037, 0 failed
progress: 90.0 s, 4765.9 tps, lat 10.494 ms stddev 7.149, 0 failed
progress: 100.0 s, 4902.0 tps, lat 10.198 ms stddev 7.030, 0 failed
progress: 110.0 s, 4815.3 tps, lat 10.381 ms stddev 7.208, 0 failed
progress: 120.0 s, 4807.1 tps, lat 10.400 ms stddev 7.059, 0 failed
progress: 130.0 s, 4932.0 tps, lat 10.137 ms stddev 6.973, 0 failed
progress: 140.0 s, 4880.6 tps, lat 10.244 ms stddev 7.009, 0 failed
progress: 150.0 s, 4613.2 tps, lat 10.837 ms stddev 7.594, 0 failed
progress: 160.0 s, 4335.8 tps, lat 11.533 ms stddev 7.776, 0 failed
progress: 170.0 s, 4904.0 tps, lat 10.194 ms stddev 6.935, 0 failed
progress: 180.0 s, 4762.6 tps, lat 10.501 ms stddev 7.194, 0 failed
transaction type: <builtin: TPC-B (sort of)>
scaling factor: 50
query mode: simple
number of clients: 50
number of threads: 20
maximum number of tries: 1
duration: 180 s
number of transactions actually processed: 863937
number of failed transactions: 0 (0.000%)
number of transactions above the 10.0 ms latency limit: 364346/863937 (42.173%)
latency average = 10.416 ms
latency stddev = 7.168 ms
initial connection time = 20.090 ms
tps = 4799.621896 (without initial connection time)
statement latencies in milliseconds and failures:
         0.001           0 \set aid random(1, 100000 * :scale)
         0.001           0 \set bid random(1, 1 * :scale)
         0.001           0 \set tid random(1, 10 * :scale)
         0.001           0 \set delta random(-5000, 5000)
         0.628           0 BEGIN;
         1.793           0 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
         0.627           0 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
         0.977           0 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
         2.694           0 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
         0.525           0 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
         3.194           0 END;




------------------------------------------

  [application/octet-stream] 0001-AIX-support.v8.patch (14.1K, 5-0001-AIX-support.v8.patch)
  download | inline diff:
From c854025252ca3dfff9f7f1c4d4aed21cf0cf5346 Mon Sep 17 00:00:00 2001
From: Sriram RK <[email protected]>
Date: Fri, 4 Apr 2025 13:16:21 -0500
Subject: [PATCH] AIX support.

---
 Makefile                           |  2 -
 configure                          | 34 ++++++++++++++---
 configure.ac                       | 34 ++++++++++++++---
 src/Makefile.shlib                 | 29 ++++++++++++++
 src/backend/Makefile               | 20 ++++++++++
 src/backend/port/aix/mkldexport.sh | 61 ++++++++++++++++++++++++++++++
 src/backend/utils/error/elog.c     |  2 +
 src/include/port/aix.h             |  4 ++
 src/include/storage/s_lock.h       | 10 ++---
 src/makefiles/Makefile.aix         | 29 ++++++++++++++
 src/port/strerror.c                |  2 +
 src/template/aix                   |  7 ++++
 12 files changed, 214 insertions(+), 20 deletions(-)
 create mode 100755 src/backend/port/aix/mkldexport.sh
 create mode 100644 src/include/port/aix.h
 create mode 100644 src/makefiles/Makefile.aix
 create mode 100644 src/template/aix

diff --git a/Makefile b/Makefile
index 8a2ec9396b6..9bc1a4ec17b 100644
--- a/Makefile
+++ b/Makefile
@@ -13,8 +13,6 @@
 
 # AIX make defaults to building *every* target of the first rule.  Start with
 # a single-target, empty rule to make the other targets non-default.
-# (We don't support AIX anymore, but if someone tries to build on AIX anyway,
-# at least they'll get the instructions to run 'configure' first.)
 all:
 
 all check install installdirs installcheck installcheck-parallel uninstall clean distclean maintainer-clean dist distcheck world check-world install-world installcheck-world:
diff --git a/configure b/configure
index 11615d1122d..6088fa26679 100755
--- a/configure
+++ b/configure
@@ -3008,6 +3008,7 @@ else
 # --with-template not given
 
 case $host_os in
+  aix*) template=aix ;;
   cygwin*|msys*) template=cygwin ;;
   darwin*) template=darwin ;;
 dragonfly*) template=netbsd ;;
@@ -16953,13 +16954,34 @@ _ACEOF
 # wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
 # much of a penalty for disk and memory space.
 
-MAX_ALIGNOF=$ac_cv_alignof_double
+if test "$PORTNAME" != "aix"; then
+    MAX_ALIGNOF=$ac_cv_alignof_double
+
+    if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
+      as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+    if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
+      as_fn_error $? "alignment of 'long long int' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+else
+# The AIX 'power' alignment rules apply the natural alignment of the "first
+# member" if it is of a floating-point data type (or is an aggregate whose
+# recursively "first" member or element is such a type). The alignment
+# associated with these types for subsequent members use an alignment value
+# where the floating-point data type is considered to have 4-byte alignment.
+# More info
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99557
+#
+# The double is aligned to 4-bytes on AIX in aggregates. But to maintain
+# alignement across platforms the max alignment of long should be considered.
+    MAX_ALIGNOF=$ac_cv_alignof_long
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_double ; then
+      MAX_ALIGNOF=$ac_cv_alignof_double
+    fi
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_int64_t; then
+      MAX_ALIGNOF="$ac_cv_alignof_int64_t"
+    fi
 
-if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
-  as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
-fi
-if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
-  as_fn_error $? "alignment of 'int64_t' is greater than the alignment of 'double'" "$LINENO" 5
 fi
 
 cat >>confdefs.h <<_ACEOF
diff --git a/configure.ac b/configure.ac
index debdf165044..c21aaa52064 100644
--- a/configure.ac
+++ b/configure.ac
@@ -62,6 +62,7 @@ PGAC_ARG_REQ(with, template, [NAME], [override operating system template],
 # --with-template not given
 
 case $host_os in
+  aix*) template=aix ;;
   cygwin*|msys*) template=cygwin ;;
   darwin*) template=darwin ;;
 dragonfly*) template=netbsd ;;
@@ -1987,13 +1988,34 @@ AC_CHECK_ALIGNOF(double)
 # wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
 # much of a penalty for disk and memory space.
 
-MAX_ALIGNOF=$ac_cv_alignof_double
+if test "$PORTNAME" != "aix"; then
+    MAX_ALIGNOF=$ac_cv_alignof_double
+
+    if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
+      as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+    if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF; then
+      as_fn_error $? "alignment of 'long long int' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+else
+# The AIX 'power' alignment rules apply the natural alignment of the "first
+# member" if it is of a floating-point data type (or is an aggregate whose
+# recursively "first" member or element is such a type). The alignment
+# associated with these types for subsequent members use an alignment value
+# where the floating-point data type is considered to have 4-byte alignment.
+# More info
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99557
+# 
+# The double is aligned to 4-bytes on AIX in aggregates. But to maintain
+# alignement across platforms the max alignment of long should be considered.
+    MAX_ALIGNOF=$ac_cv_alignof_long
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_double ; then
+      MAX_ALIGNOF=$ac_cv_alignof_double
+    fi
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_int64_t ; then
+      MAX_ALIGNOF="$ac_cv_alignof_int64_t"
+    fi
 
-if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
-  AC_MSG_ERROR([alignment of 'long' is greater than the alignment of 'double'])
-fi
-if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
-  AC_MSG_ERROR([alignment of 'int64_t' is greater than the alignment of 'double'])
 fi
 AC_DEFINE_UNQUOTED(MAXIMUM_ALIGNOF, $MAX_ALIGNOF, [Define as the maximum alignment requirement of any C data type.])
 
diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index fa81f6ffdd6..13ea84ac185 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -106,6 +106,20 @@ ifdef SO_MAJOR_VERSION
 override CPPFLAGS += -DSO_MAJOR_VERSION=$(SO_MAJOR_VERSION)
 endif
 
+ifeq ($(PORTNAME), aix)
+  LINK.shared		= $(COMPILER)
+  ifdef SO_MAJOR_VERSION
+    shlib		= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
+  endif
+  haslibarule   = yes
+  # $(exports_file) is also usable as an import file
+  exports_file		= lib$(NAME).exp
+  BUILD.exports		= ( echo '\#! $(shlib)'; $(AWK) '/^[^\#]/ {printf "%s\n",$$1}' $< ) > $@
+  ifneq (,$(SHLIB_EXPORTS))
+    LINK.shared		+= -Wl,-bE:$(exports_file)
+  endif
+endif
+
 ifeq ($(PORTNAME), darwin)
   ifdef soname
     # linkable library
@@ -254,6 +268,14 @@ $(stlib): $(OBJS) | $(SHLIB_PREREQS)
 	touch $@
 endif #haslibarule
 
+# AIX wraps both shared libraries and static library, which can be used both
+# for static and shared linking
+ifeq ($(PORTNAME), aix)
+$(stlib): $(shlib)
+	rm -f $(stlib)
+	$(AR) $(AROPT) $(stlib) $(shlib)
+endif # aix
+
 ifeq (,$(filter cygwin win32,$(PORTNAME)))
 
 # Normal case
@@ -267,8 +289,11 @@ ifneq ($(shlib), $(shlib_major))
 endif
 # Make sure we have a link to a name without any version numbers
 ifneq ($(shlib), $(shlib_bare))
+# except on AIX, where that's not a thing
+ifneq ($(PORTNAME), aix)
 	rm -f $(shlib_bare)
 	$(LN_S) $(shlib) $(shlib_bare)
+endif # aix
 endif # shlib_bare
 endif # shlib_major
 
@@ -376,6 +401,9 @@ install-lib-static: $(stlib) installdirs-lib
 
 install-lib-shared: $(shlib) installdirs-lib
 ifdef soname
+# we don't install $(shlib) on AIX
+# (see http://archives.postgresql.org/message-id/52EF20B2E3209443BC37736D00C3C1380A6E79FE@EXADV1.host.magwien.gv.at)
+ifneq ($(PORTNAME), aix)
 	$(INSTALL_SHLIB) $< '$(DESTDIR)$(libdir)/$(shlib)'
 ifneq ($(PORTNAME), cygwin)
 ifneq ($(PORTNAME), win32)
@@ -391,6 +419,7 @@ ifneq ($(shlib), $(shlib_bare))
 endif
 endif # not win32
 endif # not cygwin
+endif # not aix
 ifneq (,$(findstring $(PORTNAME),win32 cygwin))
 	$(INSTALL_SHLIB) $< '$(DESTDIR)$(bindir)/$(shlib)'
 endif
diff --git a/src/backend/Makefile b/src/backend/Makefile
index 7344c8c7f5c..572f5430a60 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -63,12 +63,14 @@ all: submake-libpgport submake-catalog-headers submake-utils-headers postgres $(
 
 ifneq ($(PORTNAME), cygwin)
 ifneq ($(PORTNAME), win32)
+ifneq ($(PORTNAME), aix)
 
 postgres: $(OBJS)
 	$(CC) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LIBS) -o $@
 
 endif
 endif
+endif
 
 ifeq ($(PORTNAME), cygwin)
 
@@ -95,6 +97,24 @@ libpostgres.a: postgres
 
 endif # win32
 
+ifeq ($(PORTNAME), aix)
+
+postgres: $(POSTGRES_IMP)
+	$(CC) $(CFLAGS) $(call expand_subsys,$(OBJS)) $(LDFLAGS) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -Wl,-brtllib -o $@
+
+# Linking to a single .o with -r is a lot faster than building a .a or passing
+# all objects to MKLDEXPORT.
+#
+# It looks alluring to use $(CC) -r instead of ld -r, but that doesn't
+# trivially work with gcc, due to gcc specific static libraries linked in with
+# -r.
+$(POSTGRES_IMP): $(OBJS)
+	ld -r -o SUBSYS.o $(call expand_subsys,$^)
+	$(MKLDEXPORT) SUBSYS.o . > $@
+	@rm -f SUBSYS.o
+
+endif # aix
+
 $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
 
 
diff --git a/src/backend/port/aix/mkldexport.sh b/src/backend/port/aix/mkldexport.sh
new file mode 100755
index 00000000000..adf3793e868
--- /dev/null
+++ b/src/backend/port/aix/mkldexport.sh
@@ -0,0 +1,61 @@
+#!/bin/sh
+#
+# mkldexport
+#	create an AIX exports file from an object file
+#
+# src/backend/port/aix/mkldexport.sh
+#
+# Usage:
+#	mkldexport objectfile [location]
+# where
+#	objectfile is the current location of the object file.
+#	location is the eventual (installed) location of the
+#		object file (if different from the current
+#		working directory).
+#
+# [This file comes from the Postgres 4.2 distribution. - ay 7/95]
+#
+# Header: /usr/local/devel/postgres/src/tools/mkldexport/RCS/mkldexport.sh,v 1.2 1994/03/13 04:59:12 aoki Exp
+#
+
+# setting this to nm -B might be better
+# ... due to changes in AIX 4.x ...
+# ... let us search in different directories - Gerhard Reithofer
+if [ -x /usr/ucb/nm ]
+then NM=/usr/ucb/nm
+elif [ -x /usr/bin/nm ]
+then NM=/usr/bin/nm
+elif [ -x /usr/ccs/bin/nm ]
+then NM=/usr/ccs/bin/nm
+elif [ -x /usr/usg/bin/nm ]
+then NM=/usr/usg/bin/nm
+else echo "Fatal error: cannot find `nm' ... please check your installation."
+     exit 1
+fi
+
+CMDNAME=`basename $0`
+if [ -z "$1" ]; then
+	echo "Usage: $CMDNAME object [location]"
+	exit 1
+fi
+OBJNAME=`basename $1`
+if [ "`basename $OBJNAME`" != "`basename $OBJNAME .o`" ]; then
+	OBJNAME=`basename $OBJNAME .o`.so
+fi
+if [ -z "$2" ]; then
+	echo '#!'
+else
+	if [ "$2" = "." ]; then
+		# for the base executable (AIX 4.2 and up)
+		echo '#! .'
+	else
+		echo '#!' $2
+	fi
+fi
+$NM -BCg $1 | \
+	egrep ' [TDB] ' | \
+	sed -e 's/.* //' | \
+	egrep -v '\$' | \
+	sed -e 's/^[.]//' | \
+	sort | \
+	uniq
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 8a6b6905079..3a8e9dc30b0 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -904,7 +904,9 @@ errcode_for_file_access(void)
 			/* Wrong object type or state */
 		case ENOTDIR:			/* Not a directory */
 		case EISDIR:			/* Is a directory */
+#if defined(ENOTEMPTY) && (ENOTEMPTY != EEXIST) /* same code on AIX */
 		case ENOTEMPTY:			/* Directory not empty */
+#endif
 			edata->sqlerrcode = ERRCODE_WRONG_OBJECT_TYPE;
 			break;
 
diff --git a/src/include/port/aix.h b/src/include/port/aix.h
new file mode 100644
index 00000000000..7d08480c8c0
--- /dev/null
+++ b/src/include/port/aix.h
@@ -0,0 +1,4 @@
+/*
+ * src/include/port/aix.h
+ */
+
diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
index 2f73f9fcf57..5da9b3acda4 100644
--- a/src/include/storage/s_lock.h
+++ b/src/include/storage/s_lock.h
@@ -421,17 +421,15 @@ tas(volatile slock_t *lock)
 	__asm__ __volatile__(
 "	lwarx   %0,0,%3,1	\n"
 "	cmpwi   %0,0		\n"
-"	bne     1f			\n"
+"	bne     $+16		\n"		/* branch to li %1,1 */
 "	addi    %0,%0,1		\n"
 "	stwcx.  %0,0,%3		\n"
-"	beq     2f			\n"
-"1: \n"
+"	beq     $+12		\n"		/* branch to lwsync */
 "	li      %1,1		\n"
-"	b       3f			\n"
-"2: \n"
+"	b       $+12		\n"		/* branch to end of asm sequence */
 "	lwsync				\n"
 "	li      %1,0		\n"
-"3: \n"
+
 :	"=&b"(_t), "=r"(_res), "+m"(*lock)
 :	"r"(lock)
 :	"memory", "cc");
diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix
new file mode 100644
index 00000000000..ab6581533d8
--- /dev/null
+++ b/src/makefiles/Makefile.aix
@@ -0,0 +1,29 @@
+# -blibpath must contain ALL directories where we should look for libraries
+libpath := $(shell echo $(subst -L,:,$(filter -L/%,$(LDFLAGS))) | sed -e's/ //g'):/usr/lib:/lib
+
+# AIX uses a stricter, more explicit approach. The runtime linker expects 
+# to tell it exactly where to look using -blibpath.
+rpath = -Wl,-blibpath:'$(rpathdir)$(libpath)'
+
+# gcc needs to know it's building a shared lib, otherwise it'll not emit
+# correct code / link to the right support libraries
+ifeq ($(GCC), yes)
+LDFLAGS_SL += -shared
+endif
+
+# env var name to use in place of LD_LIBRARY_PATH
+ld_library_path_var = LIBPATH
+
+POSTGRES_IMP= postgres.imp
+
+ifdef PGXS
+BE_DLLLIBS= -Wl,-bI:$(pkglibdir)/$(POSTGRES_IMP)
+else
+BE_DLLLIBS= -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP)
+endif
+
+MKLDEXPORT_DIR=src/backend/port/aix
+MKLDEXPORT=$(top_srcdir)/$(MKLDEXPORT_DIR)/mkldexport.sh
+
+%$(DLSUFFIX): %.o
+	$(CC) $(CFLAGS) $*.o $(LDFLAGS) $(LDFLAGS_SL) -o $@ $(BE_DLLLIBS)
diff --git a/src/port/strerror.c b/src/port/strerror.c
index f0746517770..c46b9dc91fc 100644
--- a/src/port/strerror.c
+++ b/src/port/strerror.c
@@ -214,8 +214,10 @@ get_errno_symbol(int errnum)
 			return "ENOTCONN";
 		case ENOTDIR:
 			return "ENOTDIR";
+#if defined(ENOTEMPTY) && (ENOTEMPTY != EEXIST) /* same code on AIX */
 		case ENOTEMPTY:
 			return "ENOTEMPTY";
+#endif
 		case ENOTSOCK:
 			return "ENOTSOCK";
 #ifdef ENOTSUP
diff --git a/src/template/aix b/src/template/aix
new file mode 100644
index 00000000000..48a3ce55cf7
--- /dev/null
+++ b/src/template/aix
@@ -0,0 +1,7 @@
+# src/template/aix
+
+# Extra CFLAGS for code that will go into a shared library
+CFLAGS_SL=""
+
+# Native memset() is faster.
+MEMSET_LOOP_LIMIT=0
-- 
2.41.0



^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-04-25 01:31  Thomas Munro <[email protected]>
  parent: Heikki Linnakangas <[email protected]>
  1 sibling, 0 replies; 47+ messages in thread

From: Thomas Munro @ 2025-04-25 01:31 UTC (permalink / raw)
  To: Heikki Linnakangas <[email protected]>; +Cc: Srirama Kucherlapati <[email protected]>; pgsql-hackers; Robert Haas <[email protected]>; Bruce Momjian <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; [email protected] <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>; wenhui qiu <[email protected]>; [email protected] <[email protected]>

On Mon, Apr 7, 2025 at 10:04 PM Heikki Linnakangas <[email protected]> wrote:
> I'm surprised how big the difference is, because I actually expected the
> compiler to detect the memory-zeroing loop and replace it with some
> fancy vector instructions (does powerpc have any?).

It certainly does, and we've played with explicit AltiVec
vectorisation before with the idea that our abstraction over x86 and
ARM instructions could be extended to POWER, but that was just trying
stuff and learning while wondering if those abstractions are general
enough and how well all the instructions match up.  No one with modern
hardware and a vested interest has seriously investigated it.  That's
independent of automatic vectorisation done by the compiler or libc,
and I guess it would not really be AIX-specific since it would also
apply to Linux on POWER.  One of those patches is linked from this
small list of "ideas for a future PostgreSQL/AIX maintainer":

https://wiki.postgresql.org/wiki/AIX






^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* RE: AIX support
@ 2025-09-03 16:44  Srirama Kucherlapati <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  0 siblings, 2 replies; 47+ messages in thread

From: Srirama Kucherlapati @ 2025-09-03 16:44 UTC (permalink / raw)
  To: Heikki Linnakangas <[email protected]>; pgsql-hackers; +Cc: Robert Haas <[email protected]>; Bruce Momjian <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; [email protected] <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>; wenhui qiu <[email protected]>; [email protected] <[email protected]>


Hi Heikki and team,


As part of our ongoing efforts to enhance AIX platform compatibility, we’ve been running the code across all stable PostgreSQL release branches using the build farm infrastructure. All test suites, including TAP tests, are passing consistently, indicating no regressions.

https://buildfarm.postgresql.org/cgi-bin/show_history.pl?nm=douc&br=REL_13_STABLE
https://buildfarm.postgresql.org/cgi-bin/show_history.pl?nm=douc&br=REL_14_STABLE
https://buildfarm.postgresql.org/cgi-bin/show_history.pl?nm=douc&br=REL_15_STABLE
https://buildfarm.postgresql.org/cgi-bin/show_history.pl?nm=douc&br=REL_16_STABLE << Also tested locally.

To further validated the patch, we executed the build farm scripts locally for PostgreSQL 17 and 18 on AIX. The corresponding test results are attached for reference.

We value your feedback and would appreciate your insights on the attached patch. Kindly request you to review and share your comments.


Warm regards,
Sriram.



Sun Aug 10 22:34:32 2025: buildfarm run for urus:REL_16_STABLE starting
urus:REL_16_STABLE [22:34:43] checking out source ...
running git clone -q /home/pgdev/bfarm/build-farm-19.1.16/buildroot/pgmirror.git "/home/pgdev/bfarm/build-farm-19.1.16/buildroot/HEAD/pgsql"
urus:REL_16_STABLE [22:41:18] checking if build run needed ...
urus:REL_16_STABLE [22:41:18] copying source to pgsql.build ...
urus:REL_16_STABLE [22:41:27] running configure ...
urus:REL_16_STABLE [22:42:11] running build ...
urus:REL_16_STABLE [22:53:07] running basic regression tests ...
urus:REL_16_STABLE [22:54:23] running make contrib ...
urus:REL_16_STABLE [22:55:29] running make testmodules ...
urus:REL_16_STABLE [22:55:39] running install ...
urus:REL_16_STABLE [22:56:09] running make contrib install ...
urus:REL_16_STABLE [22:56:19] running testmodules install ...
urus:REL_16_STABLE [22:56:24] running make check miscellaneous modules ...
urus:REL_16_STABLE [22:57:41] running bin test initdb ...
urus:REL_16_STABLE [22:57:52] running bin test pg_amcheck ...
urus:REL_16_STABLE [22:58:11] running bin test pg_archivecleanup ...
urus:REL_16_STABLE [22:58:12] running bin test pg_basebackup ...
urus:REL_16_STABLE [22:59:02] running bin test pg_checksums ...
urus:REL_16_STABLE [22:59:09] running bin test pg_config ...
urus:REL_16_STABLE [22:59:09] running bin test pg_controldata ...
urus:REL_16_STABLE [22:59:12] running bin test pg_ctl ...
urus:REL_16_STABLE [22:59:31] running bin test pg_dump ...
urus:REL_16_STABLE [23:00:10] running bin test pg_resetwal ...
urus:REL_16_STABLE [23:00:15] running bin test pg_rewind ...
urus:REL_16_STABLE [23:01:49] running bin test pg_test_fsync ...
urus:REL_16_STABLE [23:01:50] running bin test pg_test_timing ...
urus:REL_16_STABLE [23:01:50] running bin test pg_upgrade ...
urus:REL_16_STABLE [23:02:55] running bin test pg_verifybackup ...
urus:REL_16_STABLE [23:03:57] running bin test pg_waldump ...
urus:REL_16_STABLE [23:04:01] running bin test pgbench ...
urus:REL_16_STABLE [23:04:13] running bin test psql ...
urus:REL_16_STABLE [23:04:20] running bin test scripts ...
urus:REL_16_STABLE [23:05:10] running test misc-recovery ...
urus:REL_16_STABLE [23:11:33] running test misc-subscription ...
urus:REL_16_STABLE [23:16:21] running test misc-authentication ...
urus:REL_16_STABLE [23:16:37] running misc test module-brin ...
urus:REL_16_STABLE [23:16:50] running misc test module-commit_ts ...
urus:REL_16_STABLE [23:17:15] running misc test module-ldap_password_func ...
urus:REL_16_STABLE [23:17:16] running misc test module-libpq_pipeline ...
urus:REL_16_STABLE [23:17:19] running misc test module-ssl_passphrase_callback ...
urus:REL_16_STABLE [23:17:23] running misc test module-test_custom_rmgrs ...
urus:REL_16_STABLE [23:17:26] running misc test module-test_escape ...
urus:REL_16_STABLE [23:17:29] running misc test module-test_misc ...
urus:REL_16_STABLE [23:17:43] running misc test module-test_pg_dump ...
urus:REL_16_STABLE [23:17:53] running misc test module-libpq ...
urus:REL_16_STABLE [23:18:04] running misc test module-pg_bsd_indent ...
urus:REL_16_STABLE [23:18:08] running contrib test amcheck ...
urus:REL_16_STABLE [23:18:36] running contrib test auto_explain ...
urus:REL_16_STABLE [23:18:43] running contrib test bloom ...
urus:REL_16_STABLE [23:19:03] running contrib test oid2name ...
urus:REL_16_STABLE [23:19:04] running contrib test pg_prewarm ...
urus:REL_16_STABLE [23:19:08] running contrib test test_decoding ...
urus:REL_16_STABLE [23:19:30] running contrib test vacuumlo ...
urus:REL_16_STABLE [23:19:31] setting up db cluster (C)...
urus:REL_16_STABLE [23:19:33] starting db (C)...
urus:REL_16_STABLE [23:19:33] running installcheck (C)...
urus:REL_16_STABLE [23:20:30] restarting db (C)...
urus:REL_16_STABLE [23:20:33] running make isolation check ...
urus:REL_16_STABLE [23:21:09] restarting db (C)...
urus:REL_16_STABLE [23:21:14] running make PL installcheck (C)...
urus:REL_16_STABLE [23:21:18] restarting db (C)...
urus:REL_16_STABLE [23:21:20] running make contrib installcheck (C)...
urus:REL_16_STABLE [23:25:29] restarting db (C)...
urus:REL_16_STABLE [23:25:31] running make test-modules installcheck (C)...
urus:REL_16_STABLE [23:26:31] stopping db (C)...
urus:REL_16_STABLE [23:26:32] running make ecpg check ...
urus:REL_16_STABLE [23:27:15] OK
Branch: REL_16_STABLE
All stages succeeded

Thu Aug  7 04:52:04 2025: buildfarm run for uruspg17:HEAD starting
branch not specified, locks, logs, build artefacts etc will go in HEAD
uruspg17:HEAD          [04:52:54] running configure ...
uruspg17:HEAD          [04:53:43] running build ...
uruspg17:HEAD          [05:05:18] running basic regression tests ...
uruspg17:HEAD          [05:10:34] running make contrib ...
uruspg17:HEAD          [05:11:40] running make testmodules ...
uruspg17:HEAD          [05:11:53] running install ...
uruspg17:HEAD          [05:12:20] running make contrib install ...
uruspg17:HEAD          [05:12:31] running testmodules install ...
uruspg17:HEAD          [05:12:36] running make check miscellaneous modules ...
uruspg17:HEAD          [05:13:34] running bin test initdb ...
uruspg17:HEAD          [05:13:52] running bin test pg_amcheck ...
uruspg17:HEAD          [05:14:17] running bin test pg_archivecleanup ...
uruspg17:HEAD          [05:14:17] running bin test pg_basebackup ...
uruspg17:HEAD          [05:15:31] running bin test pg_checksums ...
uruspg17:HEAD          [05:15:37] running bin test pg_combinebackup ...
uruspg17:HEAD          [05:16:55] running bin test pg_config ...
uruspg17:HEAD          [05:16:55] running bin test pg_controldata ...
uruspg17:HEAD          [05:16:58] running bin test pg_ctl ...
uruspg17:HEAD          [05:17:18] running bin test pg_dump ...
uruspg17:HEAD          [05:20:19] running bin test pg_resetwal ...
uruspg17:HEAD          [05:20:28] running bin test pg_rewind ...
uruspg17:HEAD          [05:22:29] running bin test pg_test_fsync ...
uruspg17:HEAD          [05:22:30] running bin test pg_test_timing ...
uruspg17:HEAD          [05:22:30] running bin test pg_upgrade ...
uruspg17:HEAD          [05:30:39] running bin test pg_verifybackup ...
uruspg17:HEAD          [05:31:43] running bin test pg_waldump ...
uruspg17:HEAD          [05:31:51] running bin test pg_walsummary ...
uruspg17:HEAD          [05:31:55] running bin test pgbench ...
uruspg17:HEAD          [05:32:24] running bin test psql ...
uruspg17:HEAD          [05:32:32] running bin test scripts ...
uruspg17:HEAD          [05:33:29] running test misc-recovery ...
uruspg17:HEAD          [05:47:05] running test misc-subscription ...
uruspg17:HEAD          [05:52:54] running test misc-authentication ...
uruspg17:HEAD          [05:53:20] running misc test module-brin ...
uruspg17:HEAD          [05:53:39] running misc test module-commit_ts ...
uruspg17:HEAD          [05:54:15] running misc test module-ldap_password_func ...
uruspg17:HEAD          [05:54:15] running misc test module-libpq_pipeline ...
uruspg17:HEAD          [05:54:20] running misc test module-ssl_passphrase_callback ...
uruspg17:HEAD          [05:54:25] running misc test module-test_custom_rmgrs ...
uruspg17:HEAD          [05:54:30] running misc test module-test_escape ...
uruspg17:HEAD          [05:54:34] running misc test module-test_json_parser ...
uruspg17:HEAD          [05:54:42] running misc test module-test_misc ...
uruspg17:HEAD          [05:54:57] running misc test module-test_pg_dump ...
uruspg17:HEAD          [05:55:18] running misc test module-worker_spi ...
uruspg17:HEAD          [05:55:23] running misc test module-xid_wraparound ...
uruspg17:HEAD          [05:55:24] running misc test module-libpq ...
uruspg17:HEAD          [05:55:37] running misc test module-pg_bsd_indent ...
uruspg17:HEAD          [05:55:40] running contrib test amcheck ...
uruspg17:HEAD          [05:56:12] running contrib test auto_explain ...
uruspg17:HEAD          [05:56:15] running contrib test bloom ...
uruspg17:HEAD          [05:56:38] running contrib test oid2name ...
uruspg17:HEAD          [05:56:39] running contrib test pg_prewarm ...
uruspg17:HEAD          [05:56:45] running contrib test pg_stat_statements ...
uruspg17:HEAD          [05:56:54] running contrib test pg_visibility ...
uruspg17:HEAD          [05:57:01] running contrib test test_decoding ...
uruspg17:HEAD          [05:57:24] setting up db cluster (C)...
uruspg17:HEAD          [05:57:27] starting db (C)...
uruspg17:HEAD          [05:57:27] running installcheck (C)...
uruspg17:HEAD          [06:04:38] restarting db (C)...
uruspg17:HEAD          [06:04:40] running make isolation check ...
uruspg17:HEAD          [06:07:07] restarting db (C)...
uruspg17:HEAD          [06:07:13] running make PL installcheck (C)...
uruspg17:HEAD          [06:07:19] restarting db (C)...
uruspg17:HEAD          [06:07:21] running make contrib installcheck (C)...
uruspg17:HEAD          [06:12:56] restarting db (C)...
uruspg17:HEAD          [06:12:59] running make test-modules installcheck (C)...
uruspg17:HEAD          [06:14:37] stopping db (C)...
uruspg17:HEAD          [06:14:37] running make ecpg check ...
uruspg17:HEAD          [06:15:26] OK
Branch: HEAD
All stages succeeded

Thu Aug  7 01:40:13 2025: buildfarm run for uruspg18:HEAD starting
branch not specified, locks, logs, build artefacts etc will go in HEAD
uruspg18:HEAD          [01:40:24] running configure ...
uruspg18:HEAD          [01:41:12] running build ...
uruspg18:HEAD          [01:53:12] running basic regression tests ...
uruspg18:HEAD          [01:59:36] running make contrib ...
uruspg18:HEAD          [02:00:47] running make testmodules ...
uruspg18:HEAD          [02:01:03] running install ...
uruspg18:HEAD          [02:01:30] running make contrib install ...
uruspg18:HEAD          [02:01:43] running testmodules install ...
uruspg18:HEAD          [02:01:48] running make check miscellaneous modules ...
uruspg18:HEAD          [02:03:00] running bin test initdb ...
uruspg18:HEAD          [02:03:21] running bin test pg_amcheck ...
uruspg18:HEAD          [02:03:46] running bin test pg_archivecleanup ...
uruspg18:HEAD          [02:03:47] running bin test pg_basebackup ...
uruspg18:HEAD          [02:05:04] running bin test pg_checksums ...
uruspg18:HEAD          [02:05:10] running bin test pg_combinebackup ...
uruspg18:HEAD          [02:06:41] running bin test pg_config ...
uruspg18:HEAD          [02:06:41] running bin test pg_controldata ...
uruspg18:HEAD          [02:06:44] running bin test pg_ctl ...
uruspg18:HEAD          [02:07:03] running bin test pg_dump ...
uruspg18:HEAD          [02:11:41] running bin test pg_resetwal ...
uruspg18:HEAD          [02:11:48] running bin test pg_rewind ...
uruspg18:HEAD          [02:13:36] running bin test pg_test_fsync ...
uruspg18:HEAD          [02:13:37] running bin test pg_test_timing ...
uruspg18:HEAD          [02:13:37] running bin test pg_upgrade ...
uruspg18:HEAD          [02:24:35] running bin test pg_verifybackup ...
uruspg18:HEAD          [02:26:04] running bin test pg_waldump ...
uruspg18:HEAD          [02:26:15] running bin test pg_walsummary ...
uruspg18:HEAD          [02:26:20] running bin test pgbench ...
uruspg18:HEAD          [02:26:52] running bin test psql ...
uruspg18:HEAD          [02:27:02] running bin test scripts ...
uruspg18:HEAD          [02:28:09] running test misc-recovery ...
uruspg18:HEAD          [02:41:40] running test misc-subscription ...
uruspg18:HEAD          [02:48:12] running test misc-authentication ...
uruspg18:HEAD          [02:48:42] running misc test module-brin ...
uruspg18:HEAD          [02:49:00] running misc test module-commit_ts ...
uruspg18:HEAD          [02:49:34] running misc test module-injection_points ...
uruspg18:HEAD          [02:49:34] running misc test module-ldap_password_func ...
uruspg18:HEAD          [02:49:35] running misc test module-libpq_pipeline ...
uruspg18:HEAD          [02:49:40] running misc test module-oauth_validator ...
uruspg18:HEAD          [02:49:40] running misc test module-ssl_passphrase_callback ...
uruspg18:HEAD          [02:49:45] running misc test module-test_aio ...
uruspg18:HEAD          [02:50:02] running misc test module-test_custom_rmgrs ...
uruspg18:HEAD          [02:50:06] running misc test module-test_escape ...
uruspg18:HEAD          [02:50:11] running misc test module-test_extensions ...
uruspg18:HEAD          [02:50:21] running misc test module-test_json_parser ...
uruspg18:HEAD          [02:50:51] running misc test module-test_misc ...
uruspg18:HEAD          [02:51:11] running misc test module-test_pg_dump ...
uruspg18:HEAD          [02:51:35] running misc test module-test_slru ...
uruspg18:HEAD          [02:51:39] running misc test module-worker_spi ...
uruspg18:HEAD          [02:51:46] running misc test module-xid_wraparound ...
uruspg18:HEAD          [02:51:47] running misc test module-libpq ...
uruspg18:HEAD          [02:52:08] running misc test module-pg_bsd_indent ...
uruspg18:HEAD          [02:52:12] running contrib test amcheck ...
uruspg18:HEAD          [02:52:52] running contrib test auto_explain ...
uruspg18:HEAD          [02:52:56] running contrib test basebackup_to_shell ...
uruspg18:HEAD          [02:53:03] running contrib test bloom ...
uruspg18:HEAD          [02:53:27] running contrib test oid2name ...
uruspg18:HEAD          [02:53:28] running contrib test pg_stat_statements ...
uruspg18:HEAD          [02:53:42] running contrib test postgres_fdw ...
Use of uninitialized value $ENV{"PG_TEST_EXTRA"} in pattern match (m//) at ./run_build.pl line 2510.
uruspg18:HEAD          [02:54:02] running contrib test test_decoding ...
uruspg18:HEAD          [02:54:25] running contrib test vacuumlo ...
uruspg18:HEAD          [02:54:26] setting up db cluster (C)...
uruspg18:HEAD          [02:54:29] starting db (C)...
uruspg18:HEAD          [02:54:29] running installcheck (C)...
uruspg18:HEAD          [03:03:12] restarting db (C)...
uruspg18:HEAD          [03:03:14] running make isolation check ...
uruspg18:HEAD          [03:05:52] restarting db (C)...
uruspg18:HEAD          [03:06:00] running make PL installcheck (C)...
uruspg18:HEAD          [03:06:06] restarting db (C)...
uruspg18:HEAD          [03:06:08] running make contrib installcheck (C)...
uruspg18:HEAD          [03:11:59] restarting db (C)...
uruspg18:HEAD          [03:12:02] running make test-modules installcheck (C)...
uruspg18:HEAD          [03:14:25] stopping db (C)...
uruspg18:HEAD          [03:14:26] running make ecpg check ...
uruspg18:HEAD          [03:15:16] OK
Branch: HEAD
All stages succeeded


Attachments:

  [application/octet-stream] 0001-AIX-support.v9.patch (15.7K, 3-0001-AIX-support.v9.patch)
  download | inline diff:
From 24e96d9849f3e6a6217a284aff717ad4d7f2d45a Mon Sep 17 00:00:00 2001
From: AIX-dev <[email protected]>
Date: Wed, 3 Sep 2025 09:37:14 -0500
Subject: [PATCH] AIX support.

---
 Makefile                           |  2 -
 configure                          | 37 +++++++++++++++---
 configure.ac                       | 29 +++++++++++++-
 src/Makefile.shlib                 | 29 ++++++++++++++
 src/backend/Makefile               | 20 ++++++++++
 src/backend/port/aix/mkldexport.sh | 61 ++++++++++++++++++++++++++++++
 src/backend/utils/error/elog.c     |  2 +
 src/include/port/aix.h             |  4 ++
 src/include/storage/s_lock.h       | 48 +++--------------------
 src/makefiles/Makefile.aix         | 34 +++++++++++++++++
 src/port/strerror.c                |  2 +
 src/template/aix                   |  7 ++++
 12 files changed, 223 insertions(+), 52 deletions(-)
 create mode 100755 src/backend/port/aix/mkldexport.sh
 create mode 100644 src/include/port/aix.h
 create mode 100644 src/makefiles/Makefile.aix
 create mode 100644 src/template/aix

diff --git a/Makefile b/Makefile
index b363b2f2476..786424613ab 100644
--- a/Makefile
+++ b/Makefile
@@ -13,8 +13,6 @@
 
 # AIX make defaults to building *every* target of the first rule.  Start with
 # a single-target, empty rule to make the other targets non-default.
-# (We don't support AIX anymore, but if someone tries to build on AIX anyway,
-# at least they'll get the instructions to run 'configure' first.)
 all:
 
 all check install installdirs installcheck installcheck-parallel uninstall clean distclean maintainer-clean dist distcheck world check-world install-world installcheck-world:
diff --git a/configure b/configure
index 1b9980226c5..abda4be633e 100755
--- a/configure
+++ b/configure
@@ -3022,6 +3022,7 @@ else
 # --with-template not given
 
 case $host_os in
+  aix*) template=aix ;;
   cygwin*|msys*) template=cygwin ;;
   darwin*) template=darwin ;;
 dragonfly*) template=netbsd ;;
@@ -17204,13 +17205,37 @@ _ACEOF
 # wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
 # much of a penalty for disk and memory space.
 
-MAX_ALIGNOF=$ac_cv_alignof_double
+echo "Checking for MAX ALIGN - $PORTNAME"
+if test "$PORTNAME" != "aix"; then
+    MAX_ALIGNOF=$ac_cv_alignof_double
 
-if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
-  as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
-fi
-if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
-  as_fn_error $? "alignment of 'int64_t' is greater than the alignment of 'double'" "$LINENO" 5
+    if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
+      as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+    if test x"$HAVE_LONG_LONG_INT_64" = xyes && test $ac_cv_alignof_long_long_int -gt $MAX_ALIGNOF ; then
+      as_fn_error $? "alignment of 'long long int' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+else
+# The AIX 'power' alignment rules apply the natural alignment of the "first
+# member" if it is of a floating-point data type (or is an aggregate whose
+# recursively "first" member or element is such a type). The alignment
+# associated with these types for subsequent members use an alignment value
+# where the floating-point data type is considered to have 4-byte alignment.
+# More info
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99557
+#
+# The double is aligned to 4-bytes on AIX in aggregates. But to maintain
+# alignement across platforms the max alignment of long should be considered.
+      echo "MAX ALIGN ac_cv_alignof_long"
+    MAX_ALIGNOF=$ac_cv_alignof_long
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_double ; then
+      MAX_ALIGNOF=$ac_cv_alignof_double
+      echo "MAX ALIGN ac_cv_alignof_double"
+    fi
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_int64_t; then
+      MAX_ALIGNOF="$ac_cv_alignof_int64_t"
+      echo "MAX ALIGN ac_cv_alignof_int64_t"
+    fi
 fi
 
 cat >>confdefs.h <<_ACEOF
diff --git a/configure.ac b/configure.ac
index 3e3fcfa9831..1ef58a1d7a0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -62,6 +62,7 @@ PGAC_ARG_REQ(with, template, [NAME], [override operating system template],
 # --with-template not given
 
 case $host_os in
+  aix*) template=aix ;;
   cygwin*|msys*) template=cygwin ;;
   darwin*) template=darwin ;;
 dragonfly*) template=netbsd ;;
@@ -2021,7 +2022,33 @@ AC_CHECK_ALIGNOF(double)
 # wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
 # much of a penalty for disk and memory space.
 
-MAX_ALIGNOF=$ac_cv_alignof_double
+if test "$PORTNAME" != "aix"; then
+    MAX_ALIGNOF=$ac_cv_alignof_double
+
+    if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
+      as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+    if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF; then
+      as_fn_error $? "alignment of 'long long int' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+else
+# The AIX 'power' alignment rules apply the natural alignment of the "first
+# member" if it is of a floating-point data type (or is an aggregate whose
+# recursively "first" member or element is such a type). The alignment
+# associated with these types for subsequent members use an alignment value
+# where the floating-point data type is considered to have 4-byte alignment.
+# More info
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99557
+# 
+# The double is aligned to 4-bytes on AIX in aggregates. But to maintain
+# alignement across platforms the max alignment of long should be considered.
+    MAX_ALIGNOF=$ac_cv_alignof_long
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_double ; then
+      MAX_ALIGNOF=$ac_cv_alignof_double
+    fi
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_int64_t ; then
+      MAX_ALIGNOF="$ac_cv_alignof_int64_t"
+    fi
 
 if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
   AC_MSG_ERROR([alignment of 'long' is greater than the alignment of 'double'])
diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index 3825af5b228..35adc4174ed 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -106,6 +106,20 @@ ifdef SO_MAJOR_VERSION
 override CPPFLAGS += -DSO_MAJOR_VERSION=$(SO_MAJOR_VERSION)
 endif
 
+ifeq ($(PORTNAME), aix)
+  LINK.shared		= $(COMPILER)
+  ifdef SO_MAJOR_VERSION
+    shlib		= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
+  endif
+  haslibarule   = yes
+  # $(exports_file) is also usable as an import file
+  exports_file		= lib$(NAME).exp
+  BUILD.exports		= ( echo '\#! $(shlib)'; $(AWK) '/^[^\#]/ {printf "%s\n",$$1}' $< ) > $@
+  ifneq (,$(SHLIB_EXPORTS))
+    LINK.shared		+= -Wl,-bE:$(exports_file)
+  endif
+endif
+
 ifeq ($(PORTNAME), darwin)
   ifdef soname
     # linkable library
@@ -254,6 +268,14 @@ $(stlib): $(OBJS) | $(SHLIB_PREREQS)
 	touch $@
 endif #haslibarule
 
+# AIX wraps both shared libraries and static library, which can be used both
+# for static and shared linking
+ifeq ($(PORTNAME), aix)
+$(stlib): $(shlib)
+	rm -f $(stlib)
+	$(AR) $(AROPT) $(stlib) $(shlib)
+endif # aix
+
 ifeq (,$(filter cygwin win32,$(PORTNAME)))
 
 # Normal case
@@ -267,8 +289,11 @@ ifneq ($(shlib), $(shlib_major))
 endif
 # Make sure we have a link to a name without any version numbers
 ifneq ($(shlib), $(shlib_bare))
+# except on AIX, where that's not a thing
+ifneq ($(PORTNAME), aix)
 	rm -f $(shlib_bare)
 	$(LN_S) $(shlib) $(shlib_bare)
+endif # aix
 endif # shlib_bare
 endif # shlib_major
 
@@ -376,6 +401,9 @@ install-lib-static: $(stlib) installdirs-lib
 
 install-lib-shared: $(shlib) installdirs-lib
 ifdef soname
+# we don't install $(shlib) on AIX
+# (see http://archives.postgresql.org/message-id/52EF20B2E3209443BC37736D00C3C1380A6E79FE@EXADV1.host.magwien.gv.at)
+ifneq ($(PORTNAME), aix)
 	$(INSTALL_SHLIB) $< '$(DESTDIR)$(libdir)/$(shlib)'
 ifneq ($(PORTNAME), cygwin)
 ifneq ($(PORTNAME), win32)
@@ -391,6 +419,7 @@ ifneq ($(shlib), $(shlib_bare))
 endif
 endif # not win32
 endif # not cygwin
+endif # not aix
 ifneq (,$(findstring $(PORTNAME),win32 cygwin))
 	$(INSTALL_SHLIB) $< '$(DESTDIR)$(bindir)/$(shlib)'
 endif
diff --git a/src/backend/Makefile b/src/backend/Makefile
index 7344c8c7f5c..572f5430a60 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -63,12 +63,14 @@ all: submake-libpgport submake-catalog-headers submake-utils-headers postgres $(
 
 ifneq ($(PORTNAME), cygwin)
 ifneq ($(PORTNAME), win32)
+ifneq ($(PORTNAME), aix)
 
 postgres: $(OBJS)
 	$(CC) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LIBS) -o $@
 
 endif
 endif
+endif
 
 ifeq ($(PORTNAME), cygwin)
 
@@ -95,6 +97,24 @@ libpostgres.a: postgres
 
 endif # win32
 
+ifeq ($(PORTNAME), aix)
+
+postgres: $(POSTGRES_IMP)
+	$(CC) $(CFLAGS) $(call expand_subsys,$(OBJS)) $(LDFLAGS) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -Wl,-brtllib -o $@
+
+# Linking to a single .o with -r is a lot faster than building a .a or passing
+# all objects to MKLDEXPORT.
+#
+# It looks alluring to use $(CC) -r instead of ld -r, but that doesn't
+# trivially work with gcc, due to gcc specific static libraries linked in with
+# -r.
+$(POSTGRES_IMP): $(OBJS)
+	ld -r -o SUBSYS.o $(call expand_subsys,$^)
+	$(MKLDEXPORT) SUBSYS.o . > $@
+	@rm -f SUBSYS.o
+
+endif # aix
+
 $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
 
 
diff --git a/src/backend/port/aix/mkldexport.sh b/src/backend/port/aix/mkldexport.sh
new file mode 100755
index 00000000000..adf3793e868
--- /dev/null
+++ b/src/backend/port/aix/mkldexport.sh
@@ -0,0 +1,61 @@
+#!/bin/sh
+#
+# mkldexport
+#	create an AIX exports file from an object file
+#
+# src/backend/port/aix/mkldexport.sh
+#
+# Usage:
+#	mkldexport objectfile [location]
+# where
+#	objectfile is the current location of the object file.
+#	location is the eventual (installed) location of the
+#		object file (if different from the current
+#		working directory).
+#
+# [This file comes from the Postgres 4.2 distribution. - ay 7/95]
+#
+# Header: /usr/local/devel/postgres/src/tools/mkldexport/RCS/mkldexport.sh,v 1.2 1994/03/13 04:59:12 aoki Exp
+#
+
+# setting this to nm -B might be better
+# ... due to changes in AIX 4.x ...
+# ... let us search in different directories - Gerhard Reithofer
+if [ -x /usr/ucb/nm ]
+then NM=/usr/ucb/nm
+elif [ -x /usr/bin/nm ]
+then NM=/usr/bin/nm
+elif [ -x /usr/ccs/bin/nm ]
+then NM=/usr/ccs/bin/nm
+elif [ -x /usr/usg/bin/nm ]
+then NM=/usr/usg/bin/nm
+else echo "Fatal error: cannot find `nm' ... please check your installation."
+     exit 1
+fi
+
+CMDNAME=`basename $0`
+if [ -z "$1" ]; then
+	echo "Usage: $CMDNAME object [location]"
+	exit 1
+fi
+OBJNAME=`basename $1`
+if [ "`basename $OBJNAME`" != "`basename $OBJNAME .o`" ]; then
+	OBJNAME=`basename $OBJNAME .o`.so
+fi
+if [ -z "$2" ]; then
+	echo '#!'
+else
+	if [ "$2" = "." ]; then
+		# for the base executable (AIX 4.2 and up)
+		echo '#! .'
+	else
+		echo '#!' $2
+	fi
+fi
+$NM -BCg $1 | \
+	egrep ' [TDB] ' | \
+	sed -e 's/.* //' | \
+	egrep -v '\$' | \
+	sed -e 's/^[.]//' | \
+	sort | \
+	uniq
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 47af743990f..f0f4ff051b5 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -905,7 +905,9 @@ errcode_for_file_access(void)
 			/* Wrong object type or state */
 		case ENOTDIR:			/* Not a directory */
 		case EISDIR:			/* Is a directory */
+#if defined(ENOTEMPTY) && (ENOTEMPTY != EEXIST) /* same code on AIX */
 		case ENOTEMPTY:			/* Directory not empty */
+#endif
 			edata->sqlerrcode = ERRCODE_WRONG_OBJECT_TYPE;
 			break;
 
diff --git a/src/include/port/aix.h b/src/include/port/aix.h
new file mode 100644
index 00000000000..7d08480c8c0
--- /dev/null
+++ b/src/include/port/aix.h
@@ -0,0 +1,4 @@
+/*
+ * src/include/port/aix.h
+ */
+
diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
index 2f73f9fcf57..ba120c08d14 100644
--- a/src/include/storage/s_lock.h
+++ b/src/include/storage/s_lock.h
@@ -398,56 +398,18 @@ typedef unsigned int slock_t;
 
 #define TAS(lock) tas(lock)
 
-/* On PPC, it's a win to use a non-locking test before the lwarx */
+/* On PPC, use the compiler provided Built-in functions for atomic memory
+ * exchange operations.
+ */
 #define TAS_SPIN(lock)	(*(lock) ? 1 : TAS(lock))
 
-/*
- * The second operand of addi can hold a constant zero or a register number,
- * hence constraint "=&b" to avoid allocating r0.  "b" stands for "address
- * base register"; most operands having this register-or-zero property are
- * address bases, e.g. the second operand of lwax.
- *
- * NOTE: per the Enhanced PowerPC Architecture manual, v1.0 dated 7-May-2002,
- * an isync is a sufficient synchronization barrier after a lwarx/stwcx loop.
- * But if the spinlock is in ordinary memory, we can use lwsync instead for
- * better performance.
- */
 static __inline__ int
 tas(volatile slock_t *lock)
 {
-	slock_t _t;
-	int _res;
-
-	__asm__ __volatile__(
-"	lwarx   %0,0,%3,1	\n"
-"	cmpwi   %0,0		\n"
-"	bne     1f			\n"
-"	addi    %0,%0,1		\n"
-"	stwcx.  %0,0,%3		\n"
-"	beq     2f			\n"
-"1: \n"
-"	li      %1,1		\n"
-"	b       3f			\n"
-"2: \n"
-"	lwsync				\n"
-"	li      %1,0		\n"
-"3: \n"
-:	"=&b"(_t), "=r"(_res), "+m"(*lock)
-:	"r"(lock)
-:	"memory", "cc");
-	return _res;
+	return __sync_lock_test_and_set(lock, 1);
 }
 
-/*
- * PowerPC S_UNLOCK is almost standard but requires a "sync" instruction.
- * But we can use lwsync instead for better performance.
- */
-#define S_UNLOCK(lock)	\
-do \
-{ \
-	__asm__ __volatile__ ("	lwsync \n" ::: "memory"); \
-	*((volatile slock_t *) (lock)) = 0; \
-} while (0)
+#define S_UNLOCK(lock) __sync_lock_release(lock)
 
 #endif /* powerpc */
 
diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix
new file mode 100644
index 00000000000..4c4de8b0be7
--- /dev/null
+++ b/src/makefiles/Makefile.aix
@@ -0,0 +1,34 @@
+# -blibpath:
+# The path to be inserted into the default path (Index 0 path) field of the
+# loader section. When this flag is presented, the -L paths will not be stored. 
+# AIX uses a stricter, more explicit approach. The runtime linker expects to
+# tell it exactly where to look using -blibpath.
+# -blibpath must contain ALL directories where we should look for libraries
+libpath := $(shell echo $(subst -L,:,$(filter -L/%,$(LDFLAGS))) | sed -e's/ //g'):/usr/lib:/lib
+
+# AIX uses a stricter, more explicit approach. The runtime linker expects 
+# to tell it exactly where to look using -blibpath.
+rpath = -Wl,-blibpath:'$(rpathdir)$(libpath)'
+
+# gcc needs to know it's building a shared lib, otherwise it'll not emit
+# correct code / link to the right support libraries
+ifeq ($(GCC), yes)
+LDFLAGS_SL += -shared
+endif
+
+# env var name to use in place of LD_LIBRARY_PATH
+ld_library_path_var = LIBPATH
+
+POSTGRES_IMP= postgres.imp
+
+ifdef PGXS
+BE_DLLLIBS= -Wl,-bI:$(pkglibdir)/$(POSTGRES_IMP)
+else
+BE_DLLLIBS= -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP)
+endif
+
+MKLDEXPORT_DIR=src/backend/port/aix
+MKLDEXPORT=$(top_srcdir)/$(MKLDEXPORT_DIR)/mkldexport.sh
+
+%$(DLSUFFIX): %.o
+	$(CC) $(CFLAGS) $*.o $(LDFLAGS) $(LDFLAGS_SL) -o $@ $(BE_DLLLIBS)
diff --git a/src/port/strerror.c b/src/port/strerror.c
index f0746517770..c46b9dc91fc 100644
--- a/src/port/strerror.c
+++ b/src/port/strerror.c
@@ -214,8 +214,10 @@ get_errno_symbol(int errnum)
 			return "ENOTCONN";
 		case ENOTDIR:
 			return "ENOTDIR";
+#if defined(ENOTEMPTY) && (ENOTEMPTY != EEXIST) /* same code on AIX */
 		case ENOTEMPTY:
 			return "ENOTEMPTY";
+#endif
 		case ENOTSOCK:
 			return "ENOTSOCK";
 #ifdef ENOTSUP
diff --git a/src/template/aix b/src/template/aix
new file mode 100644
index 00000000000..bfc193348f4
--- /dev/null
+++ b/src/template/aix
@@ -0,0 +1,7 @@
+# This file is referred for specific flags wrt to AIX build process like
+# cflags.
+# src/template/aix
+
+# Extra CFLAGS for code that will go into a shared library
+# With optimization, the MemSet() and MemSetAlign() perform better.
+CFLAGS_SL=" -O2 "
-- 
2.41.0



  [text/plain] build-farm-19.pg16.log (4.3K, 4-build-farm-19.pg16.log)
  download | inline:
Sun Aug 10 22:34:32 2025: buildfarm run for urus:REL_16_STABLE starting
urus:REL_16_STABLE [22:34:43] checking out source ...
running git clone -q /home/pgdev/bfarm/build-farm-19.1.16/buildroot/pgmirror.git "/home/pgdev/bfarm/build-farm-19.1.16/buildroot/HEAD/pgsql"
urus:REL_16_STABLE [22:41:18] checking if build run needed ...
urus:REL_16_STABLE [22:41:18] copying source to pgsql.build ...
urus:REL_16_STABLE [22:41:27] running configure ...
urus:REL_16_STABLE [22:42:11] running build ...
urus:REL_16_STABLE [22:53:07] running basic regression tests ...
urus:REL_16_STABLE [22:54:23] running make contrib ...
urus:REL_16_STABLE [22:55:29] running make testmodules ...
urus:REL_16_STABLE [22:55:39] running install ...
urus:REL_16_STABLE [22:56:09] running make contrib install ...
urus:REL_16_STABLE [22:56:19] running testmodules install ...
urus:REL_16_STABLE [22:56:24] running make check miscellaneous modules ...
urus:REL_16_STABLE [22:57:41] running bin test initdb ...
urus:REL_16_STABLE [22:57:52] running bin test pg_amcheck ...
urus:REL_16_STABLE [22:58:11] running bin test pg_archivecleanup ...
urus:REL_16_STABLE [22:58:12] running bin test pg_basebackup ...
urus:REL_16_STABLE [22:59:02] running bin test pg_checksums ...
urus:REL_16_STABLE [22:59:09] running bin test pg_config ...
urus:REL_16_STABLE [22:59:09] running bin test pg_controldata ...
urus:REL_16_STABLE [22:59:12] running bin test pg_ctl ...
urus:REL_16_STABLE [22:59:31] running bin test pg_dump ...
urus:REL_16_STABLE [23:00:10] running bin test pg_resetwal ...
urus:REL_16_STABLE [23:00:15] running bin test pg_rewind ...
urus:REL_16_STABLE [23:01:49] running bin test pg_test_fsync ...
urus:REL_16_STABLE [23:01:50] running bin test pg_test_timing ...
urus:REL_16_STABLE [23:01:50] running bin test pg_upgrade ...
urus:REL_16_STABLE [23:02:55] running bin test pg_verifybackup ...
urus:REL_16_STABLE [23:03:57] running bin test pg_waldump ...
urus:REL_16_STABLE [23:04:01] running bin test pgbench ...
urus:REL_16_STABLE [23:04:13] running bin test psql ...
urus:REL_16_STABLE [23:04:20] running bin test scripts ...
urus:REL_16_STABLE [23:05:10] running test misc-recovery ...
urus:REL_16_STABLE [23:11:33] running test misc-subscription ...
urus:REL_16_STABLE [23:16:21] running test misc-authentication ...
urus:REL_16_STABLE [23:16:37] running misc test module-brin ...
urus:REL_16_STABLE [23:16:50] running misc test module-commit_ts ...
urus:REL_16_STABLE [23:17:15] running misc test module-ldap_password_func ...
urus:REL_16_STABLE [23:17:16] running misc test module-libpq_pipeline ...
urus:REL_16_STABLE [23:17:19] running misc test module-ssl_passphrase_callback ...
urus:REL_16_STABLE [23:17:23] running misc test module-test_custom_rmgrs ...
urus:REL_16_STABLE [23:17:26] running misc test module-test_escape ...
urus:REL_16_STABLE [23:17:29] running misc test module-test_misc ...
urus:REL_16_STABLE [23:17:43] running misc test module-test_pg_dump ...
urus:REL_16_STABLE [23:17:53] running misc test module-libpq ...
urus:REL_16_STABLE [23:18:04] running misc test module-pg_bsd_indent ...
urus:REL_16_STABLE [23:18:08] running contrib test amcheck ...
urus:REL_16_STABLE [23:18:36] running contrib test auto_explain ...
urus:REL_16_STABLE [23:18:43] running contrib test bloom ...
urus:REL_16_STABLE [23:19:03] running contrib test oid2name ...
urus:REL_16_STABLE [23:19:04] running contrib test pg_prewarm ...
urus:REL_16_STABLE [23:19:08] running contrib test test_decoding ...
urus:REL_16_STABLE [23:19:30] running contrib test vacuumlo ...
urus:REL_16_STABLE [23:19:31] setting up db cluster (C)...
urus:REL_16_STABLE [23:19:33] starting db (C)...
urus:REL_16_STABLE [23:19:33] running installcheck (C)...
urus:REL_16_STABLE [23:20:30] restarting db (C)...
urus:REL_16_STABLE [23:20:33] running make isolation check ...
urus:REL_16_STABLE [23:21:09] restarting db (C)...
urus:REL_16_STABLE [23:21:14] running make PL installcheck (C)...
urus:REL_16_STABLE [23:21:18] restarting db (C)...
urus:REL_16_STABLE [23:21:20] running make contrib installcheck (C)...
urus:REL_16_STABLE [23:25:29] restarting db (C)...
urus:REL_16_STABLE [23:25:31] running make test-modules installcheck (C)...
urus:REL_16_STABLE [23:26:31] stopping db (C)...
urus:REL_16_STABLE [23:26:32] running make ecpg check ...
urus:REL_16_STABLE [23:27:15] OK
Branch: REL_16_STABLE
All stages succeeded

  [text/plain] build-farm-19.pg17.log (4.7K, 5-build-farm-19.pg17.log)
  download | inline:
Thu Aug  7 04:52:04 2025: buildfarm run for uruspg17:HEAD starting
branch not specified, locks, logs, build artefacts etc will go in HEAD
uruspg17:HEAD          [04:52:54] running configure ...
uruspg17:HEAD          [04:53:43] running build ...
uruspg17:HEAD          [05:05:18] running basic regression tests ...
uruspg17:HEAD          [05:10:34] running make contrib ...
uruspg17:HEAD          [05:11:40] running make testmodules ...
uruspg17:HEAD          [05:11:53] running install ...
uruspg17:HEAD          [05:12:20] running make contrib install ...
uruspg17:HEAD          [05:12:31] running testmodules install ...
uruspg17:HEAD          [05:12:36] running make check miscellaneous modules ...
uruspg17:HEAD          [05:13:34] running bin test initdb ...
uruspg17:HEAD          [05:13:52] running bin test pg_amcheck ...
uruspg17:HEAD          [05:14:17] running bin test pg_archivecleanup ...
uruspg17:HEAD          [05:14:17] running bin test pg_basebackup ...
uruspg17:HEAD          [05:15:31] running bin test pg_checksums ...
uruspg17:HEAD          [05:15:37] running bin test pg_combinebackup ...
uruspg17:HEAD          [05:16:55] running bin test pg_config ...
uruspg17:HEAD          [05:16:55] running bin test pg_controldata ...
uruspg17:HEAD          [05:16:58] running bin test pg_ctl ...
uruspg17:HEAD          [05:17:18] running bin test pg_dump ...
uruspg17:HEAD          [05:20:19] running bin test pg_resetwal ...
uruspg17:HEAD          [05:20:28] running bin test pg_rewind ...
uruspg17:HEAD          [05:22:29] running bin test pg_test_fsync ...
uruspg17:HEAD          [05:22:30] running bin test pg_test_timing ...
uruspg17:HEAD          [05:22:30] running bin test pg_upgrade ...
uruspg17:HEAD          [05:30:39] running bin test pg_verifybackup ...
uruspg17:HEAD          [05:31:43] running bin test pg_waldump ...
uruspg17:HEAD          [05:31:51] running bin test pg_walsummary ...
uruspg17:HEAD          [05:31:55] running bin test pgbench ...
uruspg17:HEAD          [05:32:24] running bin test psql ...
uruspg17:HEAD          [05:32:32] running bin test scripts ...
uruspg17:HEAD          [05:33:29] running test misc-recovery ...
uruspg17:HEAD          [05:47:05] running test misc-subscription ...
uruspg17:HEAD          [05:52:54] running test misc-authentication ...
uruspg17:HEAD          [05:53:20] running misc test module-brin ...
uruspg17:HEAD          [05:53:39] running misc test module-commit_ts ...
uruspg17:HEAD          [05:54:15] running misc test module-ldap_password_func ...
uruspg17:HEAD          [05:54:15] running misc test module-libpq_pipeline ...
uruspg17:HEAD          [05:54:20] running misc test module-ssl_passphrase_callback ...
uruspg17:HEAD          [05:54:25] running misc test module-test_custom_rmgrs ...
uruspg17:HEAD          [05:54:30] running misc test module-test_escape ...
uruspg17:HEAD          [05:54:34] running misc test module-test_json_parser ...
uruspg17:HEAD          [05:54:42] running misc test module-test_misc ...
uruspg17:HEAD          [05:54:57] running misc test module-test_pg_dump ...
uruspg17:HEAD          [05:55:18] running misc test module-worker_spi ...
uruspg17:HEAD          [05:55:23] running misc test module-xid_wraparound ...
uruspg17:HEAD          [05:55:24] running misc test module-libpq ...
uruspg17:HEAD          [05:55:37] running misc test module-pg_bsd_indent ...
uruspg17:HEAD          [05:55:40] running contrib test amcheck ...
uruspg17:HEAD          [05:56:12] running contrib test auto_explain ...
uruspg17:HEAD          [05:56:15] running contrib test bloom ...
uruspg17:HEAD          [05:56:38] running contrib test oid2name ...
uruspg17:HEAD          [05:56:39] running contrib test pg_prewarm ...
uruspg17:HEAD          [05:56:45] running contrib test pg_stat_statements ...
uruspg17:HEAD          [05:56:54] running contrib test pg_visibility ...
uruspg17:HEAD          [05:57:01] running contrib test test_decoding ...
uruspg17:HEAD          [05:57:24] setting up db cluster (C)...
uruspg17:HEAD          [05:57:27] starting db (C)...
uruspg17:HEAD          [05:57:27] running installcheck (C)...
uruspg17:HEAD          [06:04:38] restarting db (C)...
uruspg17:HEAD          [06:04:40] running make isolation check ...
uruspg17:HEAD          [06:07:07] restarting db (C)...
uruspg17:HEAD          [06:07:13] running make PL installcheck (C)...
uruspg17:HEAD          [06:07:19] restarting db (C)...
uruspg17:HEAD          [06:07:21] running make contrib installcheck (C)...
uruspg17:HEAD          [06:12:56] restarting db (C)...
uruspg17:HEAD          [06:12:59] running make test-modules installcheck (C)...
uruspg17:HEAD          [06:14:37] stopping db (C)...
uruspg17:HEAD          [06:14:37] running make ecpg check ...
uruspg17:HEAD          [06:15:26] OK
Branch: HEAD
All stages succeeded

  [text/plain] build-farm-19.pg18.log (5.3K, 6-build-farm-19.pg18.log)
  download | inline:
Thu Aug  7 01:40:13 2025: buildfarm run for uruspg18:HEAD starting
branch not specified, locks, logs, build artefacts etc will go in HEAD
uruspg18:HEAD          [01:40:24] running configure ...
uruspg18:HEAD          [01:41:12] running build ...
uruspg18:HEAD          [01:53:12] running basic regression tests ...
uruspg18:HEAD          [01:59:36] running make contrib ...
uruspg18:HEAD          [02:00:47] running make testmodules ...
uruspg18:HEAD          [02:01:03] running install ...
uruspg18:HEAD          [02:01:30] running make contrib install ...
uruspg18:HEAD          [02:01:43] running testmodules install ...
uruspg18:HEAD          [02:01:48] running make check miscellaneous modules ...
uruspg18:HEAD          [02:03:00] running bin test initdb ...
uruspg18:HEAD          [02:03:21] running bin test pg_amcheck ...
uruspg18:HEAD          [02:03:46] running bin test pg_archivecleanup ...
uruspg18:HEAD          [02:03:47] running bin test pg_basebackup ...
uruspg18:HEAD          [02:05:04] running bin test pg_checksums ...
uruspg18:HEAD          [02:05:10] running bin test pg_combinebackup ...
uruspg18:HEAD          [02:06:41] running bin test pg_config ...
uruspg18:HEAD          [02:06:41] running bin test pg_controldata ...
uruspg18:HEAD          [02:06:44] running bin test pg_ctl ...
uruspg18:HEAD          [02:07:03] running bin test pg_dump ...
uruspg18:HEAD          [02:11:41] running bin test pg_resetwal ...
uruspg18:HEAD          [02:11:48] running bin test pg_rewind ...
uruspg18:HEAD          [02:13:36] running bin test pg_test_fsync ...
uruspg18:HEAD          [02:13:37] running bin test pg_test_timing ...
uruspg18:HEAD          [02:13:37] running bin test pg_upgrade ...
uruspg18:HEAD          [02:24:35] running bin test pg_verifybackup ...
uruspg18:HEAD          [02:26:04] running bin test pg_waldump ...
uruspg18:HEAD          [02:26:15] running bin test pg_walsummary ...
uruspg18:HEAD          [02:26:20] running bin test pgbench ...
uruspg18:HEAD          [02:26:52] running bin test psql ...
uruspg18:HEAD          [02:27:02] running bin test scripts ...
uruspg18:HEAD          [02:28:09] running test misc-recovery ...
uruspg18:HEAD          [02:41:40] running test misc-subscription ...
uruspg18:HEAD          [02:48:12] running test misc-authentication ...
uruspg18:HEAD          [02:48:42] running misc test module-brin ...
uruspg18:HEAD          [02:49:00] running misc test module-commit_ts ...
uruspg18:HEAD          [02:49:34] running misc test module-injection_points ...
uruspg18:HEAD          [02:49:34] running misc test module-ldap_password_func ...
uruspg18:HEAD          [02:49:35] running misc test module-libpq_pipeline ...
uruspg18:HEAD          [02:49:40] running misc test module-oauth_validator ...
uruspg18:HEAD          [02:49:40] running misc test module-ssl_passphrase_callback ...
uruspg18:HEAD          [02:49:45] running misc test module-test_aio ...
uruspg18:HEAD          [02:50:02] running misc test module-test_custom_rmgrs ...
uruspg18:HEAD          [02:50:06] running misc test module-test_escape ...
uruspg18:HEAD          [02:50:11] running misc test module-test_extensions ...
uruspg18:HEAD          [02:50:21] running misc test module-test_json_parser ...
uruspg18:HEAD          [02:50:51] running misc test module-test_misc ...
uruspg18:HEAD          [02:51:11] running misc test module-test_pg_dump ...
uruspg18:HEAD          [02:51:35] running misc test module-test_slru ...
uruspg18:HEAD          [02:51:39] running misc test module-worker_spi ...
uruspg18:HEAD          [02:51:46] running misc test module-xid_wraparound ...
uruspg18:HEAD          [02:51:47] running misc test module-libpq ...
uruspg18:HEAD          [02:52:08] running misc test module-pg_bsd_indent ...
uruspg18:HEAD          [02:52:12] running contrib test amcheck ...
uruspg18:HEAD          [02:52:52] running contrib test auto_explain ...
uruspg18:HEAD          [02:52:56] running contrib test basebackup_to_shell ...
uruspg18:HEAD          [02:53:03] running contrib test bloom ...
uruspg18:HEAD          [02:53:27] running contrib test oid2name ...
uruspg18:HEAD          [02:53:28] running contrib test pg_stat_statements ...
uruspg18:HEAD          [02:53:42] running contrib test postgres_fdw ...
Use of uninitialized value $ENV{"PG_TEST_EXTRA"} in pattern match (m//) at ./run_build.pl line 2510.
uruspg18:HEAD          [02:54:02] running contrib test test_decoding ...
uruspg18:HEAD          [02:54:25] running contrib test vacuumlo ...
uruspg18:HEAD          [02:54:26] setting up db cluster (C)...
uruspg18:HEAD          [02:54:29] starting db (C)...
uruspg18:HEAD          [02:54:29] running installcheck (C)...
uruspg18:HEAD          [03:03:12] restarting db (C)...
uruspg18:HEAD          [03:03:14] running make isolation check ...
uruspg18:HEAD          [03:05:52] restarting db (C)...
uruspg18:HEAD          [03:06:00] running make PL installcheck (C)...
uruspg18:HEAD          [03:06:06] restarting db (C)...
uruspg18:HEAD          [03:06:08] running make contrib installcheck (C)...
uruspg18:HEAD          [03:11:59] restarting db (C)...
uruspg18:HEAD          [03:12:02] running make test-modules installcheck (C)...
uruspg18:HEAD          [03:14:25] stopping db (C)...
uruspg18:HEAD          [03:14:26] running make ecpg check ...
uruspg18:HEAD          [03:15:16] OK
Branch: HEAD
All stages succeeded

^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-09-11 05:20  Vamshikrishna T <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  1 sibling, 2 replies; 47+ messages in thread

From: Vamshikrishna T @ 2025-09-11 05:20 UTC (permalink / raw)
  To: Srirama Kucherlapati <[email protected]>; +Cc: Heikki Linnakangas <[email protected]>; pgsql-hackers; Robert Haas <[email protected]>; Bruce Momjian <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>; wenhui qiu <[email protected]>; [email protected] <[email protected]>

Hi Team,



Just checking in regarding the AIX support patch shared earlier. As
mentioned, we’ve successfully run the patch across all stable PostgreSQL
releases using the build farm, and all tests—including TAP—have passed. We
also ran the build farm scripts locally for PostgreSQL 17 and 18 on AIX,
and the test results were attached for your reference.


We’d appreciate your review and feedback on the patch. Once we receive your
input, our next steps will be:

1. Address any comments or suggestions you may have.

2. Finalize the patch based on feedback.

3. Proceed with integration into the relevant branches.


Please let us know if you need any additional details or clarification.


Thanks

 Vamshi.


^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-09-11 06:12  Laurenz Albe <[email protected]>
  parent: Vamshikrishna T <[email protected]>
  1 sibling, 1 reply; 47+ messages in thread

From: Laurenz Albe @ 2025-09-11 06:12 UTC (permalink / raw)
  To: Vamshikrishna T <[email protected]>; Srirama Kucherlapati <[email protected]>; +Cc: Heikki Linnakangas <[email protected]>; pgsql-hackers; Robert Haas <[email protected]>; Bruce Momjian <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>; wenhui qiu <[email protected]>; [email protected] <[email protected]>

On Thu, 2025-09-11 at 10:50 +0530, Vamshikrishna T wrote:
> Just checking in regarding the AIX support patch shared earlier.

Did you create a commitfest entry?
That way, your patch is less likely to fall between the cracks.

Yours,
Laurenz Albe





^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-09-11 10:48  Vamshikrishna T <[email protected]>
  parent: Laurenz Albe <[email protected]>
  0 siblings, 0 replies; 47+ messages in thread

From: Vamshikrishna T @ 2025-09-11 10:48 UTC (permalink / raw)
  To: [email protected]; +Cc: AIX PG user <[email protected]>

Thank you Laurenz for the info, Raised the review request here.

^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-09-15 23:44  Bruce Momjian <[email protected]>
  parent: Vamshikrishna T <[email protected]>
  1 sibling, 1 reply; 47+ messages in thread

From: Bruce Momjian @ 2025-09-15 23:44 UTC (permalink / raw)
  To: Vamshikrishna T <[email protected]>; +Cc: Srirama Kucherlapati <[email protected]>; Heikki Linnakangas <[email protected]>; pgsql-hackers; Robert Haas <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>; wenhui qiu <[email protected]>; [email protected] <[email protected]>

On Thu, Sep 11, 2025 at 10:50:45AM +0530, Vamshikrishna T wrote:
> We’d appreciate your review and feedback on the patch. Once we receive your
> input, our next steps will be:
> 
> 1. Address any comments or suggestions you may have.
> 
> 2. Finalize the patch based on feedback.
> 
> 3. Proceed with integration into the relevant branches.        

I assume the only relevant branch is PG 19.

-- 
  Bruce Momjian  <[email protected]>        https://momjian.us
  EDB                                      https://enterprisedb.com

  Do not let urgent matters crowd out time for investment in the future.





^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* RE: AIX support
@ 2025-09-16 15:13  Srirama Kucherlapati <[email protected]>
  parent: Bruce Momjian <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: Srirama Kucherlapati @ 2025-09-16 15:13 UTC (permalink / raw)
  To: Bruce Momjian <[email protected]>; Vamshikrishna T <[email protected]>; +Cc: Heikki Linnakangas <[email protected]>; pgsql-hackers; Robert Haas <[email protected]>; Peter Eisentraut <[email protected]>; Alvaro Herrera <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>; wenhui qiu <[email protected]>; [email protected] <[email protected]>

Hi Bruce,
Please find the attached patch that is run on master branch PG19.
Kindly request you to go through and let us know your feedback.

Also attached are the builfarm results.

Warm regards,
Sriram.


Mon Sep 15 18:56:20 2025: buildfarm run for uruspg19:HEAD starting
branch not specified, locks, logs, build artefacts etc will go in HEAD
uruspg19:HEAD          [18:59:44] running configure ...
uruspg19:HEAD          [19:01:04] running build ...
uruspg19:HEAD          [19:01:52] running basic regression tests ...
uruspg19:HEAD          [19:10:10] running make contrib ...
uruspg19:HEAD          [19:10:11] running make testmodules ...
uruspg19:HEAD          [19:10:12] running install ...
uruspg19:HEAD          [19:10:56] running make contrib install ...
uruspg19:HEAD          [19:11:12] running testmodules install ...
uruspg19:HEAD          [19:11:19] running make check miscellaneous modules ...
uruspg19:HEAD          [19:13:31] running bin test initdb ...
uruspg19:HEAD          [19:13:57] running bin test pg_amcheck ...
uruspg19:HEAD          [19:14:23] running bin test pg_archivecleanup ...
uruspg19:HEAD          [19:14:24] running bin test pg_basebackup ...
uruspg19:HEAD          [19:15:38] running bin test pg_checksums ...
uruspg19:HEAD          [19:15:45] running bin test pg_combinebackup ...
uruspg19:HEAD          [19:17:10] running bin test pg_config ...
uruspg19:HEAD          [19:17:10] running bin test pg_controldata ...
uruspg19:HEAD          [19:17:13] running bin test pg_ctl ...
uruspg19:HEAD          [19:17:31] running bin test pg_dump ...
uruspg19:HEAD          [19:20:40] running bin test pg_resetwal ...
uruspg19:HEAD          [19:20:46] running bin test pg_rewind ...
uruspg19:HEAD          [19:22:25] running bin test pg_test_fsync ...
uruspg19:HEAD          [19:22:26] running bin test pg_test_timing ...
uruspg19:HEAD          [19:22:28] running bin test pg_upgrade ...
uruspg19:HEAD          [19:33:01] running bin test pg_verifybackup ...
uruspg19:HEAD          [19:34:38] running bin test pg_waldump ...
uruspg19:HEAD          [19:34:49] running bin test pg_walsummary ...
uruspg19:HEAD          [19:34:54] running bin test pgbench ...
uruspg19:HEAD          [19:35:25] running bin test psql ...
uruspg19:HEAD          [19:35:34] running bin test scripts ...
uruspg19:HEAD          [19:36:55] running test misc-recovery ...
uruspg19:HEAD          [19:57:56] running test misc-subscription ...
uruspg19:HEAD          [20:05:06] running test misc-authentication ...
uruspg19:HEAD          [20:05:30] running misc test module-brin ...
uruspg19:HEAD          [20:05:44] running misc test module-commit_ts ...
uruspg19:HEAD          [20:06:10] running misc test module-injection_points ...
uruspg19:HEAD          [20:06:10] running misc test module-ldap_password_func ...
uruspg19:HEAD          [20:06:11] running misc test module-libpq_pipeline ...
uruspg19:HEAD          [20:06:15] running misc test module-oauth_validator ...
uruspg19:HEAD          [20:06:16] running misc test module-ssl_passphrase_callback ...
uruspg19:HEAD          [20:06:19] running misc test module-test_aio ...
uruspg19:HEAD          [20:06:34] running misc test module-test_custom_rmgrs ...
uruspg19:HEAD          [20:06:37] running misc test module-test_escape ...
uruspg19:HEAD          [20:06:41] running misc test module-test_extensions ...
uruspg19:HEAD          [20:06:48] running misc test module-test_int128 ...
uruspg19:HEAD          [20:06:49] running misc test module-test_json_parser ...
uruspg19:HEAD          [20:07:19] running misc test module-test_misc ...
uruspg19:HEAD          [20:07:34] running misc test module-test_pg_dump ...
uruspg19:HEAD          [20:07:56] running misc test module-test_slru ...
uruspg19:HEAD          [20:07:59] running misc test module-worker_spi ...
uruspg19:HEAD          [20:08:05] running misc test module-xid_wraparound ...
uruspg19:HEAD          [20:08:06] running misc test module-libpq ...
uruspg19:HEAD          [20:08:25] running misc test module-pg_bsd_indent ...
uruspg19:HEAD          [20:08:29] running contrib test amcheck ...
uruspg19:HEAD          [20:09:09] running contrib test auto_explain ...
uruspg19:HEAD          [20:09:16] running contrib test basebackup_to_shell ...
uruspg19:HEAD          [20:09:23] running contrib test bloom ...
uruspg19:HEAD          [20:09:48] running contrib test oid2name ...
uruspg19:HEAD          [20:09:49] running contrib test pg_stat_statements ...
uruspg19:HEAD          [20:10:03] running contrib test postgres_fdw ...
Use of uninitialized value $ENV{"PG_TEST_EXTRA"} in pattern match (m//) at ./run_build.pl line 2510.
uruspg19:HEAD          [20:10:24] running contrib test test_decoding ...
uruspg19:HEAD          [20:10:47] running contrib test vacuumlo ...
uruspg19:HEAD          [20:10:48] setting up db cluster (C)...
uruspg19:HEAD          [20:10:50] starting db (C)...
uruspg19:HEAD          [20:10:50] running installcheck (C)...
uruspg19:HEAD          [20:19:31] restarting db (C)...
uruspg19:HEAD          [20:19:34] running make isolation check ...
uruspg19:HEAD          [20:22:11] restarting db (C)...
uruspg19:HEAD          [20:22:18] running make PL installcheck (C)...
uruspg19:HEAD          [20:22:24] restarting db (C)...
uruspg19:HEAD          [20:22:26] running make contrib installcheck (C)...
uruspg19:HEAD          [20:30:42] restarting db (C)...
uruspg19:HEAD          [20:30:47] running make test-modules installcheck (C)...
uruspg19:HEAD          [20:36:44] stopping db (C)...
uruspg19:HEAD          [20:36:46] running make ecpg check ...
uruspg19:HEAD          [20:37:19] OK
Branch: HEAD
All stages succeeded


Attachments:

  [application/octet-stream] 0001-Changes-to-add-support-for-AIX.v9.pg19.patch (15.7K, 3-0001-Changes-to-add-support-for-AIX.v9.pg19.patch)
  download | inline diff:
From 407b42b1fbe562dff69820f7456dbb32a8a37d79 Mon Sep 17 00:00:00 2001
From: AIX-dev <[email protected]>
Date: Tue, 16 Sep 2025 08:59:22 -0500
Subject: [PATCH] Changes to add support for AIX.

---
 Makefile                           |  2 -
 configure                          | 37 +++++++++++++++---
 configure.ac                       | 29 +++++++++++++-
 src/Makefile.shlib                 | 29 ++++++++++++++
 src/backend/Makefile               | 20 ++++++++++
 src/backend/port/aix/mkldexport.sh | 61 ++++++++++++++++++++++++++++++
 src/backend/utils/error/elog.c     |  2 +
 src/include/port/aix.h             |  4 ++
 src/include/storage/s_lock.h       | 48 +++--------------------
 src/makefiles/Makefile.aix         | 34 +++++++++++++++++
 src/port/strerror.c                |  2 +
 src/template/aix                   |  7 ++++
 12 files changed, 223 insertions(+), 52 deletions(-)
 create mode 100755 src/backend/port/aix/mkldexport.sh
 create mode 100644 src/include/port/aix.h
 create mode 100644 src/makefiles/Makefile.aix
 create mode 100644 src/template/aix

diff --git a/Makefile b/Makefile
index 8a2ec9396b6..9bc1a4ec17b 100644
--- a/Makefile
+++ b/Makefile
@@ -13,8 +13,6 @@
 
 # AIX make defaults to building *every* target of the first rule.  Start with
 # a single-target, empty rule to make the other targets non-default.
-# (We don't support AIX anymore, but if someone tries to build on AIX anyway,
-# at least they'll get the instructions to run 'configure' first.)
 all:
 
 all check install installdirs installcheck installcheck-parallel uninstall clean distclean maintainer-clean dist distcheck world check-world install-world installcheck-world:
diff --git a/configure b/configure
index 507a2437c33..67cad0f5581 100755
--- a/configure
+++ b/configure
@@ -3022,6 +3022,7 @@ else
 # --with-template not given
 
 case $host_os in
+  aix*) template=aix ;;
   cygwin*|msys*) template=cygwin ;;
   darwin*) template=darwin ;;
 dragonfly*) template=netbsd ;;
@@ -17204,13 +17205,37 @@ _ACEOF
 # wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
 # much of a penalty for disk and memory space.
 
-MAX_ALIGNOF=$ac_cv_alignof_double
+echo "Checking for MAX ALIGN - $PORTNAME"
+if test "$PORTNAME" != "aix"; then
+    MAX_ALIGNOF=$ac_cv_alignof_double
 
-if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
-  as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
-fi
-if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
-  as_fn_error $? "alignment of 'int64_t' is greater than the alignment of 'double'" "$LINENO" 5
+    if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
+      as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+    if test x"$HAVE_LONG_LONG_INT_64" = xyes && test $ac_cv_alignof_long_long_int -gt $MAX_ALIGNOF ; then
+      as_fn_error $? "alignment of 'long long int' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+else
+# The AIX 'power' alignment rules apply the natural alignment of the "first
+# member" if it is of a floating-point data type (or is an aggregate whose
+# recursively "first" member or element is such a type). The alignment
+# associated with these types for subsequent members use an alignment value
+# where the floating-point data type is considered to have 4-byte alignment.
+# More info
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99557
+#
+# The double is aligned to 4-bytes on AIX in aggregates. But to maintain
+# alignement across platforms the max alignment of long should be considered.
+      echo "MAX ALIGN ac_cv_alignof_long"
+    MAX_ALIGNOF=$ac_cv_alignof_long
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_double ; then
+      MAX_ALIGNOF=$ac_cv_alignof_double
+      echo "MAX ALIGN ac_cv_alignof_double"
+    fi
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_int64_t; then
+      MAX_ALIGNOF="$ac_cv_alignof_int64_t"
+      echo "MAX ALIGN ac_cv_alignof_int64_t"
+    fi
 fi
 
 cat >>confdefs.h <<_ACEOF
diff --git a/configure.ac b/configure.ac
index 5f4548adc5c..a25aedacef2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -62,6 +62,7 @@ PGAC_ARG_REQ(with, template, [NAME], [override operating system template],
 # --with-template not given
 
 case $host_os in
+  aix*) template=aix ;;
   cygwin*|msys*) template=cygwin ;;
   darwin*) template=darwin ;;
 dragonfly*) template=netbsd ;;
@@ -2021,7 +2022,33 @@ AC_CHECK_ALIGNOF(double)
 # wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
 # much of a penalty for disk and memory space.
 
-MAX_ALIGNOF=$ac_cv_alignof_double
+if test "$PORTNAME" != "aix"; then
+    MAX_ALIGNOF=$ac_cv_alignof_double
+
+    if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
+      as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+    if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF; then
+      as_fn_error $? "alignment of 'long long int' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+else
+# The AIX 'power' alignment rules apply the natural alignment of the "first
+# member" if it is of a floating-point data type (or is an aggregate whose
+# recursively "first" member or element is such a type). The alignment
+# associated with these types for subsequent members use an alignment value
+# where the floating-point data type is considered to have 4-byte alignment.
+# More info
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99557
+# 
+# The double is aligned to 4-bytes on AIX in aggregates. But to maintain
+# alignement across platforms the max alignment of long should be considered.
+    MAX_ALIGNOF=$ac_cv_alignof_long
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_double ; then
+      MAX_ALIGNOF=$ac_cv_alignof_double
+    fi
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_int64_t ; then
+      MAX_ALIGNOF="$ac_cv_alignof_int64_t"
+    fi
 
 if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
   AC_MSG_ERROR([alignment of 'long' is greater than the alignment of 'double'])
diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index 3825af5b228..35adc4174ed 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -106,6 +106,20 @@ ifdef SO_MAJOR_VERSION
 override CPPFLAGS += -DSO_MAJOR_VERSION=$(SO_MAJOR_VERSION)
 endif
 
+ifeq ($(PORTNAME), aix)
+  LINK.shared		= $(COMPILER)
+  ifdef SO_MAJOR_VERSION
+    shlib		= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
+  endif
+  haslibarule   = yes
+  # $(exports_file) is also usable as an import file
+  exports_file		= lib$(NAME).exp
+  BUILD.exports		= ( echo '\#! $(shlib)'; $(AWK) '/^[^\#]/ {printf "%s\n",$$1}' $< ) > $@
+  ifneq (,$(SHLIB_EXPORTS))
+    LINK.shared		+= -Wl,-bE:$(exports_file)
+  endif
+endif
+
 ifeq ($(PORTNAME), darwin)
   ifdef soname
     # linkable library
@@ -254,6 +268,14 @@ $(stlib): $(OBJS) | $(SHLIB_PREREQS)
 	touch $@
 endif #haslibarule
 
+# AIX wraps both shared libraries and static library, which can be used both
+# for static and shared linking
+ifeq ($(PORTNAME), aix)
+$(stlib): $(shlib)
+	rm -f $(stlib)
+	$(AR) $(AROPT) $(stlib) $(shlib)
+endif # aix
+
 ifeq (,$(filter cygwin win32,$(PORTNAME)))
 
 # Normal case
@@ -267,8 +289,11 @@ ifneq ($(shlib), $(shlib_major))
 endif
 # Make sure we have a link to a name without any version numbers
 ifneq ($(shlib), $(shlib_bare))
+# except on AIX, where that's not a thing
+ifneq ($(PORTNAME), aix)
 	rm -f $(shlib_bare)
 	$(LN_S) $(shlib) $(shlib_bare)
+endif # aix
 endif # shlib_bare
 endif # shlib_major
 
@@ -376,6 +401,9 @@ install-lib-static: $(stlib) installdirs-lib
 
 install-lib-shared: $(shlib) installdirs-lib
 ifdef soname
+# we don't install $(shlib) on AIX
+# (see http://archives.postgresql.org/message-id/52EF20B2E3209443BC37736D00C3C1380A6E79FE@EXADV1.host.magwien.gv.at)
+ifneq ($(PORTNAME), aix)
 	$(INSTALL_SHLIB) $< '$(DESTDIR)$(libdir)/$(shlib)'
 ifneq ($(PORTNAME), cygwin)
 ifneq ($(PORTNAME), win32)
@@ -391,6 +419,7 @@ ifneq ($(shlib), $(shlib_bare))
 endif
 endif # not win32
 endif # not cygwin
+endif # not aix
 ifneq (,$(findstring $(PORTNAME),win32 cygwin))
 	$(INSTALL_SHLIB) $< '$(DESTDIR)$(bindir)/$(shlib)'
 endif
diff --git a/src/backend/Makefile b/src/backend/Makefile
index 7344c8c7f5c..572f5430a60 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -63,12 +63,14 @@ all: submake-libpgport submake-catalog-headers submake-utils-headers postgres $(
 
 ifneq ($(PORTNAME), cygwin)
 ifneq ($(PORTNAME), win32)
+ifneq ($(PORTNAME), aix)
 
 postgres: $(OBJS)
 	$(CC) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LIBS) -o $@
 
 endif
 endif
+endif
 
 ifeq ($(PORTNAME), cygwin)
 
@@ -95,6 +97,24 @@ libpostgres.a: postgres
 
 endif # win32
 
+ifeq ($(PORTNAME), aix)
+
+postgres: $(POSTGRES_IMP)
+	$(CC) $(CFLAGS) $(call expand_subsys,$(OBJS)) $(LDFLAGS) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -Wl,-brtllib -o $@
+
+# Linking to a single .o with -r is a lot faster than building a .a or passing
+# all objects to MKLDEXPORT.
+#
+# It looks alluring to use $(CC) -r instead of ld -r, but that doesn't
+# trivially work with gcc, due to gcc specific static libraries linked in with
+# -r.
+$(POSTGRES_IMP): $(OBJS)
+	ld -r -o SUBSYS.o $(call expand_subsys,$^)
+	$(MKLDEXPORT) SUBSYS.o . > $@
+	@rm -f SUBSYS.o
+
+endif # aix
+
 $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
 
 
diff --git a/src/backend/port/aix/mkldexport.sh b/src/backend/port/aix/mkldexport.sh
new file mode 100755
index 00000000000..adf3793e868
--- /dev/null
+++ b/src/backend/port/aix/mkldexport.sh
@@ -0,0 +1,61 @@
+#!/bin/sh
+#
+# mkldexport
+#	create an AIX exports file from an object file
+#
+# src/backend/port/aix/mkldexport.sh
+#
+# Usage:
+#	mkldexport objectfile [location]
+# where
+#	objectfile is the current location of the object file.
+#	location is the eventual (installed) location of the
+#		object file (if different from the current
+#		working directory).
+#
+# [This file comes from the Postgres 4.2 distribution. - ay 7/95]
+#
+# Header: /usr/local/devel/postgres/src/tools/mkldexport/RCS/mkldexport.sh,v 1.2 1994/03/13 04:59:12 aoki Exp
+#
+
+# setting this to nm -B might be better
+# ... due to changes in AIX 4.x ...
+# ... let us search in different directories - Gerhard Reithofer
+if [ -x /usr/ucb/nm ]
+then NM=/usr/ucb/nm
+elif [ -x /usr/bin/nm ]
+then NM=/usr/bin/nm
+elif [ -x /usr/ccs/bin/nm ]
+then NM=/usr/ccs/bin/nm
+elif [ -x /usr/usg/bin/nm ]
+then NM=/usr/usg/bin/nm
+else echo "Fatal error: cannot find `nm' ... please check your installation."
+     exit 1
+fi
+
+CMDNAME=`basename $0`
+if [ -z "$1" ]; then
+	echo "Usage: $CMDNAME object [location]"
+	exit 1
+fi
+OBJNAME=`basename $1`
+if [ "`basename $OBJNAME`" != "`basename $OBJNAME .o`" ]; then
+	OBJNAME=`basename $OBJNAME .o`.so
+fi
+if [ -z "$2" ]; then
+	echo '#!'
+else
+	if [ "$2" = "." ]; then
+		# for the base executable (AIX 4.2 and up)
+		echo '#! .'
+	else
+		echo '#!' $2
+	fi
+fi
+$NM -BCg $1 | \
+	egrep ' [TDB] ' | \
+	sed -e 's/.* //' | \
+	egrep -v '\$' | \
+	sed -e 's/^[.]//' | \
+	sort | \
+	uniq
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index b7b9692f8c8..d0c4b7ba3ac 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -905,7 +905,9 @@ errcode_for_file_access(void)
 			/* Wrong object type or state */
 		case ENOTDIR:			/* Not a directory */
 		case EISDIR:			/* Is a directory */
+#if defined(ENOTEMPTY) && (ENOTEMPTY != EEXIST) /* same code on AIX */
 		case ENOTEMPTY:			/* Directory not empty */
+#endif
 			edata->sqlerrcode = ERRCODE_WRONG_OBJECT_TYPE;
 			break;
 
diff --git a/src/include/port/aix.h b/src/include/port/aix.h
new file mode 100644
index 00000000000..7d08480c8c0
--- /dev/null
+++ b/src/include/port/aix.h
@@ -0,0 +1,4 @@
+/*
+ * src/include/port/aix.h
+ */
+
diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
index 2f73f9fcf57..ba120c08d14 100644
--- a/src/include/storage/s_lock.h
+++ b/src/include/storage/s_lock.h
@@ -398,56 +398,18 @@ typedef unsigned int slock_t;
 
 #define TAS(lock) tas(lock)
 
-/* On PPC, it's a win to use a non-locking test before the lwarx */
+/* On PPC, use the compiler provided Built-in functions for atomic memory
+ * exchange operations.
+ */
 #define TAS_SPIN(lock)	(*(lock) ? 1 : TAS(lock))
 
-/*
- * The second operand of addi can hold a constant zero or a register number,
- * hence constraint "=&b" to avoid allocating r0.  "b" stands for "address
- * base register"; most operands having this register-or-zero property are
- * address bases, e.g. the second operand of lwax.
- *
- * NOTE: per the Enhanced PowerPC Architecture manual, v1.0 dated 7-May-2002,
- * an isync is a sufficient synchronization barrier after a lwarx/stwcx loop.
- * But if the spinlock is in ordinary memory, we can use lwsync instead for
- * better performance.
- */
 static __inline__ int
 tas(volatile slock_t *lock)
 {
-	slock_t _t;
-	int _res;
-
-	__asm__ __volatile__(
-"	lwarx   %0,0,%3,1	\n"
-"	cmpwi   %0,0		\n"
-"	bne     1f			\n"
-"	addi    %0,%0,1		\n"
-"	stwcx.  %0,0,%3		\n"
-"	beq     2f			\n"
-"1: \n"
-"	li      %1,1		\n"
-"	b       3f			\n"
-"2: \n"
-"	lwsync				\n"
-"	li      %1,0		\n"
-"3: \n"
-:	"=&b"(_t), "=r"(_res), "+m"(*lock)
-:	"r"(lock)
-:	"memory", "cc");
-	return _res;
+	return __sync_lock_test_and_set(lock, 1);
 }
 
-/*
- * PowerPC S_UNLOCK is almost standard but requires a "sync" instruction.
- * But we can use lwsync instead for better performance.
- */
-#define S_UNLOCK(lock)	\
-do \
-{ \
-	__asm__ __volatile__ ("	lwsync \n" ::: "memory"); \
-	*((volatile slock_t *) (lock)) = 0; \
-} while (0)
+#define S_UNLOCK(lock) __sync_lock_release(lock)
 
 #endif /* powerpc */
 
diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix
new file mode 100644
index 00000000000..4c4de8b0be7
--- /dev/null
+++ b/src/makefiles/Makefile.aix
@@ -0,0 +1,34 @@
+# -blibpath:
+# The path to be inserted into the default path (Index 0 path) field of the
+# loader section. When this flag is presented, the -L paths will not be stored. 
+# AIX uses a stricter, more explicit approach. The runtime linker expects to
+# tell it exactly where to look using -blibpath.
+# -blibpath must contain ALL directories where we should look for libraries
+libpath := $(shell echo $(subst -L,:,$(filter -L/%,$(LDFLAGS))) | sed -e's/ //g'):/usr/lib:/lib
+
+# AIX uses a stricter, more explicit approach. The runtime linker expects 
+# to tell it exactly where to look using -blibpath.
+rpath = -Wl,-blibpath:'$(rpathdir)$(libpath)'
+
+# gcc needs to know it's building a shared lib, otherwise it'll not emit
+# correct code / link to the right support libraries
+ifeq ($(GCC), yes)
+LDFLAGS_SL += -shared
+endif
+
+# env var name to use in place of LD_LIBRARY_PATH
+ld_library_path_var = LIBPATH
+
+POSTGRES_IMP= postgres.imp
+
+ifdef PGXS
+BE_DLLLIBS= -Wl,-bI:$(pkglibdir)/$(POSTGRES_IMP)
+else
+BE_DLLLIBS= -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP)
+endif
+
+MKLDEXPORT_DIR=src/backend/port/aix
+MKLDEXPORT=$(top_srcdir)/$(MKLDEXPORT_DIR)/mkldexport.sh
+
+%$(DLSUFFIX): %.o
+	$(CC) $(CFLAGS) $*.o $(LDFLAGS) $(LDFLAGS_SL) -o $@ $(BE_DLLLIBS)
diff --git a/src/port/strerror.c b/src/port/strerror.c
index f0746517770..c46b9dc91fc 100644
--- a/src/port/strerror.c
+++ b/src/port/strerror.c
@@ -214,8 +214,10 @@ get_errno_symbol(int errnum)
 			return "ENOTCONN";
 		case ENOTDIR:
 			return "ENOTDIR";
+#if defined(ENOTEMPTY) && (ENOTEMPTY != EEXIST) /* same code on AIX */
 		case ENOTEMPTY:
 			return "ENOTEMPTY";
+#endif
 		case ENOTSOCK:
 			return "ENOTSOCK";
 #ifdef ENOTSUP
diff --git a/src/template/aix b/src/template/aix
new file mode 100644
index 00000000000..bfc193348f4
--- /dev/null
+++ b/src/template/aix
@@ -0,0 +1,7 @@
+# This file is referred for specific flags wrt to AIX build process like
+# cflags.
+# src/template/aix
+
+# Extra CFLAGS for code that will go into a shared library
+# With optimization, the MemSet() and MemSetAlign() perform better.
+CFLAGS_SL=" -O2 "
-- 
2.41.0



  [text/plain] bfarm.19.log (5.3K, 4-bfarm.19.log)
  download | inline:
Mon Sep 15 18:56:20 2025: buildfarm run for uruspg19:HEAD starting
branch not specified, locks, logs, build artefacts etc will go in HEAD
uruspg19:HEAD          [18:59:44] running configure ...
uruspg19:HEAD          [19:01:04] running build ...
uruspg19:HEAD          [19:01:52] running basic regression tests ...
uruspg19:HEAD          [19:10:10] running make contrib ...
uruspg19:HEAD          [19:10:11] running make testmodules ...
uruspg19:HEAD          [19:10:12] running install ...
uruspg19:HEAD          [19:10:56] running make contrib install ...
uruspg19:HEAD          [19:11:12] running testmodules install ...
uruspg19:HEAD          [19:11:19] running make check miscellaneous modules ...
uruspg19:HEAD          [19:13:31] running bin test initdb ...
uruspg19:HEAD          [19:13:57] running bin test pg_amcheck ...
uruspg19:HEAD          [19:14:23] running bin test pg_archivecleanup ...
uruspg19:HEAD          [19:14:24] running bin test pg_basebackup ...
uruspg19:HEAD          [19:15:38] running bin test pg_checksums ...
uruspg19:HEAD          [19:15:45] running bin test pg_combinebackup ...
uruspg19:HEAD          [19:17:10] running bin test pg_config ...
uruspg19:HEAD          [19:17:10] running bin test pg_controldata ...
uruspg19:HEAD          [19:17:13] running bin test pg_ctl ...
uruspg19:HEAD          [19:17:31] running bin test pg_dump ...
uruspg19:HEAD          [19:20:40] running bin test pg_resetwal ...
uruspg19:HEAD          [19:20:46] running bin test pg_rewind ...
uruspg19:HEAD          [19:22:25] running bin test pg_test_fsync ...
uruspg19:HEAD          [19:22:26] running bin test pg_test_timing ...
uruspg19:HEAD          [19:22:28] running bin test pg_upgrade ...
uruspg19:HEAD          [19:33:01] running bin test pg_verifybackup ...
uruspg19:HEAD          [19:34:38] running bin test pg_waldump ...
uruspg19:HEAD          [19:34:49] running bin test pg_walsummary ...
uruspg19:HEAD          [19:34:54] running bin test pgbench ...
uruspg19:HEAD          [19:35:25] running bin test psql ...
uruspg19:HEAD          [19:35:34] running bin test scripts ...
uruspg19:HEAD          [19:36:55] running test misc-recovery ...
uruspg19:HEAD          [19:57:56] running test misc-subscription ...
uruspg19:HEAD          [20:05:06] running test misc-authentication ...
uruspg19:HEAD          [20:05:30] running misc test module-brin ...
uruspg19:HEAD          [20:05:44] running misc test module-commit_ts ...
uruspg19:HEAD          [20:06:10] running misc test module-injection_points ...
uruspg19:HEAD          [20:06:10] running misc test module-ldap_password_func ...
uruspg19:HEAD          [20:06:11] running misc test module-libpq_pipeline ...
uruspg19:HEAD          [20:06:15] running misc test module-oauth_validator ...
uruspg19:HEAD          [20:06:16] running misc test module-ssl_passphrase_callback ...
uruspg19:HEAD          [20:06:19] running misc test module-test_aio ...
uruspg19:HEAD          [20:06:34] running misc test module-test_custom_rmgrs ...
uruspg19:HEAD          [20:06:37] running misc test module-test_escape ...
uruspg19:HEAD          [20:06:41] running misc test module-test_extensions ...
uruspg19:HEAD          [20:06:48] running misc test module-test_int128 ...
uruspg19:HEAD          [20:06:49] running misc test module-test_json_parser ...
uruspg19:HEAD          [20:07:19] running misc test module-test_misc ...
uruspg19:HEAD          [20:07:34] running misc test module-test_pg_dump ...
uruspg19:HEAD          [20:07:56] running misc test module-test_slru ...
uruspg19:HEAD          [20:07:59] running misc test module-worker_spi ...
uruspg19:HEAD          [20:08:05] running misc test module-xid_wraparound ...
uruspg19:HEAD          [20:08:06] running misc test module-libpq ...
uruspg19:HEAD          [20:08:25] running misc test module-pg_bsd_indent ...
uruspg19:HEAD          [20:08:29] running contrib test amcheck ...
uruspg19:HEAD          [20:09:09] running contrib test auto_explain ...
uruspg19:HEAD          [20:09:16] running contrib test basebackup_to_shell ...
uruspg19:HEAD          [20:09:23] running contrib test bloom ...
uruspg19:HEAD          [20:09:48] running contrib test oid2name ...
uruspg19:HEAD          [20:09:49] running contrib test pg_stat_statements ...
uruspg19:HEAD          [20:10:03] running contrib test postgres_fdw ...
Use of uninitialized value $ENV{"PG_TEST_EXTRA"} in pattern match (m//) at ./run_build.pl line 2510.
uruspg19:HEAD          [20:10:24] running contrib test test_decoding ...
uruspg19:HEAD          [20:10:47] running contrib test vacuumlo ...
uruspg19:HEAD          [20:10:48] setting up db cluster (C)...
uruspg19:HEAD          [20:10:50] starting db (C)...
uruspg19:HEAD          [20:10:50] running installcheck (C)...
uruspg19:HEAD          [20:19:31] restarting db (C)...
uruspg19:HEAD          [20:19:34] running make isolation check ...
uruspg19:HEAD          [20:22:11] restarting db (C)...
uruspg19:HEAD          [20:22:18] running make PL installcheck (C)...
uruspg19:HEAD          [20:22:24] restarting db (C)...
uruspg19:HEAD          [20:22:26] running make contrib installcheck (C)...
uruspg19:HEAD          [20:30:42] restarting db (C)...
uruspg19:HEAD          [20:30:47] running make test-modules installcheck (C)...
uruspg19:HEAD          [20:36:44] stopping db (C)...
uruspg19:HEAD          [20:36:46] running make ecpg check ...
uruspg19:HEAD          [20:37:19] OK
Branch: HEAD
All stages succeeded

^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-09-18 06:21  Vamshikrishna T <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  0 siblings, 0 replies; 47+ messages in thread

From: Vamshikrishna T @ 2025-09-18 06:21 UTC (permalink / raw)
  To: [email protected]; +Cc: AIX PG user <[email protected]>

This patch marked 10/10 with all CI checks passing. Your feedback on the patch would be greatly appreciated.

^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-09-20 15:20  Alvaro Herrera <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  1 sibling, 1 reply; 47+ messages in thread

From: Alvaro Herrera @ 2025-09-20 15:20 UTC (permalink / raw)
  To: Srirama Kucherlapati <[email protected]>; +Cc: Heikki Linnakangas <[email protected]>; pgsql-hackers; Robert Haas <[email protected]>; Bruce Momjian <[email protected]>; Peter Eisentraut <[email protected]>; Laurenz Albe <[email protected]>; Noah Misch <[email protected]>; Michael Paquier <[email protected]>; Andres Freund <[email protected]>; Thomas Munro <[email protected]>; [email protected] <[email protected]>; Tom Lane <[email protected]>; Tristan Partin <[email protected]>; wenhui qiu <[email protected]>; [email protected] <[email protected]>

On 2025-Sep-03, Srirama Kucherlapati wrote:

> As part of our ongoing efforts to enhance AIX platform compatibility,
> we’ve been running the code across all stable PostgreSQL release
> branches using the build farm infrastructure. All test suites,
> including TAP tests, are passing consistently, indicating no
> regressions.

The buildfarm results you sent look good.  You should definitely be
testing branch master though rather than the stable ones, because it's
not clear to me, as Bruce said, that we would really backpatch AIX
support to stable branches.  (You're of course free to produce your own
packages from patched versions, in the interim).

I noticed that you add mkldexport.sh and that the makefiles use it.  I
wonder if that really is necessary with the current AIX tooling (it
looks an outdated gadget).

Also, I notice that Meson supports AIX starting from version 0.56; did
you verify whether it works to build this with that?

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/





^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-09-22 11:09  AIX PG user <[email protected]>
  parent: Alvaro Herrera <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: AIX PG user @ 2025-09-22 11:09 UTC (permalink / raw)
  To: [email protected]; +Cc: AIX PG user <[email protected]>

Hi Alvaro,
Thank you for taking your time to look into the details.

I’ve submitted the latest changes to the master branch, which are now available in the annotations section here:
    https://commitfest.postgresql.org/patch/6050/
I kindly request you to review this updated patch and share your valuable feedback.

Regarding your observation about the inclusion of mkldexport.sh and its usage in the makefiles — as previously 
discussed, this is a necessary workaround due to current limitations on AIX. To build shared libraries, we need to 
extract symbols using this script. The relevant details are as follows:
  Script Location: src/backend/port/aix/mkldexport.sh
  Purpose: Implements AIX-specific changes for shared library creation using export files.
  Background: Based on discussions with the internal linker team, this method is currently required to extract symbols and build shared libraries.
  Reference Practices: This approach is consistent with methods used in other open-source projects such as Python and OpenBLAS:
  Python
    https://github.com/python/cpython/blob/main/Modules/ld_so_aix.in
  OpenBLAS
    https://github.com/OpenMathLib/OpenBLAS/commit/892f8ff3e55e24fda9af3f6364319cce3f60116b#diff-4011a11...

As for Meson builds, we did explore them earlier but encountered some issues. Here are some issues/fixes we submitted to the meson community
  https://github.com/mesonbuild/meson/issues/14334
For now, we would like to focus initially on the regular gmake build since our buildfarms predominantly use it. That said, we do plan to submit Meson-related changes as a separate patch in the future. 

Looking forward to your feedback.

-Sriram

^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-09-22 12:27  Andres Freund <[email protected]>
  parent: AIX PG user <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: Andres Freund @ 2025-09-22 12:27 UTC (permalink / raw)
  To: AIX PG user <[email protected]>; +Cc: [email protected]

Hi,

On 2025-09-22 11:09:53 +0000, AIX PG user wrote:
> As for Meson builds, we did explore them earlier but encountered some
> issues. Here are some issues/fixes we submitted to the meson community
> https://github.com/mesonbuild/meson/issues/14334 For now, we would like to
> focus initially on the regular gmake build since our buildfarms
> predominantly use it. That said, we do plan to submit Meson-related changes
> as a separate patch in the future.

I think we should do the opposite if anything. We're planning to eventually
remove make based builds.

But I'm also suprprised - before the removal meson based builds on AIX were
working. Why didn't you just revive it as it was?

Greetings,

Andres Freund





^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-09-23 14:26  AIX PG user <[email protected]>
  parent: Andres Freund <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: AIX PG user @ 2025-09-23 14:26 UTC (permalink / raw)
  To: [email protected]; +Cc: AIX PG user <[email protected]>

Hi Andres,
Thank you for your feedback and for highlighting the importance of Meson-based builds.

We fully recognize the long-term objective of transitioning away from
make-based builds, and we are actively working on reviving Meson support for
AIX in alignment with that direction. However, we are currently encountering a
few errors with the revived changes, and we are working actively to
resolve them. I will keep you updated and share the finalized Meson-related
changes at the earliest opportunity.

In the meantime, we would sincerely appreciate it if you/team could review the patch
with respect to the gmake build and the associated source-level modifications
submitted on commitfest.
    https://commitfest.postgresql.org/patch/6050/

Your input would be invaluable in helping us ensure the correctness and
completeness of the implementation before we proceed further.  Thank you once
again for your continued guidance and support.

Warm regards,
Sriram.

^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-09-23 14:36  Andres Freund <[email protected]>
  parent: AIX PG user <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: Andres Freund @ 2025-09-23 14:36 UTC (permalink / raw)
  To: AIX PG user <[email protected]>; +Cc: [email protected]

Hi,

On 2025-09-23 14:26:08 +0000, AIX PG user wrote:
> Thank you for your feedback and for highlighting the importance of Meson-based builds.
> 
> We fully recognize the long-term objective of transitioning away from
> make-based builds, and we are actively working on reviving Meson support for
> AIX in alignment with that direction. However, we are currently encountering a
> few errors with the revived changes, and we are working actively to
> resolve them. I will keep you updated and share the finalized Meson-related
> changes at the earliest opportunity.

It worked without meson changes just before the AIX support was dropped. I do
not see why you *need* that meson patch, rather it just being convenient -
after all I had made it work before, without that.


> In the meantime, we would sincerely appreciate it if you/team could review the patch
> with respect to the gmake build and the associated source-level modifications
> submitted on commitfest.

I'd personally just not add gmake support at all, but ...

>     https://commitfest.postgresql.org/patch/6050/
> 
> Your input would be invaluable in helping us ensure the correctness and
> completeness of the implementation before we proceed further.  Thank you once
> again for your continued guidance and support.

One suggestion I do have is to split the patch into a few constitutent pieces.

Greetings,

Andres Freund





^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* RE: AIX support
@ 2025-09-23 15:28  Srirama Kucherlapati <[email protected]>
  parent: Andres Freund <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: Srirama Kucherlapati @ 2025-09-23 15:28 UTC (permalink / raw)
  To: Andres Freund <[email protected]>; AIX PG user <[email protected]>; +Cc: [email protected] <[email protected]>

Hi Andres,
> It worked without meson changes just before the AIX support was dropped. I do
> not see why you *need* that meson patch, rather it just being convenient -
> after all I had made it work before, without that.

I was able to build successfully using Meson on PostgreSQL 16. However, when attempting the same on the latest master(with the revived changes), I encountered a few errors. We are currently investigating these issues and working on the necessary fixes.
I’ll keep you updated once the Meson-related fixes are ready.

> One suggestion I do have is to split the patch into a few constitutent pieces.
Thank you for the suggestion.
Splitting the patch into smaller, constituent pieces makes sense and would certainly help with clarity and review.
Appreciate your guidance.


Warm regards,
Sriram.



^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* RE: AIX support
@ 2025-10-15 15:58  Srirama Kucherlapati <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  0 siblings, 2 replies; 47+ messages in thread

From: Srirama Kucherlapati @ 2025-10-15 15:58 UTC (permalink / raw)
  To: Andres Freund <[email protected]>; AIX PG user <[email protected]>; +Cc: [email protected] <[email protected]>

Hi Andres and team,

Please find attached the patch addressing Meson build changes for AIX.
We tried to build using below meson
## meson -v
1.6.1

For the following files, the shared_module() function requires specifying the
appropriate symbol import file, which is provided via the aix_link_args
variable:
src/backend/jit/llvm/meson.build
src/backend/replication/libpqwalreceiver/meson.build
src/backend/replication/pgoutput/meson.build
src/backend/snowball/meson.build
src/backend/utils/mb/conversion_procs/meson.build

Additionally, with the latest version of Meson, when building static libraries,
the library file name must be suffixed with “_static” in the following files:
src/interfaces/ecpg/compatlib/meson.build
src/interfaces/ecpg/ecpglib/meson.build
src/interfaces/ecpg/pgtypeslib/meson.build
src/interfaces/libpq/meson.build


Main AIX changes patch - 0001-Changes-to-add-support-for-AIX.v9.pg19.patch (previously submitted one)
Meson AIX changes patch - 0001-AIX-changes-for-meson-build.patch

Looking forward to hearing your thoughts on these changes.
Your feedback on these updates is highly valued.

Thanks,
Sriram.


Attachments:

  [application/octet-stream] 0001-AIX-changes-for-meson-build.v9.pg19.patch (12.9K, 3-0001-AIX-changes-for-meson-build.v9.pg19.patch)
  download | inline diff:
From 18dd09463342bbc836c7a8dda3a3864ceb083176 Mon Sep 17 00:00:00 2001
From: AIX-dev <[email protected]>
Date: Wed, 15 Oct 2025 09:33:07 -0500
Subject: [PATCH] AIX changes for meson build.

---
 meson.build                                   | 25 +++++++++++--
 src/backend/jit/llvm/meson.build              |  6 ++++
 src/backend/meson.build                       | 36 ++++++++++++++++++-
 .../replication/libpqwalreceiver/meson.build  |  8 ++++-
 src/backend/replication/pgoutput/meson.build  |  6 ++++
 src/backend/snowball/meson.build              |  8 ++++-
 .../utils/mb/conversion_procs/meson.build     |  6 ++++
 src/include/port/aix.h                        | 22 ++++++++++++
 src/interfaces/ecpg/compatlib/meson.build     |  8 ++++-
 src/interfaces/ecpg/ecpglib/meson.build       |  7 +++-
 src/interfaces/ecpg/pgtypeslib/meson.build    |  7 +++-
 src/interfaces/libpq/meson.build              | 14 ++++++--
 src/tools/gen_export.pl                       | 13 +++++--
 13 files changed, 154 insertions(+), 12 deletions(-)

diff --git a/meson.build b/meson.build
index a87eb913fff..27c0f38ebc8 100644
--- a/meson.build
+++ b/meson.build
@@ -198,7 +198,26 @@ endif
 # that purpose.
 portname = host_system
 
-if host_system == 'cygwin'
+if host_system == 'aix'
+  library_path_var = 'LIBPATH'
+
+  export_file_format = 'aix'
+  export_fmt = '-Wl,-bE:@0@'
+  mod_link_args_fmt = ['-Wl,-bI:@0@']
+  mod_link_with_dir = 'libdir'
+  mod_link_with_name = '@[email protected]'
+
+  # M:SRE sets a flag indicating that an object is a shared library. Seems to
+  # work in some circumstances without, but required in others.
+  ldflags_sl += '-Wl,-bM:SRE'
+  ldflags_be += '-Wl,-brtllib'
+
+  # Native memset() is faster, tested on:
+  # - AIX 5.1 and 5.2, XLC 6.0 (IBM's cc)
+  # - AIX 5.3 ML3, gcc 4.0.1
+  #memset_loop_limit = 0
+
+elif host_system == 'cygwin'
   sema_kind = 'unnamed_posix'
   cppflags += '-D_GNU_SOURCE'
   dlsuffix = '.dll'
@@ -1775,7 +1794,9 @@ endforeach
 # would be too much of a penalty for disk and memory space.
 alignof_double = cdata.get('ALIGNOF_DOUBLE')
 if cc.alignment('int64_t', args: test_c_args, prefix: '#include <stdint.h>') > alignof_double
-  error('alignment of int64_t is greater than the alignment of double')
+  if host_system != 'aix'
+    error('alignment of int64_t is greater than the alignment of double')
+  endif
 endif
 cdata.set('MAXIMUM_ALIGNOF', alignof_double)
 
diff --git a/src/backend/jit/llvm/meson.build b/src/backend/jit/llvm/meson.build
index 805fbd69006..f83db9d0d6e 100644
--- a/src/backend/jit/llvm/meson.build
+++ b/src/backend/jit/llvm/meson.build
@@ -29,11 +29,17 @@ if host_system == 'windows'
     '--FILEDESC', 'llvmjit - JIT using LLVM',])
 endif
 
+aix_link_args= []
+if host_machine.system() == 'aix'
+  aix_link_args = ['-Wl,-bI:' + meson.project_build_root() + '/src/backend/postgres.imp']
+endif
+
 llvmjit = shared_module('llvmjit',
   llvmjit_sources,
   kwargs: pg_mod_args + {
     'dependencies': pg_mod_args['dependencies'] + [llvm],
     'cpp_args': pg_mod_args['cpp_args'] + llvm.get_variable(configtool: 'cxxflags').split(),
+    link_args: aix_link_args
   }
 )
 
diff --git a/src/backend/meson.build b/src/backend/meson.build
index b831a541652..47c0eae1309 100644
--- a/src/backend/meson.build
+++ b/src/backend/meson.build
@@ -125,6 +125,40 @@ if host_system == 'windows'
     '--FILEDESC', 'PostgreSQL Server',])
 endif
 
+if host_system == 'aix'
+find_obj_files = find_program('sh', required: true)
+
+cb_o = custom_target(
+   'SUBSYS.o',
+    input: [postgres_lib.extract_all_objects(recursive: true)],
+    output: 'SUBSYS.o',
+   command: ['ld', '-r', '-o', '@OUTPUT@', '@INPUT@'],
+   install: false,
+  )
+postgres_imp = 'postgres.imp'
+
+generate_import_file = custom_target('generate_import_file', output: postgres_imp, command: ['sh', '-c', '../src/backend/port/aix/mkldexport.sh src/backend/SUBSYS.o . > src/backend/postgres.imp'], build_by_default: true, depends: [cb_o])
+
+my_dep = declare_dependency(sources:[generate_import_file])
+#libpq_aix_deps += my_dep
+backend_link_depends += generate_import_file
+
+endif
+
+if host_system == 'aix'
+ postgres = executable('postgres',
+   backend_input,
+   sources: post_export_backend_sources,
+   objects: backend_objs,
+   link_args: backend_link_args + ['-Wl,-bE:src/backend/postgres.imp'],
+   link_with: backend_link_with,
+   link_depends: backend_link_depends,
+   export_dynamic: true,
+   implib: 'postgres',
+   dependencies: backend_build_deps + [my_dep],
+   kwargs: default_bin_args,
+)
+else
 postgres = executable('postgres',
   backend_input,
   sources: post_export_backend_sources,
@@ -137,7 +171,7 @@ postgres = executable('postgres',
   dependencies: backend_build_deps,
   kwargs: default_bin_args,
 )
-
+endif
 backend_targets += postgres
 
 pg_mod_c_args = cflags_mod
diff --git a/src/backend/replication/libpqwalreceiver/meson.build b/src/backend/replication/libpqwalreceiver/meson.build
index 2150f31cfa3..135062244d4 100644
--- a/src/backend/replication/libpqwalreceiver/meson.build
+++ b/src/backend/replication/libpqwalreceiver/meson.build
@@ -10,12 +10,18 @@ if host_system == 'windows'
     '--FILEDESC', 'libpqwalreceiver - receive WAL during streaming replication',])
 endif
 
+aix_link_args= []
+if host_machine.system() == 'aix'
+  aix_link_args = ['-Wl,-bI:' + meson.project_build_root() + '/src/backend/postgres.imp']
+endif
+
 libpqwalreceiver = shared_module('pqwalreceiver',
   libpqwalreceiver_sources,
   kwargs: pg_mod_args + {
     'name_prefix': 'lib',
     'dependencies': pg_mod_args['dependencies'] + [libpq],
-  }
+  },
+  link_args: aix_link_args
 )
 
 backend_targets += libpqwalreceiver
diff --git a/src/backend/replication/pgoutput/meson.build b/src/backend/replication/pgoutput/meson.build
index 14e2f03ada0..9fbd035988b 100644
--- a/src/backend/replication/pgoutput/meson.build
+++ b/src/backend/replication/pgoutput/meson.build
@@ -10,9 +10,15 @@ if host_system == 'windows'
     '--FILEDESC', 'pgoutput - standard logical replication output plugin',])
 endif
 
+aix_link_args= []
+if host_machine.system() == 'aix'
+  aix_link_args = ['-Wl,-bI:' + meson.project_build_root() + '/src/backend/postgres.imp']
+endif
+
 pgoutput = shared_module('pgoutput',
   pgoutput_sources,
   kwargs: pg_mod_args,
+  link_args: aix_link_args
 )
 
 backend_targets += pgoutput
diff --git a/src/backend/snowball/meson.build b/src/backend/snowball/meson.build
index 8e73d9d7368..92b3934bcc6 100644
--- a/src/backend/snowball/meson.build
+++ b/src/backend/snowball/meson.build
@@ -66,12 +66,18 @@ if host_system == 'windows'
     '--FILEDESC', 'snowball - natural language stemmers',])
 endif
 
+aix_link_args= []
+if host_machine.system() == 'aix'
+  aix_link_args = ['-Wl,-bI:' + meson.project_build_root() + '/src/backend/postgres.imp']
+endif
+
 dict_snowball = shared_module('dict_snowball',
   dict_snowball_sources,
   c_pch: pch_postgres_h,
   kwargs: pg_mod_args + {
     'include_directories': [stemmer_inc],
-  }
+  },
+  link_args: aix_link_args
 )
 
 snowball_create = custom_target('snowball_create',
diff --git a/src/backend/utils/mb/conversion_procs/meson.build b/src/backend/utils/mb/conversion_procs/meson.build
index 0e8273e0b61..a76c4993055 100644
--- a/src/backend/utils/mb/conversion_procs/meson.build
+++ b/src/backend/utils/mb/conversion_procs/meson.build
@@ -38,8 +38,14 @@ foreach encoding, sources : encodings
       '--NAME', encoding])
   endif
 
+  aix_link_args= []
+  if host_machine.system() == 'aix'
+    aix_link_args = ['-Wl,-bI:' + meson.project_build_root() + '/src/backend/postgres.imp']
+  endif
+
   backend_targets += shared_module(encoding,
     source_files,
     kwargs: pg_mod_args,
+    link_args: aix_link_args
   )
 endforeach
diff --git a/src/include/port/aix.h b/src/include/port/aix.h
index 7d08480c8c0..450e68da657 100644
--- a/src/include/port/aix.h
+++ b/src/include/port/aix.h
@@ -2,3 +2,25 @@
  * src/include/port/aix.h
  */
 
+/* These changes are required for the meson changes as the autoconf is not run
+ * and corresponding  key feature macros are defined here.
+ */
+ 
+#ifdef _AIX
+#ifndef PGDLLIMPORT
+#define PGDLLIMPORT
+#endif  /* PGDLLIMPORT */
+typedef float float4;
+typedef double float8;
+
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
+#define pg_noreturn _Noreturn
+#elif defined(__GNUC__)
+#define pg_noreturn __attribute__((noreturn))
+#else
+#define pg_noreturn
+#endif
+
+#include <stdbool.h>
+
+#endif  /*_AIX */
diff --git a/src/interfaces/ecpg/compatlib/meson.build b/src/interfaces/ecpg/compatlib/meson.build
index 56e0a21651b..d199002f7ed 100644
--- a/src/interfaces/ecpg/compatlib/meson.build
+++ b/src/interfaces/ecpg/compatlib/meson.build
@@ -15,8 +15,14 @@ if host_system == 'windows'
     '--FILEDESC', 'ECPG compat - compatibility library for ECPG',])
 endif
 
+libname = 'libecpg_compat'
+if host_machine.system() == 'aix'
+  libname += '_static'
+endif
+
+
 # see src/interfaces/libpq/meson.build
-ecpg_compat_st = static_library('libecpg_compat',
+ecpg_compat_st = static_library(libname,
   ecpg_compat_sources,
   include_directories: ecpg_compat_inc,
   c_args: ecpg_compat_c_args,
diff --git a/src/interfaces/ecpg/ecpglib/meson.build b/src/interfaces/ecpg/ecpglib/meson.build
index 8f478c6a73e..448a0038a71 100644
--- a/src/interfaces/ecpg/ecpglib/meson.build
+++ b/src/interfaces/ecpg/ecpglib/meson.build
@@ -24,8 +24,13 @@ if host_system == 'windows'
     '--FILEDESC', 'ECPG - embedded SQL in C',])
 endif
 
+libname = 'libecpg'
+if host_machine.system() == 'aix'
+  libname += '_static'
+endif
+
 # see src/interfaces/libpq/meson.build
-ecpglib_st = static_library('libecpg',
+ecpglib_st = static_library(libname,
   ecpglib_sources,
   include_directories: ecpglib_inc,
   c_args: ecpglib_c_args,
diff --git a/src/interfaces/ecpg/pgtypeslib/meson.build b/src/interfaces/ecpg/pgtypeslib/meson.build
index 02301ec9acb..6421930dc05 100644
--- a/src/interfaces/ecpg/pgtypeslib/meson.build
+++ b/src/interfaces/ecpg/pgtypeslib/meson.build
@@ -20,8 +20,13 @@ if host_system == 'windows'
     '--FILEDESC', 'pgtypes - library for data type mapping',])
 endif
 
+libname = 'libpgtypes'
+if host_machine.system() == 'aix'
+  libname += '_static'
+endif
+
 # see src/interfaces/libpq/meson.build
-ecpg_pgtypes_st = static_library('libpgtypes',
+ecpg_pgtypes_st = static_library(libname,
   ecpg_pgtypes_sources,
   include_directories: ecpg_pgtypes_inc,
   c_args: ecpg_pgtypes_c_args,
diff --git a/src/interfaces/libpq/meson.build b/src/interfaces/libpq/meson.build
index a74e885b169..3e96d3f073e 100644
--- a/src/interfaces/libpq/meson.build
+++ b/src/interfaces/libpq/meson.build
@@ -49,6 +49,11 @@ libpq_c_args = ['-DSO_MAJOR_VERSION=5']
 # The OAuth implementation differs depending on the type of library being built.
 libpq_so_c_args = ['-DUSE_DYNAMIC_OAUTH']
 
+libname = 'libpq'
+if host_machine.system() == 'aix'
+  libname += '_static'
+endif
+
 # Not using both_libraries() here as
 # 1) resource files should only be in the shared library
 # 2) we want the .pc file to include a dependency to {pgport,common}_static for
@@ -57,7 +62,7 @@ libpq_so_c_args = ['-DUSE_DYNAMIC_OAUTH']
 # We could try to avoid building the source files twice, but it probably adds
 # more complexity than its worth (reusing object files requires also linking
 # to the library on windows or breaks precompiled headers).
-libpq_st = static_library('libpq',
+libpq_st = static_library(libname,
   libpq_sources,
   include_directories: [libpq_inc],
   c_args: libpq_c_args,
@@ -66,6 +71,11 @@ libpq_st = static_library('libpq',
   kwargs: default_lib_args,
 )
 
+aix_link_args = []
+if host_machine.system() == 'aix'
+  aix_link_args = ['-Wl,-bI:' + export_file.full_path()]
+endif
+
 libpq_so = shared_library('libpq',
   libpq_sources + libpq_so_sources,
   include_directories: [libpq_inc, postgres_inc],
@@ -76,7 +86,7 @@ libpq_so = shared_library('libpq',
   darwin_versions: ['5', '5.' + pg_version_major.to_string()],
   dependencies: [frontend_shlib_code, libpq_deps],
   link_depends: export_file,
-  link_args: export_fmt.format(export_file.full_path()),
+  link_args: [export_fmt.format(export_file.full_path()), aix_link_args],
   kwargs: default_lib_args,
 )
 
diff --git a/src/tools/gen_export.pl b/src/tools/gen_export.pl
index 86a7742b369..19c8b60560f 100644
--- a/src/tools/gen_export.pl
+++ b/src/tools/gen_export.pl
@@ -18,9 +18,10 @@ GetOptions(
 
 if (not(   $format eq 'darwin'
 		or $format eq 'gnu'
-		or $format eq 'win'))
+		or $format eq 'win'
+        or $format eq 'aix'))
 {
-	die "$0: $format is not yet handled (only darwin, gnu, win are)\n";
+	die "$0: $format is not yet handled (only darwin, gnu, win, aix are)\n";
 }
 
 open(my $input_handle, '<', $input)
@@ -46,6 +47,10 @@ elsif ($format eq 'win')
 	}
 	print $output_handle "EXPORTS\n";
 }
+elsif ($format eq 'aix')
+{
+	print $output_handle "#!\n";
+}
 
 while (<$input_handle>)
 {
@@ -63,6 +68,10 @@ while (<$input_handle>)
 		{
 			print $output_handle "    $1;\n";
 		}
+        elsif ($format eq 'aix')
+        {
+            print $output_handle "$1\n";
+        }
 		elsif ($format eq 'win')
 		{
 			print $output_handle "$1 @ $2\n";
-- 
2.41.0



  [application/octet-stream] 0001-Changes-to-add-support-for-AIX.v9.pg19.patch (15.7K, 4-0001-Changes-to-add-support-for-AIX.v9.pg19.patch)
  download | inline diff:
From 407b42b1fbe562dff69820f7456dbb32a8a37d79 Mon Sep 17 00:00:00 2001
From: AIX-dev <[email protected]>
Date: Tue, 16 Sep 2025 08:59:22 -0500
Subject: [PATCH] Changes to add support for AIX.

---
 Makefile                           |  2 -
 configure                          | 37 +++++++++++++++---
 configure.ac                       | 29 +++++++++++++-
 src/Makefile.shlib                 | 29 ++++++++++++++
 src/backend/Makefile               | 20 ++++++++++
 src/backend/port/aix/mkldexport.sh | 61 ++++++++++++++++++++++++++++++
 src/backend/utils/error/elog.c     |  2 +
 src/include/port/aix.h             |  4 ++
 src/include/storage/s_lock.h       | 48 +++--------------------
 src/makefiles/Makefile.aix         | 34 +++++++++++++++++
 src/port/strerror.c                |  2 +
 src/template/aix                   |  7 ++++
 12 files changed, 223 insertions(+), 52 deletions(-)
 create mode 100755 src/backend/port/aix/mkldexport.sh
 create mode 100644 src/include/port/aix.h
 create mode 100644 src/makefiles/Makefile.aix
 create mode 100644 src/template/aix

diff --git a/Makefile b/Makefile
index 8a2ec9396b6..9bc1a4ec17b 100644
--- a/Makefile
+++ b/Makefile
@@ -13,8 +13,6 @@
 
 # AIX make defaults to building *every* target of the first rule.  Start with
 # a single-target, empty rule to make the other targets non-default.
-# (We don't support AIX anymore, but if someone tries to build on AIX anyway,
-# at least they'll get the instructions to run 'configure' first.)
 all:
 
 all check install installdirs installcheck installcheck-parallel uninstall clean distclean maintainer-clean dist distcheck world check-world install-world installcheck-world:
diff --git a/configure b/configure
index 507a2437c33..67cad0f5581 100755
--- a/configure
+++ b/configure
@@ -3022,6 +3022,7 @@ else
 # --with-template not given
 
 case $host_os in
+  aix*) template=aix ;;
   cygwin*|msys*) template=cygwin ;;
   darwin*) template=darwin ;;
 dragonfly*) template=netbsd ;;
@@ -17204,13 +17205,37 @@ _ACEOF
 # wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
 # much of a penalty for disk and memory space.
 
-MAX_ALIGNOF=$ac_cv_alignof_double
+echo "Checking for MAX ALIGN - $PORTNAME"
+if test "$PORTNAME" != "aix"; then
+    MAX_ALIGNOF=$ac_cv_alignof_double
 
-if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
-  as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
-fi
-if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
-  as_fn_error $? "alignment of 'int64_t' is greater than the alignment of 'double'" "$LINENO" 5
+    if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
+      as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+    if test x"$HAVE_LONG_LONG_INT_64" = xyes && test $ac_cv_alignof_long_long_int -gt $MAX_ALIGNOF ; then
+      as_fn_error $? "alignment of 'long long int' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+else
+# The AIX 'power' alignment rules apply the natural alignment of the "first
+# member" if it is of a floating-point data type (or is an aggregate whose
+# recursively "first" member or element is such a type). The alignment
+# associated with these types for subsequent members use an alignment value
+# where the floating-point data type is considered to have 4-byte alignment.
+# More info
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99557
+#
+# The double is aligned to 4-bytes on AIX in aggregates. But to maintain
+# alignement across platforms the max alignment of long should be considered.
+      echo "MAX ALIGN ac_cv_alignof_long"
+    MAX_ALIGNOF=$ac_cv_alignof_long
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_double ; then
+      MAX_ALIGNOF=$ac_cv_alignof_double
+      echo "MAX ALIGN ac_cv_alignof_double"
+    fi
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_int64_t; then
+      MAX_ALIGNOF="$ac_cv_alignof_int64_t"
+      echo "MAX ALIGN ac_cv_alignof_int64_t"
+    fi
 fi
 
 cat >>confdefs.h <<_ACEOF
diff --git a/configure.ac b/configure.ac
index 5f4548adc5c..a25aedacef2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -62,6 +62,7 @@ PGAC_ARG_REQ(with, template, [NAME], [override operating system template],
 # --with-template not given
 
 case $host_os in
+  aix*) template=aix ;;
   cygwin*|msys*) template=cygwin ;;
   darwin*) template=darwin ;;
 dragonfly*) template=netbsd ;;
@@ -2021,7 +2022,33 @@ AC_CHECK_ALIGNOF(double)
 # wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
 # much of a penalty for disk and memory space.
 
-MAX_ALIGNOF=$ac_cv_alignof_double
+if test "$PORTNAME" != "aix"; then
+    MAX_ALIGNOF=$ac_cv_alignof_double
+
+    if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
+      as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+    if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF; then
+      as_fn_error $? "alignment of 'long long int' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+else
+# The AIX 'power' alignment rules apply the natural alignment of the "first
+# member" if it is of a floating-point data type (or is an aggregate whose
+# recursively "first" member or element is such a type). The alignment
+# associated with these types for subsequent members use an alignment value
+# where the floating-point data type is considered to have 4-byte alignment.
+# More info
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99557
+# 
+# The double is aligned to 4-bytes on AIX in aggregates. But to maintain
+# alignement across platforms the max alignment of long should be considered.
+    MAX_ALIGNOF=$ac_cv_alignof_long
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_double ; then
+      MAX_ALIGNOF=$ac_cv_alignof_double
+    fi
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_int64_t ; then
+      MAX_ALIGNOF="$ac_cv_alignof_int64_t"
+    fi
 
 if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
   AC_MSG_ERROR([alignment of 'long' is greater than the alignment of 'double'])
diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index 3825af5b228..35adc4174ed 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -106,6 +106,20 @@ ifdef SO_MAJOR_VERSION
 override CPPFLAGS += -DSO_MAJOR_VERSION=$(SO_MAJOR_VERSION)
 endif
 
+ifeq ($(PORTNAME), aix)
+  LINK.shared		= $(COMPILER)
+  ifdef SO_MAJOR_VERSION
+    shlib		= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
+  endif
+  haslibarule   = yes
+  # $(exports_file) is also usable as an import file
+  exports_file		= lib$(NAME).exp
+  BUILD.exports		= ( echo '\#! $(shlib)'; $(AWK) '/^[^\#]/ {printf "%s\n",$$1}' $< ) > $@
+  ifneq (,$(SHLIB_EXPORTS))
+    LINK.shared		+= -Wl,-bE:$(exports_file)
+  endif
+endif
+
 ifeq ($(PORTNAME), darwin)
   ifdef soname
     # linkable library
@@ -254,6 +268,14 @@ $(stlib): $(OBJS) | $(SHLIB_PREREQS)
 	touch $@
 endif #haslibarule
 
+# AIX wraps both shared libraries and static library, which can be used both
+# for static and shared linking
+ifeq ($(PORTNAME), aix)
+$(stlib): $(shlib)
+	rm -f $(stlib)
+	$(AR) $(AROPT) $(stlib) $(shlib)
+endif # aix
+
 ifeq (,$(filter cygwin win32,$(PORTNAME)))
 
 # Normal case
@@ -267,8 +289,11 @@ ifneq ($(shlib), $(shlib_major))
 endif
 # Make sure we have a link to a name without any version numbers
 ifneq ($(shlib), $(shlib_bare))
+# except on AIX, where that's not a thing
+ifneq ($(PORTNAME), aix)
 	rm -f $(shlib_bare)
 	$(LN_S) $(shlib) $(shlib_bare)
+endif # aix
 endif # shlib_bare
 endif # shlib_major
 
@@ -376,6 +401,9 @@ install-lib-static: $(stlib) installdirs-lib
 
 install-lib-shared: $(shlib) installdirs-lib
 ifdef soname
+# we don't install $(shlib) on AIX
+# (see http://archives.postgresql.org/message-id/52EF20B2E3209443BC37736D00C3C1380A6E79FE@EXADV1.host.magwien.gv.at)
+ifneq ($(PORTNAME), aix)
 	$(INSTALL_SHLIB) $< '$(DESTDIR)$(libdir)/$(shlib)'
 ifneq ($(PORTNAME), cygwin)
 ifneq ($(PORTNAME), win32)
@@ -391,6 +419,7 @@ ifneq ($(shlib), $(shlib_bare))
 endif
 endif # not win32
 endif # not cygwin
+endif # not aix
 ifneq (,$(findstring $(PORTNAME),win32 cygwin))
 	$(INSTALL_SHLIB) $< '$(DESTDIR)$(bindir)/$(shlib)'
 endif
diff --git a/src/backend/Makefile b/src/backend/Makefile
index 7344c8c7f5c..572f5430a60 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -63,12 +63,14 @@ all: submake-libpgport submake-catalog-headers submake-utils-headers postgres $(
 
 ifneq ($(PORTNAME), cygwin)
 ifneq ($(PORTNAME), win32)
+ifneq ($(PORTNAME), aix)
 
 postgres: $(OBJS)
 	$(CC) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LIBS) -o $@
 
 endif
 endif
+endif
 
 ifeq ($(PORTNAME), cygwin)
 
@@ -95,6 +97,24 @@ libpostgres.a: postgres
 
 endif # win32
 
+ifeq ($(PORTNAME), aix)
+
+postgres: $(POSTGRES_IMP)
+	$(CC) $(CFLAGS) $(call expand_subsys,$(OBJS)) $(LDFLAGS) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -Wl,-brtllib -o $@
+
+# Linking to a single .o with -r is a lot faster than building a .a or passing
+# all objects to MKLDEXPORT.
+#
+# It looks alluring to use $(CC) -r instead of ld -r, but that doesn't
+# trivially work with gcc, due to gcc specific static libraries linked in with
+# -r.
+$(POSTGRES_IMP): $(OBJS)
+	ld -r -o SUBSYS.o $(call expand_subsys,$^)
+	$(MKLDEXPORT) SUBSYS.o . > $@
+	@rm -f SUBSYS.o
+
+endif # aix
+
 $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
 
 
diff --git a/src/backend/port/aix/mkldexport.sh b/src/backend/port/aix/mkldexport.sh
new file mode 100755
index 00000000000..adf3793e868
--- /dev/null
+++ b/src/backend/port/aix/mkldexport.sh
@@ -0,0 +1,61 @@
+#!/bin/sh
+#
+# mkldexport
+#	create an AIX exports file from an object file
+#
+# src/backend/port/aix/mkldexport.sh
+#
+# Usage:
+#	mkldexport objectfile [location]
+# where
+#	objectfile is the current location of the object file.
+#	location is the eventual (installed) location of the
+#		object file (if different from the current
+#		working directory).
+#
+# [This file comes from the Postgres 4.2 distribution. - ay 7/95]
+#
+# Header: /usr/local/devel/postgres/src/tools/mkldexport/RCS/mkldexport.sh,v 1.2 1994/03/13 04:59:12 aoki Exp
+#
+
+# setting this to nm -B might be better
+# ... due to changes in AIX 4.x ...
+# ... let us search in different directories - Gerhard Reithofer
+if [ -x /usr/ucb/nm ]
+then NM=/usr/ucb/nm
+elif [ -x /usr/bin/nm ]
+then NM=/usr/bin/nm
+elif [ -x /usr/ccs/bin/nm ]
+then NM=/usr/ccs/bin/nm
+elif [ -x /usr/usg/bin/nm ]
+then NM=/usr/usg/bin/nm
+else echo "Fatal error: cannot find `nm' ... please check your installation."
+     exit 1
+fi
+
+CMDNAME=`basename $0`
+if [ -z "$1" ]; then
+	echo "Usage: $CMDNAME object [location]"
+	exit 1
+fi
+OBJNAME=`basename $1`
+if [ "`basename $OBJNAME`" != "`basename $OBJNAME .o`" ]; then
+	OBJNAME=`basename $OBJNAME .o`.so
+fi
+if [ -z "$2" ]; then
+	echo '#!'
+else
+	if [ "$2" = "." ]; then
+		# for the base executable (AIX 4.2 and up)
+		echo '#! .'
+	else
+		echo '#!' $2
+	fi
+fi
+$NM -BCg $1 | \
+	egrep ' [TDB] ' | \
+	sed -e 's/.* //' | \
+	egrep -v '\$' | \
+	sed -e 's/^[.]//' | \
+	sort | \
+	uniq
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index b7b9692f8c8..d0c4b7ba3ac 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -905,7 +905,9 @@ errcode_for_file_access(void)
 			/* Wrong object type or state */
 		case ENOTDIR:			/* Not a directory */
 		case EISDIR:			/* Is a directory */
+#if defined(ENOTEMPTY) && (ENOTEMPTY != EEXIST) /* same code on AIX */
 		case ENOTEMPTY:			/* Directory not empty */
+#endif
 			edata->sqlerrcode = ERRCODE_WRONG_OBJECT_TYPE;
 			break;
 
diff --git a/src/include/port/aix.h b/src/include/port/aix.h
new file mode 100644
index 00000000000..7d08480c8c0
--- /dev/null
+++ b/src/include/port/aix.h
@@ -0,0 +1,4 @@
+/*
+ * src/include/port/aix.h
+ */
+
diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
index 2f73f9fcf57..ba120c08d14 100644
--- a/src/include/storage/s_lock.h
+++ b/src/include/storage/s_lock.h
@@ -398,56 +398,18 @@ typedef unsigned int slock_t;
 
 #define TAS(lock) tas(lock)
 
-/* On PPC, it's a win to use a non-locking test before the lwarx */
+/* On PPC, use the compiler provided Built-in functions for atomic memory
+ * exchange operations.
+ */
 #define TAS_SPIN(lock)	(*(lock) ? 1 : TAS(lock))
 
-/*
- * The second operand of addi can hold a constant zero or a register number,
- * hence constraint "=&b" to avoid allocating r0.  "b" stands for "address
- * base register"; most operands having this register-or-zero property are
- * address bases, e.g. the second operand of lwax.
- *
- * NOTE: per the Enhanced PowerPC Architecture manual, v1.0 dated 7-May-2002,
- * an isync is a sufficient synchronization barrier after a lwarx/stwcx loop.
- * But if the spinlock is in ordinary memory, we can use lwsync instead for
- * better performance.
- */
 static __inline__ int
 tas(volatile slock_t *lock)
 {
-	slock_t _t;
-	int _res;
-
-	__asm__ __volatile__(
-"	lwarx   %0,0,%3,1	\n"
-"	cmpwi   %0,0		\n"
-"	bne     1f			\n"
-"	addi    %0,%0,1		\n"
-"	stwcx.  %0,0,%3		\n"
-"	beq     2f			\n"
-"1: \n"
-"	li      %1,1		\n"
-"	b       3f			\n"
-"2: \n"
-"	lwsync				\n"
-"	li      %1,0		\n"
-"3: \n"
-:	"=&b"(_t), "=r"(_res), "+m"(*lock)
-:	"r"(lock)
-:	"memory", "cc");
-	return _res;
+	return __sync_lock_test_and_set(lock, 1);
 }
 
-/*
- * PowerPC S_UNLOCK is almost standard but requires a "sync" instruction.
- * But we can use lwsync instead for better performance.
- */
-#define S_UNLOCK(lock)	\
-do \
-{ \
-	__asm__ __volatile__ ("	lwsync \n" ::: "memory"); \
-	*((volatile slock_t *) (lock)) = 0; \
-} while (0)
+#define S_UNLOCK(lock) __sync_lock_release(lock)
 
 #endif /* powerpc */
 
diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix
new file mode 100644
index 00000000000..4c4de8b0be7
--- /dev/null
+++ b/src/makefiles/Makefile.aix
@@ -0,0 +1,34 @@
+# -blibpath:
+# The path to be inserted into the default path (Index 0 path) field of the
+# loader section. When this flag is presented, the -L paths will not be stored. 
+# AIX uses a stricter, more explicit approach. The runtime linker expects to
+# tell it exactly where to look using -blibpath.
+# -blibpath must contain ALL directories where we should look for libraries
+libpath := $(shell echo $(subst -L,:,$(filter -L/%,$(LDFLAGS))) | sed -e's/ //g'):/usr/lib:/lib
+
+# AIX uses a stricter, more explicit approach. The runtime linker expects 
+# to tell it exactly where to look using -blibpath.
+rpath = -Wl,-blibpath:'$(rpathdir)$(libpath)'
+
+# gcc needs to know it's building a shared lib, otherwise it'll not emit
+# correct code / link to the right support libraries
+ifeq ($(GCC), yes)
+LDFLAGS_SL += -shared
+endif
+
+# env var name to use in place of LD_LIBRARY_PATH
+ld_library_path_var = LIBPATH
+
+POSTGRES_IMP= postgres.imp
+
+ifdef PGXS
+BE_DLLLIBS= -Wl,-bI:$(pkglibdir)/$(POSTGRES_IMP)
+else
+BE_DLLLIBS= -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP)
+endif
+
+MKLDEXPORT_DIR=src/backend/port/aix
+MKLDEXPORT=$(top_srcdir)/$(MKLDEXPORT_DIR)/mkldexport.sh
+
+%$(DLSUFFIX): %.o
+	$(CC) $(CFLAGS) $*.o $(LDFLAGS) $(LDFLAGS_SL) -o $@ $(BE_DLLLIBS)
diff --git a/src/port/strerror.c b/src/port/strerror.c
index f0746517770..c46b9dc91fc 100644
--- a/src/port/strerror.c
+++ b/src/port/strerror.c
@@ -214,8 +214,10 @@ get_errno_symbol(int errnum)
 			return "ENOTCONN";
 		case ENOTDIR:
 			return "ENOTDIR";
+#if defined(ENOTEMPTY) && (ENOTEMPTY != EEXIST) /* same code on AIX */
 		case ENOTEMPTY:
 			return "ENOTEMPTY";
+#endif
 		case ENOTSOCK:
 			return "ENOTSOCK";
 #ifdef ENOTSUP
diff --git a/src/template/aix b/src/template/aix
new file mode 100644
index 00000000000..bfc193348f4
--- /dev/null
+++ b/src/template/aix
@@ -0,0 +1,7 @@
+# This file is referred for specific flags wrt to AIX build process like
+# cflags.
+# src/template/aix
+
+# Extra CFLAGS for code that will go into a shared library
+# With optimization, the MemSet() and MemSetAlign() perform better.
+CFLAGS_SL=" -O2 "
-- 
2.41.0



^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-10-15 18:15  Peter Eisentraut <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  1 sibling, 1 reply; 47+ messages in thread

From: Peter Eisentraut @ 2025-10-15 18:15 UTC (permalink / raw)
  To: Srirama Kucherlapati <[email protected]>; Andres Freund <[email protected]>; AIX PG user <[email protected]>; +Cc: [email protected] <[email protected]>

On 15.10.25 17:58, Srirama Kucherlapati wrote:
> Main AIX changes patch - 0001-Changes-to-add-support-for- 
> AIX.v9.pg19.patch (previously submitted one)
> 
> Meson AIX changes patch - 0001-AIX-changes-for-meson-build.patch
> 
> Looking forward to hearing your thoughts on these changes.
> 
> Your feedback on these updates is highly valued.

The largest problem I see in this patch set is that you are making 
unexplained changes in src/include/storage/s_lock.h.  The code that you 
are changing does not only affect AIX but also PPC with other operating 
systems.  AFAICT, the change you are proposing does not correspond to 
the commit that removed AIX support.

Maybe the proposed changes are beneficial for other operating systems as 
well.  But in that case, propose this as a separate patch in a separate 
thread, with supporting information (and probably benchmarks in this case).

If not, then you need to find a way to make this work on AIX without 
materially changing the code that exists for already-supported operating 
systems.





^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-10-16 15:28  AIX PG user <[email protected]>
  parent: Peter Eisentraut <[email protected]>
  0 siblings, 2 replies; 47+ messages in thread

From: AIX PG user @ 2025-10-16 15:28 UTC (permalink / raw)
  To: [email protected]; +Cc: AIX PG user <[email protected]>

Hi Peter,
Thank you for your comments.

We’ve had a few discussions in the past regarding the changes related to the
spin lock. Some of those conversations stemmed from this thread:
        "https://www.postgresql.org/message-id/95a44be0-b2f8-464a-8984-771d892b1cac%40iki.fi";
The earlier assembly code was generic across the PPC platform. However, based
on previous discussions, we transitioned to using GCC-specific routines to
enhance platform independence and maintain generality.

These are the comments I have added, let me know if you need more info here.
    +/* On PPC, use the compiler provided Built-in functions for atomic memory
    + * exchange operations.
    + */

For reference, here are some benchmark statistics we gathered earlier:
       "https://www.postgresql.org/message-id/CY8PR15MB5602EB54EFE30D4C21F061BEDB722%40CY8PR15MB5602.namprd1...;

I'll run some more benchmarking on this sync_lock and submit the results.
Meanwhile, it would be helpful if you and your team could take a look at the remaining changes.

Thank you,
Sriram.

The new status of this patch is: Needs review


^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-10-22 03:52  AIX PG user <[email protected]>
  parent: AIX PG user <[email protected]>
  1 sibling, 0 replies; 47+ messages in thread

From: AIX PG user @ 2025-10-22 03:52 UTC (permalink / raw)
  To: [email protected]; +Cc: AIX PG user <[email protected]>

Hi Team, 
We look forward to your comments and kindly request you to share your feedback on the proposed changes(in the annotations).
Your input is greatly appreciated and will help us refine the solution while ensuring all aspects are thoughtfully addressed.
Thank you in advance for your time and support.

-Sriram.

^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-10-31 17:33  Heikki Linnakangas <[email protected]>
  parent: AIX PG user <[email protected]>
  1 sibling, 1 reply; 47+ messages in thread

From: Heikki Linnakangas @ 2025-10-31 17:33 UTC (permalink / raw)
  To: AIX PG user <[email protected]>; [email protected]

On 16/10/2025 18:28, AIX PG user wrote:
> diff --git a/src/template/aix b/src/template/aix                                                                                                                           
> new file mode 100644                                                                                                                                                       
> index 00000000000..bfc193348f4                                                                                                                                             
> --- /dev/null                                                                                                                                                              
> +++ b/src/template/aix                                                                                                                                                     
> @@ -0,0 +1,7 @@                                                                                                                                                            
> +# This file is referred for specific flags wrt to AIX build process like                                                                                                  
> +# cflags.                                                                                                                                                                 
> +# src/template/aix                                                                                                                                                        
> +                                                                                                                                                                          
> +# Extra CFLAGS for code that will go into a shared library                                                                                                                
> +# With optimization, the MemSet() and MemSetAlign() perform better.                                                                                                       
> +CFLAGS_SL=" -O2 "                                                                                                                                                         
> --     

This looks weird. Sure, "-O2" makes things faster, but we shouldn't 
force that here. If you want optimizations, you should use pass 
CFLAGS="-O2" or CFLAGS="-O3" to configure. And why the special mention 
of MemSet() and MemSetAlign()?

> @@ -95,6 +97,24 @@ libpostgres.a: postgres
>  
>  endif # win32
>  
> +ifeq ($(PORTNAME), aix)
> +
> +postgres: $(POSTGRES_IMP)
> +	$(CC) $(CFLAGS) $(call expand_subsys,$(OBJS)) $(LDFLAGS) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -Wl,-brtllib -o $@
> +
> +# Linking to a single .o with -r is a lot faster than building a .a or passing
> +# all objects to MKLDEXPORT.
> +#
> +# It looks alluring to use $(CC) -r instead of ld -r, but that doesn't
> +# trivially work with gcc, due to gcc specific static libraries linked in with
> +# -r.
> +$(POSTGRES_IMP): $(OBJS)
> +	ld -r -o SUBSYS.o $(call expand_subsys,$^)
> +	$(MKLDEXPORT) SUBSYS.o . > $@
> +	@rm -f SUBSYS.o
> +
> +endif # aix
> +
>  $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport

I see there's some references to MAKE_EXPORTS in src/backend/Makefile. 
They seem related to MKLDEXPORT, but we never set MAKE_EXPORTS. Are they 
still needed?

- Heikki






^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-11-03 14:46  AIX PG user <[email protected]>
  parent: Heikki Linnakangas <[email protected]>
  0 siblings, 0 replies; 47+ messages in thread

From: AIX PG user @ 2025-11-03 14:46 UTC (permalink / raw)
  To: [email protected]; +Cc: AIX PG user <[email protected]>

Hi Heikki, 
Thank you for your feedback.

> This looks weird. Sure, "-O2" makes things faster, but we shouldn't 
> force that here. If you want optimizations, you should use pass 
> CFLAGS="-O2" or CFLAGS="-O3" to configure. And why the special mention 
> of MemSet() and MemSetAlign()?

I have removed these.

> I see there's some references to MAKE_EXPORTS in src/backend/Makefile. 
> They seem related to MKLDEXPORT, but we never set MAKE_EXPORTS. Are they 
> still needed?

If MAKE_EXPORTS is not being used by any platforms other than AIX, we can
consider removing it. However, I’m not entirely certain whether it might still
be required elsewhere.  Since these changes appear to be general and not
strictly AIX-specific, would it be fine to submit them as a separate
patch?

Looking forward to your continued support and guidance.

- Sriram.

^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-11-07 16:28  Peter Eisentraut <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  1 sibling, 1 reply; 47+ messages in thread

From: Peter Eisentraut @ 2025-11-07 16:28 UTC (permalink / raw)
  To: Srirama Kucherlapati <[email protected]>; Andres Freund <[email protected]>; AIX PG user <[email protected]>; +Cc: [email protected] <[email protected]>

On 15.10.25 17:58, Srirama Kucherlapati wrote:
> Hi Andres and team,
> 
> Please find attached the patch addressing Meson build changes for AIX.
> 
> We tried to build using below meson
> 
> ## meson -v
> 
> 1.6.1
> 
> For the following files, the shared_module() function requires 
> specifying the
> 
> appropriate symbol import file, which is provided via the aix_link_args
> 
> variable:
> 
> src/backend/jit/llvm/meson.build
> 
> src/backend/replication/libpqwalreceiver/meson.build
> 
> src/backend/replication/pgoutput/meson.build
> 
> src/backend/snowball/meson.build
> 
> src/backend/utils/mb/conversion_procs/meson.build
> 
> Additionally, with the latest version of Meson, when building static 
> libraries,
> 
> the library file name must be suffixed with “_static” in the following 
> files:
> 
> src/interfaces/ecpg/compatlib/meson.build
> 
> src/interfaces/ecpg/ecpglib/meson.build
> 
> src/interfaces/ecpg/pgtypeslib/meson.build
> 
> src/interfaces/libpq/meson.build

It is not going to be acceptable to sprinkle this much AIX-specific code 
around.  Those changes to the meson.build files were not needed before 
AIX support was removed.  You should find a way to do it without these 
changes.

The changes in src/include/port/aix.h in your patch don't make sense. 
This indicates that you are doing something wrong in your local builds. 
Please fix that.






^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-11-10 17:00  AIX PG user <[email protected]>
  parent: Peter Eisentraut <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: AIX PG user @ 2025-11-10 17:00 UTC (permalink / raw)
  To: [email protected]; +Cc: AIX PG user <[email protected]>

Hi Peter,
>> Those changes to the meson.build files were not needed before
>> AIX support was removed.  You should find a way to do it without these
>> changes.

The change was necessary to ensure that the import file used during the static
PostgreSQL library build begins with the required #! directive and includes the
correct symbol references from the object files. This structure is essential
for compatibility with AIX's linking behaviour, which relies on explicitly
defined symbol import files during static linking. Without this adjustment, the
build process may fail or result in incomplete symbol resolution, particularly
on AIX systems. By aligning the import file format and symbol inclusion with
platform-specific requirements.

We referred to previously removed code that handled similar logic and found it
to be effective. Based on this, we plan to revert the changes in the affected
files and proceed with a more robust solution.

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=0b16bb8776bb834eb1ef8204ca95dd766...
src/backend/jit/llvm/meson.build
src/backend/replication/libpqwalreceiver/meson.build
src/backend/replication/pgoutput/meson.build
src/backend/snowball/meson.build
src/backend/utils/mb/conversion_procs/meson.build

Regarding the archiving of shared and static libraries, the latest version of
Meson raises a conflict as both targets have the same name. This issue
arises because, on AIX, both shared and static libraries are named as same
archive, which leads to naming collisions during the build process. We
would still need the below changes.

src/interfaces/ecpg/compatlib/meson.build
src/interfaces/ecpg/ecpglib/meson.build
ecpglib_st = static_library(libname,
src/interfaces/ecpg/pgtypeslib/meson.build
	ecpg_pgtypes_st = static_library(libname,
src/interfaces/libpq/meson.build
	libpq_st = static_library(libname


>> The changes in src/include/port/aix.h in your patch don't make sense.
>> This indicates that you are doing something wrong in your local builds.
>> Please fix that.

We had to do these changes in the src/include/c.h, 
As the MACROS, are getting undefined by the below sys header files.


We made changes to src/include/c.h because certain macros were being 
undefined by the system header files listed below. To address this issue, 
we introduced updates in aix.h.
+#ifndef PGDLLIMPORT +#define PGDLLIMPORT

#include <stdio.h> 
#include <stdlib.h> 
#include <string.h>

We are continuing to analyze the impact of these changes and will refine 
the solution as needed. Once finalized, we will submit the updated changes accordingly.

-Sriram.

^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* RE: AIX support
@ 2025-12-09 16:50  Srirama Kucherlapati <[email protected]>
  parent: AIX PG user <[email protected]>
  0 siblings, 3 replies; 47+ messages in thread

From: Srirama Kucherlapati @ 2025-12-09 16:50 UTC (permalink / raw)
  To: AIX PG user <[email protected]>; [email protected] <[email protected]>; Peter Eisentraut <[email protected]>; Heikki Linnakangas <[email protected]>

Hi Team, (Peter/Heikki)

I have implemented the requested modifications in the latest patch. Below are the key technical updates:

• Meson Build Configuration: Adjusted below meson.build scripts to incorporate the suggested changes, ensuring proper dependency resolution and improved build consistency.

    Removed the AIX changes in the below from the previous patch.

    src/backend/jit/llvm/meson.build
src/backend/replication/libpqwalreceiver/meson.build
src/backend/replication/pgoutput/meson.build
src/backend/snowball/meson.build
src/backend/utils/mb/conversion_procs/meson.build

    Added the static_library() changes.

    > Regarding the archiving of shared and static libraries, the latest version of
> Meson raises a conflict as both targets have the same name. This issue
> arises because, on AIX, both shared and static libraries are named as same
> archive, which leads to naming collisions during the build process. We
> would still need the below changes.

     src/interfaces/ecpg/compatlib/meson.build
src/interfaces/ecpg/ecpglib/meson.build
src/interfaces/ecpg/pgtypeslib/meson.build
src/interfaces/libpq/meson.build


• CFLAGS Optimization Removal: Removed high-level optimization flags from CFLAGS to prevent unpredictable behaviour and maintain stability during compilation.

I would greatly appreciate it if you could review the patch and share your feedback or any additional recommendations.

Apologies for the delayed response; I was occupied with other tasks.

Your insights are greatly appreciated and will help enhance the patch.

Warm regards,
-Sriram.





Attachments:

  [application/octet-stream] 0001-Support-for-AIX.pg19.v10.patch (22.5K, 3-0001-Support-for-AIX.pg19.v10.patch)
  download | inline diff:
From 98af27c6331c4fe161f7cab5c16768587f7fcb9a Mon Sep 17 00:00:00 2001
From: AIX-dev <[email protected]>
Date: Tue, 9 Dec 2025 09:49:31 -0600
Subject: [PATCH] Support for AIX.

---
 Makefile                                   |  2 -
 configure                                  | 37 ++++++++++---
 configure.ac                               | 29 +++++++++-
 meson.build                                | 27 ++++++++--
 src/Makefile.shlib                         | 29 ++++++++++
 src/backend/Makefile                       | 20 +++++++
 src/backend/meson.build                    | 18 +++++++
 src/backend/port/aix/mkldexport.sh         | 61 ++++++++++++++++++++++
 src/backend/utils/error/elog.c             |  2 +
 src/include/port/aix.h                     | 26 +++++++++
 src/include/storage/s_lock.h               | 52 +++---------------
 src/interfaces/ecpg/compatlib/meson.build  |  2 +-
 src/interfaces/ecpg/ecpglib/meson.build    |  2 +-
 src/interfaces/ecpg/pgtypeslib/meson.build |  2 +-
 src/interfaces/libpq/meson.build           |  2 +-
 src/makefiles/Makefile.aix                 | 34 ++++++++++++
 src/port/strerror.c                        |  2 +
 src/template/aix                           |  6 +++
 src/tools/gen_export.pl                    | 11 +++-
 19 files changed, 300 insertions(+), 64 deletions(-)
 create mode 100755 src/backend/port/aix/mkldexport.sh
 create mode 100644 src/include/port/aix.h
 create mode 100644 src/makefiles/Makefile.aix
 create mode 100644 src/template/aix

diff --git a/Makefile b/Makefile
index 8a2ec9396b6..9bc1a4ec17b 100644
--- a/Makefile
+++ b/Makefile
@@ -13,8 +13,6 @@
 
 # AIX make defaults to building *every* target of the first rule.  Start with
 # a single-target, empty rule to make the other targets non-default.
-# (We don't support AIX anymore, but if someone tries to build on AIX anyway,
-# at least they'll get the instructions to run 'configure' first.)
 all:
 
 all check install installdirs installcheck installcheck-parallel uninstall clean distclean maintainer-clean dist distcheck world check-world install-world installcheck-world:
diff --git a/configure b/configure
index 3a0ed11fa8e..c4749a8e5b6 100755
--- a/configure
+++ b/configure
@@ -3020,6 +3020,7 @@ else
 # --with-template not given
 
 case $host_os in
+  aix*) template=aix ;;
   cygwin*|msys*) template=cygwin ;;
   darwin*) template=darwin ;;
 dragonfly*) template=netbsd ;;
@@ -17006,13 +17007,37 @@ _ACEOF
 # wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
 # much of a penalty for disk and memory space.
 
-MAX_ALIGNOF=$ac_cv_alignof_double
+echo "Checking for MAX ALIGN - $PORTNAME"
+if test "$PORTNAME" != "aix"; then
+    MAX_ALIGNOF=$ac_cv_alignof_double
 
-if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
-  as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
-fi
-if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF ; then
-  as_fn_error $? "alignment of 'int64_t' is greater than the alignment of 'double'" "$LINENO" 5
+    if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
+      as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+    if test x"$HAVE_LONG_LONG_INT_64" = xyes && test $ac_cv_alignof_long_long_int -gt $MAX_ALIGNOF ; then
+      as_fn_error $? "alignment of 'long long int' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+else
+# The AIX 'power' alignment rules apply the natural alignment of the "first
+# member" if it is of a floating-point data type (or is an aggregate whose
+# recursively "first" member or element is such a type). The alignment
+# associated with these types for subsequent members use an alignment value
+# where the floating-point data type is considered to have 4-byte alignment.
+# More info
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99557
+#
+# The double is aligned to 4-bytes on AIX in aggregates. But to maintain
+# alignement across platforms the max alignment of long should be considered.
+      echo "MAX ALIGN ac_cv_alignof_long"
+    MAX_ALIGNOF=$ac_cv_alignof_long
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_double ; then
+      MAX_ALIGNOF=$ac_cv_alignof_double
+      echo "MAX ALIGN ac_cv_alignof_double"
+    fi
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_int64_t; then
+      MAX_ALIGNOF="$ac_cv_alignof_int64_t"
+      echo "MAX ALIGN ac_cv_alignof_int64_t"
+    fi
 fi
 
 cat >>confdefs.h <<_ACEOF
diff --git a/configure.ac b/configure.ac
index c2413720a18..7f1530df2b1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -62,6 +62,7 @@ PGAC_ARG_REQ(with, template, [NAME], [override operating system template],
 # --with-template not given
 
 case $host_os in
+  aix*) template=aix ;;
   cygwin*|msys*) template=cygwin ;;
   darwin*) template=darwin ;;
 dragonfly*) template=netbsd ;;
@@ -2006,7 +2007,33 @@ AC_CHECK_ALIGNOF(double)
 # wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8 would be too
 # much of a penalty for disk and memory space.
 
-MAX_ALIGNOF=$ac_cv_alignof_double
+if test "$PORTNAME" != "aix"; then
+    MAX_ALIGNOF=$ac_cv_alignof_double
+
+    if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
+      as_fn_error $? "alignment of 'long' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+    if test $ac_cv_alignof_int64_t -gt $MAX_ALIGNOF; then
+      as_fn_error $? "alignment of 'long long int' is greater than the alignment of 'double'" "$LINENO" 5
+    fi
+else
+# The AIX 'power' alignment rules apply the natural alignment of the "first
+# member" if it is of a floating-point data type (or is an aggregate whose
+# recursively "first" member or element is such a type). The alignment
+# associated with these types for subsequent members use an alignment value
+# where the floating-point data type is considered to have 4-byte alignment.
+# More info
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99557
+# 
+# The double is aligned to 4-bytes on AIX in aggregates. But to maintain
+# alignement across platforms the max alignment of long should be considered.
+    MAX_ALIGNOF=$ac_cv_alignof_long
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_double ; then
+      MAX_ALIGNOF=$ac_cv_alignof_double
+    fi
+    if test $MAX_ALIGNOF -lt $ac_cv_alignof_int64_t ; then
+      MAX_ALIGNOF="$ac_cv_alignof_int64_t"
+    fi
 
 if test $ac_cv_alignof_long -gt $MAX_ALIGNOF ; then
   AC_MSG_ERROR([alignment of 'long' is greater than the alignment of 'double'])
diff --git a/meson.build b/meson.build
index 6e7ddd74683..304a9184075 100644
--- a/meson.build
+++ b/meson.build
@@ -206,6 +206,25 @@ if host_system == 'cygwin'
   mod_link_with_name = 'lib@[email protected]'
   mod_link_with_dir = 'libdir'
 
+elif host_system == 'aix'
+  sema_kind = 'unnamed_posix'
+  library_path_var = 'LIBPATH'
+  export_file_format = 'aix'
+  export_fmt = '-Wl,-bE:@0@'
+  mod_link_args_fmt = ['-Wl,-bI:@0@']
+  mod_link_with_dir = 'libdir'
+  mod_link_with_name = '@[email protected]'
+  dl_suffix = '.a'
+  cppflags += '-D_GNU_SOURCE'
+
+  # M:SRE sets a flag indicating that an object is a shared library. Seems to
+  # work in some circumstances without, but required in others.
+  ldflags_sl += '-Wl,-bM:SRE'
+  ldflags_be += '-Wl,-brtllib'
+
+  # Native memset() is faster, tested on:
+  memset_loop_limit = 0
+
 elif host_system == 'darwin'
   dlsuffix = '.dylib'
   library_path_var = 'DYLD_LIBRARY_PATH'
@@ -1766,9 +1785,9 @@ endforeach
 # any types wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8
 # would be too much of a penalty for disk and memory space.
 alignof_double = cdata.get('ALIGNOF_DOUBLE')
-if cc.alignment('int64_t', args: test_c_args, prefix: '#include <stdint.h>') > alignof_double
-  error('alignment of int64_t is greater than the alignment of double')
-endif
+#if cc.alignment('int64_t', args: test_c_args, prefix: '#include <stdint.h>') > alignof_double
+#  error('alignment of int64_t is greater than the alignment of double')
+#endif
 cdata.set('MAXIMUM_ALIGNOF', alignof_double)
 
 cdata.set('SIZEOF_LONG', cc.sizeof('long', args: test_c_args))
@@ -1820,7 +1839,7 @@ if cc.links('''
   if not meson.is_cross_build()
     r = cc.run('''
     /* This must match the corresponding code in c.h: */
-    #if defined(__GNUC__)
+    #if defined(__GNUC__) || defined(__IBMC__)
     #define pg_attribute_aligned(a) __attribute__((aligned(a)))
     #elif defined(_MSC_VER)
     #define pg_attribute_aligned(a) __declspec(align(a))
diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index 3825af5b228..35adc4174ed 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -106,6 +106,20 @@ ifdef SO_MAJOR_VERSION
 override CPPFLAGS += -DSO_MAJOR_VERSION=$(SO_MAJOR_VERSION)
 endif
 
+ifeq ($(PORTNAME), aix)
+  LINK.shared		= $(COMPILER)
+  ifdef SO_MAJOR_VERSION
+    shlib		= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
+  endif
+  haslibarule   = yes
+  # $(exports_file) is also usable as an import file
+  exports_file		= lib$(NAME).exp
+  BUILD.exports		= ( echo '\#! $(shlib)'; $(AWK) '/^[^\#]/ {printf "%s\n",$$1}' $< ) > $@
+  ifneq (,$(SHLIB_EXPORTS))
+    LINK.shared		+= -Wl,-bE:$(exports_file)
+  endif
+endif
+
 ifeq ($(PORTNAME), darwin)
   ifdef soname
     # linkable library
@@ -254,6 +268,14 @@ $(stlib): $(OBJS) | $(SHLIB_PREREQS)
 	touch $@
 endif #haslibarule
 
+# AIX wraps both shared libraries and static library, which can be used both
+# for static and shared linking
+ifeq ($(PORTNAME), aix)
+$(stlib): $(shlib)
+	rm -f $(stlib)
+	$(AR) $(AROPT) $(stlib) $(shlib)
+endif # aix
+
 ifeq (,$(filter cygwin win32,$(PORTNAME)))
 
 # Normal case
@@ -267,8 +289,11 @@ ifneq ($(shlib), $(shlib_major))
 endif
 # Make sure we have a link to a name without any version numbers
 ifneq ($(shlib), $(shlib_bare))
+# except on AIX, where that's not a thing
+ifneq ($(PORTNAME), aix)
 	rm -f $(shlib_bare)
 	$(LN_S) $(shlib) $(shlib_bare)
+endif # aix
 endif # shlib_bare
 endif # shlib_major
 
@@ -376,6 +401,9 @@ install-lib-static: $(stlib) installdirs-lib
 
 install-lib-shared: $(shlib) installdirs-lib
 ifdef soname
+# we don't install $(shlib) on AIX
+# (see http://archives.postgresql.org/message-id/52EF20B2E3209443BC37736D00C3C1380A6E79FE@EXADV1.host.magwien.gv.at)
+ifneq ($(PORTNAME), aix)
 	$(INSTALL_SHLIB) $< '$(DESTDIR)$(libdir)/$(shlib)'
 ifneq ($(PORTNAME), cygwin)
 ifneq ($(PORTNAME), win32)
@@ -391,6 +419,7 @@ ifneq ($(shlib), $(shlib_bare))
 endif
 endif # not win32
 endif # not cygwin
+endif # not aix
 ifneq (,$(findstring $(PORTNAME),win32 cygwin))
 	$(INSTALL_SHLIB) $< '$(DESTDIR)$(bindir)/$(shlib)'
 endif
diff --git a/src/backend/Makefile b/src/backend/Makefile
index 7344c8c7f5c..572f5430a60 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -63,12 +63,14 @@ all: submake-libpgport submake-catalog-headers submake-utils-headers postgres $(
 
 ifneq ($(PORTNAME), cygwin)
 ifneq ($(PORTNAME), win32)
+ifneq ($(PORTNAME), aix)
 
 postgres: $(OBJS)
 	$(CC) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LIBS) -o $@
 
 endif
 endif
+endif
 
 ifeq ($(PORTNAME), cygwin)
 
@@ -95,6 +97,24 @@ libpostgres.a: postgres
 
 endif # win32
 
+ifeq ($(PORTNAME), aix)
+
+postgres: $(POSTGRES_IMP)
+	$(CC) $(CFLAGS) $(call expand_subsys,$(OBJS)) $(LDFLAGS) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -Wl,-brtllib -o $@
+
+# Linking to a single .o with -r is a lot faster than building a .a or passing
+# all objects to MKLDEXPORT.
+#
+# It looks alluring to use $(CC) -r instead of ld -r, but that doesn't
+# trivially work with gcc, due to gcc specific static libraries linked in with
+# -r.
+$(POSTGRES_IMP): $(OBJS)
+	ld -r -o SUBSYS.o $(call expand_subsys,$^)
+	$(MKLDEXPORT) SUBSYS.o . > $@
+	@rm -f SUBSYS.o
+
+endif # aix
+
 $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
 
 
diff --git a/src/backend/meson.build b/src/backend/meson.build
index b831a541652..4838f245ab3 100644
--- a/src/backend/meson.build
+++ b/src/backend/meson.build
@@ -125,6 +125,24 @@ if host_system == 'windows'
     '--FILEDESC', 'PostgreSQL Server',])
 endif
 
+if host_system == 'aix'
+  # The '.' argument leads mkldexport.sh to emit "#! .", which refers to the
+  # main executable, allowing extension libraries to resolve their undefined
+  # symbols to symbols in the postgres binary.
+  postgres_imp = custom_target('postgres.imp',
+    command: [files('port/aix/mkldexport.sh'), '@INPUT@', '.'],
+    input: postgres_lib,
+    output: 'postgres.imp',
+    capture: true,
+    install: true,
+    install_dir: dir_lib,
+    build_by_default: false,
+  )
+  backend_link_args += '-Wl,-bE:@0@'.format(postgres_imp.full_path())
+  backend_link_depends += postgres_imp
+endif
+
+
 postgres = executable('postgres',
   backend_input,
   sources: post_export_backend_sources,
diff --git a/src/backend/port/aix/mkldexport.sh b/src/backend/port/aix/mkldexport.sh
new file mode 100755
index 00000000000..adf3793e868
--- /dev/null
+++ b/src/backend/port/aix/mkldexport.sh
@@ -0,0 +1,61 @@
+#!/bin/sh
+#
+# mkldexport
+#	create an AIX exports file from an object file
+#
+# src/backend/port/aix/mkldexport.sh
+#
+# Usage:
+#	mkldexport objectfile [location]
+# where
+#	objectfile is the current location of the object file.
+#	location is the eventual (installed) location of the
+#		object file (if different from the current
+#		working directory).
+#
+# [This file comes from the Postgres 4.2 distribution. - ay 7/95]
+#
+# Header: /usr/local/devel/postgres/src/tools/mkldexport/RCS/mkldexport.sh,v 1.2 1994/03/13 04:59:12 aoki Exp
+#
+
+# setting this to nm -B might be better
+# ... due to changes in AIX 4.x ...
+# ... let us search in different directories - Gerhard Reithofer
+if [ -x /usr/ucb/nm ]
+then NM=/usr/ucb/nm
+elif [ -x /usr/bin/nm ]
+then NM=/usr/bin/nm
+elif [ -x /usr/ccs/bin/nm ]
+then NM=/usr/ccs/bin/nm
+elif [ -x /usr/usg/bin/nm ]
+then NM=/usr/usg/bin/nm
+else echo "Fatal error: cannot find `nm' ... please check your installation."
+     exit 1
+fi
+
+CMDNAME=`basename $0`
+if [ -z "$1" ]; then
+	echo "Usage: $CMDNAME object [location]"
+	exit 1
+fi
+OBJNAME=`basename $1`
+if [ "`basename $OBJNAME`" != "`basename $OBJNAME .o`" ]; then
+	OBJNAME=`basename $OBJNAME .o`.so
+fi
+if [ -z "$2" ]; then
+	echo '#!'
+else
+	if [ "$2" = "." ]; then
+		# for the base executable (AIX 4.2 and up)
+		echo '#! .'
+	else
+		echo '#!' $2
+	fi
+fi
+$NM -BCg $1 | \
+	egrep ' [TDB] ' | \
+	sed -e 's/.* //' | \
+	egrep -v '\$' | \
+	sed -e 's/^[.]//' | \
+	sort | \
+	uniq
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 29643c51439..1c933b5afad 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -914,7 +914,9 @@ errcode_for_file_access(void)
 			/* Wrong object type or state */
 		case ENOTDIR:			/* Not a directory */
 		case EISDIR:			/* Is a directory */
+#if defined(ENOTEMPTY) && (ENOTEMPTY != EEXIST) /* same code on AIX */
 		case ENOTEMPTY:			/* Directory not empty */
+#endif
 			edata->sqlerrcode = ERRCODE_WRONG_OBJECT_TYPE;
 			break;
 
diff --git a/src/include/port/aix.h b/src/include/port/aix.h
new file mode 100644
index 00000000000..dd7cfb197cd
--- /dev/null
+++ b/src/include/port/aix.h
@@ -0,0 +1,26 @@
+/*
+ * src/include/port/aix.h
+ */
+
+/* This change is required for the meson changes as the autoconf is not run and
+ * to resolve the conflicts in picking the float.h details by default from the
+ * postgres defined datatypes.
+ */
+#ifdef _AIX
+#ifndef PGDLLIMPORT
+#define PGDLLIMPORT
+#endif  /* PGDLLIMPORT */
+typedef float float4;
+typedef double float8;
+
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
+#define pg_noreturn _Noreturn
+#elif defined(__GNUC__)
+#define pg_noreturn __attribute__((noreturn))
+#else
+#define pg_noreturn
+#endif
+
+#include <stdbool.h>
+
+#endif  /*_AIX */
diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
index 7f8f566bd40..1a0cd5ec019 100644
--- a/src/include/storage/s_lock.h
+++ b/src/include/storage/s_lock.h
@@ -398,60 +398,20 @@ typedef unsigned int slock_t;
 
 #define TAS(lock) tas(lock)
 
-/* On PPC, it's a win to use a non-locking test before the lwarx */
+/* On PPC, use the compiler provided Built-in functions for atomic memory
+ * exchange operations.
+ */
 #define TAS_SPIN(lock)	(*(lock) ? 1 : TAS(lock))
 
-/*
- * The second operand of addi can hold a constant zero or a register number,
- * hence constraint "=&b" to avoid allocating r0.  "b" stands for "address
- * base register"; most operands having this register-or-zero property are
- * address bases, e.g. the second operand of lwax.
- *
- * NOTE: per the Enhanced PowerPC Architecture manual, v1.0 dated 7-May-2002,
- * an isync is a sufficient synchronization barrier after a lwarx/stwcx loop.
- * But if the spinlock is in ordinary memory, we can use lwsync instead for
- * better performance.
- */
 static __inline__ int
 tas(volatile slock_t *lock)
 {
-	slock_t _t;
-	int _res;
-
-	__asm__ __volatile__(
-"	lwarx   %0,0,%3,1	\n"
-"	cmpwi   %0,0		\n"
-"	bne     1f			\n"
-"	addi    %0,%0,1		\n"
-"	stwcx.  %0,0,%3		\n"
-"	beq     2f			\n"
-"1: \n"
-"	li      %1,1		\n"
-"	b       3f			\n"
-"2: \n"
-"	lwsync				\n"
-"	li      %1,0		\n"
-"3: \n"
-:	"=&b"(_t), "=r"(_res), "+m"(*lock)
-:	"r"(lock)
-:	"memory", "cc");
-	return _res;
+  return __sync_lock_test_and_set(lock, 1);
 }
-
-/*
- * PowerPC S_UNLOCK is almost standard but requires a "sync" instruction.
- * But we can use lwsync instead for better performance.
- */
-#define S_UNLOCK(lock)	\
-do \
-{ \
-	__asm__ __volatile__ ("	lwsync \n" ::: "memory"); \
-	*((volatile slock_t *) (lock)) = 0; \
-} while (0)
+#define S_UNLOCK(lock) __sync_lock_release(lock)
 
 #endif /* powerpc */
-
-
+ 
 #if defined(__mips__) && !defined(__sgi)	/* non-SGI MIPS */
 #define HAS_TEST_AND_SET
 
diff --git a/src/interfaces/ecpg/compatlib/meson.build b/src/interfaces/ecpg/compatlib/meson.build
index 56e0a21651b..3f39187cdcc 100644
--- a/src/interfaces/ecpg/compatlib/meson.build
+++ b/src/interfaces/ecpg/compatlib/meson.build
@@ -16,7 +16,7 @@ if host_system == 'windows'
 endif
 
 # see src/interfaces/libpq/meson.build
-ecpg_compat_st = static_library('libecpg_compat',
+ecpg_compat_st = static_library('libecpg_compat_static',
   ecpg_compat_sources,
   include_directories: ecpg_compat_inc,
   c_args: ecpg_compat_c_args,
diff --git a/src/interfaces/ecpg/ecpglib/meson.build b/src/interfaces/ecpg/ecpglib/meson.build
index 8f478c6a73e..e9faf290a2b 100644
--- a/src/interfaces/ecpg/ecpglib/meson.build
+++ b/src/interfaces/ecpg/ecpglib/meson.build
@@ -25,7 +25,7 @@ if host_system == 'windows'
 endif
 
 # see src/interfaces/libpq/meson.build
-ecpglib_st = static_library('libecpg',
+ecpglib_st = static_library('libecpg_static',
   ecpglib_sources,
   include_directories: ecpglib_inc,
   c_args: ecpglib_c_args,
diff --git a/src/interfaces/ecpg/pgtypeslib/meson.build b/src/interfaces/ecpg/pgtypeslib/meson.build
index 02301ec9acb..94d1d0ad1ef 100644
--- a/src/interfaces/ecpg/pgtypeslib/meson.build
+++ b/src/interfaces/ecpg/pgtypeslib/meson.build
@@ -21,7 +21,7 @@ if host_system == 'windows'
 endif
 
 # see src/interfaces/libpq/meson.build
-ecpg_pgtypes_st = static_library('libpgtypes',
+ecpg_pgtypes_st = static_library('libpgtypes_static',
   ecpg_pgtypes_sources,
   include_directories: ecpg_pgtypes_inc,
   c_args: ecpg_pgtypes_c_args,
diff --git a/src/interfaces/libpq/meson.build b/src/interfaces/libpq/meson.build
index a74e885b169..eea175ad14a 100644
--- a/src/interfaces/libpq/meson.build
+++ b/src/interfaces/libpq/meson.build
@@ -57,7 +57,7 @@ libpq_so_c_args = ['-DUSE_DYNAMIC_OAUTH']
 # We could try to avoid building the source files twice, but it probably adds
 # more complexity than its worth (reusing object files requires also linking
 # to the library on windows or breaks precompiled headers).
-libpq_st = static_library('libpq',
+libpq_st = static_library('libpq_static',
   libpq_sources,
   include_directories: [libpq_inc],
   c_args: libpq_c_args,
diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix
new file mode 100644
index 00000000000..e91b250fd19
--- /dev/null
+++ b/src/makefiles/Makefile.aix
@@ -0,0 +1,34 @@
+# -blibpath:
+# The path to be inserted into the default path (Index 0 path) field of the
+# loader section. When this flag is presented, the -L paths will not be stored.
+# AIX uses a stricter, more explicit approach. The runtime linker expects to
+# tell it exactly where to look using -blibpath.
+# -blibpath must contain ALL directories where we should look for libraries
+libpath := $(shell echo $(subst -L,:,$(filter -L/%,$(LDFLAGS))) | sed -e's/ //g'):/usr/lib:/lib
+
+# AIX uses a stricter, more explicit approach. The runtime linker expects
+# to tell it exactly where to look using -blibpath.
+rpath = -Wl,-blibpath:'$(rpathdir)$(libpath)'
+
+# gcc needs to know it's building a shared lib, otherwise it'll not emit
+# correct code / link to the right support libraries
+ifeq ($(GCC), yes)
+LDFLAGS_SL += -shared
+endif
+
+# env var name to use in place of LD_LIBRARY_PATH
+ld_library_path_var = LIBPATH
+
+POSTGRES_IMP= postgres.imp
+
+ifdef PGXS
+BE_DLLLIBS= -Wl,-bI:$(pkglibdir)/$(POSTGRES_IMP)
+else
+BE_DLLLIBS= -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP)
+endif
+
+MKLDEXPORT_DIR=src/backend/port/aix
+MKLDEXPORT=$(top_srcdir)/$(MKLDEXPORT_DIR)/mkldexport.sh
+
+%$(DLSUFFIX): %.o
+	$(CC) $(CFLAGS) $*.o $(LDFLAGS) $(LDFLAGS_SL) -o $@ $(BE_DLLLIBS)
diff --git a/src/port/strerror.c b/src/port/strerror.c
index f0746517770..c46b9dc91fc 100644
--- a/src/port/strerror.c
+++ b/src/port/strerror.c
@@ -214,8 +214,10 @@ get_errno_symbol(int errnum)
 			return "ENOTCONN";
 		case ENOTDIR:
 			return "ENOTDIR";
+#if defined(ENOTEMPTY) && (ENOTEMPTY != EEXIST) /* same code on AIX */
 		case ENOTEMPTY:
 			return "ENOTEMPTY";
+#endif
 		case ENOTSOCK:
 			return "ENOTSOCK";
 #ifdef ENOTSUP
diff --git a/src/template/aix b/src/template/aix
new file mode 100644
index 00000000000..22f61093b1b
--- /dev/null
+++ b/src/template/aix
@@ -0,0 +1,6 @@
+# This file is referred for specific flags wrt to AIX build process like
+# cflags.
+# src/template/aix
+
+# Extra CFLAGS for code that will go into a shared library
+CFLAGS_SL=" "
diff --git a/src/tools/gen_export.pl b/src/tools/gen_export.pl
index 86a7742b369..25827c42a68 100644
--- a/src/tools/gen_export.pl
+++ b/src/tools/gen_export.pl
@@ -18,7 +18,8 @@ GetOptions(
 
 if (not(   $format eq 'darwin'
 		or $format eq 'gnu'
-		or $format eq 'win'))
+		or $format eq 'win'
+        or $format eq 'aix'))
 {
 	die "$0: $format is not yet handled (only darwin, gnu, win are)\n";
 }
@@ -46,6 +47,10 @@ elsif ($format eq 'win')
 	}
 	print $output_handle "EXPORTS\n";
 }
+elsif ($format eq 'aix')
+{
+	print $output_handle "#!\n";
+}
 
 while (<$input_handle>)
 {
@@ -63,6 +68,10 @@ while (<$input_handle>)
 		{
 			print $output_handle "    $1;\n";
 		}
+        elsif ($format eq 'aix')
+        {
+            print $output_handle "$1\n";
+        }
 		elsif ($format eq 'win')
 		{
 			print $output_handle "$1 @ $2\n";
-- 
2.41.0



^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-12-09 21:00  Heikki Linnakangas <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  2 siblings, 0 replies; 47+ messages in thread

From: Heikki Linnakangas @ 2025-12-09 21:00 UTC (permalink / raw)
  To: Srirama Kucherlapati <[email protected]>; AIX PG user <[email protected]>; [email protected] <[email protected]>; Peter Eisentraut <[email protected]>

On 09/12/2025 18:50, Srirama Kucherlapati wrote:
> @@ -1766,9 +1785,9 @@ endforeach
>  # any types wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8
>  # would be too much of a penalty for disk and memory space.
>  alignof_double = cdata.get('ALIGNOF_DOUBLE')
> -if cc.alignment('int64_t', args: test_c_args, prefix: '#include <stdint.h>') > alignof_double
> -  error('alignment of int64_t is greater than the alignment of double')
> -endif
> +#if cc.alignment('int64_t', args: test_c_args, prefix: '#include <stdint.h>') > alignof_double
> +#  error('alignment of int64_t is greater than the alignment of double')
> +#endif
>  cdata.set('MAXIMUM_ALIGNOF', alignof_double)
>  
>  cdata.set('SIZEOF_LONG', cc.sizeof('long', args: test_c_args))

This is unfinished.

> @@ -1820,7 +1839,7 @@ if cc.links('''
>    if not meson.is_cross_build()
>      r = cc.run('''
>      /* This must match the corresponding code in c.h: */
> -    #if defined(__GNUC__)
> +    #if defined(__GNUC__) || defined(__IBMC__)
>      #define pg_attribute_aligned(a) __attribute__((aligned(a)))
>      #elif defined(_MSC_VER)
>      #define pg_attribute_aligned(a) __declspec(align(a))

There's a comment right there that it must match the corresponding code 
in c.h, but you didn't modify c.h.

> +  # Native memset() is faster, tested on:
> +  memset_loop_limit = 0

Incomplete sentence: tested on what?

We talked about this before. I'm reluctant to have a special case for 
AIX, because I suspect this has little to do with the operating system, 
and more with the compiler and the CPU architecture. I could be wrong; 
maybe the libc memset() implementation on AIX is superior to that on 
linux, for example. I'd love to see thorough performance testing of 
MemSetAligned() vs memset() on common combinations of CPUs and libc 
implementations.  Ideally, we can just replace MemSetAligned() with 
memset() everywhere.

If you do such testing, please start a separate thread for that. On this 
thread, it will get lost with all the AIX-specific stuff.

> +/* This change is required for the meson changes as the autoconf is not run and
> + * to resolve the conflicts in picking the float.h details by default from the
> + * postgres defined datatypes.
> + */
> +#ifdef _AIX
> +#ifndef PGDLLIMPORT
> +#define PGDLLIMPORT
> +#endif  /* PGDLLIMPORT */
> +typedef float float4;
> +typedef double float8;

I don't understand these typedefs. What is the conflict the comment 
talks about?

> +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
> +#define pg_noreturn _Noreturn
> +#elif defined(__GNUC__)
> +#define pg_noreturn __attribute__((noreturn))
> +#else
> +#define pg_noreturn
> +#endif

Isn't this just duplicating the snippet in c.h?

> +#include <stdbool.h>

This is in c.h too.

 > src/include/storage/s_lock.h
 > [ switches to __sync_lock_release(lock) on all powerpc systems ]

We talked about this before.

> @@ -18,7 +18,8 @@ GetOptions(
>  
>  if (not(   $format eq 'darwin'
>  		or $format eq 'gnu'
> -		or $format eq 'win'))
> +		or $format eq 'win'
> +        or $format eq 'aix'))
>  {
>  	die "$0: $format is not yet handled (only darwin, gnu, win are)\n";
>  }

Forgot to update the error message.


I didn't review the autoconf / Makefile changes.

> Apologies for the delayed response; I was occupied with other tasks.

Oh no worries, I'm not in any hurry with this. On the contrary to be honest.

- Heikki






^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-12-09 21:08  Peter Eisentraut <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  2 siblings, 1 reply; 47+ messages in thread

From: Peter Eisentraut @ 2025-12-09 21:08 UTC (permalink / raw)
  To: Srirama Kucherlapati <[email protected]>; AIX PG user <[email protected]>; [email protected] <[email protected]>; Heikki Linnakangas <[email protected]>

On 09.12.25 17:50, Srirama Kucherlapati wrote:
> Hi Team, (Peter/Heikki)
> 
> I have implemented the requested modifications in the latest patch. 
> Below are the key technical updates:
> 
> • Meson Build Configuration: Adjusted below meson.build scripts to 
> incorporate the suggested changes, ensuring proper dependency resolution 
> and improved build consistency.
> 
>      Removed the AIX changes in the below from the previous patch.
> 
>      src/backend/jit/llvm/meson.build
> src/backend/replication/libpqwalreceiver/meson.build
> src/backend/replication/pgoutput/meson.build
> src/backend/snowball/meson.build
> src/backend/utils/mb/conversion_procs/meson.build
> 
>      Added the static_library() changes.
> 
>      > Regarding the archiving of shared and static libraries, the 
> latest version of
>> Meson raises a conflict as both targets have the same name. This issue
>> arises because, on AIX, both shared and static libraries are named as same
>> archive, which leads to naming collisions during the build process. We
>> would still need the below changes.     
> 
>       src/interfaces/ecpg/compatlib/meson.build
> src/interfaces/ecpg/ecpglib/meson.build
> src/interfaces/ecpg/pgtypeslib/meson.build
> src/interfaces/libpq/meson.build
> 
> • CFLAGS Optimization Removal: Removed high-level optimization flags 
> from CFLAGS to prevent unpredictable behaviour and maintain stability 
> during compilation.
> 
> I would greatly appreciate it if you could review the patch and share 
> your feedback or any additional recommendations.
> 
> Apologies for the delayed response; I was occupied with other tasks.
> 
> Your insights are greatly appreciated and will help enhance the patch.
> 
> 
> Warm regards,
> -Sriram.
> 
> 

1) In meson.build:

+  cppflags += '-D_GNU_SOURCE'

I don't think this symbol is applicable to AIX.

2) In meson.build:

+  # Native memset() is faster, tested on:
+  memset_loop_limit = 0

The comment sentence appears to be truncated.

3) In meson.build:

+#if cc.alignment('int64_t', args: test_c_args, prefix: '#include 
<stdint.h>') > alignof_double
+#  error('alignment of int64_t is greater than the alignment of double')
+#endif

This commented out code cannot be left like this.  Either remove it or 
adjust it as required.

4) In meson.build:

      /* This must match the corresponding code in c.h: */
-    #if defined(__GNUC__)
+    #if defined(__GNUC__) || defined(__IBMC__)

You code does not observe what the comment says.

5) The changes in src/include/port/aix.h are nonsense.  This was 
previously pointed out and you said you would address this.

6) I had previously pointed out that the changes in 
src/include/storage/s_lock.h are not acceptable like that and you had 
said that you would address that.





^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-12-09 21:56  Tristan Partin <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  2 siblings, 1 reply; 47+ messages in thread

From: Tristan Partin @ 2025-12-09 21:56 UTC (permalink / raw)
  To: Srirama Kucherlapati <[email protected]>; AIX PG user <[email protected]>; +Cc: Heikki Linnakangas <[email protected]>; Peter Eisentraut <[email protected]>; pgsql-hackers <[email protected]>

Howdy,

Heikki asked me to look at the renames of the static Meson targets. 
I don't understand the reasoning for the changes. I am completely 
unfamiliar with AIX, so maybe it's obvious. Does Meson produce a static 
library and a shared library with the same file extension? If so, why is 
that? That's the only reason I can think of for making those changes. Is 
it AIX-specific or whatever OS you are testing on?

In your patch, I found a link to 
https://www.postgresql.org/message-id/[email protected].... 

> -> On AIX, you can do a static as well as a dynamic
> -> link against a shared library, it depends on how you
> -> invoke the linker.
> 
> When you link statically, the shared objects from
> the library are added to your executable as required;
> when you link dynamically, only references
> to the shared objects are included in the executable.
> 
> Consequently you do not need a separate static library
> on AIX if you have a dynamic library.

This seems to imply that we don't need a static library at all on AIX. 
However this email is also nearing 20 years old :D. Could we get away 
without the renames on the Meson targets by just not defining the static 
library targets?

-- 
Tristan Partin
Databricks (https://databricks.com)





^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* RE: AIX support
@ 2025-12-10 14:31  Srirama Kucherlapati <[email protected]>
  parent: Tristan Partin <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: Srirama Kucherlapati @ 2025-12-10 14:31 UTC (permalink / raw)
  To: Tristan Partin <[email protected]>; AIX PG user <[email protected]>; +Cc: Heikki Linnakangas <[email protected]>; Peter Eisentraut <[email protected]>; pgsql-hackers <[email protected]>

Hi Tristan,


Thank you for reviewing the patch.

We encountered the following error when building without the "_static" suffix in the library name:
    Found ninja-1.12.1 at /opt/freeware/bin/ninja
    ERROR: Multiple producers for Ninja target "src/interfaces/ecpg/compatlib/libecpg_compat.a”.
    Please rename your targets.

On AIX, shared libraries are archived in a way that allows multiple versions to
coexist within the same archive. This is primarily because shared library(.so)
is archived into .a, which leads to naming conflicts between static and shared
libraries. To address this, we suffixed the library with “_static".

However, we later tested by completely skipping the static library build, and
this approach worked successfully since it eliminates the conflict between
static and shared libraries. I'm working on the changes and will validate
further on this.


BTW, thank you, Heikki and Peter, for your comments. I’m working on the comments

and I’ll keep you updated.


Warm regards,

Sriram.






^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-12-10 18:37  Tristan Partin <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  0 siblings, 0 replies; 47+ messages in thread

From: Tristan Partin @ 2025-12-10 18:37 UTC (permalink / raw)
  To: Srirama Kucherlapati <[email protected]>; AIX PG user <[email protected]>; +Cc: Heikki Linnakangas <[email protected]>; Peter Eisentraut <[email protected]>; pgsql-hackers <[email protected]>

On Wed Dec 10, 2025 at 8:32 AM CST, Srirama Kucherlapati wrote:
> We encountered the following error when building without the "_static" suffix in the library name:
>     Found ninja-1.12.1 at /opt/freeware/bin/ninja
>     ERROR: Multiple producers for Ninja target "src/interfaces/ecpg/compatlib/libecpg_compat.a”.
>     Please rename your targets.
>
> On AIX, shared libraries are archived in a way that allows multiple versions to
> coexist within the same archive. This is primarily because shared library(.so)
> is archived into .a, which leads to naming conflicts between static and shared
> libraries. To address this, we suffixed the library with “_static".
>
> However, we later tested by completely skipping the static library build, and
> this approach worked successfully since it eliminates the conflict between
> static and shared libraries. I'm working on the changes and will validate
> further on this.

Thanks for the explanation. I'm glad we can workaround this without 
renaming the targets!

-- 
Tristan Partin
Databricks (https://databricks.com)





^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* RE: AIX support
@ 2025-12-19 15:34  Srirama Kucherlapati <[email protected]>
  parent: Peter Eisentraut <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: Srirama Kucherlapati @ 2025-12-19 15:34 UTC (permalink / raw)
  To: Peter Eisentraut <[email protected]>; [email protected] <[email protected]>; Heikki Linnakangas <[email protected]>; +Cc: Tristan Partin <[email protected]>; AIX PG user <[email protected]>

Hi Peter/Heikki/Tristan

Please find the attached changes for the below comments. Along with comments from Tristan.
Please let me know if these meson specific changes are fine.

0001-Support-for-AIX-meson-updates.pg19.patch - has the changes for the below comments only.
0001-Support-for-AIX-all-meson.pg19.patch - has all the meson specific changes.

>> 1) In meson.build:

>> +  cppflags += '-D_GNU_SOURCE’
>> I don't think this symbol is applicable to AIX.

    AIX provides certain functions similar to Linux, but with different names and
    signatures. To align them with Linux behaviour, the GNU_SOURCE macro is defined,
    which enables AIX functions to behave like their Linux counterparts.
    You are right, this is not needed for AIX. I have removed and everything got build.

>> 2) In meson.build:

>> +  # Native memset() is faster, tested on:
>> +  memset_loop_limit = 0

>> The comment sentence appears to be truncated.

    For now, removed this, I’ll provide statistics in a different thread as Heikki suggested.

>> 3) In meson.build:

>> +#if cc.alignment('int64_t', args: test_c_args, prefix: ‘#include
>> <stdint.h>') > alignof_double
>>+#  error('alignment of int64_t is greater than the alignment of double’)
>> +#endif

>> This commented out code cannot be left like this.  Either remove it or
>> adjust it as required.

    I have updated the similar logic as in regular GNU configure file.

>> 4) In meson.build:

>>      /* This must match the corresponding code in c.h: */
>> -    #if defined(__GNUC__)
>> +    #if defined(__GNUC__) || defined(__IBMC__)

>> You code does not observe what the comment says.

    You are right, I have removed this as this is relevant only if we are compiling with XLC. Right now, its compiled with gcc

>> 5) The changes in src/include/port/aix.h are nonsense.  This was
>> previously pointed out and you said you would address this.

    The changes are irrelevant now, removed them. As all these additional definitions are covered  by the postgres defined header file (src/include/utils/float.h). We can use “_H_FLOAT” to skip the system header "float.h”.



I’d like to finalize all Meson-specific changes first. Meanwhile, I’m also working on the other comments.

Kindly let me know your thoughts and feedback on the changes.


Thanks,

Sriram.



Attachments:

  [application/octet-stream] 0001-Support-for-AIX-all-meson.pg19.patch (8.1K, 3-0001-Support-for-AIX-all-meson.pg19.patch)
  download | inline diff:

diff --git a/meson.build b/meson.build
index 6e7ddd74683..6ba24187d15 100644
--- a/meson.build
+++ b/meson.build
@@ -206,6 +206,26 @@ if host_system == 'cygwin'
   mod_link_with_name = 'lib@[email protected]'
   mod_link_with_dir = 'libdir'
 
+elif host_system == 'aix'
+  sema_kind = 'unnamed_posix'
+  library_path_var = 'LIBPATH'
+  export_file_format = 'aix'
+  export_fmt = '-Wl,-bE:@0@'
+  mod_link_args_fmt = ['-Wl,-bI:@0@']
+  mod_link_with_dir = 'libdir'
+  mod_link_with_name = '@[email protected]'
+  dl_suffix = '.a'
+  # This flag is required to make sure the user spefic float.h is
+  # picked instead of the system float.h header file, which doesnot
+  # have definition like float8, etc
+  cflags += '-D_H_FLOAT'
+
+  # M:SRE sets a flag indicating that an object is a shared library. Seems to
+  # work in some circumstances without, but required in others.
+  ldflags_sl += '-Wl,-bM:SRE'
+  ldflags_be += '-Wl,-brtllib'
+
+
 elif host_system == 'darwin'
   dlsuffix = '.dylib'
   library_path_var = 'DYLD_LIBRARY_PATH'
@@ -1765,10 +1785,49 @@ endforeach
 # as long, char, short, or int.  Note that we intentionally do not consider
 # any types wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8
 # would be too much of a penalty for disk and memory space.
-alignof_double = cdata.get('ALIGNOF_DOUBLE')
-if cc.alignment('int64_t', args: test_c_args, prefix: '#include <stdint.h>') > alignof_double
-  error('alignment of int64_t is greater than the alignment of double')
-endif
+if host_system != 'aix'
+  alignof_double = cdata.get('ALIGNOF_DOUBLE')
+  if cc.alignment('int64_t', args: test_c_args, prefix: '#include <stdint.h>') > alignof_double
+       error('alignment of int64_t is greater than the alignment of double')
+  endif
+else
+  # The AIX 'power' alignment rules apply the natural alignment of the "first
+  # member" if it is of a floating-point data type (or is an aggregate whose
+  # recursively "first" member or element is such a type). The alignment
+  # associated with these types for subsequent members use an alignment value
+  # where the floating-point data type is considered to have 4-byte alignment.
+  # More info
+  # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99557
+  #
+  # The double is aligned to 4-bytes on AIX in aggregates. But to maintain
+  # alignement across platforms the max alignment of long should be considered.
+
+  # Get the alignment values
+  ac_cv_alignof_long    = cc.alignment('long', args: test_c_args, prefix: '#include <stdint.h>')
+  ac_cv_alignof_double  = cc.alignment('double', args: test_c_args, prefix: '#include <stdint.h>') 
+  ac_cv_alignof_int64_t = cc.alignment('int64_t', args: test_c_args, prefix: '#include <stdint.h>')
+ 
+  message('Alignment of long    : @0@'.format(ac_cv_alignof_long))
+  message('Alignment of double  : @0@'.format(ac_cv_alignof_double))
+  message('Alignment of int64_t : @0@'.format(ac_cv_alignof_int64_t))
+  
+  # Start with long
+  alignof_double = ac_cv_alignof_long
+  message('MAX ALIGN ac_cv_alignof_long')
+
+  # Compare with double
+  if alignof_double < ac_cv_alignof_double
+    alignof_double = ac_cv_alignof_double
+    message('MAX ALIGN ac_cv_alignof_double')
+  endif
+
+  # Compare with int64_t
+  if alignof_double < ac_cv_alignof_int64_t
+    alignof_double = ac_cv_alignof_int64_t
+    message('MAX ALIGN ac_cv_alignof_int64_t')
+  endif
+endif
+message('MAX ALIGN OF DOUBLE : @0@'.format(alignof_double))
 cdata.set('MAXIMUM_ALIGNOF', alignof_double)
 
 cdata.set('SIZEOF_LONG', cc.sizeof('long', args: test_c_args))
@@ -3466,13 +3525,17 @@ endif
 installed_targets = [
   backend_targets,
   bin_targets,
-  libpq_st,
   pl_targets,
   contrib_targets,
   nls_mo_targets,
   ecpg_targets,
 ]
 
+# The static libpq is skipped in AIX. This is not required.
+if host_system != 'aix'
+  installed_targets += [libpq_st]
+endif
+
 if oauth_flow_supported
   installed_targets += [
     libpq_oauth_so,
@@ -3816,7 +3879,13 @@ add_test_setup('running',
 ###############################################################
 
 alias_target('backend', backend_targets)
-alias_target('bin', bin_targets + [libpq_st])
+if host_system != 'aix'
+  alias_target('bin', bin_targets + [libpq_st])
+else
+  # The static libpq is skipped in AIX. This is not required.
+  alias_target('bin', bin_targets)
+endif
+
 alias_target('pl', pl_targets)
 alias_target('contrib', contrib_targets)
 alias_target('testprep', testprep_targets)
diff --git a/src/backend/meson.build b/src/backend/meson.build
index b831a541652..4838f245ab3 100644
--- a/src/backend/meson.build
+++ b/src/backend/meson.build
@@ -125,6 +125,24 @@ if host_system == 'windows'
     '--FILEDESC', 'PostgreSQL Server',])
 endif
 
+if host_system == 'aix'
+  # The '.' argument leads mkldexport.sh to emit "#! .", which refers to the
+  # main executable, allowing extension libraries to resolve their undefined
+  # symbols to symbols in the postgres binary.
+  postgres_imp = custom_target('postgres.imp',
+    command: [files('port/aix/mkldexport.sh'), '@INPUT@', '.'],
+    input: postgres_lib,
+    output: 'postgres.imp',
+    capture: true,
+    install: true,
+    install_dir: dir_lib,
+    build_by_default: false,
+  )
+  backend_link_args += '-Wl,-bE:@0@'.format(postgres_imp.full_path())
+  backend_link_depends += postgres_imp
+endif
+
+
 postgres = executable('postgres',
   backend_input,
   sources: post_export_backend_sources,
diff --git a/src/interfaces/ecpg/compatlib/meson.build b/src/interfaces/ecpg/compatlib/meson.build
index 56e0a21651b..af96e375a9b 100644
--- a/src/interfaces/ecpg/compatlib/meson.build
+++ b/src/interfaces/ecpg/compatlib/meson.build
@@ -16,6 +16,7 @@ if host_system == 'windows'
 endif
 
 # see src/interfaces/libpq/meson.build
+if host_system != 'aix'
 ecpg_compat_st = static_library('libecpg_compat',
   ecpg_compat_sources,
   include_directories: ecpg_compat_inc,
@@ -25,6 +26,7 @@ ecpg_compat_st = static_library('libecpg_compat',
   kwargs: default_lib_args,
 )
 ecpg_targets += ecpg_compat_st
+endif
 
 ecpg_compat_so = shared_library('libecpg_compat',
   ecpg_compat_sources + ecpg_compat_so_sources,
diff --git a/src/interfaces/ecpg/ecpglib/meson.build b/src/interfaces/ecpg/ecpglib/meson.build
index 8f478c6a73e..7d28cd67388 100644
--- a/src/interfaces/ecpg/ecpglib/meson.build
+++ b/src/interfaces/ecpg/ecpglib/meson.build
@@ -25,6 +25,7 @@ if host_system == 'windows'
 endif
 
 # see src/interfaces/libpq/meson.build
+if host_system != 'aix'
 ecpglib_st = static_library('libecpg',
   ecpglib_sources,
   include_directories: ecpglib_inc,
@@ -35,6 +36,7 @@ ecpglib_st = static_library('libecpg',
   kwargs: default_lib_args,
 )
 ecpg_targets += ecpglib_st
+endif
 
 ecpglib_so = shared_library('libecpg',
   ecpglib_sources + ecpglib_so_sources,
diff --git a/src/interfaces/ecpg/pgtypeslib/meson.build b/src/interfaces/ecpg/pgtypeslib/meson.build
index 02301ec9acb..97f4e1c6eda 100644
--- a/src/interfaces/ecpg/pgtypeslib/meson.build
+++ b/src/interfaces/ecpg/pgtypeslib/meson.build
@@ -21,6 +21,7 @@ if host_system == 'windows'
 endif
 
 # see src/interfaces/libpq/meson.build
+if host_system != 'aix'
 ecpg_pgtypes_st = static_library('libpgtypes',
   ecpg_pgtypes_sources,
   include_directories: ecpg_pgtypes_inc,
@@ -30,6 +31,7 @@ ecpg_pgtypes_st = static_library('libpgtypes',
   kwargs: default_lib_args,
 )
 ecpg_targets += ecpg_pgtypes_st
+endif
 
 ecpg_pgtypes_so = shared_library('libpgtypes',
   ecpg_pgtypes_sources + ecpg_pgtypes_so_sources,
diff --git a/src/interfaces/libpq/meson.build b/src/interfaces/libpq/meson.build
index a74e885b169..98ced9376d9 100644
--- a/src/interfaces/libpq/meson.build
+++ b/src/interfaces/libpq/meson.build
@@ -57,6 +57,7 @@ libpq_so_c_args = ['-DUSE_DYNAMIC_OAUTH']
 # We could try to avoid building the source files twice, but it probably adds
 # more complexity than its worth (reusing object files requires also linking
 # to the library on windows or breaks precompiled headers).
+if host_system != 'aix'
 libpq_st = static_library('libpq',
   libpq_sources,
   include_directories: [libpq_inc],
@@ -65,6 +66,7 @@ libpq_st = static_library('libpq',
   dependencies: [frontend_stlib_code, libpq_deps],
   kwargs: default_lib_args,
 )
+endif
 
 libpq_so = shared_library('libpq',
   libpq_sources + libpq_so_sources,


  [application/octet-stream] 0001-Support-for-AIX-meson-updates.pg19.patch (8.9K, 4-0001-Support-for-AIX-meson-updates.pg19.patch)
  download | inline diff:
diff --git a/meson.build b/meson.build
index 304a9184075..6ba24187d15 100644
--- a/meson.build
+++ b/meson.build
@@ -215,15 +215,16 @@ elif host_system == 'aix'
   mod_link_with_dir = 'libdir'
   mod_link_with_name = '@[email protected]'
   dl_suffix = '.a'
-  cppflags += '-D_GNU_SOURCE'
+  # This flag is required to make sure the user spefic float.h is
+  # picked instead of the system float.h header file, which doesnot
+  # have definition like float8, etc
+  cflags += '-D_H_FLOAT'
 
   # M:SRE sets a flag indicating that an object is a shared library. Seems to
   # work in some circumstances without, but required in others.
   ldflags_sl += '-Wl,-bM:SRE'
   ldflags_be += '-Wl,-brtllib'
 
-  # Native memset() is faster, tested on:
-  memset_loop_limit = 0
 
 elif host_system == 'darwin'
   dlsuffix = '.dylib'
@@ -1784,10 +1785,49 @@ endforeach
 # as long, char, short, or int.  Note that we intentionally do not consider
 # any types wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8
 # would be too much of a penalty for disk and memory space.
-alignof_double = cdata.get('ALIGNOF_DOUBLE')
-#if cc.alignment('int64_t', args: test_c_args, prefix: '#include <stdint.h>') > alignof_double
-#  error('alignment of int64_t is greater than the alignment of double')
-#endif
+if host_system != 'aix'
+  alignof_double = cdata.get('ALIGNOF_DOUBLE')
+  if cc.alignment('int64_t', args: test_c_args, prefix: '#include <stdint.h>') > alignof_double
+       error('alignment of int64_t is greater than the alignment of double')
+  endif
+else
+  # The AIX 'power' alignment rules apply the natural alignment of the "first
+  # member" if it is of a floating-point data type (or is an aggregate whose
+  # recursively "first" member or element is such a type). The alignment
+  # associated with these types for subsequent members use an alignment value
+  # where the floating-point data type is considered to have 4-byte alignment.
+  # More info
+  # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99557
+  #
+  # The double is aligned to 4-bytes on AIX in aggregates. But to maintain
+  # alignement across platforms the max alignment of long should be considered.
+
+  # Get the alignment values
+  ac_cv_alignof_long    = cc.alignment('long', args: test_c_args, prefix: '#include <stdint.h>')
+  ac_cv_alignof_double  = cc.alignment('double', args: test_c_args, prefix: '#include <stdint.h>') 
+  ac_cv_alignof_int64_t = cc.alignment('int64_t', args: test_c_args, prefix: '#include <stdint.h>')
+ 
+  message('Alignment of long    : @0@'.format(ac_cv_alignof_long))
+  message('Alignment of double  : @0@'.format(ac_cv_alignof_double))
+  message('Alignment of int64_t : @0@'.format(ac_cv_alignof_int64_t))
+  
+  # Start with long
+  alignof_double = ac_cv_alignof_long
+  message('MAX ALIGN ac_cv_alignof_long')
+
+  # Compare with double
+  if alignof_double < ac_cv_alignof_double
+    alignof_double = ac_cv_alignof_double
+    message('MAX ALIGN ac_cv_alignof_double')
+  endif
+
+  # Compare with int64_t
+  if alignof_double < ac_cv_alignof_int64_t
+    alignof_double = ac_cv_alignof_int64_t
+    message('MAX ALIGN ac_cv_alignof_int64_t')
+  endif
+endif
+message('MAX ALIGN OF DOUBLE : @0@'.format(alignof_double))
 cdata.set('MAXIMUM_ALIGNOF', alignof_double)
 
 cdata.set('SIZEOF_LONG', cc.sizeof('long', args: test_c_args))
@@ -1839,7 +1879,7 @@ if cc.links('''
   if not meson.is_cross_build()
     r = cc.run('''
     /* This must match the corresponding code in c.h: */
-    #if defined(__GNUC__) || defined(__IBMC__)
+    #if defined(__GNUC__)
     #define pg_attribute_aligned(a) __attribute__((aligned(a)))
     #elif defined(_MSC_VER)
     #define pg_attribute_aligned(a) __declspec(align(a))
@@ -3485,13 +3525,17 @@ endif
 installed_targets = [
   backend_targets,
   bin_targets,
-  libpq_st,
   pl_targets,
   contrib_targets,
   nls_mo_targets,
   ecpg_targets,
 ]
 
+# The static libpq is skipped in AIX. This is not required.
+if host_system != 'aix'
+  installed_targets += [libpq_st]
+endif
+
 if oauth_flow_supported
   installed_targets += [
     libpq_oauth_so,
@@ -3835,7 +3879,13 @@ add_test_setup('running',
 ###############################################################
 
 alias_target('backend', backend_targets)
-alias_target('bin', bin_targets + [libpq_st])
+if host_system != 'aix'
+  alias_target('bin', bin_targets + [libpq_st])
+else
+  # The static libpq is skipped in AIX. This is not required.
+  alias_target('bin', bin_targets)
+endif
+
 alias_target('pl', pl_targets)
 alias_target('contrib', contrib_targets)
 alias_target('testprep', testprep_targets)
diff --git a/src/include/port/aix.h b/src/include/port/aix.h
index dd7cfb197cd..c86983a4452 100644
--- a/src/include/port/aix.h
+++ b/src/include/port/aix.h
@@ -1,26 +1,3 @@
 /*
  * src/include/port/aix.h
  */
-
-/* This change is required for the meson changes as the autoconf is not run and
- * to resolve the conflicts in picking the float.h details by default from the
- * postgres defined datatypes.
- */
-#ifdef _AIX
-#ifndef PGDLLIMPORT
-#define PGDLLIMPORT
-#endif  /* PGDLLIMPORT */
-typedef float float4;
-typedef double float8;
-
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
-#define pg_noreturn _Noreturn
-#elif defined(__GNUC__)
-#define pg_noreturn __attribute__((noreturn))
-#else
-#define pg_noreturn
-#endif
-
-#include <stdbool.h>
-
-#endif  /*_AIX */
diff --git a/src/interfaces/ecpg/compatlib/meson.build b/src/interfaces/ecpg/compatlib/meson.build
index 3f39187cdcc..af96e375a9b 100644
--- a/src/interfaces/ecpg/compatlib/meson.build
+++ b/src/interfaces/ecpg/compatlib/meson.build
@@ -16,7 +16,8 @@ if host_system == 'windows'
 endif
 
 # see src/interfaces/libpq/meson.build
-ecpg_compat_st = static_library('libecpg_compat_static',
+if host_system != 'aix'
+ecpg_compat_st = static_library('libecpg_compat',
   ecpg_compat_sources,
   include_directories: ecpg_compat_inc,
   c_args: ecpg_compat_c_args,
@@ -25,6 +26,7 @@ ecpg_compat_st = static_library('libecpg_compat_static',
   kwargs: default_lib_args,
 )
 ecpg_targets += ecpg_compat_st
+endif
 
 ecpg_compat_so = shared_library('libecpg_compat',
   ecpg_compat_sources + ecpg_compat_so_sources,
diff --git a/src/interfaces/ecpg/ecpglib/meson.build b/src/interfaces/ecpg/ecpglib/meson.build
index e9faf290a2b..7d28cd67388 100644
--- a/src/interfaces/ecpg/ecpglib/meson.build
+++ b/src/interfaces/ecpg/ecpglib/meson.build
@@ -25,7 +25,8 @@ if host_system == 'windows'
 endif
 
 # see src/interfaces/libpq/meson.build
-ecpglib_st = static_library('libecpg_static',
+if host_system != 'aix'
+ecpglib_st = static_library('libecpg',
   ecpglib_sources,
   include_directories: ecpglib_inc,
   c_args: ecpglib_c_args,
@@ -35,6 +36,7 @@ ecpglib_st = static_library('libecpg_static',
   kwargs: default_lib_args,
 )
 ecpg_targets += ecpglib_st
+endif
 
 ecpglib_so = shared_library('libecpg',
   ecpglib_sources + ecpglib_so_sources,
diff --git a/src/interfaces/ecpg/pgtypeslib/meson.build b/src/interfaces/ecpg/pgtypeslib/meson.build
index 94d1d0ad1ef..97f4e1c6eda 100644
--- a/src/interfaces/ecpg/pgtypeslib/meson.build
+++ b/src/interfaces/ecpg/pgtypeslib/meson.build
@@ -21,7 +21,8 @@ if host_system == 'windows'
 endif
 
 # see src/interfaces/libpq/meson.build
-ecpg_pgtypes_st = static_library('libpgtypes_static',
+if host_system != 'aix'
+ecpg_pgtypes_st = static_library('libpgtypes',
   ecpg_pgtypes_sources,
   include_directories: ecpg_pgtypes_inc,
   c_args: ecpg_pgtypes_c_args,
@@ -30,6 +31,7 @@ ecpg_pgtypes_st = static_library('libpgtypes_static',
   kwargs: default_lib_args,
 )
 ecpg_targets += ecpg_pgtypes_st
+endif
 
 ecpg_pgtypes_so = shared_library('libpgtypes',
   ecpg_pgtypes_sources + ecpg_pgtypes_so_sources,
diff --git a/src/interfaces/libpq/meson.build b/src/interfaces/libpq/meson.build
index eea175ad14a..98ced9376d9 100644
--- a/src/interfaces/libpq/meson.build
+++ b/src/interfaces/libpq/meson.build
@@ -57,7 +57,8 @@ libpq_so_c_args = ['-DUSE_DYNAMIC_OAUTH']
 # We could try to avoid building the source files twice, but it probably adds
 # more complexity than its worth (reusing object files requires also linking
 # to the library on windows or breaks precompiled headers).
-libpq_st = static_library('libpq_static',
+if host_system != 'aix'
+libpq_st = static_library('libpq',
   libpq_sources,
   include_directories: [libpq_inc],
   c_args: libpq_c_args,
@@ -65,6 +66,7 @@ libpq_st = static_library('libpq_static',
   dependencies: [frontend_stlib_code, libpq_deps],
   kwargs: default_lib_args,
 )
+endif
 
 libpq_so = shared_library('libpq',
   libpq_sources + libpq_so_sources,
diff --git a/src/tools/gen_export.pl b/src/tools/gen_export.pl
index 25827c42a68..19c8b60560f 100644
--- a/src/tools/gen_export.pl
+++ b/src/tools/gen_export.pl
@@ -21,7 +21,7 @@ if (not(   $format eq 'darwin'
 		or $format eq 'win'
         or $format eq 'aix'))
 {
-	die "$0: $format is not yet handled (only darwin, gnu, win are)\n";
+	die "$0: $format is not yet handled (only darwin, gnu, win, aix are)\n";
 }
 
 open(my $input_handle, '<', $input)


^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* Re: AIX support
@ 2025-12-21 08:19  Tristan Partin <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: Tristan Partin @ 2025-12-21 08:19 UTC (permalink / raw)
  To: Srirama Kucherlapati <[email protected]>; Peter Eisentraut <[email protected]>; [email protected] <[email protected]>; Heikki Linnakangas <[email protected]>; +Cc: AIX PG user <[email protected]>

Thanks for your continued push for AIX support! Here are a few comments:

> # The static libpq is skipped in AIX. This is not required.

For comments like this, I would generally like to see some links or 
inline documentation to why this is the case. Maybe Peter or Heikki 
disagree.

There are a few places in the Meson code like the following:

	if AIX:
		don't define the static library target
	endif

Make sure that the innards of the if statements are indented. 
Alternatively, you could define something like:

	static_library_dependencies = []
	if host_machine.system() == 'AIX'
		# TODO: Document this
		AIX_poison_pill = disabler()
		static_library_dependencies += AIX_poison_pill
	endif

And then for all static library definitions, you would just make sure 
that they all depend on the poison pill. You could document the AIX 
shared/static library situation where the AIX_poison_pill variable is 
defined. I'd like to see if Peter thinks this is a good idea before 
implementing it.

I'm also a little confused by the second patch. Some of it seems to be 
the same, and some other parts seem to be new. Should we consolidate all 
Meson AIX support into one patch? Overall, I think the size of the patch 
is good, and seem pretty maintainable.

-- 
Tristan Partin
Databricks (https://databricks.com)





^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* RE: AIX support
@ 2025-12-24 15:34  Srirama Kucherlapati <[email protected]>
  parent: Tristan Partin <[email protected]>
  0 siblings, 1 reply; 47+ messages in thread

From: Srirama Kucherlapati @ 2025-12-24 15:34 UTC (permalink / raw)
  To: Tristan Partin <[email protected]>; Peter Eisentraut <[email protected]>; [email protected] <[email protected]>; Heikki Linnakangas <[email protected]>; +Cc: AIX PG user <[email protected]>


Hi Tristan,
Thank you for your feedback and suggestions.


As suggested, we have tried to implement a dependency-driven approach for static library builds, rather than using AIX platform tags.

    modified:   meson.build
        dep_static_lib = declare_dependency()                       << new dependency

        if host_system == 'aix'
            dep_static_lib = disabler()
        endif

    modified:   src/interfaces/ecpg/compatlib/meson.build
        ecpg_compat_st = static_library('libecpg_compat',
          ecpg_compat_sources,
          include_directories: ecpg_compat_inc,
          c_args: ecpg_compat_c_args,
          dependencies: [frontend_stlib_code, thread_dep, dep_static_lib],                       << new dependency
          link_with: [ecpglib_st, ecpg_pgtypes_st],
          kwargs: default_lib_args,
        )

    modified:   src/interfaces/ecpg/ecpglib/meson.build
        ecpglib_st = static_library('libecpg',
          ecpglib_sources,
          include_directories: ecpglib_inc,
          c_args: ecpglib_c_args,
          c_pch: pch_postgres_fe_h,
          dependencies: [frontend_stlib_code, thread_dep, libpq, dep_static_lib],                       << new dependency
          link_with: [ecpg_pgtypes_st],
          kwargs: default_lib_args,
        )

    modified:   src/interfaces/ecpg/pgtypeslib/meson.build
        ecpg_pgtypes_st = static_library('libpgtypes',
          ecpg_pgtypes_sources,
          include_directories: ecpg_pgtypes_inc,
          c_args: ecpg_pgtypes_c_args,
          c_pch: pch_postgres_fe_h,
          dependencies: [frontend_stlib_code, dep_static_lib],                       << new dependency
          kwargs: default_lib_args,
        )

    modified:   src/interfaces/libpq/meson.build
        libpq_st = static_library('libpq',
          libpq_sources,
          include_directories: [libpq_inc],
          c_args: libpq_c_args,
          c_pch: pch_postgres_fe_h,
          dependencies: [frontend_stlib_code, libpq_deps, dep_static_lib],                       << new dependency
          kwargs: default_lib_args,
        )

>  I'd like to see if Peter thinks this is a good idea before implementing it.
Also I would like to understand Peter/Heikki thoughts as well on this new implementation.

> Should we consolidate all Meson AIX support into one patch?
> Overall, I think the size of the patch is good, and seem pretty maintainable.

Thank you, Tristan, for your assistance. At present, the build appears stable

with the recent changes, however, the new dependency is causing impacts

elsewhere(with tmp_install). I will provide the consolidated patch after addressing these concerns.

Thanks,
Sriram.


^ permalink  raw  reply  [nested|flat] 47+ messages in thread

* RE: AIX support
@ 2026-03-12 12:05  Joe Hatcher <[email protected]>
  parent: Srirama Kucherlapati <[email protected]>
  0 siblings, 0 replies; 47+ messages in thread

From: Joe Hatcher @ 2026-03-12 12:05 UTC (permalink / raw)
  To: Aditya Kamath <[email protected]>; Srirama Kucherlapati <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; +Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>


Attesting to the demand for Postgres support on AIX, associated with the use of SAS, I am aware of ~200 Customers running Postgres on AIX on some 600 unique deployments.

SAS is engaged with IBM regarding Postgres on AX and is a strong advocate to have support for this operating system restored.




-------------------------------------------------------------------
Joe Hatcher
SAS Cloud and Platform - Compute Services ▪ Product Manager
Tel: 919-531-0692 ▪ Mobile: 919-624-6149
www.sas.com<http://www.sas.com/;

SAS® … THE POWER TO KNOW®

From: Aditya Kamath <[email protected]>
Sent: Wednesday, January 28, 2026 10:20 AM
To: Srirama Kucherlapati <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: AIX support


EXTERNAL
Hi Andres,

I can explain this differently as well.

We know that include_directories property in meson will include the source and the build directory in the command. Ex: If we give “src/include” then “-Isrc/include” and “-I../src/include” are added.

>> +  # This flag is required to make sure the user spefic float.h is
>> +  # picked instead of the system float.h header file, which doesnot
>> +  # have definition like float8, etc
>> +  cflags += '-D_H_FLOAT’

>I don't understand this one - how does defining _H_FLOAT lead to a >different
>header being picked?

Below is the error message we get in AIX if we do not use '-D_H_FLOAT’
FAILED: src/backend/utils/activity/wait_event_names.a.p/wait_event_funcs.c.o
gcc -Isrc/backend/utils/activity/wait_event_names.a.p -Isrc/include/utils -I../src/include/utils -Isrc/include -I../src/include -I/opt/freeware/include -I/opt/freeware/include/libxml2 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O2 -g -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wmissing-prototypes -Wpointer-arith -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -Wdeclaration-after-statement -Wno-format-truncation -Wno-stringop-truncation -maix64 -fPIC -pthread -DBUILDING_DLL1233 -MD -MQ
./src/include/utils/float.h:28:19: error: expected ';' before 'int'
   28 | extern PGDLLIMPORT int extra_float_digits;


There is a clear missing of float.h definitions, the reason being float.h got included before "src/include/c.h”.


Kindly observe the command  "-I../src/include/utils” flag came in the front.

Now in c.h when stdio.h is called in AIX at line 65, then AIX system limits.h is called and then within that AIX system float.h is called.

But here is the catch. It won’t pick the AIX system float.h. It will pick the Postgres "src/include/utilsfloat.h”.

The reason being the compiler is designed to pick what comes first in -I flag. One proof of that is here. https://gcc.gnu.org/onlinedocs/cpp/Wrapper-Headers.html<https://protect.checkpoint.com/v2/r01/___...;

I am assuming all systems behave like this.

This is the root cause of the problem. That "-I../src/include/utils” which meson adds.

So now "src/include/utils/float.h”.is picked up first even before "src/include/c.h”.

That is why we saw the error. When we define “_H_FLOAT” we essentially force the system header to be ignored in the system limits.h where it is called and then the Postgres  "src/include/utils/float.h” takes over.

Hope this explains Andres.

There are multiple things we can do here.

One being define “_H_FLOAT”

The other being use  #include_next float.h under ifdef _AIX guard

The third we are experimenting is to have implicit_include_directories: false as per document here https://mesonbuild.com/Include-directories.html<https://protect.checkpoint.com/v2/r01/___https://...;, but that might difficult since recursive include directories exists in Postgres.


Kindly let us know if this explanation helps and what you think. Also If there is a preferred or cleaner way you know let us know.



Have a nice day ahead.



Thanks and regards,

Aditya.


From: Aditya Kamath <[email protected]<mailto:[email protected]>>
Date: Wednesday, 28 January 2026 at 3:55 PM
To: Srirama Kucherlapati <[email protected]<mailto:[email protected]>>, [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>, [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>
Cc: [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>, [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>, [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>, [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>
Subject: Re: [EXTERNAL] Re: AIX support
Hi Andrew,

Thank you for your review comments for AIX so far.

While we are working on the rest of the comments you had sent here is our explanation for using the  '-D_H_FLOAT’ flag in the source directory meson.build file.

>> +  # This flag is required to make sure the user spefic float.h is
>> +  # picked instead of the system float.h header file, which doesnot
>> +  # have definition like float8, etc
>> +  cflags += '-D_H_FLOAT’

>I don't understand this one - how does defining _H_FLOAT lead to a >different
>header being picked? Also, float8 is defined in c.h, so it hardly could >be
>influenced by a system float.h header?

>Our float.h header is only included as "utils/float.h", so it really >shouldn’t
>be confused with a system header?


So If we do not use the flag the error we get is as follows,

FAILED: src/backend/utils/activity/wait_event_names.a.p/wait_event_funcs.c.o
gcc -Isrc/backend/utils/activity/wait_event_names.a.p -Isrc/include/utils -I../src/include/utils -Isrc/include -I../src/include -I/opt/freeware/include -I/opt/freeware/include/libxml2 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O2 -g -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wmissing-prototypes -Wpointer-arith -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -Wdeclaration-after-statement -Wno-format-truncation -Wno-stringop-truncation -maix64 -fPIC -pthread -DBUILDING_DLL1233 -MD -MQ src/backend/utils/activity/wait_event_names.a.p/wait_event_funcs.c.o -MF src/backend/utils/activity/wait_event_names.a.p/wait_event_funcs.c.o.d -o src/backend/utils/activity/wait_event_names.a.p/wait_event_funcs.c.o -c ../src/backend/utils/activity/wait_event_funcs.c
In file included from /usr/include/sys/limits.h:307,
                 from /opt/freeware/lib/gcc/powerpc-ibm-aix7.3.0.0/13/include-fixed/stdio.h:589,
                 from ../src/include/c.h:65,
                 from ../src/include/postgres.h:48,
                 from ../src/backend/utils/activity/wait_event_funcs.c:15:
../src/include/utils/float.h:28:19: error: expected ';' before 'int'
   28 | extern PGDLLIMPORT int extra_float_digits;
../src/include/utils/float.h:289:37: error: unknown type name 'float4'
  289 | float4_min(const float4 val1, const float4 val2)
../src/include/utils/float.h:294:15: error: unknown type name 'float8'
  294 | static inline float8

The reason this happened is because -I../src/include/utils argument in the command included the float.h header first before the ./src/include/c.h header of postgresql which actually has the
PGDLLIMPORT, float4 and float8 definitions.

So, the header files have mismatched in the order they are processed. If we eliminate -I../src/include/utils in the command, then it will work.

But that will not happen automatically since we use include_directories() everywhere which adds both the source and the build directory includes. If we can get meson to not use
-I../src/include/ in AIX while including headers we will be able to compile.

We are currently experimenting with implicit_include_directories from the document below to see if we can remove the same
https://mesonbuild.com/Include-directories.html<https://protect.checkpoint.com/v2/r01/___https://...;.

Reason for -D_H_FLOAT

This prevents AIX libc’s float.h to be included via c.h -> stdio.h -> limits.h -> float.h. The real problem is header include order in AIX. Compiler sees src/include/utils/float.h first and then c.h. This is a problem. When this flag is set, AIX’s float.h is skipped causing system header include chain to change. AIX no longer injects float.h early which results in c.h included before utils/float.h. the way Postgres expects.

Let us know what you think.


Is there a preferred or cleaner way you know to ensure the correct include ordering like using implicit_include_directories so that utils/float.h is not included before c.h?
Have a nice day ahead.

Thanks and regards,
Aditya.



From: Srirama Kucherlapati <[email protected]<mailto:[email protected]>>
Date: Wednesday, 28 January 2026 at 9:34 AM
To: Aditya Kamath <[email protected]<mailto:[email protected]>>
Subject: FW: [EXTERNAL] Re: AIX support
FYI


Warm regards,

Sriram.



------------------------------------------

VIOS/SSP Development,

ISDL, IBM India Pvt Ltd.


From: Andres Freund <[email protected]<mailto:[email protected]>>
Date: Monday, 26 January 2026 at 21:11
To: Srirama Kucherlapati <[email protected]<mailto:[email protected]>>
Cc: Peter Eisentraut <[email protected]<mailto:[email protected]>>, [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>, Heikki Linnakangas <[email protected]<mailto:[email protected]>>, Tristan Partin <[email protected]<mailto:[email protected]>>, AIX PG user <[email protected]<mailto:[email protected]>>
Subject: [EXTERNAL] Re: AIX support
Hi,

From what I can tell the meson patch *AGAIN* is missing mkldexport.sh. Also,
you seem to reference the script as files('port/aix/mkldexport.sh'), but that
that's not a path that makes sense for our source code structure (nor where
the "complete" patch adds it).

You really need to actually start testing your patches.


Doesn't the meson patch also require the changes to src/tools/gen_export.pl?


On 2026-01-23 16:11:25 +0000, Srirama Kucherlapati wrote:
> diff --git a/meson.build b/meson.build
> index 6e7ddd74683..17ad9c6ca32 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -198,6 +198,8 @@ endif
>  # that purpose.
>  portname = host_system
>
> +dep_static_lib = declare_dependency()

Add a comment saying something like

# In some configurations we don't want to install static libraries. For those
# dep_static_lib can be set to disabler() below.


The introduction of dep_static_lib should be broken out into its own patch.



> +  # This flag is required to make sure the user spefic float.h is
> +  # picked instead of the system float.h header file, which doesnot
> +  # have definition like float8, etc
> +  cflags += '-D_H_FLOAT'

I don't understand this one - how does defining _H_FLOAT lead to a different
header being picked? Also, float8 is defined in c.h, so it hardly could be
influenced by a system float.h header?

Our float.h header is only included as "utils/float.h", so it really shouldn't
be confused with a system header?


> @@ -1765,10 +1793,49 @@ endforeach
>  # as long, char, short, or int.  Note that we intentionally do not consider
>  # any types wider than 64 bits, as allowing MAXIMUM_ALIGNOF to exceed 8
>  # would be too much of a penalty for disk and memory space.
> -alignof_double = cdata.get('ALIGNOF_DOUBLE')
> -if cc.alignment('int64_t', args: test_c_args, prefix: '#include <stdint.h>') > alignof_double
> -  error('alignment of int64_t is greater than the alignment of double')
> -endif
> +if host_system != 'aix'
> +  alignof_double = cdata.get('ALIGNOF_DOUBLE')
> +  if cc.alignment('int64_t', args: test_c_args, prefix: '#include <stdint.h>') > alignof_double
> +       error('alignment of int64_t is greater than the alignment of double')
> +  endif
> +else
> +  # The AIX 'power' alignment rules apply the natural alignment of the "first
> +  # member" if it is of a floating-point data type (or is an aggregate whose
> +  # recursively "first" member or element is such a type). The alignment
> +  # associated with these types for subsequent members use an alignment value
> +  # where the floating-point data type is considered to have 4-byte alignment.
> +  # More info
> +  # https://urldefense.proofpoint.com/v2/url?u=https-3A__gcc.gnu.org_bugzilla_show-5Fbug.cgi-3Fid-3D9955...;
> +  #
> +  # The double is aligned to 4-bytes on AIX in aggregates. But to maintain
> +  # alignement across platforms the max alignment of long should be considered.

How are these "AIX 'power' alignment rules" for float not just completely
broken?

I assume this means that 4 byte aligned floats work just fine, but have
degraded peformance?

Is there documentation about this that isn't an already fixed bug report in gcc?


Maybe I'm confused, but doesn't this power alignment rule mean that the
cc.alignment('double') will always return 8? That computation won't apply the
"subsequent member" rule, and therefore will have an alignment of 8. Which in
turn seems to make this entire change pointless?


> +  # Get the alignment values
> +  ac_cv_alignof_long    = cc.alignment('long', args: test_c_args, prefix: '#include <stdint.h>')
> +  ac_cv_alignof_double  = cc.alignment('double', args: test_c_args, prefix: '#include <stdint.h>')
> +  ac_cv_alignof_int64_t = cc.alignment('int64_t', args: test_c_args, prefix: '#include <stdint.h>')

I've previously complained about these av_cv_ variable names. This isn't
autoconf. What is this doing here?

Why do we need a platform specific alignment determination for long, int64?


> +  message('Alignment of long    : @0@'.format(ac_cv_alignof_long))
> +  message('Alignment of double  : @0@'.format(ac_cv_alignof_double))
> +  message('Alignment of int64_t : @0@'.format(ac_cv_alignof_int64_t))

These are already going to be output by cc.alignment, this is just redundant,
no?


> +  # Start with long
> +  alignof_double = ac_cv_alignof_long
> +  message('MAX ALIGN ac_cv_alignof_long')
> +
> +  # Compare with double
> +  if alignof_double < ac_cv_alignof_double
> +    alignof_double = ac_cv_alignof_double
> +    message('MAX ALIGN ac_cv_alignof_double')
> +  endif
> +
> +  # Compare with int64_t
> +  if alignof_double < ac_cv_alignof_int64_t
> +    alignof_double = ac_cv_alignof_int64_t
> +    message('MAX ALIGN ac_cv_alignof_int64_t')
> +  endif
> +endif
> +message('MAX ALIGN OF DOUBLE : @0@'.format(alignof_double))

This is a lot of output for something that's just computing a maximum of three
variables.



> diff --git a/src/backend/meson.build b/src/backend/meson.build
> index b831a541652..4838f245ab3 100644
> --- a/src/backend/meson.build
> +++ b/src/backend/meson.build
> @@ -125,6 +125,24 @@ if host_system == 'windows'
>      '--FILEDESC', 'PostgreSQL Server',])
>  endif
>
> +if host_system == 'aix'
> +  # The '.' argument leads mkldexport.sh to emit "#! .", which refers to the
> +  # main executable, allowing extension libraries to resolve their undefined
> +  # symbols to symbols in the postgres binary.
> +  postgres_imp = custom_target('postgres.imp',
> +    command: [files('port/aix/mkldexport.sh'), '@INPUT@', '.'],
> +    input: postgres_lib,
> +    output: 'postgres.imp',
> +    capture: true,
> +    install: true,
> +    install_dir: dir_lib,
> +    build_by_default: false,
> +  )
> +  backend_link_args += '-Wl,-bE:@0@'.format(postgres_imp.full_path())
> +  backend_link_depends += postgres_imp
> +endif

This should be moved next to the msvc specific block (the one about
postgres_def) and should use an elif.



Greetings,

Andres Freund


^ permalink  raw  reply  [nested|flat] 47+ messages in thread


end of thread, other threads:[~2026-03-12 12:05 UTC | newest]

Thread overview: 47+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-02-07 16:50 RE: AIX support Srirama Kucherlapati <[email protected]>
2025-03-07 14:11 ` Srirama Kucherlapati <[email protected]>
2025-03-07 16:20   ` Robert Haas <[email protected]>
2025-03-17 16:58     ` Srirama Kucherlapati <[email protected]>
2025-04-03 08:25       ` wenhui qiu <[email protected]>
2025-04-03 13:45         ` Srirama Kucherlapati <[email protected]>
2025-04-03 13:49           ` Heikki Linnakangas <[email protected]>
2025-04-04 19:31             ` Srirama Kucherlapati <[email protected]>
2025-04-04 20:44               ` Heikki Linnakangas <[email protected]>
2025-04-05 18:29                 ` Srirama Kucherlapati <[email protected]>
2025-04-07 10:04                   ` Heikki Linnakangas <[email protected]>
2025-04-12 16:41                     ` Srirama Kucherlapati <[email protected]>
2025-04-12 17:09                       ` Srirama Kucherlapati <[email protected]>
2025-04-15 16:20                       ` Srirama Kucherlapati <[email protected]>
2025-09-03 16:44                         ` Srirama Kucherlapati <[email protected]>
2025-09-11 05:20                           ` Vamshikrishna T <[email protected]>
2025-09-11 06:12                             ` Laurenz Albe <[email protected]>
2025-09-11 10:48                               ` Vamshikrishna T <[email protected]>
2025-09-15 23:44                             ` Bruce Momjian <[email protected]>
2025-09-16 15:13                               ` Srirama Kucherlapati <[email protected]>
2025-09-18 06:21                                 ` Vamshikrishna T <[email protected]>
2025-09-20 15:20                           ` Alvaro Herrera <[email protected]>
2025-09-22 11:09                             ` AIX PG user <[email protected]>
2025-09-22 12:27                               ` Andres Freund <[email protected]>
2025-09-23 14:26                                 ` AIX PG user <[email protected]>
2025-09-23 14:36                                   ` Andres Freund <[email protected]>
2025-09-23 15:28                                     ` Srirama Kucherlapati <[email protected]>
2025-10-15 15:58                                       ` Srirama Kucherlapati <[email protected]>
2025-10-15 18:15                                         ` Peter Eisentraut <[email protected]>
2025-10-16 15:28                                           ` AIX PG user <[email protected]>
2025-10-22 03:52                                             ` AIX PG user <[email protected]>
2025-10-31 17:33                                             ` Heikki Linnakangas <[email protected]>
2025-11-03 14:46                                               ` AIX PG user <[email protected]>
2025-11-07 16:28                                         ` Peter Eisentraut <[email protected]>
2025-11-10 17:00                                           ` AIX PG user <[email protected]>
2025-12-09 16:50                                             ` Srirama Kucherlapati <[email protected]>
2025-12-09 21:00                                               ` Heikki Linnakangas <[email protected]>
2025-12-09 21:08                                               ` Peter Eisentraut <[email protected]>
2025-12-19 15:34                                                 ` Srirama Kucherlapati <[email protected]>
2025-12-21 08:19                                                   ` Tristan Partin <[email protected]>
2025-12-24 15:34                                                     ` Srirama Kucherlapati <[email protected]>
2026-03-12 12:05                                                       ` Joe Hatcher <[email protected]>
2025-12-09 21:56                                               ` Tristan Partin <[email protected]>
2025-12-10 14:31                                                 ` Srirama Kucherlapati <[email protected]>
2025-12-10 18:37                                                   ` Tristan Partin <[email protected]>
2025-04-25 01:31                     ` Thomas Munro <[email protected]>
2025-04-03 13:54           ` Andres Freund <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox