Adjust new pg_read_file() test cases for more portability.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 30 Jul 2022 15:17:07 +0000 (11:17 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 30 Jul 2022 15:17:07 +0000 (11:17 -0400)
It's allowed for an installation to remove postgresql.auto.conf,
so don't rely on that being present.  Instead probe whether we can
read postmaster.pid.  (If you've removed that, you broke the data
directory's multiple-postmaster interlock, not to mention pg_ctl.)
Per gripe from Michael Paquier.

Discussion: https://postgr.es/m/YuSZTsoBMObyY+vT@paquier.xyz

src/test/regress/expected/misc_functions.out
src/test/regress/sql/misc_functions.sql

index ca82d91f1af857dd976cdd18717b8ac9ac4b0f48..9f106c2a108e680e6df46714e27fb489db3ac904 100644 (file)
@@ -373,16 +373,16 @@ select count(*) >= 0 as ok from pg_ls_archive_statusdir();
 (1 row)
 
 -- pg_read_file()
-select length(pg_read_file('postgresql.auto.conf')) > 30;
+select length(pg_read_file('postmaster.pid')) > 20;
  ?column? 
 ----------
  t
 (1 row)
 
-select length(pg_read_file('postgresql.auto.conf', 1, 30));
+select length(pg_read_file('postmaster.pid', 1, 20));
  length 
 --------
-     30
+     20
 (1 row)
 
 -- Test missing_ok
@@ -400,16 +400,16 @@ ERROR:  requested length cannot be negative
 select pg_read_file('does not exist', 0, -1, true); -- error
 ERROR:  requested length cannot be negative
 -- pg_read_binary_file()
-select length(pg_read_binary_file('postgresql.auto.conf')) > 30;
+select length(pg_read_binary_file('postmaster.pid')) > 20;
  ?column? 
 ----------
  t
 (1 row)
 
-select length(pg_read_binary_file('postgresql.auto.conf', 1, 30));
+select length(pg_read_binary_file('postmaster.pid', 1, 20));
  length 
 --------
-     30
+     20
 (1 row)
 
 -- Test missing_ok
@@ -427,7 +427,7 @@ ERROR:  requested length cannot be negative
 select pg_read_binary_file('does not exist', 0, -1, true); -- error
 ERROR:  requested length cannot be negative
 -- pg_stat_file()
-select size > 30, isdir from pg_stat_file('postgresql.auto.conf');
+select size > 20, isdir from pg_stat_file('postmaster.pid');
  ?column? | isdir 
 ----------+-------
  t        | f
index 30212103cafda834b67c42e0618aa756514170af..639e9b352cfa3169cc44cfe989e8ea256ef4d0d4 100644 (file)
@@ -124,8 +124,8 @@ from (select pg_ls_waldir() w) ss where length((w).name) = 24 limit 1;
 select count(*) >= 0 as ok from pg_ls_archive_statusdir();
 
 -- pg_read_file()
-select length(pg_read_file('postgresql.auto.conf')) > 30;
-select length(pg_read_file('postgresql.auto.conf', 1, 30));
+select length(pg_read_file('postmaster.pid')) > 20;
+select length(pg_read_file('postmaster.pid', 1, 20));
 -- Test missing_ok
 select pg_read_file('does not exist'); -- error
 select pg_read_file('does not exist', true) IS NULL; -- ok
@@ -134,8 +134,8 @@ select pg_read_file('does not exist', 0, -1); -- error
 select pg_read_file('does not exist', 0, -1, true); -- error
 
 -- pg_read_binary_file()
-select length(pg_read_binary_file('postgresql.auto.conf')) > 30;
-select length(pg_read_binary_file('postgresql.auto.conf', 1, 30));
+select length(pg_read_binary_file('postmaster.pid')) > 20;
+select length(pg_read_binary_file('postmaster.pid', 1, 20));
 -- Test missing_ok
 select pg_read_binary_file('does not exist'); -- error
 select pg_read_binary_file('does not exist', true) IS NULL; -- ok
@@ -144,7 +144,7 @@ select pg_read_binary_file('does not exist', 0, -1); -- error
 select pg_read_binary_file('does not exist', 0, -1, true); -- error
 
 -- pg_stat_file()
-select size > 30, isdir from pg_stat_file('postgresql.auto.conf');
+select size > 20, isdir from pg_stat_file('postmaster.pid');
 
 -- pg_ls_dir()
 select * from (select pg_ls_dir('.') a) a where a = 'base' limit 1;