diff --git a/meson.build b/meson.build
index 6e7ddd74683..0c03481d721 100644
--- a/meson.build
+++ b/meson.build
@@ -198,6 +198,8 @@ endif
 # that purpose.
 portname = host_system
 
+dep_static_lib = declare_dependency()
+
 if host_system == 'cygwin'
   sema_kind = 'unnamed_posix'
   cppflags += '-D_GNU_SOURCE'
@@ -206,6 +208,32 @@ if host_system == 'cygwin'
   mod_link_with_name = 'lib@0@.a'
   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 = '@0@.imp'
+  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'
+
+  # https://mesonbuild.com/Release-notes-for-1-6-0.html
+  # According to Mesons documentation for AIX, both shared and static libraries
+  # are typically archived, and they should have distinct names if a project
+  # requires building both. However, in this case, only shared libraries are
+  # used on AIX, so we are skipping the build for static libraries.
+  dep_static_lib = disabler()
+
 elif host_system == 'darwin'
   dlsuffix = '.dylib'
   library_path_var = 'DYLD_LIBRARY_PATH'
@@ -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://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 +3533,17 @@ endif
 installed_targets = [
   backend_targets,
   bin_targets,
-  libpq_st,
   pl_targets,
   contrib_targets,
   nls_mo_targets,
   ecpg_targets,
 ]
 
+# Include the libpq only if its build. For AIX its skipped.
+if not dep_static_lib.disabled()
+  installed_targets += [libpq_st]
+endif
+
 if oauth_flow_supported
   installed_targets += [
     libpq_oauth_so,
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/interfaces/ecpg/compatlib/meson.build b/src/interfaces/ecpg/compatlib/meson.build
index 56e0a21651b..5d32636c1e3 100644
--- a/src/interfaces/ecpg/compatlib/meson.build
+++ b/src/interfaces/ecpg/compatlib/meson.build
@@ -20,11 +20,13 @@ 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],
+  dependencies: [frontend_stlib_code, thread_dep, dep_static_lib],
   link_with: [ecpglib_st, ecpg_pgtypes_st],
   kwargs: default_lib_args,
 )
-ecpg_targets += ecpg_compat_st
+if not dep_static_lib.disabled()
+  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..3c61bdeeffd 100644
--- a/src/interfaces/ecpg/ecpglib/meson.build
+++ b/src/interfaces/ecpg/ecpglib/meson.build
@@ -30,11 +30,13 @@ ecpglib_st = static_library('libecpg',
   include_directories: ecpglib_inc,
   c_args: ecpglib_c_args,
   c_pch: pch_postgres_fe_h,
-  dependencies: [frontend_stlib_code, thread_dep, libpq],
+  dependencies: [frontend_stlib_code, thread_dep, libpq, dep_static_lib],
   link_with: [ecpg_pgtypes_st],
   kwargs: default_lib_args,
 )
-ecpg_targets += ecpglib_st
+if not ecpglib_st.disabled()
+  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..b6fc20e9db6 100644
--- a/src/interfaces/ecpg/pgtypeslib/meson.build
+++ b/src/interfaces/ecpg/pgtypeslib/meson.build
@@ -26,10 +26,12 @@ ecpg_pgtypes_st = static_library('libpgtypes',
   include_directories: ecpg_pgtypes_inc,
   c_args: ecpg_pgtypes_c_args,
   c_pch: pch_postgres_fe_h,
-  dependencies: frontend_stlib_code,
+  dependencies: [frontend_stlib_code, dep_static_lib],
   kwargs: default_lib_args,
 )
-ecpg_targets += ecpg_pgtypes_st
+if not ecpg_pgtypes_st.disabled()
+  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..ea3f540f8bc 100644
--- a/src/interfaces/libpq/meson.build
+++ b/src/interfaces/libpq/meson.build
@@ -62,7 +62,7 @@ libpq_st = static_library('libpq',
   include_directories: [libpq_inc],
   c_args: libpq_c_args,
   c_pch: pch_postgres_fe_h,
-  dependencies: [frontend_stlib_code, libpq_deps],
+  dependencies: [frontend_stlib_code, libpq_deps, dep_static_lib],
   kwargs: default_lib_args,
 )
 
