diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 12:32:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 12:32:55 +0000 |
commit | 9cc2995e4c35f593d1770c29f8e0619fc0f7a9f4 (patch) | |
tree | 617657a386230bac3fe383433eaa9bddc1ccce42 | |
parent | Adding upstream version 258. (diff) | |
download | postgresql-common-9cc2995e4c35f593d1770c29f8e0619fc0f7a9f4.tar.xz postgresql-common-9cc2995e4c35f593d1770c29f8e0619fc0f7a9f4.zip |
Adding upstream version 259.upstream/259
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
-rw-r--r-- | PgCommon.pm | 26 | ||||
-rw-r--r-- | doc/postgresql-debian-packaging.md | 2 | ||||
-rwxr-xr-x | pg_backupcluster | 61 | ||||
-rwxr-xr-x | pg_buildext | 32 | ||||
-rw-r--r-- | pg_buildext.pod | 8 | ||||
-rwxr-xr-x | pg_restorecluster | 13 | ||||
-rw-r--r-- | t/045_backup.t | 6 |
7 files changed, 57 insertions, 91 deletions
diff --git a/PgCommon.pm b/PgCommon.pm index df4d060..918d228 100644 --- a/PgCommon.pm +++ b/PgCommon.pm @@ -5,7 +5,7 @@ PgCommon - Common functions for the postgresql-common framework =head1 COPYRIGHT AND LICENSE (C) 2008-2009 Martin Pitt <mpitt@debian.org> - (C) 2012-2023 Christoph Berg <myon@debian.org> + (C) 2012-2024 Christoph Berg <myon@debian.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -1348,7 +1348,7 @@ sub get_db_encoding { owner. (For versions >= 8.4; for older versions use get_cluster_locales()). Arguments: <version> <cluster> <database> - Returns: (LC_CTYPE, LC_COLLATE) or (undef,undef) if it cannot be determined. + Returns: (LC_CTYPE, LC_COLLATE, locprovider, iculocale, icurules) or undef if it cannot be determined. PG15 adds locale provider and icu locale to the returned values PG16 adds icu rules @@ -1368,32 +1368,24 @@ sub get_db_locales { my $orig_euid = $>; $> = (stat (cluster_data_directory $version, $cluster))[4]; + my $datlocprovider = $version >= 15 ? "CASE datlocprovider::text WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' WHEN 'b' THEN 'builtin' END" : "NULL"; + my $daticulocale = ($version >= 15 and $version < 17) ? "daticulocale" : "NULL"; + my $daticurules = $version >= 16 ? "daticurules" : "NULL"; + open PSQL, '-|', $psql, '-h', $socketdir, '-p', $port, '-AXtc', - "SELECT datctype, datcollate FROM pg_database where datname = current_database()", $db or + "SELECT datctype, datcollate, $datlocprovider, $daticulocale, $daticurules FROM pg_database where datname = current_database()", $db or die "Internal error: could not call $psql to determine datctype and datcollate: $!"; my $out = <PSQL> // error 'could not determine datctype and datcollate'; close PSQL; ($out) = $out =~ /^(.*)$/; # untaint - ($ctype, $collate) = split /\|/, $out; - - if ($version >= 15) { - open PSQL, '-|', $psql, '-h', $socketdir, '-p', $port, '-AXtc', - "SELECT CASE datlocprovider::text WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END, daticulocale" . - ($version >= 16 ? ", daticurules" : "") . - " FROM pg_database where datname = current_database()", $db or - die "Internal error: could not call $psql to determine datlocprovider: $!"; - $out = <PSQL> // error 'could not determine datlocprovider'; - close PSQL; - ($out) = $out =~ /^(.*)$/; # untaint - ($locale_provider, $icu_locale, $icu_rules) = split /\|/, $out; - } + ($ctype, $collate, $locale_provider, $icu_locale, $icu_rules) = split /\|/, $out; $> = $orig_euid; restore_exec; chomp $ctype; chomp $collate; return ($ctype, $collate, $locale_provider, $icu_locale, $icu_rules) unless $?; - return (undef, undef); + return (undef, undef, undef, undef, undef); } diff --git a/doc/postgresql-debian-packaging.md b/doc/postgresql-debian-packaging.md index 4edd9ca..79d4a8a 100644 --- a/doc/postgresql-debian-packaging.md +++ b/doc/postgresql-debian-packaging.md @@ -115,7 +115,7 @@ either as download from the upstream homepage, or for projects hosted on GitHub, often a tarball automatically generated by GitHub from an upstream Git tag. -The `.debiar.tar.xz` file contains the `debian/` directory. +The `.debian.tar.xz` file contains the `debian/` directory. The `.dsc` file is a descriptor that contains pointers to the other files in the source package, and more meta information. diff --git a/pg_backupcluster b/pg_backupcluster index 2959056..671ed29 100755 --- a/pg_backupcluster +++ b/pg_backupcluster @@ -2,7 +2,7 @@ # simple pg_basebackup front-end # -# Copyright (C) 2021-2023 Christoph Berg <myon@debian.org> +# Copyright (C) 2021-2024 Christoph Berg <myon@debian.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -142,16 +142,25 @@ sub create_dumpall($) { my $backupdir = shift; mkdir($backupdir, 0750) or error "mkdir $backupdir: $!"; - my $pg16 = $version >= 16 ? "|| ' --icu-rules ' || daticurules" : ""; - my $pg15 = $version >= 15 ? "CASE datlocprovider::text - WHEN 'c' THEN '--locale-provider libc' - WHEN 'i' THEN '--locale-provider icu --icu-locale ' || daticulocale $pg16 - END," : ""; + my $icu = ""; + if ($version >= 15) { + $icu = "CASE datlocprovider::text + WHEN 'c' THEN '--locale-provider libc' + WHEN 'b' THEN '--locale-provider builtin' + WHEN 'i' THEN '--locale-provider icu'"; + if ($version < 17) { + $icu .= " || ' --icu-locale ' || daticulocale"; + } + if ($version >= 16) { + $icu .= " || ' --icu-rules ' || daticurules"; + } + $icu .= "\nEND,"; + } my $clusterquery = "SELECT '--encoding', pg_catalog.pg_encoding_to_char(encoding), '--lc-collate', datcollate, '--lc-ctype', datctype, - $pg15 + $icu CASE WHEN current_setting('data_checksums')::boolean THEN '-- --data-checksums' END FROM pg_database WHERE datname = 'template0'"; system_or_error "psql", @@ -164,44 +173,6 @@ FROM pg_database WHERE datname = 'template0'"; "--globals-only", "--file", "$backupdir/globals.sql"; - $pg16 = $version >= 16 ? "|| ' ICU_RULES ' || quote_literal(coalesce(daticurules, ''))" : ""; - $pg15 = $version >= 15 ? "|| CASE datlocprovider::text - WHEN 'c' THEN 'LOCALE_PROVIDER libc' - WHEN 'i' THEN 'LOCALE_PROVIDER icu ICU_LOCALE ' || quote_literal(daticulocale) $pg16 - END" : ""; - my $dbquery = "/* database creation */ -SELECT - format('CREATE DATABASE %I WITH OWNER %I TEMPLATE template0 ENCODING %L LC_COLLATE %L LC_CTYPE %L', - datname, rolname, pg_encoding_to_char(encoding), datcollate, datctype) $pg15 || ';' AS command -FROM pg_database -LEFT JOIN pg_roles r ON r.oid = datdba -WHERE datallowconn AND datname NOT IN ('postgres', 'template1') - -UNION ALL - -/* database options */ -SELECT - CASE - WHEN rolname IS NULL THEN format('ALTER DATABASE %I', datname) - ELSE format('ALTER ROLE %I IN DATABASE %I', rolname, datname) - END || - format(' SET %I = ', match[1]) || - CASE - WHEN match[1] IN ('local_preload_libraries', 'search_path', 'session_preload_libraries', 'shared_preload_libraries', 'temp_tablespaces', 'unix_socket_directories') - THEN match[2] - ELSE quote_literal(match[2]) - END || - ';' AS command -FROM pg_db_role_setting s -JOIN pg_database d ON d.oid = setdatabase -LEFT JOIN pg_roles r ON r.oid = setrole, -unnest(setconfig) u(setting), -regexp_matches(setting, '(.+)=(.+)') m(match)"; - system_or_error "psql", - "--cluster", "$version/$cluster", - "-XAtc", $dbquery, - "-o", "$backupdir/databases.sql"; - my $dblist = 'SELECT datname FROM pg_database WHERE datallowconn ORDER BY datname'; my $databases = `psql --cluster '$version/$cluster' -XAtc '$dblist'`; for my $datname ($databases =~ /(.+)/g) { diff --git a/pg_buildext b/pg_buildext index 304e8a1..c498de6 100755 --- a/pg_buildext +++ b/pg_buildext @@ -4,7 +4,7 @@ # versions # # (C) 2010 Dimitri Fontaine <dfontaine@hi-media.com> -# (C) 2011-2023 Christoph Berg <myon@debian.org> +# (C) 2011-2024 Christoph Berg <myon@debian.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,13 +23,11 @@ die() { exit 1 } -VENVARGS="" -MAKEVARS="" while getopts "c:i:m:o:s" opt ; do case $opt in - c|i|o) VENVARGS="$VENVARGS -$opt $OPTARG" ;; + c|i|o) PG_VIRTUALENV_ARGS="${PG_VIRTUALENV_ARGS:-} -$opt $OPTARG" ;; m) MAKEVARS="$OPTARG" ;; - s) VENVARGS="$VENVARGS -$opt" ;; + s) PG_VIRTUALENV_ARGS="${PG_VIRTUALENV_ARGS:-} -$opt" ;; *) exit 1 ;; esac done @@ -80,7 +78,7 @@ build() { mkdir -p $vtarget # if a Makefile was created by configure, use it, else the top level Makefile [ -f $vtarget/Makefile ] || makefile="-f $srcdir/Makefile" - make -C $vtarget ${makefile:-} PG_CONFIG="$pgc" VPATH="$srcdir" USE_PGXS=1 $MAKEVARS || return $? + make -C $vtarget ${makefile:-} PG_CONFIG="$pgc" VPATH="$srcdir" USE_PGXS=1 ${MAKEVARS:-} || return $? } substvars() { @@ -113,7 +111,7 @@ install() { mkdir -p $vtarget # if a Makefile was created by configure, use it, else the top level Makefile [ -f $vtarget/Makefile ] || makefile="-f $srcdir/Makefile" - make -C $vtarget ${makefile:-} install DESTDIR="$PWD/debian/$package" PG_CONFIG="$pgc" VPATH="$srcdir" USE_PGXS=1 $MAKEVARS || return $? + make -C $vtarget ${makefile:-} install DESTDIR="$PWD/debian/$package" PG_CONFIG="$pgc" VPATH="$srcdir" USE_PGXS=1 ${MAKEVARS:-} || return $? substvars "$1" "$package" } @@ -129,12 +127,12 @@ loop() { package=$(echo $target | sed -e "s:%v:$1:g") echo "# $1: make" - make -C "$srcdir" PG_CONFIG="$pgc" USE_PGXS=1 $MAKEVARS || return $? + make -C "$srcdir" PG_CONFIG="$pgc" USE_PGXS=1 ${MAKEVARS:-} || return $? echo "# $1: make install" - make -C "$srcdir" install DESTDIR="$PWD/debian/$package" PG_CONFIG="$pgc" USE_PGXS=1 $MAKEVARS || return $? + make -C "$srcdir" install DESTDIR="$PWD/debian/$package" PG_CONFIG="$pgc" USE_PGXS=1 ${MAKEVARS:-} || return $? substvars "$1" "$package" echo "# $1: make clean" - make -C "$srcdir" clean PG_CONFIG="$pgc" USE_PGXS=1 $MAKEVARS # clean errors are fatal + make -C "$srcdir" clean PG_CONFIG="$pgc" USE_PGXS=1 ${MAKEVARS:-} # clean errors are fatal } installcheck() { @@ -158,9 +156,9 @@ installcheck() { if [ "$target" ] && [ "$target" != "." ]; then # if target is given, use it, else stay in the top source dir # if a Makefile was created by configure, use it, else the top level Makefile [ -f $vtarget/Makefile ] || makefile="-f $srcdir/Makefile" - if ! pg_virtualenv ${PKGARGS:-} $VENVARGS -v $1 \ + if ! pg_virtualenv ${PKGARGS:-} ${PG_VIRTUALENV_ARGS:-} -v $1 \ make -C $vtarget ${makefile:-} installcheck ${DESTDIR:-} \ - PG_CONFIG="$pgc" VPATH="$srcdir" USE_PGXS=1 $MAKEVARS; then + PG_CONFIG="$pgc" VPATH="$srcdir" USE_PGXS=1 ${MAKEVARS:-}; then if [ -r $vtarget/regression.diffs ]; then echo "**** $vtarget/regression.diffs ****" cat $vtarget/regression.diffs @@ -168,8 +166,8 @@ installcheck() { return 1 fi else - if ! pg_virtualenv ${PKGARGS:-} $VENVARGS -v $1 \ - make installcheck ${DESTDIR:-} PG_CONFIG="$pgc" USE_PGXS=1 $MAKEVARS; then + if ! pg_virtualenv ${PKGARGS:-} ${PG_VIRTUALENV_ARGS:-} -v $1 \ + make installcheck ${DESTDIR:-} PG_CONFIG="$pgc" USE_PGXS=1 ${MAKEVARS:-}; then if [ -r regression.diffs ]; then echo "**** regression.diffs ****" cat regression.diffs @@ -177,7 +175,7 @@ installcheck() { return 1 fi # since we are in the top-level directory, clean up behind us - make clean PG_CONFIG="$pgc" USE_PGXS=1 $MAKEVARS + make clean PG_CONFIG="$pgc" USE_PGXS=1 ${MAKEVARS:-} fi } @@ -213,7 +211,7 @@ run_psql () { if [ "$target" ] && [ "$target" != "." ]; then # if target is given, use it, else stay in the top source dir cd $target fi - pg_virtualenv ${PKGARGS:-} $VENVARGS -v $1 \ + pg_virtualenv ${PKGARGS:-} ${PG_VIRTUALENV_ARGS:-} -v $1 \ psql -Xe -v ON_ERROR_STOP=1 < $PSQLTMP ) || return $? } @@ -237,7 +235,7 @@ run_virtualenv () { if [ "$target" ] && [ "$target" != "." ]; then # if target is given, use it, else stay in the top source dir cd $target fi - pg_virtualenv ${PKGARGS:-} $VENVARGS -v $1 ${SHELL:-/bin/sh} -ex < $PSQLTMP + pg_virtualenv ${PKGARGS:-} ${PG_VIRTUALENV_ARGS:-} -v $1 ${SHELL:-/bin/sh} -ex < $PSQLTMP ) || return $? } diff --git a/pg_buildext.pod b/pg_buildext.pod index d76c701..0bc6aab 100644 --- a/pg_buildext.pod +++ b/pg_buildext.pod @@ -64,6 +64,9 @@ is fine to provide the tests control file directly.) Passed to B<pg_virtualenv> when running B<installcheck>. +These arguments can also be set via the B<PG_VIRTUALENV_ARGS> environment +variable. + =item B<-m> I<arg> Passed to B<make>. @@ -278,6 +281,9 @@ configure the list of supported versions on your system. override_dh_installdocs: dh_installdocs --all README.* + override_dh_pgxs_test: + +pg_buildext installcheck . build-%v postgresql-%v-foobar + override_dh_auto_clean: +pg_buildext clean build-%v @@ -346,6 +352,8 @@ The replacement of B<PGVERSIONS> (plural) in debian/control.in and B<pg_buildext run> and B<run_installed> were introduced in postgresql-common (>= 256~). +Setting B<pg_virtualenv> arguments from B<PG_VIRTUALENV_ARGS> was introduced in +postgresql-common (>= 259~). =head1 SEE ALSO diff --git a/pg_restorecluster b/pg_restorecluster index 0a4af55..b3335ca 100755 --- a/pg_restorecluster +++ b/pg_restorecluster @@ -2,7 +2,7 @@ # pg_restorecluster: restore from a pg_backupcluster backup # -# Copyright (C) 2021 Christoph Berg <myon@debian.org> +# Copyright (C) 2021-2024 Christoph Berg <myon@debian.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -243,13 +243,6 @@ sub restore_globals($$) { error "psql failed" if ($?); } -sub create_databases($) { - my ($backup) = @_; - - print "Creating databases from $backup/databases.sql ...\n"; - system_or_error "psql", "--cluster", "$version/$cluster", "-vON_ERROR_STOP=1", "-Xqf", "$backup/databases.sql"; -} - sub restore_dumps($) { my ($backup) = @_; @@ -258,7 +251,8 @@ sub restore_dumps($) { $dump = $1; # untaint my $db = $2; print "Restoring $dump to database $db ...\n"; - system_or_error "pg_restore", "--cluster", "$version/$cluster", "-d", $db, $dump; + my @create = ($db eq "postgres" or $db eq "template1") ? () : ("--create"); + system_or_error "pg_restore", "--cluster", "$version/$cluster", @create, "-d", "postgres", $dump; } } @@ -339,7 +333,6 @@ if ($backup =~ /\.backup$/) { start_cluster(); switch_to_cluster_owner($owneruid, $ownergid); restore_globals($backup, $owneruid); - create_databases($backup); restore_dumps($backup); analyze(); print "\n"; diff --git a/t/045_backup.t b/t/045_backup.t index 1258ea3..1a47c27 100644 --- a/t/045_backup.t +++ b/t/045_backup.t @@ -38,6 +38,7 @@ foreach my $v (@MAJORS) { program_ok $pg_uid, "psql -c 'create table foo (t text)' mydb"; program_ok $pg_uid, "psql -c \"insert into foo values ('data from backup')\" mydb"; program_ok $pg_uid, "psql -c 'CREATE USER myuser'"; + program_ok $pg_uid, "psql -c 'grant create on database mydb to myuser'"; program_ok $pg_uid, "psql -c 'alter role myuser set search_path=public, myschema'"; program_ok $pg_uid, "createdb --locale-provider icu --icu-locale de -T template0 myicudb" if ($v >= 15); @@ -94,6 +95,8 @@ foreach my $v (@MAJORS) { } } if ($systemd) { + program_ok $pg_uid, "psql -c 'alter system set checkpoint_timeout=30'"; # minimum + program_ok $pg_uid, "psql -c 'select pg_reload_conf()'"; program_ok 0, "systemctl start pg_basebackup\@$v-main"; } else { program_ok 0, "pg_backupcluster --checkpoint=fast $v main basebackup"; @@ -131,7 +134,8 @@ foreach my $v (@MAJORS) { like_program_out 0, "pg_lsclusters -h", 0, qr/$v main 5432 online postgres .var.lib.postgresql.$v.snowflake/; my $outref; is exec_as($pg_uid, "psql -XAtl", $outref), 0, 'psql -XAtl'; - like $$outref, qr/^mydb\|postgres\|SQL_ASCII\|(libc\|)?en_US.UTF-8\|en_US.UTF-8\|(\|libc\||\|\|)?$/m, "mydb locales"; + like $$outref, qr/^mydb\|postgres\|SQL_ASCII\|(libc\|)?en_US.UTF-8\|en_US.UTF-8\|(\|libc\||\|\|)?(=Tc\/postgres)?$/m, "mydb locales"; + like $$outref, qr/myuser=C\/postgres/m, "mydb grants" if ($v >= 11); # pg_restore --create support in 11 like $$outref, qr/^myicudb\|postgres\|UTF8\|(icu\|)?en_US.UTF-8\|en_US.UTF-8\|(de\|icu\||de\|\|)?$/m, "myicudb locales" if ($v >= 15); is_program_out $pg_uid, "psql -XAtc 'show work_mem'", 0, "11MB\n"; is_program_out $pg_uid, "psql -XAtc 'select * from foo' mydb", 0, "data from backup\n"; |