agora inbox for [email protected]  
help / color / mirror / Atom feed
[PATCH v5 4/4] Move pg_upgrade kludges to sql script
10+ messages / 4 participants
[nested] [flat]

* [PATCH v5 4/4] Move pg_upgrade kludges to sql script
@ 2021-03-07 00:35  Justin Pryzby <[email protected]>
  0 siblings, 0 replies; 10+ messages in thread

From: Justin Pryzby @ 2021-03-07 00:35 UTC (permalink / raw)

---
 src/bin/pg_upgrade/test-upgrade.sql | 70 +++++++++++++++++++++
 src/bin/pg_upgrade/test.sh          | 97 +----------------------------
 2 files changed, 71 insertions(+), 96 deletions(-)
 create mode 100644 src/bin/pg_upgrade/test-upgrade.sql

diff --git a/src/bin/pg_upgrade/test-upgrade.sql b/src/bin/pg_upgrade/test-upgrade.sql
new file mode 100644
index 0000000000..8c7cceb211
--- /dev/null
+++ b/src/bin/pg_upgrade/test-upgrade.sql
@@ -0,0 +1,70 @@
+-- This file has a bunch of kludges needed for testing upgrades across major versions
+
+SELECT
+	ver >= 804 AND ver <= 1100 AS oldpgversion_84_11,
+	ver >= 905 AND ver <= 1300 AS oldpgversion_95_13,
+	ver >= 906 AND ver <= 1300 AS oldpgversion_96_13,
+	ver >= 906 AND ver <= 1000 AS oldpgversion_96_10,
+	ver >= 1000 AS oldpgversion_ge10,
+	ver <= 804 AS oldpgversion_le84,
+	ver <= 1300 AS oldpgversion_le13
+	FROM (SELECT current_setting('server_version_num')::int/100 AS ver) AS v;
+\gset
+
+\if :oldpgversion_le84
+DROP FUNCTION public.myfunc(integer);
+\endif
+
+-- last in 9.6 -- commit 5ded4bd21
+DROP FUNCTION IF EXISTS public.oldstyle_length(integer, text);
+DROP FUNCTION IF EXISTS public.putenv(text);
+
+\if :oldpgversion_le13
+-- last in v13 commit 76f412ab3
+-- public.!=- This one is only needed for v11+ ??
+-- Note, until v10, operators could only be dropped one at a time
+DROP OPERATOR IF EXISTS public.#@# (pg_catalog.int8, NONE);
+DROP OPERATOR IF EXISTS public.#%# (pg_catalog.int8, NONE);
+DROP OPERATOR IF EXISTS public.!=- (pg_catalog.int8, NONE);
+DROP OPERATOR IF EXISTS public.#@%# (pg_catalog.int8, NONE);
+\endif
+
+\if :oldpgversion_ge10
+-- commit 068503c76511cdb0080bab689662a20e86b9c845
+DROP TRANSFORM FOR integer LANGUAGE sql CASCADE;
+\endif
+
+\if :oldpgversion_96_10
+-- commit db3af9feb19f39827e916145f88fa5eca3130cb2
+DROP FUNCTION boxarea(box);
+DROP FUNCTION funny_dup17();
+
+-- commit cda6a8d01d391eab45c4b3e0043a1b2b31072f5f
+DROP TABLE abstime_tbl;
+DROP TABLE reltime_tbl;
+DROP TABLE tinterval_tbl;
+\endif
+
+\if :oldpgversion_96_13
+-- Various things removed for v14
+DROP AGGREGATE first_el_agg_any(anyelement);
+\endif
+
+\if :oldpgversion_95_13
+-- commit 9e38c2bb5 and 97f73a978
+-- DROP AGGREGATE array_larger_accum(anyarray);
+DROP AGGREGATE array_cat_accum(anyarray);
+
+-- commit 76f412ab3
+-- DROP OPERATOR @#@(bigint,NONE);
+DROP OPERATOR @#@(NONE,bigint);
+\endif
+
+\if :oldpgversion_84_11
+-- commit 578b22971: OIDS removed in v12
+ALTER TABLE public.tenk1 SET WITHOUT OIDS;
+ALTER TABLE public.tenk1 SET WITHOUT OIDS;
+-- fix_sql="$fix_sql ALTER TABLE public.stud_emp SET WITHOUT OIDS;" # inherited
+ALTER TABLE public.emp SET WITHOUT OIDS;
+ALTER TABLE public.tt7 SET WITHOUT OIDS;
+\endif
diff --git a/src/bin/pg_upgrade/test.sh b/src/bin/pg_upgrade/test.sh
index 2bdd8c19de..61bcca3673 100644
--- a/src/bin/pg_upgrade/test.sh
+++ b/src/bin/pg_upgrade/test.sh
@@ -177,104 +177,9 @@ if "$MAKE" -C "$oldsrc" installcheck-parallel; then
 
 	# before dumping, get rid of objects not feasible in later versions
 	if [ "$newsrc" != "$oldsrc" ]; then
