backports/postgresql15: new aport

This commit is contained in:
Antoine Martin 2023-07-12 17:16:48 -04:00
parent 31a53678e1
commit 0ade28bd8d
Signed by: forge
GPG key ID: D62A472A4AA7D541
18 changed files with 3124 additions and 0 deletions

View file

@ -0,0 +1,551 @@
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
# Contributor: G.J.R. Timmer <gjr.timmer@gmail.com>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
_pkgname=postgresql
pkgver=15.3
pkgrel=1
_majorver=${pkgver%%[_.]*}
# Should this aport provide libpq* and libecpg*? true/false
# Exactly one postgresql aport must be the default one!
_default_ver=true
pkgname=$_pkgname$_majorver
pkgdesc="A sophisticated object-relational DBMS, version $_majorver"
url="https://www.postgresql.org/"
arch="all"
license="PostgreSQL"
_llvmver=13
depends="$pkgname-client postgresql-common tzdata"
depends_dev="
libpq-dev
libecpg-dev
clang
icu-dev
llvm$_llvmver
lz4-dev
openssl-dev
zstd-dev
"
checkdepends="
diffutils
icu-data-full
perl-ipc-run
"
makedepends="$depends_dev
bison
flex
libxml2-dev
linux-headers
llvm$_llvmver-dev
openldap-dev
perl-dev
python3-dev
readline-dev
tcl-dev
util-linux-dev
zlib-dev
"
pkgusers="postgres"
pkggroups="postgres"
install="$pkgname.post-install $pkgname.pre-deinstall"
provider_priority=$_majorver
provides="postgresql"
replaces="postgresql" # for backward compatibility
$_default_ver && subpackages="
libpq
libpq-dev:libpq_dev
libecpg
libecpg-dev:libecpg_dev
"
subpackages="
$subpackages
$pkgname-client
$pkgname-jit
$pkgname-contrib
$pkgname-plperl
$pkgname-plperl-contrib:plperl_contrib
$pkgname-plpython3
$pkgname-plpython3-contrib:plpython3_contrib
$pkgname-pltcl
$pkgname-contrib-jit:contrib_jit
$pkgname-dev
$pkgname-doc
$pkgname-openrc
"
source="https://ftp.postgresql.org/pub/source/v$pkgver/postgresql-$pkgver.tar.bz2
initdb.patch
perl-rpath.patch
per-version-dirs.patch
unix_socket_directories.patch
disable-html-docs.patch
remove-libecpg_compat.patch
czech-snowball-stemmer.patch
make-split-headers.patch
jit-datalayout-mismatch-on-s390x-and-x86.patch
pg_config-add-major-version.patch
dont-use-locale-a-on-musl.patch
icu-collations-hack.patch
libpgport-pkglibdir.patch.txt
external-libpq.patch.txt
pltcl_create_tables.sql
"
builddir="$srcdir/$_pkgname-$pkgver"
# FIXME: https://gitlab.alpinelinux.org/alpine/aports/-/issues/14359
options="net !check"
# secfixes:
# 15.3-r0:
# - CVE-2023-2454
# - CVE-2023-2455
# 15.2-r0:
# - CVE-2022-41862
# 14.5-r0:
# - CVE-2022-2625
# 14.3-r0:
# - CVE-2022-1552
# 14.1-r0:
# - CVE-2021-23214
# - CVE-2021-23222
# 13.4-r0:
# - CVE-2021-3677
# 13.3-r0:
# - CVE-2021-32027
# - CVE-2021-32028
# - CVE-2021-32029
# 13.2-r0:
# - CVE-2021-3393
# - CVE-2021-20229
# 12.5-r0:
# - CVE-2020-25694
# - CVE-2020-25695
# - CVE-2020-25696
# 12.4-r0:
# - CVE-2020-14349
# - CVE-2020-14350
# 12.2-r0:
# - CVE-2020-1720
# 11.5-r0:
# - CVE-2019-10208
# - CVE-2019-10209
# 11.4-r0:
# - CVE-2019-10164
# 11.3-r0:
# - CVE-2019-10129
# - CVE-2019-10130
# 11.1-r0:
# - CVE-2018-16850
# 10.5-r0:
# - CVE-2018-10915
# - CVE-2018-10925
# 10.4-r0:
# - CVE-2018-1115
# 10.3-r0:
# - CVE-2018-1058
# 10.2-r0:
# - CVE-2018-1052
# - CVE-2018-1053
# 10.1-r0:
# - CVE-2017-15098
# - CVE-2017-15099
# 9.6.4-r0:
# - CVE-2017-7546
# - CVE-2017-7547
# - CVE-2017-7548
# 9.6.3-r0:
# - CVE-2017-7484
# - CVE-2017-7485
# - CVE-2017-7486
_bindir=usr/libexec/$pkgname
_datadir=usr/share/$pkgname
_docdir=usr/share/doc/$pkgname
_mandir=$_datadir/man
_includedir=usr/include/postgresql
# Directory for server-related libraries. This is hard-coded in
# per-version-dirs.patch.
_srvlibdir=usr/lib/$pkgname
# Programs to be included in the -client subpackage.
# TODO: This was probably originally copied from Debian and I have no idea
# why these are considered as front-end (client) programs and the rest of
# the programs are not. So it should be reviewed.
_client_cmds="
clusterdb
createdb
createuser
dropdb
dropuser
pg_amcheck
pg_basebackup
pg_dump
pg_dumpall
pg_isready
pg_receivewal
pg_recvlogical
pg_restore
pg_verifybackup
pgbench
psql
reindexdb
vacuumdb
"
prepare() {
default_prepare
if $_default_ver; then
cp -rl "$builddir" "$builddir-ifaces"
else
msg 'external-libpq.patch'
patch -p1 < "$srcdir"/external-libpq.patch.txt
fi
# Note: This must be applied after clonning $builddir-ifaces.
patch -p1 < "$srcdir"/libpgport-pkglibdir.patch.txt
}
build() {
export LLVM_CONFIG="/usr/lib/llvm$_llvmver/bin/llvm-config"
export PYTHON=/usr/bin/python3
export CFLAGS="${CFLAGS/-Os/-O2}"
export CPPFLAGS="${CPPFLAGS/-Os/-O2}"
# older clang versions don't have a 'clang' exe anymore.
export CLANG=clang-$_llvmver
_configure --with-ldap
make world
if $_default_ver; then
cd "$builddir-ifaces"
_configure --without-ldap
local dir; for dir in include common port interfaces bin/pg_config; do
make -C src/$dir
done
fi
}
_configure() {
local _extra_opts
# When disable-spinlocks is no longer required - check postgresql-bdr package.
case "$CARCH" in
riscv64) _extra_opts='--disable-spinlocks';;
esac
want_check && _extra_opts="$_extra_opts --enable-tap-tests"
./configure \
--build=$CBUILD \
--host=$CHOST \
--prefix=/usr \
--bindir=/$_bindir \
--datarootdir=/usr/share \
--datadir=/$_datadir \
--docdir=/$_docdir \
--includedir=/$_includedir \
--libdir=/usr/lib \
--mandir=/$_mandir \
--sysconfdir=/etc/postgresql \
--disable-rpath \
--with-system-tzdata=/usr/share/zoneinfo \
--with-libxml \
--with-openssl \
--with-uuid=e2fs \
--with-llvm \
--with-icu \
--with-perl \
--with-python \
--with-tcl \
--with-lz4 \
--with-zstd \
$_extra_opts \
"$@"
}
check() {
_run_tests src/test
_run_tests src/pl
_run_tests contrib
}
package() {
make DESTDIR="$pkgdir" install install-docs
if $_default_ver; then
cd "$builddir-ifaces"
# Override libpq and libecpg files with the build without LDAP support.
local dir; for dir in common port interfaces bin/pg_config; do
make -C src/$dir DESTDIR="$pkgdir" bindir=/usr/bin install
done
make -C src/include DESTDIR="$pkgdir" install-interfaces
fi
cd "$pkgdir"
# Duplicate of usr/bin/ecpg.
rm -f ./$_bindir/ecpg
mkdir -p ./usr/bin
ln -s /$_bindir/postgres ./usr/bin/postgres$_majorver
# This file is used by pg_versions and init script.
echo "$_majorver" > ./$_bindir/PG_VERSION
install -d -m750 -o postgres -g postgres \
./etc/postgresql$_majorver \
./var/lib/postgresql \
./var/log/postgresql
local server_cmds=$(_setdiff "$(ls -1 $_bindir)" "$_client_cmds pg_config ecpg PG_VERSION")
[ "$server_cmds" ] || die 'package: variable server_cmds is empty'
# These commands are symlinked to /usr/bin by pg_versions script after
# installation.
provides="$provides $(echo "$server_cmds" | sed 's/^/cmd:&/')"
}
libpq() {
pkgdesc="PostgreSQL client library"
depends=""
replaces=""
amove usr/lib/libpq.so.*
}
libpq_dev() {
pkgdesc="PostgreSQL client library (development files)"
depends=""
replaces=""
amove usr/bin/pg_config
amove $_includedir/internal/*
amove $_includedir/libpq-*.h
amove $_includedir/libpq/*
amove $_includedir/pg_config*.h
amove $_includedir/postgres_ext.h
amove usr/lib/libpq.*
amove usr/lib/libpgcommon*.a
amove usr/lib/libpgport*.a
amove usr/lib/pkgconfig/libpq.pc
}
libecpg() {
pkgdesc="ECPG - Embedded SQL in C"
depends=""
provides="postgresql-libs" # for backward compatibility (Alpine <3.15)
replaces="$provides" # for backward compatibility (Alpine <3.15)
amove usr/lib/libecpg.so.*
amove usr/lib/libpgtypes.so.*
}
libecpg_dev() {
pkgdesc="ECPG - Embedded SQL in C (development files)"
depends="libpq-dev=$pkgver-r$pkgrel"
replaces=""
amove usr/bin/ecpg
amove $_includedir/ecpg*.h
amove $_includedir/informix/*
amove $_includedir/pgtypes*.h
amove $_includedir/sql3types.h
amove $_includedir/sqlca.h
amove $_includedir/sqlda*.h
amove usr/lib/libecpg.*
amove usr/lib/libpgtypes.*
amove usr/lib/pkgconfig/libecpg.pc
amove usr/lib/pkgconfig/libpgtypes.pc
}
client() {
pkgdesc="PostgreSQL client"
depends="postgresql-common"
_subpkg_common
local cmd; for cmd in $_client_cmds; do
amove $_bindir/$cmd
# These commands are symlinked to /usr/bin by pg_versions script after
# installation.
provides="$provides cmd:$cmd"
done
amove $_bindir/PG_VERSION
}
jit() {
pkgdesc="Just-in-time compilation support for PostgreSQL"
depends="$pkgname=$pkgver-r$pkgrel"
_subpkg_common
amove $_srvlibdir/bitcode/*
amove $_srvlibdir/llvmjit.so
amove $_srvlibdir/llvmjit_types.bc
}
contrib() {
pkgdesc="Extension modules distributed with PostgreSQL"
depends="$pkgname=$pkgver-r$pkgrel"
_subpkg_common
cd "$builddir"
# Avoid installing plperl and plpython extensions, these will be
# installed into separate subpackages.
sed -Ei -e 's/(.*_plperl)/#\1/' \
-e 's/(.*_plpython)/#\1/' \
contrib/Makefile
make -C contrib DESTDIR="$subpkgdir" install
_contrib_common
provides="$provides $(ls -1 "$subpkgdir"/$_bindir | sed 's/^/cmd:&/')"
}
pltcl() {
pkgdesc="PL/Tcl procedural language for PostgreSQL"
depends="$pkgname=$pkgver-r$pkgrel pgtcl"
_subpkg_common
amove $_srvlibdir/pltcl.so
amove $_datadir/extension/pltcl*
install -m 644 "$srcdir"/pltcl_create_tables.sql -t "$subpkgdir"/$_datadir/
}
plperl() {
pkgdesc="PL/Perl procedural language for PostgreSQL"
depends="$pkgname=$pkgver-r$pkgrel"
_subpkg_common
amove $_srvlibdir/plperl.so
amove $_datadir/extension/plperl*
}
plperl_contrib() {
_plcontrib plperl "PL/Perl"
cd "$builddir"
make -C contrib/hstore_plperl DESTDIR="$subpkgdir" install
_contrib_common
}
plpython3() {
pkgdesc="PL/Python3 procedural language for PostgreSQL"
depends="$pkgname=$pkgver-r$pkgrel python3"
_subpkg_common
amove $_srvlibdir/plpython3.so
amove $_datadir/extension/plpython*
}
plpython3_contrib() {
_plcontrib plpython3 "PL/Python 3"
cd "$builddir"
make -C contrib/hstore_plpython DESTDIR="$subpkgdir" install
make -C contrib/ltree_plpython DESTDIR="$subpkgdir" install
_contrib_common
}
contrib_jit() {
pkgdesc="Extension modules distributed with PostgreSQL (JIT support)"
depends="$pkgname-contrib=$pkgver-r$pkgrel"
install_if="$pkgname-jit $pkgname-contrib=$pkgver-r$pkgrel"
_subpkg_common
amove $_srvlibdir/bitcode/*
}
dev() {
default_dev
_subpkg_common
replaces=""
amove $_srvlibdir/pgxs/*
}
doc() {
default_doc
_subpkg_common
amove $_mandir
}
openrc() {
default_openrc
depends="postgresql-common-openrc"
mkdir -p "$subpkgdir"
}
_plcontrib() {
local subname="$1"
pkgdesc="$2 extension modules distributed with PostgreSQL"
depends="$pkgname-$subname=$pkgver-r$pkgrel"
install_if="$pkgname-$subname=$pkgver-r$pkgrel $pkgname-contrib=$pkgver-r$pkgrel"
_subpkg_common
}
_subpkg_common() {
provides="postgresql${subpkgname#$pkgname}"
replaces="$provides" # for backward compatibility
}
_contrib_common() {
# Move headers, bitcode and docs from subpackage back to pkgdir, so it
# can be catched by subsequent split functions.
local dir; for dir in $_includedir $_srvlibdir/bitcode $_docdir; do
[ -d "$subpkgdir"/$dir ] || continue
mkdir -p "$pkgdir"/$dir
cp -rf "$subpkgdir"/$dir/* "$pkgdir"/$dir/
rm -rf "$subpkgdir"/$dir/*
rmdir -p "$subpkgdir"/$dir || true
done
}
_run_tests() {
local path="$1"; shift
msg "Running test suite at $path..."
# Note: some tests fail when running in parallel.
make -k -j 1 -C "$path" "$@" check MAX_CONNECTIONS=5 || {
printf "\n%s\n\n" "Trying to find all regression.diffs files in build directory..." >&2
find "$path" -name regression.diffs | while read -r file; do
echo "=== test failure: $file ===" >&2
cat "$file" >&2
done
return 1
}
}
# $1: whitespace-separated items of set A
# $2: whitespace-separated items of set B
# stdout: newline-separated items of A - B
_setdiff() {
python3 -c 'import sys;print("\n".join(set(sys.argv[1].split()).difference(set(sys.argv[2].split()))))' "$@"
}
sha512sums="
cac97edeb40df1e8f2162f401b465751132929d7249495ef001e950645a2db46343bd732e7bd6504a7f795e25aea66724f2f4ab0065e3d9331b36db4b3a3bec6 postgresql-15.3.tar.bz2
73080f61ae274a214966d2d010de49c8c90eb3180e4f56d86a9e23063eaddbe7f8d2c40ed414591c16bc9cfe88577866af2a965c2b6effb54965d19ef96a3fa9 initdb.patch
27e00b58fe5c3899c66fc0dde51846c14701bcfedd132b106d676783ba603e8cbdc6e620f29b52dc892bdaa9302052788cf5e575a1659f61c017a12e0d2ee4d0 perl-rpath.patch
413e979745f81a5b95b7ad9ea44452217d095e3ee6b4a82b636a7b3c89093fefbe7b8d210e4f6bfdab1d6f81309133719e90b7eab93ba60ef2bb78308c52b3b9 per-version-dirs.patch
d0040599d7646b709af4e3413bf0c228090f256395e806f3fee230ccc6037ed9c0df1cd160d01b6a73b25a742fdd3fb070733a14a78f53d297fbdbbb44f6f878 unix_socket_directories.patch
2e33e1ae38d60e0daf3ed18e6eaa9ddf6762b4b1bb7e51f1d2690e3df9d602aa1a700e603ba3ee69314a75a963131c7dc67c1b1f8b7eb5564e9c4253e81a4db4 disable-html-docs.patch
d8eb4274a54b94bed4a2ded7ae775c5a95ca0f051b831b859ccf78bf6d2ea6fe89a9a0611771f6ad85573995a7e3af1fdf5859e20cae3267a52239f12e1b61c3 remove-libecpg_compat.patch
673707b331cd09c105d18f39e83ec39371886d5d8cf706b6ebbd30ace294fa3377c391bea1ab409c001644c90ac718e3250cbc4acd9224bc0e7ac1f86c832424 czech-snowball-stemmer.patch
5262f4944844bccc839c4441570b9eb2e0792390234ebfdb8ebb7b83380ce5f5de84b038cb03045526da202a185af9c3972c2ae1b9e0e743a95c6e84f4621cf9 make-split-headers.patch
c24986becfd73546a062612335e53b4da34829e42a0c30e85ed7481924f13b1fd0a0e5079d680905a52afea1e99f2210cc3692c529a34a74cd6961c88cce9163 jit-datalayout-mismatch-on-s390x-and-x86.patch
7790e4e4374f7bdc6b4484ba87a5fa709d30d3cbdce61ee7bf9c5dfce40cb51c7bd54ab42f4050fb48eede08ef573624d819128e57cc8c976e01202854740308 pg_config-add-major-version.patch
b0688d66fdd7d612c24d9aa69bdd80d30787d2d6409b4524c79b41797144fc743213460e6de9c536bfb72da089f92cf89731f15137b1407fd04ca97fd393bfd2 dont-use-locale-a-on-musl.patch
a98e5ecdd421f68f11b55bf07bf60280cf80508f89c5d21a084c7e7aa3be0a22c88b8e2ce611a13dd5c11efdd052eb9018271b549040c30663b9fd9b7c4fc611 icu-collations-hack.patch
f8ed2b7b96fd22cd87c982151e659d82bcae10033a97f403f7847fce6daa8fc580e998cfb3813af9cb59a12f0c6bcc276397c28b1fc48321eed8c7ba5f3f92ed libpgport-pkglibdir.patch.txt
6078defb3da67e7df96665cc130d32b69eebfcaf49d92eef368ea8eea8bb311fab56064c104bc97f53da9cd925301bef696b506af33e0b66d65bc6cd41ec7499 external-libpq.patch.txt
5c9bfd9e295dcf678298bf0aa974347a7c311d6e7c2aa76a6920fcb751d01fd1ab77abbec11f3c672f927ad9deaa88e04e370c0b5cd1b60087554c474b748731 pltcl_create_tables.sql
"

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,38 @@
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Thu, 28 Oct 2021 01:27:53 +0200
Subject: [PATCH] Disable HTML docs, install only man pages
HTML docs are big and they are available only anyway.
--- a/doc/src/sgml/Makefile
+++ b/doc/src/sgml/Makefile
@@ -26,9 +26,9 @@
include $(top_builddir)/src/Makefile.global
-all: html man
+all: man
-distprep: html distprep-man
+distprep: distprep-man
ifndef DBTOEPUB
@@ -220,14 +220,14 @@
## Install
##
-install: install-html install-man
+install: install-man
installdirs:
- $(MKDIR_P) '$(DESTDIR)$(htmldir)'/html $(addprefix '$(DESTDIR)$(mandir)'/man, 1 3 $(sqlmansectnum))
+ $(MKDIR_P) $(addprefix '$(DESTDIR)$(mandir)'/man, 1 3 $(sqlmansectnum))
# If the install used a man directory shared with other applications, this will remove all files.
uninstall:
- rm -f '$(DESTDIR)$(htmldir)/html/'* $(addprefix '$(DESTDIR)$(mandir)'/man, 1/* 3/* $(sqlmansectnum)/*)
+ rm -f $(addprefix '$(DESTDIR)$(mandir)'/man, 1/* 3/* $(sqlmansectnum)/*)
## Install html

View file

@ -0,0 +1,31 @@
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Wed, 03 Aug 2022 20:40:33 +0200
Subject: [PATCH] Don't generate collations based on locale(1)
When the PostgreSQL cluster is initialized (using initdb(1)) or the
DB administrator calls `pg_import_system_collations()` directly, this
function creates COLLATIONs in the system catalog (pg_collations).
If the locale(1) command is available, this function creates COLLATIONs
based on the `locale -a` output.
The locale(1) command is normally not available on Alpine Linux, so it
does nothing and only the default and ICU-based COLLATIONs are created.
However, there's a musl-locales package that provides locale(1), but it
doesn't implement any collations. This package just provides locale
translations. So if the user happens to have locale(1) installed and they
initialize the cluster or call `pg_import_system_collations()`, they end
up with dozens of libc-based COLLATIONs in the system catalog that
actually do not work! They will all behave like "C", because musl libc
doesn't implement locales.
--- a/src/backend/commands/collationcmds.c
+++ b/src/backend/commands/collationcmds.c
@@ -401,7 +401,7 @@
/* will we use "locale -a" in pg_import_system_collations? */
-#if defined(HAVE_LOCALE_T) && !defined(WIN32)
+#if defined(HAVE_LOCALE_T) && !defined(WIN32) && defined(__GLIBC__) // XXX-Patched
#define READ_LOCALE_A_OUTPUT
#endif

View file

@ -0,0 +1,41 @@
Patch-Source: https://src.fedoraproject.org/rpms/postgresql/blob/f35/f/postgresql-external-libpq.patch
This patch is applied only when building non-default postgresql aport, i.e.
we want to link against libpq provided by the default postgresql aport.
diff --git a/src/Makefile b/src/Makefile
index bcdbd95..4bea236 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -20,7 +20,6 @@ SUBDIRS = \
backend/utils/mb/conversion_procs \
backend/snowball \
include \
- interfaces \
backend/replication/libpqwalreceiver \
backend/replication/pgoutput \
fe_utils \
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index b9d86ac..29df69f 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -549,7 +549,7 @@ endif
# How to link to libpq. (This macro may be used as-is by backend extensions.
# Client-side code should go through libpq_pgport or libpq_pgport_shlib,
# instead.)
-libpq = -L$(libpq_builddir) -lpq
+libpq = -lpq
# libpq_pgport is for use by client executables (not libraries) that use libpq.
# We force clients to pull symbols from the non-shared libraries libpgport
@@ -579,7 +579,6 @@ endif
# Commonly used submake targets
submake-libpq: | submake-generated-headers
- $(MAKE) -C $(libpq_builddir) all
submake-libpgport: | submake-generated-headers
$(MAKE) -C $(top_builddir)/src/port all
--
2.21.0

View file

@ -0,0 +1,893 @@
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Wed, 03 Aug 2022 20:40:33 +0200
Subject: [PATCH] Hack to generate usable ICU-based collations with
icu-data-en
This is a downstream patch for Alpine Linux, it should never be
upstreamed in this form!
When the PostgreSQL cluster is initialized (using initdb(1)) or the
DB administrator calls `pg_import_system_collations()` directly, this
function creates COLLATIONs in the system catalog (pg_collations).
There are two types: libc-based and ICU-based. The latter are created
based on *locales* (not collations) known to ICU, i.e. based on the ICU
data installed at the time.
collationcmds.c includes the following comment:
> We use uloc_countAvailable()/uloc_getAvailable() rather than
> ucol_countAvailable()/ucol_getAvailable(). The former returns a full
> set of language+region combinations, whereas the latter only returns
> language+region combinations if they are distinct from the language's
> base collation. So there might not be a de-DE or en-GB, which would be
> confusing.
There's a problem with this approach: locales and collations are two
different things. ICU data may include collation algorithms and data for
all or some languages, but not locales (language + country/region).
The collation data is small compared to locales. There are ~800 locales
(combinations of language, country and variants), but only 98 collations.
There's a mapping between collations and locales hidden somewhere in ICU
data.
Since full ICU data is very big (30 MiB), we have created a stripped down
variant with only English locale (package icu-data-en, 2.6 MiB). It also
includes a subset of 18 collations that cover hundreds of languages.
When the cluster is initialized or `pg_import_system_collations()` is
called directly and only icu-data-en (default) is installed, the user
ends up with only und, en and en_GB ICU-based COLLATIONs. The user can
create missing COLLATIONs manually, but this a) is not expected nor
reasonable behaviour, b) it's not easy to find out for which locales
there's a collation available for.
I couldn't find any way how to list all language+country variants for the
given collation. It can be constructed when we iterate over all locales,
but this approach is useless when we don't have the locale data
available... I should also note that the reverse lookup (locale ->
collation) is not a problem for ICU when full locale data is stripped.
So I ended up with a very ugly workaround: pre-generating a list of
collation -> locale mapping and embedding it in the collationcmds.c
source. Then we replace `uloc_countAvailable()`/`uloc_getAvailable()`
with `ucol_countAvailable()` / `ucol_getAvailable()` to iterate over
the collations instead of locales and lookup the locales in the
pre-generated list.
This data is quite stable, there's a very low risk of getting outdated in
a way that would be a problem.
`icu_coll_locales` has been generated using the following code:
#include <stdio.h>
#include <string.h>
#include <unicode/ucol.h>
// Copy-pasted from collationcmds.c.
static char *get_icu_language_tag(const char *localename) {
char buf[ULOC_FULLNAME_CAPACITY];
UErrorCode status = U_ZERO_ERROR;
uloc_toLanguageTag(localename, buf, sizeof(buf), true, &status);
if (U_FAILURE(status)) {
fprintf(stderr, "could not convert locale name \"%s\" to language tag: %s\n",
localename, u_errorName(status));
return strdup(localename);
}
return strdup(buf);
}
int main() {
UErrorCode status = U_ZERO_ERROR;
for (int i = 0; i < uloc_countAvailable(); i++) {
const char *locale = uloc_getAvailable(i);
UCollator *collator = ucol_open(locale, &status);
const char *actual_locale = ucol_getLocaleByType(collator, ULOC_ACTUAL_LOCALE, &status);
// Strip @.*
char *ptr = strchr(actual_locale, '@');
if (ptr != NULL) {
*ptr = '\0';
}
if (strcmp(actual_locale, "root") == 0) {
actual_locale = "";
}
if (strcmp(actual_locale, locale) != 0) {
printf("\"%s\", \"%s\",\n", actual_locale, get_icu_language_tag(locale));
}
ucol_close(collator);
}
return 0;
}
compiled and executed using:
gcc -o main main.c $(pkg-config --libs icu-uc icu-io) && ./main | sort | uniq
--- a/src/backend/commands/collationcmds.c
+++ b/src/backend/commands/collationcmds.c
@@ -572,6 +572,715 @@
return result;
}
+
+/*
+ * XXX-Patched: Added a static mapping: collation name (parent) to locale (children)
+ * I'm gonna burn in hell for this...
+ */
+static char* icu_coll_locales[] = {
+ "", "agq",
+ "", "agq-CM",
+ "", "ak",
+ "", "ak-GH",
+ "", "asa",
+ "", "asa-TZ",
+ "", "ast",
+ "", "ast-ES",
+ "", "bas",
+ "", "bas-CM",
+ "", "bem",
+ "", "bem-ZM",
+ "", "bez",
+ "", "bez-TZ",
+ "", "bm",
+ "", "bm-ML",
+ "", "brx",
+ "", "brx-IN",
+ "", "ca",
+ "", "ca-AD",
+ "", "ca-ES",
+ "", "ca-FR",
+ "", "ca-IT",
+ "", "ccp",
+ "", "ccp-BD",
+ "", "ccp-IN",
+ "", "ce",
+ "", "ce-RU",
+ "", "cgg",
+ "", "cgg-UG",
+ "", "ckb",
+ "", "ckb-IQ",
+ "", "ckb-IR",
+ "", "dav",
+ "", "dav-KE",
+ "", "de",
+ "", "de-AT",
+ "", "de-BE",
+ "", "de-CH",
+ "", "de-DE",
+ "", "de-IT",
+ "", "de-LI",
+ "", "de-LU",
+ "", "dje",
+ "", "dje-NE",
+ "", "doi",
+ "", "doi-IN",
+ "", "dua",
+ "", "dua-CM",
+ "", "dyo",
+ "", "dyo-SN",
+ "", "dz",
+ "", "dz-BT",
+ "", "ebu",
+ "", "ebu-KE",
+ "", "en",
+ "", "en-001",
+ "", "en-150",
+ "", "en-AE",
+ "", "en-AG",
+ "", "en-AI",
+ "", "en-AS",
+ "", "en-AT",
+ "", "en-AU",
+ "", "en-BB",
+ "", "en-BE",
+ "", "en-BI",
+ "", "en-BM",
+ "", "en-BS",
+ "", "en-BW",
+ "", "en-BZ",
+ "", "en-CA",
+ "", "en-CC",
+ "", "en-CH",
+ "", "en-CK",
+ "", "en-CM",
+ "", "en-CX",
+ "", "en-CY",
+ "", "en-DE",
+ "", "en-DG",
+ "", "en-DK",
+ "", "en-DM",
+ "", "en-ER",
+ "", "en-FI",
+ "", "en-FJ",
+ "", "en-FK",
+ "", "en-FM",
+ "", "en-GB",
+ "", "en-GD",
+ "", "en-GG",
+ "", "en-GH",
+ "", "en-GI",
+ "", "en-GM",
+ "", "en-GU",
+ "", "en-GY",
+ "", "en-HK",
+ "", "en-IE",
+ "", "en-IL",
+ "", "en-IM",
+ "", "en-IN",
+ "", "en-IO",
+ "", "en-JE",
+ "", "en-JM",
+ "", "en-KE",
+ "", "en-KI",
+ "", "en-KN",
+ "", "en-KY",
+ "", "en-LC",
+ "", "en-LR",
+ "", "en-LS",
+ "", "en-MG",
+ "", "en-MH",
+ "", "en-MO",
+ "", "en-MP",
+ "", "en-MS",
+ "", "en-MT",
+ "", "en-MU",
+ "", "en-MV",
+ "", "en-MW",
+ "", "en-MY",
+ "", "en-NA",
+ "", "en-NF",
+ "", "en-NG",
+ "", "en-NL",
+ "", "en-NR",
+ "", "en-NU",
+ "", "en-NZ",
+ "", "en-PG",
+ "", "en-PH",
+ "", "en-PK",
+ "", "en-PN",
+ "", "en-PR",
+ "", "en-PW",
+ "", "en-RW",
+ "", "en-SB",
+ "", "en-SC",
+ "", "en-SD",
+ "", "en-SE",
+ "", "en-SG",
+ "", "en-SH",
+ "", "en-SI",
+ "", "en-SL",
+ "", "en-SS",
+ "", "en-SX",
+ "", "en-SZ",
+ "", "en-TC",
+ "", "en-TK",
+ "", "en-TO",
+ "", "en-TT",
+ "", "en-TV",
+ "", "en-TZ",
+ "", "en-UG",
+ "", "en-UM",
+ "", "en-US",
+ "", "en-VC",
+ "", "en-VG",
+ "", "en-VI",
+ "", "en-VU",
+ "", "en-WS",
+ "", "en-ZA",
+ "", "en-ZM",
+ "", "en-ZW",
+ "", "eu",
+ "", "eu-ES",
+ "", "ewo",
+ "", "ewo-CM",
+ "", "ff",
+ "", "ff-Latn",
+ "", "ff-Latn-BF",
+ "", "ff-Latn-CM",
+ "", "ff-Latn-GH",
+ "", "ff-Latn-GM",
+ "", "ff-Latn-GN",
+ "", "ff-Latn-GW",
+ "", "ff-Latn-LR",
+ "", "ff-Latn-MR",
+ "", "ff-Latn-NE",
+ "", "ff-Latn-NG",
+ "", "ff-Latn-SL",
+ "", "ff-Latn-SN",
+ "", "fr",
+ "", "fr-BE",
+ "", "fr-BF",
+ "", "fr-BI",
+ "", "fr-BJ",
+ "", "fr-BL",
+ "", "fr-CD",
+ "", "fr-CF",
+ "", "fr-CG",
+ "", "fr-CH",
+ "", "fr-CI",
+ "", "fr-CM",
+ "", "fr-DJ",
+ "", "fr-DZ",
+ "", "fr-FR",
+ "", "fr-GA",
+ "", "fr-GF",
+ "", "fr-GN",
+ "", "fr-GP",
+ "", "fr-GQ",
+ "", "fr-HT",
+ "", "fr-KM",
+ "", "fr-LU",
+ "", "fr-MA",
+ "", "fr-MC",
+ "", "fr-MF",
+ "", "fr-MG",
+ "", "fr-ML",
+ "", "fr-MQ",
+ "", "fr-MR",
+ "", "fr-MU",
+ "", "fr-NC",
+ "", "fr-NE",
+ "", "fr-PF",
+ "", "fr-PM",
+ "", "fr-RE",
+ "", "fr-RW",
+ "", "fr-SC",
+ "", "fr-SN",
+ "", "fr-SY",
+ "", "fr-TD",
+ "", "fr-TG",
+ "", "fr-TN",
+ "", "fr-VU",
+ "", "fr-WF",
+ "", "fr-YT",
+ "", "fur",
+ "", "fur-IT",
+ "", "fy",
+ "", "fy-NL",
+ "", "ga",
+ "", "ga-GB",
+ "", "ga-IE",
+ "", "gd",
+ "", "gd-GB",
+ "", "gsw",
+ "", "gsw-CH",
+ "", "gsw-FR",
+ "", "gsw-LI",
+ "", "guz",
+ "", "guz-KE",
+ "", "gv",
+ "", "gv-IM",
+ "", "ia",
+ "", "ia-001",
+ "", "id",
+ "", "id-ID",
+ "", "ii",
+ "", "ii-CN",
+ "", "it",
+ "", "it-CH",
+ "", "it-IT",
+ "", "it-SM",
+ "", "it-VA",
+ "", "jgo",
+ "", "jgo-CM",
+ "", "jmc",
+ "", "jmc-TZ",
+ "", "jv",
+ "", "jv-ID",
+ "", "kab",
+ "", "kab-DZ",
+ "", "kam",
+ "", "kam-KE",
+ "", "kde",
+ "", "kde-TZ",
+ "", "kea",
+ "", "kea-CV",
+ "", "kgp",
+ "", "kgp-BR",
+ "", "khq",
+ "", "khq-ML",
+ "", "ki",
+ "", "ki-KE",
+ "", "kkj",
+ "", "kkj-CM",
+ "", "kln",
+ "", "kln-KE",
+ "", "ks",
+ "", "ks-Arab",
+ "", "ks-Arab-IN",
+ "", "ks-Deva",
+ "", "ks-Deva-IN",
+ "", "ksb",
+ "", "ksb-TZ",
+ "", "ksf",
+ "", "ksf-CM",
+ "", "ksh",
+ "", "ksh-DE",
+ "", "kw",
+ "", "kw-GB",
+ "", "lag",
+ "", "lag-TZ",
+ "", "lb",
+ "", "lb-LU",
+ "", "lg",
+ "", "lg-UG",
+ "", "lrc",
+ "", "lrc-IQ",
+ "", "lrc-IR",
+ "", "lu",
+ "", "lu-CD",
+ "", "luo",
+ "", "luo-KE",
+ "", "luy",
+ "", "luy-KE",
+ "", "mai",
+ "", "mai-IN",
+ "", "mas",
+ "", "mas-KE",
+ "", "mas-TZ",
+ "", "mer",
+ "", "mer-KE",
+ "", "mfe",
+ "", "mfe-MU",
+ "", "mg",
+ "", "mg-MG",
+ "", "mgh",
+ "", "mgh-MZ",
+ "", "mgo",
+ "", "mgo-CM",
+ "", "mi",
+ "", "mi-NZ",
+ "", "mni",
+ "", "mni-Beng",
+ "", "mni-Beng-IN",
+ "", "ms",
+ "", "ms-BN",
+ "", "ms-ID",
+ "", "ms-MY",
+ "", "ms-SG",
+ "", "mua",
+ "", "mua-CM",
+ "", "mzn",
+ "", "mzn-IR",
+ "", "naq",
+ "", "naq-NA",
+ "", "nd",
+ "", "nd-ZW",
+ "", "nl",
+ "", "nl-AW",
+ "", "nl-BE",
+ "", "nl-BQ",
+ "", "nl-CW",
+ "", "nl-NL",
+ "", "nl-SR",
+ "", "nl-SX",
+ "", "nmg",
+ "", "nmg-CM",
+ "", "nnh",
+ "", "nnh-CM",
+ "", "nus",
+ "", "nus-SS",
+ "", "nyn",
+ "", "nyn-UG",
+ "", "os",
+ "", "os-GE",
+ "", "os-RU",
+ "", "pcm",
+ "", "pcm-NG",
+ "", "pt",
+ "", "pt-AO",
+ "", "pt-BR",
+ "", "pt-CH",
+ "", "pt-CV",
+ "", "pt-GQ",
+ "", "pt-GW",
+ "", "pt-LU",
+ "", "pt-MO",
+ "", "pt-MZ",
+ "", "pt-PT",
+ "", "pt-ST",
+ "", "pt-TL",
+ "", "qu",
+ "", "qu-BO",
+ "", "qu-EC",
+ "", "qu-PE",
+ "", "rm",
+ "", "rm-CH",
+ "", "rn",
+ "", "rn-BI",
+ "", "rof",
+ "", "rof-TZ",
+ "", "rw",
+ "", "rw-RW",
+ "", "rwk",
+ "", "rwk-TZ",
+ "", "sa",
+ "", "sa-IN",
+ "", "sah",
+ "", "sah-RU",
+ "", "saq",
+ "", "saq-KE",
+ "", "sat",
+ "", "sat-Olck",
+ "", "sat-Olck-IN",
+ "", "sbp",
+ "", "sbp-TZ",
+ "", "sc",
+ "", "sc-IT",
+ "", "sd",
+ "", "sd-Arab",
+ "", "sd-Arab-PK",
+ "", "sd-Deva",
+ "", "sd-Deva-IN",
+ "", "seh",
+ "", "seh-MZ",
+ "", "ses",
+ "", "ses-ML",
+ "", "sg",
+ "", "sg-CF",
+ "", "shi",
+ "", "shi-Latn",
+ "", "shi-Latn-MA",
+ "", "shi-Tfng",
+ "", "shi-Tfng-MA",
+ "", "sn",
+ "", "sn-ZW",
+ "", "so",
+ "", "so-DJ",
+ "", "so-ET",
+ "", "so-KE",
+ "", "so-SO",
+ "", "su",
+ "", "su-Latn",
+ "", "su-Latn-ID",
+ "", "sw",
+ "", "sw-CD",
+ "", "sw-KE",
+ "", "sw-TZ",
+ "", "sw-UG",
+ "", "teo",
+ "", "teo-KE",
+ "", "teo-UG",
+ "", "tg",
+ "", "tg-TJ",
+ "", "ti",
+ "", "ti-ER",
+ "", "ti-ET",
+ "", "tt",
+ "", "tt-RU",
+ "", "twq",
+ "", "twq-NE",
+ "", "tzm",
+ "", "tzm-MA",
+ "", "vai",
+ "", "vai-Latn",
+ "", "vai-Latn-LR",
+ "", "vai-Vaii",
+ "", "vai-Vaii-LR",
+ "", "vun",
+ "", "vun-TZ",
+ "", "wae",
+ "", "wae-CH",
+ "", "xh",
+ "", "xh-ZA",
+ "", "xog",
+ "", "xog-UG",
+ "", "yav",
+ "", "yav-CM",
+ "", "yrl",
+ "", "yrl-BR",
+ "", "yrl-CO",
+ "", "yrl-VE",
+ "", "zgh",
+ "", "zgh-MA",
+ "", "zu",
+ "", "zu-ZA",
+ "af", "af-NA",
+ "af", "af-ZA",
+ "am", "am-ET",
+ "ar", "ar-001",
+ "ar", "ar-AE",
+ "ar", "ar-BH",
+ "ar", "ar-DJ",
+ "ar", "ar-DZ",
+ "ar", "ar-EG",
+ "ar", "ar-EH",
+ "ar", "ar-ER",
+ "ar", "ar-IL",
+ "ar", "ar-IQ",
+ "ar", "ar-JO",
+ "ar", "ar-KM",
+ "ar", "ar-KW",
+ "ar", "ar-LB",
+ "ar", "ar-LY",
+ "ar", "ar-MA",
+ "ar", "ar-MR",
+ "ar", "ar-OM",
+ "ar", "ar-PS",
+ "ar", "ar-QA",
+ "ar", "ar-SA",
+ "ar", "ar-SD",
+ "ar", "ar-SO",
+ "ar", "ar-SS",
+ "ar", "ar-SY",
+ "ar", "ar-TD",
+ "ar", "ar-TN",
+ "ar", "ar-YE",
+ "as", "as-IN",
+ "az", "az-Cyrl",
+ "az", "az-Cyrl-AZ",
+ "az", "az-Latn",
+ "az", "az-Latn-AZ",
+ "be", "be-BY",
+ "bg", "bg-BG",
+ "bn", "bn-BD",
+ "bn", "bn-IN",
+ "bo", "bo-CN",
+ "bo", "bo-IN",
+ "br", "br-FR",
+ "bs", "bs-Latn",
+ "bs", "bs-Latn-BA",
+ "bs_Cyrl", "bs-Cyrl-BA",
+ "ceb", "ceb-PH",
+ "chr", "chr-US",
+ "cs", "cs-CZ",
+ "cy", "cy-GB",
+ "da", "da-DK",
+ "da", "da-GL",
+ "dsb", "dsb-DE",
+ "ee", "ee-GH",
+ "ee", "ee-TG",
+ "el", "el-CY",
+ "el", "el-GR",
+ "eo", "eo-001",
+ "es", "es-419",
+ "es", "es-AR",
+ "es", "es-BO",
+ "es", "es-BR",
+ "es", "es-BZ",
+ "es", "es-CL",
+ "es", "es-CO",
+ "es", "es-CR",
+ "es", "es-CU",
+ "es", "es-DO",
+ "es", "es-EA",
+ "es", "es-EC",
+ "es", "es-ES",
+ "es", "es-GQ",
+ "es", "es-GT",
+ "es", "es-HN",
+ "es", "es-IC",
+ "es", "es-MX",
+ "es", "es-NI",
+ "es", "es-PA",
+ "es", "es-PE",
+ "es", "es-PH",
+ "es", "es-PR",
+ "es", "es-PY",
+ "es", "es-SV",
+ "es", "es-US",
+ "es", "es-UY",
+ "es", "es-VE",
+ "et", "et-EE",
+ "fa", "fa-IR",
+ "ff_Adlm", "ff-Adlm-BF",
+ "ff_Adlm", "ff-Adlm-CM",
+ "ff_Adlm", "ff-Adlm-GH",
+ "ff_Adlm", "ff-Adlm-GM",
+ "ff_Adlm", "ff-Adlm-GN",
+ "ff_Adlm", "ff-Adlm-GW",
+ "ff_Adlm", "ff-Adlm-LR",
+ "ff_Adlm", "ff-Adlm-MR",
+ "ff_Adlm", "ff-Adlm-NE",
+ "ff_Adlm", "ff-Adlm-NG",
+ "ff_Adlm", "ff-Adlm-SL",
+ "ff_Adlm", "ff-Adlm-SN",
+ "fi", "fi-FI",
+ "fil", "fil-PH",
+ "fo", "fo-DK",
+ "fo", "fo-FO",
+ "gl", "gl-ES",
+ "gu", "gu-IN",
+ "ha", "ha-GH",
+ "ha", "ha-NE",
+ "ha", "ha-NG",
+ "haw", "haw-US",
+ "he", "he-IL",
+ "hi", "hi-IN",
+ "hi", "hi-Latn",
+ "hi", "hi-Latn-IN",
+ "hr", "hr-BA",
+ "hr", "hr-HR",
+ "hsb", "hsb-DE",
+ "hu", "hu-HU",
+ "hy", "hy-AM",
+ "ig", "ig-NG",
+ "is", "is-IS",
+ "ja", "ja-JP",
+ "ka", "ka-GE",
+ "kk", "kk-KZ",
+ "kl", "kl-GL",
+ "km", "km-KH",
+ "kn", "kn-IN",
+ "ko", "ko-KP",
+ "ko", "ko-KR",
+ "kok", "kok-IN",
+ "ku", "ku-TR",
+ "ky", "ky-KG",
+ "lkt", "lkt-US",
+ "ln", "ln-AO",
+ "ln", "ln-CD",
+ "ln", "ln-CF",
+ "ln", "ln-CG",
+ "lo", "lo-LA",
+ "lt", "lt-LT",
+ "lv", "lv-LV",
+ "mk", "mk-MK",
+ "ml", "ml-IN",
+ "mn", "mn-MN",
+ "mr", "mr-IN",
+ "mt", "mt-MT",
+ "my", "my-MM",
+ "ne", "ne-IN",
+ "ne", "ne-NP",
+ "no", "nb",
+ "no", "nb-NO",
+ "no", "nb-SJ",
+ "no", "nn",
+ "no", "nn-NO",
+ "om", "om-ET",
+ "om", "om-KE",
+ "or", "or-IN",
+ "pa", "pa-Arab",
+ "pa", "pa-Arab-PK",
+ "pa", "pa-Guru",
+ "pa", "pa-Guru-IN",
+ "pl", "pl-PL",
+ "ps", "ps-AF",
+ "ps", "ps-PK",
+ "ro", "ro-MD",
+ "ro", "ro-RO",
+ "ru", "ru-BY",
+ "ru", "ru-KG",
+ "ru", "ru-KZ",
+ "ru", "ru-MD",
+ "ru", "ru-RU",
+ "ru", "ru-UA",
+ "se", "se-FI",
+ "se", "se-NO",
+ "se", "se-SE",
+ "si", "si-LK",
+ "sk", "sk-SK",
+ "sl", "sl-SI",
+ "smn", "smn-FI",
+ "sq", "sq-AL",
+ "sq", "sq-MK",
+ "sq", "sq-XK",
+ "sr", "sr-Cyrl",
+ "sr", "sr-Cyrl-BA",
+ "sr", "sr-Cyrl-ME",
+ "sr", "sr-Cyrl-RS",
+ "sr", "sr-Cyrl-XK",
+ "sr_Latn", "sr-Latn-BA",
+ "sr_Latn", "sr-Latn-ME",
+ "sr_Latn", "sr-Latn-RS",
+ "sr_Latn", "sr-Latn-XK",
+ "sv", "sv-AX",
+ "sv", "sv-FI",
+ "sv", "sv-SE",
+ "ta", "ta-IN",
+ "ta", "ta-LK",
+ "ta", "ta-MY",
+ "ta", "ta-SG",
+ "te", "te-IN",
+ "th", "th-TH",
+ "tk", "tk-TM",
+ "to", "to-TO",
+ "tr", "tr-CY",
+ "tr", "tr-TR",
+ "ug", "ug-CN",
+ "uk", "uk-UA",
+ "ur", "ur-IN",
+ "ur", "ur-PK",
+ "uz", "uz-Arab",
+ "uz", "uz-Arab-AF",
+ "uz", "uz-Cyrl",
+ "uz", "uz-Cyrl-UZ",
+ "uz", "uz-Latn",
+ "uz", "uz-Latn-UZ",
+ "vi", "vi-VN",
+ "wo", "wo-SN",
+ "yi", "yi-001",
+ "yo", "yo-BJ",
+ "yo", "yo-NG",
+ "zh", "yue",
+ "zh", "yue-Hans",
+ "zh", "yue-Hans-CN",
+ "zh", "yue-Hant",
+ "zh", "yue-Hant-HK",
+ "zh", "zh-Hans",
+ "zh", "zh-Hans-CN",
+ "zh", "zh-Hans-HK",
+ "zh", "zh-Hans-MO",
+ "zh", "zh-Hans-SG",
+ "zh", "zh-Hant",
+ "zh", "zh-Hant-HK",
+ "zh", "zh-Hant-MO",
+ "zh", "zh-Hant-TW",
+ NULL, NULL,
+};
+
#endif /* USE_ICU */
@@ -772,18 +1481,19 @@
* Start the loop at -1 to sneak in the root locale without too much
* code duplication.
*/
- for (i = -1; i < uloc_countAvailable(); i++)
+ for (i = -1; i < ucol_countAvailable(); i++) /* XXX-Patched: changed from uloc_countAvailable() */
{
const char *name;
char *langtag;
char *icucomment;
const char *iculocstr;
Oid collid;
+ char **ptr; /* XXX-Patched: added */
if (i == -1)
name = ""; /* ICU root locale */
else
- name = uloc_getAvailable(i);
+ name = ucol_getAvailable(i); /* XXX-Patched: changed from uloc_getAvailable() */
langtag = get_icu_language_tag(name);
iculocstr = U_ICU_VERSION_MAJOR_NUM >= 54 ? langtag : name;
@@ -812,6 +1523,44 @@
CreateComments(collid, CollationRelationId, 0,
icucomment);
}
+
+ /*
+ * XXX-Patched: The following block is added to create collations also for derived
+ * locales (combination of language+country/region).
+ * It's terribly inefficient, but in the big picture, it doesn't matter that much
+ * (it's typically called only once in the life of the cluster).
+ */
+ for (ptr = icu_coll_locales; *ptr != NULL; ptr++)
+ {
+ /*
+ * icu_coll_locales is a 1D array of pairs: collation name and locale (langtag).
+ * ptr++ moves pointer to the second string of the pair and it's a post-increment,
+ * so after the comparison with name is evaluated.
+ */
+ if (strcmp(*ptr++, name) == 0) {
+ const char *langtag;
+
+ langtag = pstrdup(*ptr);
+ collid = CollationCreate(psprintf("%s-x-icu", langtag),
+ nspid, GetUserId(),
+ COLLPROVIDER_ICU, true, -1,
+ NULL, NULL, langtag,
+ get_collation_actual_version(COLLPROVIDER_ICU, langtag),
+ true, true);
+
+ if (OidIsValid(collid))
+ {
+ ncreated++;
+
+ CommandCounterIncrement();
+
+ icucomment = get_icu_locale_comment(langtag);
+ if (icucomment)
+ CreateComments(collid, CollationRelationId, 0,
+ icucomment);
+ }
+ }
+ }
}
}
#endif /* USE_ICU */

