Skip to content

Commit

Permalink
Merge pull request omniosorg#1522 from mvwieringen/mvw/pg17
Browse files Browse the repository at this point in the history
Add postgresql 17
  • Loading branch information
oetiker authored Oct 17, 2024
2 parents 6cab528 + 108d813 commit 6dcaf68
Show file tree
Hide file tree
Showing 9 changed files with 345 additions and 7 deletions.
6 changes: 2 additions & 4 deletions build/meta/extra-build-tools.p5m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ depend fmri=ooce/library/postgresql-12 type=require
depend fmri=ooce/library/postgresql-13 type=require
depend fmri=ooce/library/postgresql-14 type=require
depend fmri=ooce/library/postgresql-15 type=require
depend fmri=ooce/library/postgresql-16 type=require
depend fmri=ooce/library/postgresql-17 type=require
depend fmri=ooce/library/security/libsasl2 type=require
depend fmri=ooce/library/serf type=require
depend fmri=ooce/library/slang type=require
Expand Down Expand Up @@ -100,10 +102,6 @@ depend fmri=ooce/x11/library/libxcb type=require
depend fmri=ooce/developer/llvm-15 type=conditional \
predicate=release/[email protected]

# Added postgresql 16 from r151044 onwards
depend fmri=ooce/library/postgresql-16 type=conditional \
predicate=release/[email protected]

# clang 15 is the default clang compiler from r151045 onwards
depend fmri=ooce/developer/clang-15 type=conditional \
predicate=release/[email protected]
Expand Down
5 changes: 2 additions & 3 deletions build/pg_extension/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
# http://www.illumos.org/license/CDDL.
# }}}

# Copyright 2023 OmniOS Community Edition (OmniOSce) Association.
# Copyright 2024 OmniOS Community Edition (OmniOSce) Association.

PGVERSIONS="13 14 15"
test_relver '>=' 151044 && PGVERSIONS+=" 16"
PGVERSIONS="13 14 15 16 17"

for v in $PGVERSIONS; do
BUILD_DEPENDS_IPS+=" ooce/library/postgresql-$v"
Expand Down
190 changes: 190 additions & 0 deletions build/postgresql/build-17.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
#!/usr/bin/bash
#
# {{{ CDDL HEADER
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
# }}}

# Copyright 2016 OmniTI Computer Consulting, Inc. All rights reserved.
# Copyright 2024 OmniOS Community Edition (OmniOSce) Association.

. ../../lib/build.sh

PROG=postgresql
PKG=ooce/database/postgresql-17
VER=17.0
SUMMARY="PostgreSQL 17"
DESC="The World's Most Advanced Open Source Relational Database"

SKIP_LICENCES=postgresql

# The icu4c ABI changes frequently. Lock the version
# pulled into each build of postgres.
ICUVER=`pkg_ver icu4c`
ICUVER=${ICUVER%%.*}
BUILD_DEPENDS_IPS="=ooce/library/icu4c@$ICUVER"

# We want to populate the clang-related environment variables
# and set PATH to point to the correct llvm/clang version for
# the postgres JIT code, but we want to build with gcc.
set_clangver
BASEPATH=$PATH set_gccver $DEFAULT_GCC_VER