-		fix_sql=""
-		case $oldpgversion in
-			804??)
-				fix_sql="DROP FUNCTION public.myfunc(integer);"
-				;;
-		esac
-		fix_sql="$fix_sql
-				 DROP FUNCTION IF EXISTS
-					public.oldstyle_length(integer, text);"	# last in 9.6 -- commit 5ded4bd21
-		fix_sql="$fix_sql
-				 DROP FUNCTION IF EXISTS
-					public.putenv(text);"	# last in v13
-		# last in v13 commit 76f412ab3
-		# public.!=- This one is only needed for v11+ ??
-		# Note, until v10, operators could only be dropped one at a time
-		fix_sql="$fix_sql
-				 DROP OPERATOR IF EXISTS
-					public.#@# (pg_catalog.int8, NONE);"
-		fix_sql="$fix_sql
-				 DROP OPERATOR IF EXISTS
-					public.#%# (pg_catalog.int8, NONE);"
-		fix_sql="$fix_sql
-				 DROP OPERATOR IF EXISTS
-					public.!=- (pg_catalog.int8, NONE);"
-		fix_sql="$fix_sql
-				 DROP OPERATOR IF EXISTS
-					public.#@%# (pg_catalog.int8, NONE);"
-
-		# commit 068503c76511cdb0080bab689662a20e86b9c845
-		case $oldpgversion in
-			10????)
-				fix_sql="$fix_sql
-					DROP TRANSFORM FOR integer LANGUAGE sql CASCADE;"
-				;;
-		esac
-
-		# commit db3af9feb19f39827e916145f88fa5eca3130cb2
-		case $oldpgversion in
-			10????)
-				fix_sql="$fix_sql
-					DROP FUNCTION boxarea(box);"
-				fix_sql="$fix_sql
-					DROP FUNCTION funny_dup17();"
-				;;
-		esac
-
-		# commit cda6a8d01d391eab45c4b3e0043a1b2b31072f5f
-		case $oldpgversion in
-			10????)
-				fix_sql="$fix_sql
-					DROP TABLE abstime_tbl;"
-				fix_sql="$fix_sql
-					DROP TABLE reltime_tbl;"
-				fix_sql="$fix_sql
-					DROP TABLE tinterval_tbl;"
-				;;
-		esac
-
-		# Various things removed for v14
-		case $oldpgversion in
-			906??|10????|11????|12????|13????)
-				fix_sql="$fix_sql
-					DROP AGGREGATE first_el_agg_any(anyelement);"
-				;;
-		esac
-		case $oldpgversion in
-			90[56]??|10????|11????|12????|13????)
-				# commit 9e38c2bb5 and 97f73a978
-				# fix_sql="$fix_sql DROP AGGREGATE array_larger_accum(anyarray);"
-				fix_sql="$fix_sql
-					DROP AGGREGATE array_cat_accum(anyarray);"
-
-				# commit 76f412ab3
-				#fix_sql="$fix_sql DROP OPERATOR @#@(bigint,NONE);"
-				fix_sql="$fix_sql
-					DROP OPERATOR @#@(NONE,bigint);"
-				;;
-		esac
-
-		# commit 578b22971: OIDS removed in v12
-		case $oldpgversion in
-			804??|9????|10????|11????)
-				fix_sql="$fix_sql
-					ALTER TABLE public.tenk1 SET WITHOUT OIDS;"
-				fix_sql="$fix_sql
-					ALTER TABLE public.tenk1 SET WITHOUT OIDS;"
-				#fix_sql="$fix_sql ALTER TABLE public.stud_emp SET WITHOUT OIDS;" # inherited
-				fix_sql="$fix_sql
-					ALTER TABLE public.emp SET WITHOUT OIDS;"
-				fix_sql="$fix_sql
-					ALTER TABLE public.tt7 SET WITHOUT OIDS;"
-				;;
-		esac
-
-		psql -X -d regression -c "$fix_sql;" || psql_fix_sql_status=$?
+		psql -X -d regression -f "test-upgrade.sql" || psql_fix_sql_status=$?
 	fi
 
-	echo "fix_sql: $oldpgversion: $fix_sql" >&2
 	pg_dumpall --extra-float-digits=0 --no-sync -f "$temp_root"/dump1.sql || pg_dumpall1_status=$?
 
 	if [ "$newsrc" != "$oldsrc" ]; then
-- 
2.17.0


--54u2kuW9sGWg/X+X
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
 filename="v5-0003-pg_upgrade-test-to-exercise-binary-compatibility.patch"



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

* [PATCH v5 4/4] Move pg_upgrade kludges to sql script
@ 2021-03-07 00:35  Justin Pryzby <[email protected]>
  0 siblings, 0 replies; 10+ messages in thread

From: Justin Pryzby @ 2021-03-07 00:35 UTC (permalink / raw)

---
 src/bin/pg_upgrade/test-upgrade.sql | 89 ++++++++++++++++++++++++++
 src/bin/pg_upgrade/test.sh          | 96 +----------------------------
 2 files changed, 90 insertions(+), 95 deletions(-)
 create mode 100644 src/bin/pg_upgrade/test-upgrade.sql

diff --git a/src/bin/pg_upgrade/test-upgrade.sql b/src/bin/pg_upgrade/test-upgrade.sql
new file mode 100644
index 0000000000..3dadd6ea74
--- /dev/null
+++ b/src/bin/pg_upgrade/test-upgrade.sql
@@ -0,0 +1,89 @@
+-- This file has a bunch of kludges needed for upgrading testing across major versions
+
+SELECT
+	ver >= 804 AND ver <= 1100 AS fromv84v11,
+	ver >= 905 AND ver <= 1300 AS fromv95v13,
+	ver >= 906 AND ver <= 1300 AS fromv96v13,
+	ver <= 80400 AS fromv84,
+	ver <= 90500 AS fromv95,
+	ver <= 90600 AS fromv96,
+	ver <= 100000 AS fromv10,
+	ver <= 110000 AS fromv11,
+	ver <= 120000 AS fromv12,
+	ver <= 130000 AS fromv13
+	FROM (SELECT current_setting('server_version_num')::int/100 AS ver) AS v;
+\gset
+
+\if :fromv84
+DROP FUNCTION public.myfunc(integer);
+\endif
+
+-- last in 9.6 -- commit 5ded4bd21
+DROP FUNCTION IF EXISTS public.oldstyle_length(integer, text);
+DROP FUNCTION IF EXISTS public.putenv(text);
+
+\if :fromv13
+-- last in v13 commit 76f412ab3
+-- public.!=- This one is only needed for v11+ ??
+-- Note, until v10, operators could only be dropped one at a time
+DROP OPERATOR IF EXISTS public.#@# (pg_catalog.int8, NONE);
+DROP OPERATOR IF EXISTS public.#%# (pg_catalog.int8, NONE);
+DROP OPERATOR IF EXISTS public.!=- (pg_catalog.int8, NONE);
+DROP OPERATOR IF EXISTS public.#@%# (pg_catalog.int8, NONE);
+\endif
+
+\if :fromv10
+-- commit 068503c76511cdb0080bab689662a20e86b9c845
+DROP TRANSFORM FOR integer LANGUAGE sql CASCADE;
+
+-- commit db3af9feb19f39827e916145f88fa5eca3130cb2
+DROP FUNCTION boxarea(box);
+DROP FUNCTION funny_dup17();
+
+-- commit cda6a8d01d391eab45c4b3e0043a1b2b31072f5f
+DROP TABLE abstime_tbl;
+DROP TABLE reltime_tbl;
+DROP TABLE tinterval_tbl;
+\endif
+
+\if :fromv96v13
+-- Various things removed for v14
+DROP AGGREGATE first_el_agg_any(anyelement);
+\endif
+
+\if :fromv95v13
+-- commit 9e38c2bb5 and 97f73a978
+-- DROP AGGREGATE array_larger_accum(anyarray);
+DROP AGGREGATE array_cat_accum(anyarray);
+
+-- commit 76f412ab3
+-- DROP OPERATOR @#@(bigint,NONE);
+DROP OPERATOR @#@(NONE,bigint);
+\endif
+
+-- \if :fromv84v11
+\if :fromv11
+-- commit 578b22971: OIDS removed in v12
+ALTER TABLE public.tenk1 SET WITHOUT OIDS;
+ALTER TABLE public.tenk1 SET WITHOUT OIDS;
+-- fix_sql="$fix_sql ALTER TABLE public.stud_emp SET WITHOUT OIDS;" # inherited
+ALTER TABLE public.emp SET WITHOUT OIDS;
+ALTER TABLE public.tt7 SET WITHOUT OIDS;
+\endif
+
+-- if [ "$newsrc" != "$oldsrc" ]; then
+-- 	# update references to old source tree's regress.so etc
+-- 	fix_sql=""
+-- 	case $oldpgversion in
+-- 		804??)
+-- 			fix_sql="UPDATE pg_proc SET probin = replace(probin::text, '$oldsrc', '$newsrc')::bytea WHERE probin LIKE '$oldsrc%';"
+-- 			;;
+-- 		*)
+-- 			fix_sql="UPDATE pg_proc SET probin = replace(probin, '$oldsrc', '$newsrc') WHERE probin LIKE '$oldsrc%';"
+-- 			;;
+-- 	esac
+-- 	psql -X -d regression -c "$fix_sql;" || psql_fix_sql_status=$?
+--
+--	mv "$temp_root"/dump1.sql "$temp_root"/dump1.sql.orig
+-- 	sed "s;$oldsrc;$newsrc;g" "$temp_root"/dump1.sql.orig >"$temp_root"/dump1.sql
+-- fi
diff --git a/src/bin/pg_upgrade/test.sh b/src/bin/pg_upgrade/test.sh
index 74c29229ac..a3df427f1d 100644
--- a/src/bin/pg_upgrade/test.sh
+++ b/src/bin/pg_upgrade/test.sh
@@ -178,101 +178,7 @@ if "$MAKE" -C "$oldsrc" installcheck-parallel; then
 
 	# before dumping, get rid of objects not feasible in later versions
 	if [ "$newsrc" != "$oldsrc" ]; then