View file

@ -0,0 +1,14 @@
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -3259,9 +3259,7 @@
/* translator: This is a placeholder in a shell command. */
appendPQExpBuffer(start_db_cmd, " -l %s start", _("logfile"));
- printf(_("\nSuccess. You can now start the database server using:\n\n"
- " %s\n\n"),
- start_db_cmd->data);
+ printf(_("\nSuccess.\n\n"));
destroyPQExpBuffer(start_db_cmd);
}

View file

@ -0,0 +1,111 @@
From: Tom Stellard <tstellar@redhat.com>
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Sat, 18 Dec 2021 23:09:03 +0100
Subject: [PATCH] jit: Workaround datalayout mismatch on s390x and x86
This patch is based on https://src.fedoraproject.org/rpms/postgresql/blob/f35/f/postgresql-datalayout-mismatch-on-s390.patch.
Original description:
> LLVM's s390x target uses a different datalayout for z13 and newer processors.
> If llvmjit_types.bc is compiled to target a processor older than z13, and
> then the JIT runs on a z13 or newer processor, then there will be a mismatch
> in datalayouts between llvmjit_types.bc and the JIT engine. This mismatch
> causes the JIT to fail at runtime.
We encountered an analogous problem even on x86 (legacy 32bit arch).
However, I didn't wanna waste my time researching what exact CPU features
are problematic on this dead architecture, so I just disabled usage of any
host specific CPU features when creating the JIT on x86. And while I was on
it, I also conditioned the s390x workaround for s390x only. -jirutka
diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
index 98a27f08bf..05b6438ba8 100644
--- a/src/backend/jit/llvm/llvmjit.c
+++ b/src/backend/jit/llvm/llvmjit.c
@@ -776,7 +776,38 @@
errhidecontext(true)));
}
+#if defined(__s390__) || defined(__s390x__)
/*
+ * For the systemz target, LLVM uses a different datalayout for z13 and newer
+ * CPUs than it does for older CPUs. This can cause a mismatch in datalayouts
+ * in the case where the llvm_types_module is compiled with a pre-z13 CPU
+ * and the JIT is running on z13 or newer.
+ * See computeDataLayout() function in
+ * llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp for information on the
+ * datalayout differences.
+ */
+static bool
+needs_systemz_workaround(void)
+{
+ bool ret = false;
+ LLVMContextRef llvm_context;
+ LLVMTypeRef vec_type;
+ LLVMTargetDataRef llvm_layoutref;
+ if (strncmp(LLVMGetTargetName(llvm_targetref), "systemz", strlen("systemz")))
+ {
+ return false;
+ }
+
+ llvm_context = LLVMGetModuleContext(llvm_types_module);
+ vec_type = LLVMVectorType(LLVMIntTypeInContext(llvm_context, 32), 4);
+ llvm_layoutref = LLVMCreateTargetData(llvm_layout);
+ ret = (LLVMABIAlignmentOfType(llvm_layoutref, vec_type) == 16);
+ LLVMDisposeTargetData(llvm_layoutref);
+ return ret;
+}
+#endif
+
+/*
* Per session initialization.
*/
static void
@@ -785,6 +816,7 @@
MemoryContext oldcontext;
char *error = NULL;
char *cpu = NULL;
+ char *host_features = NULL;
char *features = NULL;
LLVMTargetMachineRef opt0_tm;
LLVMTargetMachineRef opt3_tm;
@@ -815,11 +847,22 @@
* latter is needed because some CPU architectures default to enabling
* features not all CPUs have (weird, huh).
*/
+#if !defined(__i386__) && !defined(__i386) // XXX: quick workaround for 32-bit x86
cpu = LLVMGetHostCPUName();
- features = LLVMGetHostCPUFeatures();
+ features = host_features = LLVMGetHostCPUFeatures();
elog(DEBUG2, "LLVMJIT detected CPU \"%s\", with features \"%s\"",
cpu, features);
+#endif
+#if defined(__s390__) || defined(__s390x__)
+ if (needs_systemz_workaround())
+ {
+ const char *no_vector =",-vector";
+ features = malloc(sizeof(char) * (strlen(host_features) + strlen(no_vector) + 1));
+ sprintf(features, "%s%s", host_features, no_vector);
+ }
+#endif
+
opt0_tm =
LLVMCreateTargetMachine(llvm_targetref, llvm_triple, cpu, features,
LLVMCodeGenLevelNone,
@@ -833,8 +876,13 @@
LLVMDisposeMessage(cpu);
cpu = NULL;
- LLVMDisposeMessage(features);
+ if (features != host_features)
+ {
+ free(features);
+ }
features = NULL;
+ LLVMDisposeMessage(host_features);
+ host_features = NULL;
/* force symbols in main binary to be loaded */
LLVMLoadLibraryPermanently(NULL);

View file

@ -0,0 +1,84 @@
Patch-Source: https://sources.debian.org/src/postgresql-14/14.0-1/debian/patches/libpgport-pkglibdir
Author: Christoph Berg <myon@debian.org>
Description: Move libpgport/libpgcommon/libpgfeutils from libdir to pkglibdir
This allows client applications to link to version-specific libraries.
Used by pg-checksums.
--- a/src/common/Makefile
+++ b/src/common/Makefile
@@ -68,15 +68,15 @@ all: libpgcommon.a libpgcommon_shlib.a l
# libpgcommon is needed by some contrib
install: all installdirs
- $(INSTALL_STLIB) libpgcommon.a '$(DESTDIR)$(libdir)/libpgcommon.a'
- $(INSTALL_STLIB) libpgcommon_shlib.a '$(DESTDIR)$(libdir)/libpgcommon_shlib.a'
+ $(INSTALL_STLIB) libpgcommon.a '$(DESTDIR)$(pkglibdir)/libpgcommon.a'
+ $(INSTALL_STLIB) libpgcommon_shlib.a '$(DESTDIR)$(pkglibdir)/libpgcommon_shlib.a'
installdirs:
- $(MKDIR_P) '$(DESTDIR)$(libdir)'
+ $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
uninstall:
- rm -f '$(DESTDIR)$(libdir)/libpgcommon.a'
- rm -f '$(DESTDIR)$(libdir)/libpgcommon_shlib.a'
+ rm -f '$(DESTDIR)$(pkglibdir)/libpgcommon.a'
+ rm -f '$(DESTDIR)$(pkglibdir)/libpgcommon_shlib.a'
libpgcommon.a: $(OBJS_FRONTEND)
rm -f $@
--- a/src/fe_utils/Makefile
+++ b/src/fe_utils/Makefile
@@ -35,13 +35,13 @@ distprep: psqlscan.c
# libpgfeutils could be useful to contrib, so install it
install: all installdirs
- $(INSTALL_STLIB) libpgfeutils.a '$(DESTDIR)$(libdir)/libpgfeutils.a'
+ $(INSTALL_STLIB) libpgfeutils.a '$(DESTDIR)$(pkglibdir)/libpgfeutils.a'
installdirs:
- $(MKDIR_P) '$(DESTDIR)$(libdir)'
+ $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
uninstall:
- rm -f '$(DESTDIR)$(libdir)/libpgfeutils.a'
+ rm -f '$(DESTDIR)$(pkglibdir)/libpgfeutils.a'
clean distclean:
rm -f libpgfeutils.a $(OBJS) lex.backup
--- a/src/port/Makefile
+++ b/src/port/Makefile
@@ -54,15 +54,15 @@ all: libpgport.a libpgport_shlib.a libpg
# libpgport is needed by some contrib
install: all installdirs
- $(INSTALL_STLIB) libpgport.a '$(DESTDIR)$(libdir)/libpgport.a'
- $(INSTALL_STLIB) libpgport_shlib.a '$(DESTDIR)$(libdir)/libpgport_shlib.a'
+ $(INSTALL_STLIB) libpgport.a '$(DESTDIR)$(pkglibdir)/libpgport.a'
+ $(INSTALL_STLIB) libpgport_shlib.a '$(DESTDIR)$(pkglibdir)/libpgport_shlib.a'
installdirs:
- $(MKDIR_P) '$(DESTDIR)$(libdir)'
+ $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
uninstall:
- rm -f '$(DESTDIR)$(libdir)/libpgport.a'
- rm -f '$(DESTDIR)$(libdir)/libpgport_shlib.a'
+ rm -f '$(DESTDIR)$(pkglibdir)/libpgport.a'
+ rm -f '$(DESTDIR)$(pkglibdir)/libpgport_shlib.a'
libpgport.a: $(OBJS)
rm -f $@
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -549,8 +549,8 @@ libpq = -L$(libpq_builddir) -lpq
# on client link lines, since that also appears in $(LIBS).
# libpq_pgport_shlib is the same idea, but for use in client shared libraries.
ifdef PGXS
-libpq_pgport = -L$(libdir) -lpgcommon -lpgport $(libpq)
-libpq_pgport_shlib = -L$(libdir) -lpgcommon_shlib -lpgport_shlib $(libpq)
+libpq_pgport = -L$(pkglibdir) -lpgcommon -lpgport $(libpq)
+libpq_pgport_shlib = -L$(pkglibdir) -lpgcommon_shlib -lpgport_shlib $(libpq)
else
libpq_pgport = -L$(top_builddir)/src/common -lpgcommon -L$(top_builddir)/src/port -lpgport $(libpq)
libpq_pgport_shlib = -L$(top_builddir)/src/common -lpgcommon_shlib -L$(top_builddir)/src/port -lpgport_shlib $(libpq)

View file

@ -0,0 +1,50 @@
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Mon, 08 Nov 2021 14:56:33 +0100
Subject: [PATCH] Allow to install interfaces headers and server headers separately
Don't install headers of the interfaces (libpq and libecpg) by the install
target, allow to install them separately from the headers needed for server.
We need this for two reasons:
a. Allow building PostgreSQL server with LDAP support, but libpq without
dependency on LDAP.
b. Allow building/installing PostgreSQL server without the interfaces.
This is used for non-default postgresql aports (older versions of
PostgreSQL) - we want to provide just one version of libpq and libecpg
library provided by the default (newest) postgresql aport.
--- a/src/include/Makefile
+++ b/src/include/Makefile
@@ -26,8 +26,10 @@
port/win32_msvc/sys port/win32/arpa port/win32/netinet \
port/win32/sys portability
-# Install all headers
-install: all installdirs
+# Install server headers
+install: install-server
+install-interfaces: all
+ $(MKDIR_P) '$(DESTDIR)$(includedir)/libpq' '$(DESTDIR)$(includedir_internal)/libpq'
# These headers are needed by the public headers of the interfaces.
$(INSTALL_DATA) $(srcdir)/postgres_ext.h '$(DESTDIR)$(includedir)'
$(INSTALL_DATA) $(srcdir)/libpq/libpq-fs.h '$(DESTDIR)$(includedir)/libpq'
@@ -40,6 +42,8 @@
$(INSTALL_DATA) $(srcdir)/port.h '$(DESTDIR)$(includedir_internal)'
$(INSTALL_DATA) $(srcdir)/postgres_fe.h '$(DESTDIR)$(includedir_internal)'
$(INSTALL_DATA) $(srcdir)/libpq/pqcomm.h '$(DESTDIR)$(includedir_internal)/libpq'
+install-server: all
+ $(MKDIR_P) $(addprefix '$(DESTDIR)$(includedir_server)'/, $(SUBDIRS))
# These headers are needed for server-side development
$(INSTALL_DATA) pg_config.h '$(DESTDIR)$(includedir_server)'
$(INSTALL_DATA) pg_config_ext.h '$(DESTDIR)$(includedir_server)'
@@ -64,10 +68,6 @@
chmod $(INSTALL_DATA_MODE) *.h || exit; \
done
-installdirs:
- $(MKDIR_P) '$(DESTDIR)$(includedir)/libpq' '$(DESTDIR)$(includedir_internal)/libpq'
- $(MKDIR_P) $(addprefix '$(DESTDIR)$(includedir_server)'/, $(SUBDIRS))
-
uninstall:
rm -f $(addprefix '$(DESTDIR)$(includedir)'/, pg_config.h pg_config_ext.h pg_config_os.h pg_config_manual.h postgres_ext.h libpq/libpq-fs.h)

View file

@ -0,0 +1,69 @@
Author: Martin Pitt <mpitt@debian.org>
Description: Use version specific installation directories so that several major versions can be installed in parallel.
* Install server lib files into /usr/lib/postgresql<version>/
* Install server related header files into /usr/include/postgresql/<version>/server/
* Disable PostgreSQL's automagic path mangling and fix libdir for pg_config,
so that pg_config in /usr/bin and /usr/libexec/postgresql<version> behave
identically.
Bug-Debian: http://bugs.debian.org/462037
Patch-Source: https://sources.debian.org/src/postgresql-14/14.0-1/debian/patches/50-per-version-dirs.patch
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -119,7 +119,7 @@ libdir := @libdir@
pkglibdir = $(libdir)
ifeq "$(findstring pgsql, $(pkglibdir))" ""
ifeq "$(findstring postgres, $(pkglibdir))" ""
-override pkglibdir := $(pkglibdir)/postgresql
+override pkglibdir := /usr/lib/postgresql@PG_MAJORVERSION@
endif
endif
@@ -167,7 +167,7 @@ endif # PGXS
# These derived path variables aren't separately configurable.
-includedir_server = $(pkgincludedir)/server
+includedir_server = $(pkgincludedir)/@PG_MAJORVERSION@/server
includedir_internal = $(pkgincludedir)/internal
pgxsdir = $(pkglibdir)/pgxs
bitcodedir = $(pkglibdir)/bitcode
--- a/src/bin/pg_config/pg_config.c
+++ b/src/bin/pg_config/pg_config.c
@@ -27,6 +27,8 @@
#include "common/config_info.h"
#include "port.h"
+#include "../port/pg_config_paths.h"
+
static const char *progname;
/*
@@ -149,11 +151,7 @@ main(int argc, char **argv)
}
}
- if (find_my_exec(argv[0], my_exec_path) < 0)
- {
- fprintf(stderr, _("%s: could not find own program executable\n"), progname);
- exit(1);
- }
+ snprintf(my_exec_path, sizeof(my_exec_path), "%s/%s", PGBINDIR, progname);
configdata = get_configdata(my_exec_path, &configdata_len);
/* no arguments -> print everything */
--- a/src/test/perl/PostgreSQL/Test/Utils.pm
+++ b/src/test/perl/PostgreSQL/Test/Utils.pm
@@ -688,6 +688,10 @@
chomp($stdout);
$stdout =~ s/\r$//;
+ # Alpine's pg_config is not relocatable, manually check for correct location
+ if (-d "../../../build/tmp_install/usr/include/postgresql") {
+ $stdout = "../../../build/tmp_install/usr/include/postgresql";
+ }
open my $pg_config_h, '<', "$stdout/pg_config.h" or die "$!";
my $match = (grep { /^$regexp/ } <$pg_config_h>);
close $pg_config_h;

View file

@ -0,0 +1,22 @@
We configure Postgres with --disable-rpath because for the most part we
want to leave it to ldconfig to determine where libraries are. However,
for some reason the Perl package puts libperl.so in a nonstandard place
and doesn't add that place to the ldconfig search path. I think this
is a Perl packaging bug, myself, but apparently it's not going to change.
So work around it by adding an rpath spec to plperl.so (only).
Alpine notes:
This patch is copied from Fedora.
--- a/src/pl/plperl/GNUmakefile
+++ b/src/pl/plperl/GNUmakefile
@@ -55,6 +55,9 @@
SHLIB_LINK = $(perl_embed_ldflags)
+# Force rpath to be used even though we disable it everywhere else
+SHLIB_LINK += $(rpath)
+
REGRESS_OPTS = --dbname=$(PL_TESTDB)
REGRESS = plperl_setup plperl plperl_lc plperl_trigger plperl_shared \
plperl_elog plperl_util plperl_init plperlu plperl_array \

View file

@ -0,0 +1,49 @@
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Tue, 09 Nov 2021 00:33:22 +0100
Subject: [PATCH] pg_config: Add new option --major-version
We use this option in aports for PostgreSQL extensions to easily get major
version of the default postgresql.
--- a/src/bin/pg_config/pg_config.c
+++ b/src/bin/pg_config/pg_config.c
@@ -65,6 +65,7 @@
{"--ldflags_ex", "LDFLAGS_EX"},
{"--ldflags_sl", "LDFLAGS_SL"},
{"--libs", "LIBS"},
+ {"--major-version", "MAJOR-VERSION"},
{"--version", "VERSION"},
{NULL, NULL}
};
@@ -101,6 +102,8 @@
printf(_(" --ldflags_ex show LDFLAGS_EX value used when PostgreSQL was built\n"));
printf(_(" --ldflags_sl show LDFLAGS_SL value used when PostgreSQL was built\n"));
printf(_(" --libs show LIBS value used when PostgreSQL was built\n"));
+ printf(_(" --major-version show the PostgreSQL major version number\n"
+ " (Alpine Linux specific option)\n"));
printf(_(" --version show the PostgreSQL version\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("\nWith no arguments, all known items are shown.\n\n"));
--- a/src/common/config_info.c
+++ b/src/common/config_info.c
@@ -38,7 +38,7 @@
int i = 0;
/* Adjust this to match the number of items filled below */
- *configdata_len = 23;
+ *configdata_len = 24;
configdata = (ConfigData *) palloc(*configdata_len * sizeof(ConfigData));
configdata[i].name = pstrdup("BINDIR");
@@ -193,6 +193,11 @@
configdata[i].name = pstrdup("VERSION");
configdata[i].setting = pstrdup("PostgreSQL " PG_VERSION);
+ i++;
+
+ // XXX-Patched: Alpine Linux specific, used in extension aports.
+ configdata[i].name = pstrdup("MAJOR-VERSION");
+ configdata[i].setting = pstrdup(PG_MAJORVERSION);
i++;
Assert(i == *configdata_len);

View file

@ -0,0 +1,13 @@
-- Create tables needed for PL/Tcl autoloading. This script should be run by
-- the database administrator only.
--
-- Statements in this script are extracted from pltcl_loadmod script.
--
-- Author: G.J.R. Timmer
-- Date: 2017-01-28
create table pltcl_modules (modname name, modseq int2, modsrc text);
create index pltcl_modules_i on pltcl_modules using btree (modname name_ops);
create table pltcl_modfuncs (funcname name, modname name);
create index pltcl_modfuncs_i on pltcl_modfuncs using hash (funcname name_ops);

View file

@ -0,0 +1,12 @@
#!/bin/sh
majorver=${1%%.*}
cat >&2 <<EOF
*
* If you want to use JIT in PostgreSQL, install postgresql$majorver-jit or
* postgresql-jit (if you didn't install specific major version of postgresql).
*
EOF
exit 0

View file

@ -0,0 +1,35 @@
#!/bin/sh
pkgver=$1
pkgver_major=${pkgver%%.*}
default_ver=$(pg_versions get-default 2>/dev/null) || true
# If this package is not set as the default PostgreSQL version (see
# pg_versions), let it go.
[ "$default_ver" = "$pkgver_major" ] || exit 0
# If this package ('postgresql<majorver>') has been installed explicitly, i.e.
# not via 'postgresql' provider or as a dependency, the user is apparently
# uninstalling it intentionally, so let it go.
grep -Fqx "postgresql$pkgver_major" /etc/apk/world 2>/dev/null && exit 0
data_dir=$(
. /etc/conf.d/postgresql 2>/dev/null
echo "${data_dir:-"/var/lib/postgresql/$pkgver_major/data"}"
)
# If data_dir for this version does not exist or is empty, let it go.
[ -f "$data_dir"/PG_VERSION ] || exit 0
cat >&2 <<EOF
*
* You are uninstalling your default PostgreSQL version ($default_ver) which seems to be
* in use! If it's *not* intentional and you want to preserve this version,
* install it explicitly: \`apk add postgresql$default_ver\`.
*
* Please note that to upgrade your cluster to a new major version using
* pg_upgrade(1), you must have both the old and new versions installed.
*
EOF
exit 1

View file

@ -0,0 +1,18 @@
Nothing ever depended on libecpg_compat.so.3 in Fedora, so don't build
it now, at least till somebody explicitly requests that.
Patch-Source: https://src.fedoraproject.org/rpms/libecpg/blob/f35/f/libecpg-10.5-no-compat-lib.patch
diff --git a/src/interfaces/ecpg/Makefile b/src/interfaces/ecpg/Makefile
index 41460a1..cc3dd37 100644
--- a/src/interfaces/ecpg/Makefile
+++ b/src/interfaces/ecpg/Makefile
@@ -2,7 +2,7 @@ subdir = src/interfaces/ecpg
top_builddir = ../../..
include $(top_builddir)/src/Makefile.global
-SUBDIRS = include pgtypeslib ecpglib compatlib preproc
+SUBDIRS = include pgtypeslib ecpglib preproc
# Suppress parallel build of subdirectories to avoid a bug in GNU make 3.82, cf
# http://savannah.gnu.org/bugs/?30653

View file

@ -0,0 +1,29 @@
Using /tmp for sockets allows everyone to spoof a PostgreSQL server. Thus use
/run/postgresql/ for "system" clusters which run as 'postgres' (user
clusters will still use /tmp). Since system cluster are by far the common case,
set it as default.
This is inspired by Fedora and Debian patches.
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -63,7 +63,7 @@
#port = 5432 # (change requires restart)
#max_connections = 100 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
-#unix_socket_directories = '/tmp' # comma-separated list of directories
+unix_socket_directories = '/run/postgresql' # comma-separated list of directories
# (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = 0777 # begin with 0 to use octal notation
--- a/src/include/pg_config_manual.h
+++ b/src/include/pg_config_manual.h
@@ -201,7 +201,7 @@
* support them yet.
*/
#ifndef WIN32
-#define DEFAULT_PGSOCKET_DIR "/tmp"
+#define DEFAULT_PGSOCKET_DIR "/run/postgresql"
#else
#define DEFAULT_PGSOCKET_DIR ""
#endif