MAJVER=${VER%.*} # M.m
sMAJVER=${MAJVER//./} # Mm
set_patchdir patches-$sMAJVER

OPREFIX=$PREFIX
PREFIX+=/pgsql-$MAJVER
CONFPATH=/etc$PREFIX
LOGPATH=/var/log$PREFIX
VARPATH=/var$PREFIX
RUNPATH=$VARPATH/run

reset_configure_opts

SKIP_RTIME_CHECK=1
SKIP_SSP_CHECK=1
NO_SONAME_EXPECTED=1

XFORM_ARGS="
-DPREFIX=${PREFIX#/}
-DOPREFIX=${OPREFIX#/}
-DPROG=$PROG
-DPKGROOT=pgsql-$MAJVER
-DMEDIATOR=$PROG -DMEDIATOR_VERSION=$MAJVER
-DVERSION=$MAJVER
-DsVERSION=$sMAJVER
"

CFLAGS+=" -O3"
CPPFLAGS+=" -DWAIT_USE_POLL -DOOCEVER=$RELVER"
# postgresql has large enumerations
CTF_FLAGS+=" -s"

CONFIGURE_OPTS="
--prefix=$PREFIX
--sysconfdir=$CONFPATH
--localstatedir=$VARPATH
--enable-thread-safety
--with-pam
--with-ssl=openssl
--with-lz4
--with-zstd
--with-libxml
--with-libxslt
--with-readline
--without-systemd
--with-system-tzdata=/usr/share/lib/zoneinfo
"

CONFIGURE_OPTS[amd64_WS]+="
--bindir=$PREFIX/bin
--with-llvm LLVM_CONFIG=\"$CLANGPATH/bin/llvm-config --link-static\"
--enable-dtrace DTRACEFLAGS=-64
"
CONFIGURE_OPTS[aarch64]+="
--disable-dtrace
"

# need to build world
MAKE_TARGET=world-bin
MAKE_INSTALL_TARGET=install-world-bin

pre_configure() {
typeset arch=$1

LDFLAGS[$arch]+=" -Wl,-R$OPREFIX/${LIBDIRS[$arch]}"
}

install_man() {
logmsg "Fetching and installing pre-built man pages"

download_source $PROG $PROG $VER-docs $TMPDIR/manpages

for s in 1 3 5; do
logcmd $MKDIR -p "$DESTDIR/$PREFIX/share/man/man$s" \
|| logerr "mkdir failed"
done

pushd $TMPDIR/manpages/$PROG-$VER/doc/src/sgml >/dev/null

logmsg "Renaming man section"

for s in 1 3; do
for f in man$s/*.$s; do $SED -e '/^\.TH/s/"7"/"5"/' \
-e 's/\\fR(7)/\\fR(5sql)/g' \
-e '1s/^\.so man7/.so man5/g;1s/^\(\.so.*\)\.7$/\1.5sql/g' \
$f >| $DESTDIR/$PREFIX/share/man/man$s/`basename $f` \
|| logerr "failed to rename man section for $f"
done
done
for f in man7/*.7; do $SED -e '/^\.TH/s/"7"/"5"/' \
-e 's/\\fR(7)/\\fR(5sql)/g' \
-e '1s/^\.so man7/.so man5/g;1s/^\(\.so.*\)\.7$/\1.5sql/g' \
$f >| $DESTDIR/$PREFIX/share/man/man5/`basename $f \
| $SED s/\.7$/.5sql/` || logerr "failed to rename man section for $f"
done

popd >/dev/null
}

post_install() {
typeset arch=$1

[ $arch = i386 ] && return

# Make ISA binaries for pg_config, to allow software to find the
# right settings for 32/64-bit when pkg-config is not used.
if [ $arch = amd64 ]; then
pushd $DESTDIR$PREFIX/bin >/dev/null
logcmd mkdir -p amd64
logcmd mv pg_config amd64/ || logerr "mv pg_config"
make_isaexec_stub_arch amd64 $PREFIX/bin
popd >/dev/null
fi

install_man

xform $SRCDIR/files/postgres.xml > $TMPDIR/$PROG-$sMAJVER.xml
install_smf ooce $PROG-$sMAJVER.xml

manifest_start $TMPDIR/manifest.client
manifest_add_dir $PREFIX/include '.*'
manifest_add_dir $PREFIX/lib/pkgconfig
manifest_add_dir $PREFIX/lib/amd64/pkgconfig
manifest_add_dir $PREFIX/lib/pgxs '.*'
manifest_add_dir $PREFIX/lib/amd64/pgxs '.*'
manifest_add $PREFIX/lib '.*lib(pq\.|ecpg|pgtypes|pgcommon|pgport).*'
manifest_add $PREFIX/bin '.*pg_config' psql ecpg
manifest_add $PREFIX/share/man/man1 pg_config.1 psql.1 ecpg.1
manifest_add $PREFIX/share psqlrc.sample
manifest_finalise $TMPDIR/manifest.client $OPREFIX

manifest_uniq $TMPDIR/manifest.{server,client}
manifest_finalise $TMPDIR/manifest.server $OPREFIX etc
}

init
download_source $PROG $PROG $VER
patch_source
prep_build
build
#run_testsuite check-world-bin
PKG=${PKG/database/library} SUMMARY+=" client and libraries" \
make_package -seed $TMPDIR/manifest.client
[ "$FLAVOR" != libsandheaders ] \
&& RUN_DEPENDS_IPS="ooce/database/postgresql-common \
=ooce/library/icu4c@$ICUVER" \
make_package -seed $TMPDIR/manifest.server server.mog
clean_up

# Vim hints
# vim:ts=4:sw=4:et:fdm=marker
93 changes: 93 additions & 0 deletions build/postgresql/patches-17/dism.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
On Solaris we want to use DISM or ISM e.g. Dynamic Intimate Shared Memory or Intimate Shared Memory
which is available via sysv SHM only. This patch changes the default shared memory system to be sysv
on Solaris based systems e.g. which have SHM_SHARE_MMU (which translates to ISM) and when SHM_PAGEABLE
is defined in sys/shm.h we set the default PG_SHMAT_FLAGS to SHM_PAGEABLE which will lead to DISM being
used. The patch to the postgresql.conf.sample is to show that sysv is the default for Solaris and the
ordering is changed as by default it used to be mmap and posix for the defaults and you could always
override things using the sysv setting.
--
diff -wpruN --no-dereference '--exclude=*.orig' a~/src/backend/utils/misc/postgresql.conf.sample a/src/backend/utils/misc/postgresql.conf.sample
--- a~/src/backend/utils/misc/postgresql.conf.sample 1970-01-01 00:00:00
+++ a/src/backend/utils/misc/postgresql.conf.sample 1970-01-01 00:00:00
@@ -143,16 +143,15 @@
#autovacuum_work_mem = -1 # min 64kB, or -1 to use maintenance_work_mem
#logical_decoding_work_mem = 64MB # min 64kB
#max_stack_depth = 2MB # min 100kB
-#shared_memory_type = mmap # the default is the first option
+#shared_memory_type = sysv # the default is the first option
# supported by the operating system:
- # mmap
# sysv
# windows
# (change requires restart)
-#dynamic_shared_memory_type = posix # the default is usually the first option
+#dynamic_shared_memory_type = sysv # the default is usually the first option
# supported by the operating system:
- # posix
# sysv
+ # posix
# windows
# mmap
# (change requires restart)
diff -wpruN --no-dereference '--exclude=*.orig' a~/src/include/portability/mem.h a/src/include/portability/mem.h
--- a~/src/include/portability/mem.h 1970-01-01 00:00:00
+++ a/src/include/portability/mem.h 1970-01-01 00:00:00
@@ -14,11 +14,15 @@

#define IPCProtection (0600) /* access/modify by user only */

+#ifdef SHM_PAGEABLE /* use dynamic intimate shared memory on Solaris */
+#define PG_SHMAT_FLAGS SHM_PAGEABLE
+#else
#ifdef SHM_SHARE_MMU /* use intimate shared memory on Solaris */
#define PG_SHMAT_FLAGS SHM_SHARE_MMU
#else
#define PG_SHMAT_FLAGS 0
#endif
+#endif

/* Linux prefers MAP_ANONYMOUS, but the flag is called MAP_ANON on other systems. */
#ifndef MAP_ANONYMOUS
diff -wpruN --no-dereference '--exclude=*.orig' a~/src/include/storage/dsm_impl.h a/src/include/storage/dsm_impl.h
--- a~/src/include/storage/dsm_impl.h 1970-01-01 00:00:00
+++ a/src/include/storage/dsm_impl.h 1970-01-01 00:00:00
@@ -19,6 +19,13 @@
#define DSM_IMPL_WINDOWS 3
#define DSM_IMPL_MMAP 4

+#ifdef HAVE_SYS_SHM_H
+/*
+ * For SHM_SHARE_MMU.
+ */
+#include <sys/shm.h>
+#endif
+
/*
* Determine which dynamic shared memory implementations will be supported
* on this platform, and which one will be the default.
@@ -34,6 +41,11 @@
#define USE_DSM_SYSV
#ifndef DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE
#define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_SYSV
+#else
+#ifdef SHM_SHARE_MMU
+#undef DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE
+#define DEFAULT_DYNAMIC_SHARED_MEMORY_TYPE DSM_IMPL_SYSV
+#endif
#endif
#define USE_DSM_MMAP
#endif
diff -wpruN --no-dereference '--exclude=*.orig' a~/src/include/storage/pg_shmem.h a/src/include/storage/pg_shmem.h
--- a~/src/include/storage/pg_shmem.h 1970-01-01 00:00:00
+++ a/src/include/storage/pg_shmem.h 1970-01-01 00:00:00
@@ -71,7 +71,9 @@ extern PGDLLIMPORT void *ShmemProtective
#endif
extern PGDLLIMPORT void *UsedShmemSegAddr;

-#if !defined(WIN32) && !defined(EXEC_BACKEND)
+#if defined(SHM_SHARE_MMU)
+#define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_SYSV
+#elif !defined(WIN32) && !defined(EXEC_BACKEND)
#define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_MMAP
#elif !defined(WIN32)
#define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_SYSV
30 changes: 30 additions & 0 deletions build/postgresql/patches-17/pam-illumos.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
see: https://www.illumos.org/issues/15657
struct pam_message in struct pam_conv is not const in illumos before r151051

diff -wpruN --no-dereference '--exclude=*.orig' a~/src/backend/libpq/auth.c a/src/backend/libpq/auth.c
--- a~/src/backend/libpq/auth.c 1970-01-01 00:00:00
+++ a/src/backend/libpq/auth.c 1970-01-01 00:00:00
@@ -96,7 +96,11 @@ static int auth_peer(hbaPort *port);
#define PGSQL_PAM_SERVICE "postgresql" /* Service name passed to PAM */

static int CheckPAMAuth(Port *port, const char *user, const char *password);
+#if OOCEVER >= 151051
static int pam_passwd_conv_proc(int num_msg, const struct pam_message **msg,
+#else
+static int pam_passwd_conv_proc(int num_msg, struct pam_message **msg,
+#endif
struct pam_response **resp, void *appdata_ptr);

static struct pam_conv pam_passw_conv = {
@@ -1910,7 +1914,11 @@ auth_peer(hbaPort *port)
*/

static int
+#if OOCEVER >= 151051
pam_passwd_conv_proc(int num_msg, const struct pam_message **msg,
+#else
+pam_passwd_conv_proc(int num_msg, struct pam_message **msg,
+#endif
struct pam_response **resp, void *appdata_ptr)
{
const char *passwd;
19 changes: 19 additions & 0 deletions build/postgresql/patches-17/perl_plpgsql.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff -wpruN --no-dereference '--exclude=*.orig' a~/src/pl/plpgsql/src/pl_exec.c a/src/pl/plpgsql/src/pl_exec.c
--- a~/src/pl/plpgsql/src/pl_exec.c 1970-01-01 00:00:00
+++ a/src/pl/plpgsql/src/pl_exec.c 1970-01-01 00:00:00
@@ -8381,6 +8381,15 @@ exec_set_found(PLpgSQL_execstate *estate
PLpgSQL_var *var;

var = (PLpgSQL_var *) (estate->datums[estate->found_varno]);
+
+ /*
+ * Prevent spurious warning due to compiler not realizing
+ * VARATT_IS_EXTERNAL_NON_EXPANDED() branch in assign_simple_var() isn't
+ * reachable due to "found" being byvalue.
+ */
+ if (var->datatype->typlen != 1)
+ pg_unreachable();
+
assign_simple_var(estate, var, BoolGetDatum(state), false, false);
}

3 changes: 3 additions & 0 deletions build/postgresql/patches-17/series
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dism.patch
pam-illumos.patch
perl_plpgsql.patch
5 changes: 5 additions & 0 deletions doc/baseline
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ extra.omnios ooce/database/postgresql-16
extra.omnios ooce/database/postgresql-16/citus
extra.omnios ooce/database/postgresql-16/mysql_fdw
extra.omnios ooce/database/postgresql-16/pg_repack
extra.omnios ooce/database/postgresql-17
extra.omnios ooce/database/postgresql-17/citus
extra.omnios ooce/database/postgresql-17/mysql_fdw
extra.omnios ooce/database/postgresql-17/pg_repack
extra.omnios ooce/database/postgresql-common
extra.omnios ooce/database/rrdtool
extra.omnios ooce/database/victoriametrics
Expand Down Expand Up @@ -177,6 +181,7 @@ extra.omnios ooce/library/postgresql-13
extra.omnios ooce/library/postgresql-14
extra.omnios ooce/library/postgresql-15
extra.omnios ooce/library/postgresql-16
extra.omnios ooce/library/postgresql-17
extra.omnios ooce/library/security/libsasl2
extra.omnios ooce/library/serf
extra.omnios ooce/library/slang
Expand Down
1 change: 1 addition & 0 deletions doc/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
| ooce/database/postgresql-14 | 14.13 | https://www.postgresql.org/ftp/source/ | [omniosorg](https://github.com/omniosorg)
| ooce/database/postgresql-15 | 15.8 | https://www.postgresql.org/ftp/source/ | [omniosorg](https://github.com/omniosorg)
| ooce/database/postgresql-16 | 16.4 | https://www.postgresql.org/ftp/source/ | [omniosorg](https://github.com/omniosorg)
| ooce/database/postgresql-17 | 17.0 | https://www.postgresql.org/ftp/source/ | [omniosorg](https://github.com/omniosorg)
| ooce/database/postgresql-XX/citus | 12.1.0 | https://github.com/citusdata/citus/releases | [omniosorg](https://github.com/omniosorg)
| ooce/database/postgresql-XX/mysql_fdw | 2.9.1 | https://github.com/EnterpriseDB/mysql_fdw/releases | [omniosorg](https://github.com/omniosorg)
| ooce/database/postgresql-XX/pg_repack | 1.5.0 | https://github.com/reorg/pg_repack/tags | [omniosorg](https://github.com/omniosorg)
Expand Down

0 comments on commit 6dcaf68

Please sign in to comment.