-		fix_sql=""
-		case $oldpgversion in
-			804??)
-				fix_sql="DROP FUNCTION public.myfunc(integer);"
-				;;
-		esac
-		fix_sql="$fix_sql
-				 DROP FUNCTION IF EXISTS
-					public.oldstyle_length(integer, text);"	# last in 9.6 -- commit 5ded4bd21
-		fix_sql="$fix_sql
-				 DROP FUNCTION IF EXISTS
-					public.putenv(text);"	# last in v13
-		# last in v13 commit 76f412ab3
-		# public.!=- This one is only needed for v11+ ??
-		# Note, until v10, operators could only be dropped one at a time
-		fix_sql="$fix_sql
-				 DROP OPERATOR IF EXISTS
-					public.#@# (pg_catalog.int8, NONE);"
-		fix_sql="$fix_sql
-				 DROP OPERATOR IF EXISTS
-					public.#%# (pg_catalog.int8, NONE);"
-		fix_sql="$fix_sql
-				 DROP OPERATOR IF EXISTS
-					public.!=- (pg_catalog.int8, NONE);"
-		fix_sql="$fix_sql
-				 DROP OPERATOR IF EXISTS
-					public.#@%# (pg_catalog.int8, NONE);"
-
-		# commit 068503c76511cdb0080bab689662a20e86b9c845
-		case $oldpgversion in
-			10????)
-				fix_sql="$fix_sql
-					DROP TRANSFORM FOR integer LANGUAGE sql CASCADE;"
-				;;
-		esac
-
-		# commit db3af9feb19f39827e916145f88fa5eca3130cb2
-		case $oldpgversion in
-			10????)
-				fix_sql="$fix_sql
-					DROP FUNCTION boxarea(box);"
-				fix_sql="$fix_sql
-					DROP FUNCTION funny_dup17();"
-				;;
-		esac
-
-		# commit cda6a8d01d391eab45c4b3e0043a1b2b31072f5f
-		case $oldpgversion in
-			10????)
-				fix_sql="$fix_sql
-					DROP TABLE abstime_tbl;"
-				fix_sql="$fix_sql
-					DROP TABLE reltime_tbl;"
-				fix_sql="$fix_sql
-					DROP TABLE tinterval_tbl;"
-				;;
-		esac
-
-		# Various things removed for v14
-		case $oldpgversion in
-			906??|10????|11????|12????|13????)
-				fix_sql="$fix_sql
-					DROP AGGREGATE first_el_agg_any(anyelement);"
-				;;
-		esac
-		case $oldpgversion in
-			90[56]??|10????|11????|12????|13????)
-				# commit 9e38c2bb5 and 97f73a978
-				# fix_sql="$fix_sql DROP AGGREGATE array_larger_accum(anyarray);"
-				fix_sql="$fix_sql
-					DROP AGGREGATE array_cat_accum(anyarray);"
-
-				# commit 76f412ab3
-				#fix_sql="$fix_sql DROP OPERATOR @#@(bigint,NONE);"
-				fix_sql="$fix_sql
-					DROP OPERATOR @#@(NONE,bigint);"
-				;;
-		esac
-
-		# commit 578b22971: OIDS removed in v12
-		case $oldpgversion in
-			804??|9????|10????|11????)
-				fix_sql="$fix_sql
-					ALTER TABLE public.tenk1 SET WITHOUT OIDS;"
-				fix_sql="$fix_sql
-					ALTER TABLE public.tenk1 SET WITHOUT OIDS;"
-				#fix_sql="$fix_sql ALTER TABLE public.stud_emp SET WITHOUT OIDS;" # inherited
-				fix_sql="$fix_sql
-					ALTER TABLE public.emp SET WITHOUT OIDS;"
-				fix_sql="$fix_sql
-					ALTER TABLE public.tt7 SET WITHOUT OIDS;"
-				;;
-		esac
-
-		psql -X -d regression -c "$fix_sql;" || psql_fix_sql_status=$?
+		psql -X -d regression -f "test-upgrade.sql" || psql_fix_sql_status=$?
 	fi
 
 	echo "fix_sql: $oldpgversion: $fix_sql" >&2
-- 
2.17.0


--EuxKj2iCbKjpUGkD--





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

* [PATCH v6 2/2] Move pg_upgrade kludges to sql script
@ 2021-03-07 00:35  Justin Pryzby <[email protected]>
  0 siblings, 0 replies; 10+ messages in thread

From: Justin Pryzby @ 2021-03-07 00:35 UTC (permalink / raw)

NOTE, "IF EXISTS" isn't necessary in fa66b6dee
---
 src/bin/pg_upgrade/test-upgrade.sql | 51 +++++++++++++++++++++++++++++
 src/bin/pg_upgrade/test.sh          | 48 +--------------------------
 2 files changed, 52 insertions(+), 47 deletions(-)
 create mode 100644 src/bin/pg_upgrade/test-upgrade.sql

diff --git a/src/bin/pg_upgrade/test-upgrade.sql b/src/bin/pg_upgrade/test-upgrade.sql
new file mode 100644
index 0000000000..74fad312cb
--- /dev/null
+++ b/src/bin/pg_upgrade/test-upgrade.sql
@@ -0,0 +1,51 @@
+-- This file has a bunch of kludges needed for testing upgrades across major versions
+-- It supports testing the most recent version of an old release (not any arbitrary minor version).
+
+SELECT
+	ver <= 804 AS oldpgversion_le84,
+	ver < 1000 AS oldpgversion_lt10,
+	ver < 1200 AS oldpgversion_lt12,
+	ver < 1400 AS oldpgversion_lt14
+	FROM (SELECT current_setting('server_version_num')::int/100 AS ver) AS v;
+\gset
+
+\if :oldpgversion_le84
+DROP FUNCTION public.myfunc(integer);
+\endif
+
+\if :oldpgversion_lt10
+-- last in 9.6 -- commit 5ded4bd21
+DROP FUNCTION public.oldstyle_length(integer, text);
+\endif
+
+\if :oldpgversion_lt14
+-- last in v13 commit 7ca37fb04
+DROP FUNCTION IF EXISTS public.putenv(text);
+-- last in v13 commit 76f412ab3
+-- public.!=- This one is only needed for v11+ ??
+-- Note, until v10, operators could only be dropped one at a time
+DROP OPERATOR public.#@# (pg_catalog.int8, NONE);
+DROP OPERATOR public.#%# (pg_catalog.int8, NONE);
+DROP OPERATOR public.!=- (pg_catalog.int8, NONE);
+DROP OPERATOR public.#@%# (pg_catalog.int8, NONE);
+\endif
+
+\if :oldpgversion_lt12
+-- WITH OIDS is not supported anymore in v12, so remove support
+-- for any relations marked as such.
+DO $stmt$
+	DECLARE
+		rec text;
+	BEGIN
+	FOR rec in
+		SELECT oid::regclass::text
+		FROM pg_class
+		WHERE relname !~ '^pg_'
+			AND relhasoids
+			AND relkind in ('r','m')
+		ORDER BY 1
+	LOOP
+		execute 'ALTER TABLE ' || rec || ' SET WITHOUT OIDS';
+	END LOOP;
+	END; $stmt$;
+\endif
diff --git a/src/bin/pg_upgrade/test.sh b/src/bin/pg_upgrade/test.sh
index 8593488907..46a1ebb4ab 100644
--- a/src/bin/pg_upgrade/test.sh
+++ b/src/bin/pg_upgrade/test.sh
@@ -181,53 +181,7 @@ if "$MAKE" -C "$oldsrc" installcheck-parallel; then
 	# Before dumping, tweak the database of the old instance depending
 	# on its version.
 	if [ "$newsrc" != "$oldsrc" ]; then
-		fix_sql=""
-		# Get rid of objects not feasible in later versions
-		case $oldpgversion in
-			804??)
-				fix_sql="DROP FUNCTION public.myfunc(integer);"
-				;;
-		esac
-
-		# Last appeared in v9.6
-		if [ $oldpgversion -lt 100000 ]; then
-			fix_sql="$fix_sql
-					 DROP FUNCTION IF EXISTS
-						public.oldstyle_length(integer, text);"
-		fi
-		# Last appeared in v13
-		if [ $oldpgversion -lt 140000 ]; then
-			fix_sql="$fix_sql
-				 DROP FUNCTION IF EXISTS
-					public.putenv(text);	-- last in v13
-				 DROP OPERATOR IF EXISTS	-- last in v13
-					public.#@# (pg_catalog.int8, NONE),
-					public.#%# (pg_catalog.int8, NONE),
-					public.!=- (pg_catalog.int8, NONE),
-					public.#@%# (pg_catalog.int8, NONE);"
-		fi
-		psql -X -d regression -c "$fix_sql;" || psql_fix_sql_status=$?
-
-		# WITH OIDS is not supported anymore in v12, so remove support
-		# for any relations marked as such.
-		if [ $oldpgversion -lt 120000 ]; then
-			fix_sql="DO \$stmt\$
-				DECLARE
-					rec text;
-				BEGIN
-				FOR rec in
-					SELECT oid::regclass::text
-					FROM pg_class
-					WHERE relname !~ '^pg_'
-						AND relhasoids
-						AND relkind in ('r','m')
-					ORDER BY 1
-				LOOP
-					execute 'ALTER TABLE ' || rec || ' SET WITHOUT OIDS';
-				END LOOP;
-				END; \$stmt\$;"
-			psql -X -d regression -c "$fix_sql;" || psql_fix_sql_status=$?
-		fi
+		psql -X -d regression -f "test-upgrade.sql" || psql_fix_sql_status=$?
 
 		# Handling of --extra-float-digits gets messy after v12.
 		# Note that this changes the dumps from the old and new
-- 
2.17.0


--g4MvFqI7wmANiPDo--





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

* [PATCH v7 1/2] Move pg_upgrade kludges to sql script
@ 2021-03-07 00:35  Justin Pryzby <[email protected]>
  0 siblings, 0 replies; 10+ messages in thread

From: Justin Pryzby @ 2021-03-07 00:35 UTC (permalink / raw)

NOTE, "IF EXISTS" isn't necessary in fa66b6dee
---
 src/bin/pg_upgrade/test-upgrade.sql | 52 +++++++++++++++++++++++++++++
 src/bin/pg_upgrade/test.sh          | 48 +-------------------------
 2 files changed, 53 insertions(+), 47 deletions(-)
 create mode 100644 src/bin/pg_upgrade/test-upgrade.sql

diff --git a/src/bin/pg_upgrade/test-upgrade.sql b/src/bin/pg_upgrade/test-upgrade.sql
new file mode 100644
index 0000000000..5d74232c2b
--- /dev/null
+++ b/src/bin/pg_upgrade/test-upgrade.sql
@@ -0,0 +1,52 @@
+-- This file has a bunch of kludges needed for testing upgrades across major versions
+-- It supports testing the most recent version of an old release (not any arbitrary minor version).
+
+SELECT
+	ver <= 804 AS oldpgversion_le84,
+	ver < 1000 AS oldpgversion_lt10,
+	ver < 1200 AS oldpgversion_lt12,
+	ver < 1400 AS oldpgversion_lt14
+	FROM (SELECT current_setting('server_version_num')::int/100 AS ver) AS v;
+\gset
+
+\if :oldpgversion_le84
+DROP FUNCTION public.myfunc(integer);
+\endif
+
+\if :oldpgversion_lt10
+-- last in 9.6 -- commit 5ded4bd21
+DROP FUNCTION public.oldstyle_length(integer, text);
+\endif
+
+\if :oldpgversion_lt14
+-- last in v13 commit 7ca37fb04
+DROP FUNCTION IF EXISTS public.putenv(text);
+
+-- last in v13 commit 76f412ab3
+-- public.!=- This one is only needed for v11+ ??
+-- Note, until v10, operators could only be dropped one at a time
+DROP OPERATOR public.#@# (pg_catalog.int8, NONE);
+DROP OPERATOR public.#%# (pg_catalog.int8, NONE);
+DROP OPERATOR public.!=- (pg_catalog.int8, NONE);
+DROP OPERATOR public.#@%# (pg_catalog.int8, NONE);
+\endif
+
+\if :oldpgversion_lt12
+-- WITH OIDS is not supported anymore in v12, so remove support
+-- for any relations marked as such.
+DO $stmt$
+	DECLARE
+		rec text;
+	BEGIN
+	FOR rec in
+		SELECT oid::regclass::text
+		FROM pg_class
+		WHERE relname !~ '^pg_'
+			AND relhasoids
+			AND relkind in ('r','m')
+		ORDER BY 1
+	LOOP
+		execute 'ALTER TABLE ' || rec || ' SET WITHOUT OIDS';
+	END LOOP;
+	END; $stmt$;
+\endif
diff --git a/src/bin/pg_upgrade/test.sh b/src/bin/pg_upgrade/test.sh
index 8593488907..46a1ebb4ab 100644
--- a/src/bin/pg_upgrade/test.sh
+++ b/src/bin/pg_upgrade/test.sh
@@ -181,53 +181,7 @@ if "$MAKE" -C "$oldsrc" installcheck-parallel; then
 	# Before dumping, tweak the database of the old instance depending
 	# on its version.
 	if [ "$newsrc" != "$oldsrc" ]; then
-		fix_sql=""
-		# Get rid of objects not feasible in later versions
-		case $oldpgversion in
-			804??)
-				fix_sql="DROP FUNCTION public.myfunc(integer);"
-				;;
-		esac
-
-		# Last appeared in v9.6
-		if [ $oldpgversion -lt 100000 ]; then
-			fix_sql="$fix_sql
-					 DROP FUNCTION IF EXISTS
-						public.oldstyle_length(integer, text);"
-		fi
-		# Last appeared in v13
-		if [ $oldpgversion -lt 140000 ]; then
-			fix_sql="$fix_sql
-				 DROP FUNCTION IF EXISTS
-					public.putenv(text);	-- last in v13
-				 DROP OPERATOR IF EXISTS	-- last in v13
-					public.#@# (pg_catalog.int8, NONE),
-					public.#%# (pg_catalog.int8, NONE),
-					public.!=- (pg_catalog.int8, NONE),
-					public.#@%# (pg_catalog.int8, NONE);"
-		fi
-		psql -X -d regression -c "$fix_sql;" || psql_fix_sql_status=$?
-
-		# WITH OIDS is not supported anymore in v12, so remove support
-		# for any relations marked as such.
-		if [ $oldpgversion -lt 120000 ]; then
-			fix_sql="DO \$stmt\$
-				DECLARE
-					rec text;
-				BEGIN
-				FOR rec in
-					SELECT oid::regclass::text
-					FROM pg_class
-					WHERE relname !~ '^pg_'
-						AND relhasoids
-						AND relkind in ('r','m')
-					ORDER BY 1
-				LOOP
-					execute 'ALTER TABLE ' || rec || ' SET WITHOUT OIDS';
-				END LOOP;
-				END; \$stmt\$;"
-			psql -X -d regression -c "$fix_sql;" || psql_fix_sql_status=$?
-		fi
+		psql -X -d regression -f "test-upgrade.sql" || psql_fix_sql_status=$?
 
 		# Handling of --extra-float-digits gets messy after v12.
 		# Note that this changes the dumps from the old and new
-- 
2.17.0


--qD80nKKiJWXm4UaL
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
 filename="v7-0002-wip-support-pg_upgrade-from-older-versions.patch"



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

* as per commit 643a1a61985bef2590496, move create/open dir code to function using switch case of pg_backup_directory.c file also
@ 2025-04-07 12:25  Mahendra Singh Thalor <[email protected]>
  0 siblings, 1 reply; 10+ messages in thread

From: Mahendra Singh Thalor @ 2025-04-07 12:25 UTC (permalink / raw)
  To: PostgreSQL Hackers <[email protected]>; +Cc: Andrew Dunstan <[email protected]>

Hi,
In commit 643a1a61985bef2590496, we did some cleanup and we replaced
if-else with switch case.
Basically, we made a function to open a directory in pg_dumpall.
In pg_backup_directory.c file also, we are opening a directory with if-else.
Here, I am attaching a patch which makes both the files similar.

We can move this similar function into one common file also but as of now,
I made a static function same as pg_dumpall.c.

-- 
Thanks and Regards
Mahendra Singh Thalor
EnterpriseDB: http://www.enterprisedb.com


Attachments:

  [application/octet-stream] v01_move-create-dir-code-to-the-switch-in-pg_backup_dir.patch (3.3K, ../../CAKYtNApO30tdtRfe6rJK59pj6Mr=xW8hQELJ8+Vz95goHk3pQg@mail.gmail.com/3-v01_move-create-dir-code-to-the-switch-in-pg_backup_dir.patch)
  download | inline diff:
From 0a2222476df6eea6f4ffba176395b589d42b22be Mon Sep 17 00:00:00 2001
From: Mahendra Singh Thalor <[email protected]>
Date: Mon, 7 Apr 2025 17:43:05 +0530
Subject: [PATCH] move create dir code to the switch as per commit in
 pg_dumpall

in commit 643a1a61985bef2590496, we moved code of create/open directory
into switch case.
Same code we are using in InitArchiveFmt_Directory also.
(file: src/bin/pg_dump/pg_backup_directory.c)

As per pg_dumpall, we can make same here.

If we want, we can move common code to other common file also.
---
 src/bin/pg_dump/pg_backup_directory.c | 71 ++++++++++++++-------------
 1 file changed, 37 insertions(+), 34 deletions(-)

diff --git a/src/bin/pg_dump/pg_backup_directory.c b/src/bin/pg_dump/pg_backup_directory.c
index b2a841bb0ff..7db1bae334b 100644
--- a/src/bin/pg_dump/pg_backup_directory.c
+++ b/src/bin/pg_dump/pg_backup_directory.c
@@ -39,6 +39,7 @@
 #include <dirent.h>
 #include <sys/stat.h>
 
+#include "common/file_perm.h"
 #include "common/file_utils.h"
 #include "compress_io.h"
 #include "parallel.h"
@@ -94,6 +95,7 @@ static int	_WorkerJobDumpDirectory(ArchiveHandle *AH, TocEntry *te);
 
 static void setFilePath(ArchiveHandle *AH, char *buf,
 						const char *relativeFilename);
+static void create_or_open_dir(const char *dirname);
 
 /*
  *	Init routine required by ALL formats. This is a global routine
@@ -156,41 +158,8 @@ InitArchiveFmt_Directory(ArchiveHandle *AH)
 
 	if (AH->mode == archModeWrite)
 	{
-		struct stat st;
-		bool		is_empty = false;
-
 		/* we accept an empty existing directory */
-		if (stat(ctx->directory, &st) == 0 && S_ISDIR(st.st_mode))
-		{
-			DIR		   *dir = opendir(ctx->directory);
-
-			if (dir)
-			{
-				struct dirent *d;
-
-				is_empty = true;
-				while (errno = 0, (d = readdir(dir)))
-				{
-					if (strcmp(d->d_name, ".") != 0 && strcmp(d->d_name, "..") != 0)
-					{
-						is_empty = false;
-						break;
-					}
-				}
-
-				if (errno)
-					pg_fatal("could not read directory \"%s\": %m",
-							 ctx->directory);
-
-				if (closedir(dir))
-					pg_fatal("could not close directory \"%s\": %m",
-							 ctx->directory);
-			}
-		}
-
-		if (!is_empty && mkdir(ctx->directory, 0700) < 0)
-			pg_fatal("could not create directory \"%s\": %m",
-					 ctx->directory);
+		create_or_open_dir(ctx->directory);
 	}
 	else
 	{							/* Read Mode */
@@ -875,3 +844,37 @@ _WorkerJobRestoreDirectory(ArchiveHandle *AH, TocEntry *te)
 {
 	return parallel_restore(AH, te);
 }
+
+/*
+ * create_or_open_dir
+ *
+ * This will create a new directory with the given dirname. If there is
+ * already an empty directory with that name, then use it.
+ */
+void
+create_or_open_dir(const char *dirname)
+{
+	int		ret;
+
+	switch ((ret = pg_check_dir(dirname)))
+	{
+		case -1:
+			/* opendir failed but not with ENOENT */
+			pg_fatal("could not open directory \"%s\": %m", dirname);
+			break;
+		case 0:
+			/* directory does not exist */
+			if (mkdir(dirname, pg_dir_create_mode) < 0)
+				pg_fatal("could not create directory \"%s\": %m", dirname);
+			break;
+		case 1:
+			/* exists and is empty, fix perms */
+			if (chmod(dirname, pg_dir_create_mode) != 0)
+				pg_fatal("could not change permissions of directory \"%s\": %m",
+						dirname);
+			break;
+		default:
+			/* exists and is not empty */
+			pg_fatal("directory \"%s\" is not empty", dirname);
+	}
+}
-- 
2.39.3



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

* Re: as per commit 643a1a61985bef2590496, move create/open dir code to function using switch case of pg_backup_directory.c file also
@ 2025-04-07 13:22  Andrew Dunstan <[email protected]>
  parent: Mahendra Singh Thalor <[email protected]>
  0 siblings, 1 reply; 10+ messages in thread

From: Andrew Dunstan @ 2025-04-07 13:22 UTC (permalink / raw)
  To: Mahendra Singh Thalor <[email protected]>; PostgreSQL Hackers <[email protected]>


On 2025-04-07 Mo 8:25 AM, Mahendra Singh Thalor wrote:
> Hi,
> In commit 643a1a61985bef2590496, we did some cleanup and we replaced 
> if-else with switch case.
> Basically, we made a function to open a directory in pg_dumpall. 
> In pg_backup_directory.c file also, we are opening a directory with 
> if-else.
> Here, I am attaching a patch which makes both the files similar.
>
> We can move this similar function into one common file also but as of 
> now, I made a static function same as pg_dumpall.c.


Yeah, let's put it in a common file. There's no point in duplicating it.


cheers


andrew



--
Andrew Dunstan
EDB: https://www.enterprisedb.com






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

* Re: as per commit 643a1a61985bef2590496, move create/open dir code to function using switch case of pg_backup_directory.c file also
@ 2025-04-07 18:59  Mahendra Singh Thalor <[email protected]>
  parent: Andrew Dunstan <[email protected]>
  0 siblings, 2 replies; 10+ messages in thread

From: Mahendra Singh Thalor @ 2025-04-07 18:59 UTC (permalink / raw)
  To: Andrew Dunstan <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>

On Mon, 7 Apr 2025 at 18:52, Andrew Dunstan <[email protected]> wrote:
>
>
> On 2025-04-07 Mo 8:25 AM, Mahendra Singh Thalor wrote:
> > Hi,
> > In commit 643a1a61985bef2590496, we did some cleanup and we replaced
> > if-else with switch case.
> > Basically, we made a function to open a directory in pg_dumpall.
> > In pg_backup_directory.c file also, we are opening a directory with
> > if-else.
> > Here, I am attaching a patch which makes both the files similar.
> >
> > We can move this similar function into one common file also but as of
> > now, I made a static function same as pg_dumpall.c.
>
>
> Yeah, let's put it in a common file. There's no point in duplicating it.

Thanks Andrew.

I moved this common function dumputils.c file. Here, I am attaching a
patch for the same.


-- 
Thanks and Regards
Mahendra Singh Thalor
EnterpriseDB: http://www.enterprisedb.com


Attachments:

  [application/octet-stream] v02_move-create-dir-code-to-the-switch-in-pg_backup_dir.patch (5.7K, ../../CAKYtNApihL8X1h7XO-zOjznc8Ca66Aevgvhc9zOTh6DBh2iaeA@mail.gmail.com/2-v02_move-create-dir-code-to-the-switch-in-pg_backup_dir.patch)
  download | inline diff:
From 5554ac118a137aa9808f20c02f5a185d637749ec Mon Sep 17 00:00:00 2001
From: Mahendra Singh Thalor <[email protected]>
Date: Tue, 8 Apr 2025 00:25:02 +0530
Subject: [PATCH] Move code of create/open dir to the switch as per commit in
 pg_dumpall and move it to commom file (dumputils.c)

in commit 643a1a61985bef2590496, we moved code of create/open directory
into switch case.
Same code we are using in InitArchiveFmt_Directory also.
(file: src/bin/pg_dump/pg_backup_directory.c)

Removing duplicate code by moving function into dumputils.c file.
---
 src/bin/pg_dump/dumputils.c           | 36 ++++++++++++++++++++++++++
 src/bin/pg_dump/dumputils.h           |  1 +
 src/bin/pg_dump/pg_backup_directory.c | 36 ++------------------------
 src/bin/pg_dump/pg_dumpall.c          | 37 ---------------------------
 4 files changed, 39 insertions(+), 71 deletions(-)

diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c
index ab0e9e6da3c..1d8ffe363e7 100644
--- a/src/bin/pg_dump/dumputils.c
+++ b/src/bin/pg_dump/dumputils.c
@@ -16,6 +16,8 @@
 
 #include <ctype.h>
 
+#include "common/file_perm.h"
+#include "common/logging.h"
 #include "dumputils.h"
 #include "fe_utils/string_utils.h"
 
@@ -884,3 +886,37 @@ makeAlterConfigCommand(PGconn *conn, const char *configitem,
 
 	pg_free(mine);
 }
+
+/*
+ * create_or_open_dir
+ *
+ * This will create a new directory with the given dirname. If there is
+ * already an empty directory with that name, then use it.
+ */
+void
+create_or_open_dir(const char *dirname)
+{
+	int		ret;
+
+	switch ((ret = pg_check_dir(dirname)))
+	{
+		case -1:
+			/* opendir failed but not with ENOENT */
+			pg_fatal("could not open directory \"%s\": %m", dirname);
+			break;
+		case 0:
+			/* directory does not exist */
+			if (mkdir(dirname, pg_dir_create_mode) < 0)
+				pg_fatal("could not create directory \"%s\": %m", dirname);
+			break;
+		case 1:
+			/* exists and is empty, fix perms */
+			if (chmod(dirname, pg_dir_create_mode) != 0)
+				pg_fatal("could not change permissions of directory \"%s\": %m",
+						dirname);
+			break;
+		default:
+			/* exists and is not empty */
+			pg_fatal("directory \"%s\" is not empty", dirname);
+	}
+}
diff --git a/src/bin/pg_dump/dumputils.h b/src/bin/pg_dump/dumputils.h
index a4bd16857ce..91c6e612e28 100644
--- a/src/bin/pg_dump/dumputils.h
+++ b/src/bin/pg_dump/dumputils.h
@@ -62,5 +62,6 @@ extern void makeAlterConfigCommand(PGconn *conn, const char *configitem,
 								   const char *type, const char *name,
 								   const char *type2, const char *name2,
 								   PQExpBuffer buf);
+extern void create_or_open_dir(const char *dirname);
 
 #endif							/* DUMPUTILS_H */
diff --git a/src/bin/pg_dump/pg_backup_directory.c b/src/bin/pg_dump/pg_backup_directory.c
index b2a841bb0ff..21b00792a8a 100644
--- a/src/bin/pg_dump/pg_backup_directory.c
+++ b/src/bin/pg_dump/pg_backup_directory.c
@@ -41,6 +41,7 @@
 
 #include "common/file_utils.h"
 #include "compress_io.h"
+#include "dumputils.h"
 #include "parallel.h"
 #include "pg_backup_utils.h"
 
@@ -156,41 +157,8 @@ InitArchiveFmt_Directory(ArchiveHandle *AH)
 
 	if (AH->mode == archModeWrite)
 	{
-		struct stat st;
-		bool		is_empty = false;
-
 		/* we accept an empty existing directory */
-		if (stat(ctx->directory, &st) == 0 && S_ISDIR(st.st_mode))
-		{
-			DIR		   *dir = opendir(ctx->directory);
-
-			if (dir)
-			{
-				struct dirent *d;
-
-				is_empty = true;
-				while (errno = 0, (d = readdir(dir)))
-				{
-					if (strcmp(d->d_name, ".") != 0 && strcmp(d->d_name, "..") != 0)
-					{
-						is_empty = false;
-						break;
-					}
-				}
-
-				if (errno)
-					pg_fatal("could not read directory \"%s\": %m",
-							 ctx->directory);
-
-				if (closedir(dir))
-					pg_fatal("could not close directory \"%s\": %m",
-							 ctx->directory);
-			}
-		}
-
-		if (!is_empty && mkdir(ctx->directory, 0700) < 0)
-			pg_fatal("could not create directory \"%s\": %m",
-					 ctx->directory);
+		create_or_open_dir(ctx->directory);
 	}
 	else
 	{							/* Read Mode */
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index 18b544b0214..1f272b7525b 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -15,7 +15,6 @@
 
 #include "postgres_fe.h"
 
-#include <sys/stat.h>
 #include <time.h>
 #include <unistd.h>
 
@@ -78,7 +77,6 @@ static void executeCommand(PGconn *conn, const char *query);
 static void expand_dbname_patterns(PGconn *conn, SimpleStringList *patterns,
 								   SimpleStringList *names);
 static void read_dumpall_filters(const char *filename, SimpleStringList *pattern);
-static void create_or_open_dir(const char *dirname);
 static ArchiveFormat parseDumpFormat(const char *format);
 
 static char pg_dump_bin[MAXPGPATH];
@@ -1946,41 +1944,6 @@ read_dumpall_filters(const char *filename, SimpleStringList *pattern)
 	filter_free(&fstate);
 }
 
-/*
- * create_or_open_dir
- *
- * This will create a new directory with the given dirname. If there is
- * already an empty directory with that name, then use it.
- */
-static void
-create_or_open_dir(const char *dirname)
-{
-	int			ret;
-
-	switch ((ret = pg_check_dir(dirname)))
-	{
-		case -1:
-			/* opendir failed but not with ENOENT */
-			pg_fatal("could not open directory \"%s\": %m", dirname);
-			break;
-		case 0:
-			/* directory does not exist */
-			if (mkdir(dirname, pg_dir_create_mode) < 0)
-				pg_fatal("could not create directory \"%s\": %m", dirname);
-			break;
-		case 1:
-			/* exists and is empty, fix perms */
-			if (chmod(dirname, pg_dir_create_mode) != 0)
-				pg_fatal("could not change permissions of directory \"%s\": %m",
-						 dirname);
-
-			break;
-		default:
-			/* exists and is not empty */
-			pg_fatal("directory \"%s\" is not empty", dirname);
-	}
-}
-
 /*
  * parseDumpFormat
  *
-- 
2.39.3



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

* Re: as per commit 643a1a61985bef2590496, move create/open dir code to function using switch case of pg_backup_directory.c file also
@ 2025-04-10 16:17  Andrew Dunstan <[email protected]>
  parent: Mahendra Singh Thalor <[email protected]>
  1 sibling, 1 reply; 10+ messages in thread

From: Andrew Dunstan @ 2025-04-10 16:17 UTC (permalink / raw)
  To: Mahendra Singh Thalor <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>


On 2025-04-07 Mo 2:59 PM, Mahendra Singh Thalor wrote:
> On Mon, 7 Apr 2025 at 18:52, Andrew Dunstan <[email protected]> wrote:
>>
>> On 2025-04-07 Mo 8:25 AM, Mahendra Singh Thalor wrote:
>>> Hi,
>>> In commit 643a1a61985bef2590496, we did some cleanup and we replaced
>>> if-else with switch case.
>>> Basically, we made a function to open a directory in pg_dumpall.
>>> In pg_backup_directory.c file also, we are opening a directory with
>>> if-else.
>>> Here, I am attaching a patch which makes both the files similar.
>>>
>>> We can move this similar function into one common file also but as of
>>> now, I made a static function same as pg_dumpall.c.
>>
>> Yeah, let's put it in a common file. There's no point in duplicating it.
> Thanks Andrew.
>
> I moved this common function dumputils.c file. Here, I am attaching a
> patch for the same.
>
>


Pushed with a slight tweaking.


cheers


andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com






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

* Re: as per commit 643a1a61985bef2590496, move create/open dir code to function using switch case of pg_backup_directory.c file also
@ 2025-04-10 17:12  Mahendra Singh Thalor <[email protected]>
  parent: Andrew Dunstan <[email protected]>
  0 siblings, 0 replies; 10+ messages in thread

From: Mahendra Singh Thalor @ 2025-04-10 17:12 UTC (permalink / raw)
  To: Andrew Dunstan <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>

On Thu, 10 Apr 2025 at 21:48, Andrew Dunstan <[email protected]> wrote:
>
>
> On 2025-04-07 Mo 2:59 PM, Mahendra Singh Thalor wrote:
> > On Mon, 7 Apr 2025 at 18:52, Andrew Dunstan <[email protected]> wrote:
> >>
> >> On 2025-04-07 Mo 8:25 AM, Mahendra Singh Thalor wrote:
> >>> Hi,
> >>> In commit 643a1a61985bef2590496, we did some cleanup and we replaced
> >>> if-else with switch case.
> >>> Basically, we made a function to open a directory in pg_dumpall.
> >>> In pg_backup_directory.c file also, we are opening a directory with
> >>> if-else.
> >>> Here, I am attaching a patch which makes both the files similar.
> >>>
> >>> We can move this similar function into one common file also but as of
> >>> now, I made a static function same as pg_dumpall.c.
> >>
> >> Yeah, let's put it in a common file. There's no point in duplicating it.
> > Thanks Andrew.
> >
> > I moved this common function dumputils.c file. Here, I am attaching a
> > patch for the same.
> >
> >
>
>
> Pushed with a slight tweaking.
>
>
> cheers
>
>
> andrew
>
> --
> Andrew Dunstan
> EDB: https://www.enterprisedb.com
>

Thanks Andrew for committing this.

-- 
Thanks and Regards
Mahendra Singh Thalor
EnterpriseDB: http://www.enterprisedb.com





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

* Re: as per commit 643a1a61985bef2590496, move create/open dir code to function using switch case of pg_backup_directory.c file also
@ 2025-04-11 12:07  Álvaro Herrera <[email protected]>
  parent: Mahendra Singh Thalor <[email protected]>
  1 sibling, 0 replies; 10+ messages in thread

From: Álvaro Herrera @ 2025-04-11 12:07 UTC (permalink / raw)
  To: Mahendra Singh Thalor <[email protected]>; +Cc: Andrew Dunstan <[email protected]>; PostgreSQL Hackers <[email protected]>

I don't understand why the routine is called "create_or_open_dir".  In
what sense does this open the directory?  I think "check_or_create_dir"
would be closer to what this seem to be doing.

Is there no TOCTTOU bug in pg_dumpall because of the way this code is
written?  A malicious user that can create an empty directory that
pg_dumpall is going to use as output destination could remove it after
the opendir(), then replace it with another directory with a symlink
called "global.dat" that causes some other file to be overwritten with
the privileges of the user running pg_dumpall.  Maybe there's no problem
here, but I don't see what the explanation for that is.

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/





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


end of thread, other threads:[~2025-04-11 12:07 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-03-07 00:35 [PATCH v6 2/2] Move pg_upgrade kludges to sql script Justin Pryzby <[email protected]>
2021-03-07 00:35 [PATCH v5 4/4] Move pg_upgrade kludges to sql script Justin Pryzby <[email protected]>
2021-03-07 00:35 [PATCH v5 4/4] Move pg_upgrade kludges to sql script Justin Pryzby <[email protected]>
2021-03-07 00:35 [PATCH v7 1/2] Move pg_upgrade kludges to sql script Justin Pryzby <[email protected]>
2025-04-07 12:25 as per commit 643a1a61985bef2590496, move create/open dir code to function using switch case of pg_backup_directory.c file also Mahendra Singh Thalor <[email protected]>
2025-04-07 13:22 ` Re: as per commit 643a1a61985bef2590496, move create/open dir code to function using switch case of pg_backup_directory.c file also Andrew Dunstan <[email protected]>
2025-04-07 18:59   ` Re: as per commit 643a1a61985bef2590496, move create/open dir code to function using switch case of pg_backup_directory.c file also Mahendra Singh Thalor <[email protected]>
2025-04-10 16:17     ` Re: as per commit 643a1a61985bef2590496, move create/open dir code to function using switch case of pg_backup_directory.c file also Andrew Dunstan <[email protected]>
2025-04-10 17:12       ` Re: as per commit 643a1a61985bef2590496, move create/open dir code to function using switch case of pg_backup_directory.c file also Mahendra Singh Thalor <[email protected]>
2025-04-11 12:07     ` Re: as per commit 643a1a61985bef2590496, move create/open dir code to function using switch case of pg_backup_directory.c file also Álvaro Herrera <[email protected]>

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