@@ -30,6 +30,27 @@ sub generate_db
30
30
" created database with ASCII characters from $from_char to $to_char " );
31
31
}
32
32
33
+ # Filter the contents of a dump before its use in a content comparison.
34
+ # This returns the path to the filtered dump.
35
+ sub filter_dump
36
+ {
37
+ my ($node , $dump_file ) = @_ ;
38
+ my $dump_contents = slurp_file($dump_file );
39
+
40
+ # Remove the comments.
41
+ $dump_contents =~ s / ^\-\- .*// mgx ;
42
+ # Remove empty lines.
43
+ $dump_contents =~ s / ^\n // mgx ;
44
+
45
+ my $dump_file_filtered = " ${dump_file} _filtered" ;
46
+ open (my $dh , ' >' , $dump_file_filtered )
47
+ || die " opening $dump_file_filtered " ;
48
+ print $dh $dump_contents ;
49
+ close ($dh );
50
+
51
+ return $dump_file_filtered ;
52
+ }
53
+
33
54
# The test of pg_upgrade requires two clusters, an old one and a new one
34
55
# that gets upgraded. Before running the upgrade, a logical dump of the
35
56
# old cluster is taken, and a second logical dump of the new one is taken
@@ -49,8 +70,10 @@ sub generate_db
49
70
die " olddump or oldinstall is undefined" ;
50
71
}
51
72
52
- # Temporary location for the dumps taken
53
- my $tempdir = PostgreSQL::Test::Utils::tempdir;
73
+ # Paths to the dumps taken during the tests.
74
+ my $tempdir = PostgreSQL::Test::Utils::tempdir;
75
+ my $dump1_file = " $tempdir /dump1.sql" ;
76
+ my $dump2_file = " $tempdir /dump2.sql" ;
54
77
55
78
# Initialize node to upgrade
56
79
my $oldnode =
@@ -60,7 +83,10 @@ sub generate_db
60
83
# To increase coverage of non-standard segment size and group access without
61
84
# increasing test runtime, run these tests with a custom setting.
62
85
# --allow-group-access and --wal-segsize have been added in v11.
63
- $oldnode -> init(extra => [ ' --wal-segsize' , ' 1' , ' --allow-group-access' ]);
86
+ my %node_params = ();
87
+ $node_params {extra } = [ ' --wal-segsize' , ' 1' , ' --allow-group-access' ]
88
+ if $oldnode -> pg_version >= 11;
89
+ $oldnode -> init(%node_params );
64
90
$oldnode -> start;
65
91
66
92
# The default location of the source code is the root of this directory.
@@ -129,37 +155,38 @@ sub generate_db
129
155
is($rc , 0, ' regression tests pass' );
130
156
}
131
157
158
+ # Initialize a new node for the upgrade.
159
+ my $newnode = PostgreSQL::Test::Cluster-> new(' new_node' );
160
+ $newnode -> init(%node_params );
161
+
162
+ my $newbindir = $newnode -> config_data(' --bindir' );
163
+ my $oldbindir = $oldnode -> config_data(' --bindir' );
164
+
132
165
# Before dumping, get rid of objects not existing or not supported in later
133
166
# versions. This depends on the version of the old server used, and matters
134
167
# only if different major versions are used for the dump.
135
168
if (defined ($ENV {oldinstall }))
136
169
{
137
- # Note that upgrade_adapt.sql from the new version is used, to
138
- # cope with an upgrade to this version.
139
- $oldnode -> command_ok(
170
+ # Note that upgrade_adapt.sql and psql from the new version are used,
171
+ # to cope with an upgrade to this version.
172
+ $newnode -> command_ok(
140
173
[
141
174
' psql' , ' -X' ,
142
- ' -f' , " $srcdir /src/bin/pg_upgrade/upgrade_adapt.sql" ,
143
- ' regression'
175
+ ' -f' , " $srcdir /src/bin/pg_upgrade/upgrade_adapt.sql" ,
176
+ ' -d ' , $oldnode -> connstr( ' regression' ),
144
177
],
145
178
' ran adapt script' );
146
179
}
147
180
148
- # Initialize a new node for the upgrade.
149
- my $newnode = PostgreSQL::Test::Cluster-> new(' new_node' );
150
- $newnode -> init(extra => [ ' --wal-segsize' , ' 1' , ' --allow-group-access' ]);
151
- my $newbindir = $newnode -> config_data(' --bindir' );
152
- my $oldbindir = $oldnode -> config_data(' --bindir' );
153
-
154
181
# Take a dump before performing the upgrade as a base comparison. Note
155
182
# that we need to use pg_dumpall from the new node here.
156
- $newnode -> command_ok (
157
- [
158
- ' pg_dumpall ' , ' --no-sync ' ,
159
- ' -d ' , $oldnode -> connstr( ' postgres ' ),
160
- ' -f ' , " $tempdir /dump1.sql "
161
- ],
162
- ' dump before running pg_upgrade' );
183
+ my @dump_command = (
184
+ ' pg_dumpall ' , ' --no-sync ' , ' -d ' , $oldnode -> connstr( ' postgres ' ),
185
+ ' -f ' , $dump1_file );
186
+ # --extra-float-digits is needed when upgrading from a version older than 11.
187
+ push ( @dump_command , ' --extra-float-digits ' , ' 0 ' )
188
+ if ( $oldnode -> pg_version < 12);
189
+ $newnode -> command_ok(\ @dump_command , ' dump before running pg_upgrade' );
163
190
164
191
# After dumping, update references to the old source tree's regress.so
165
192
# to point to the new tree.
@@ -173,7 +200,7 @@ sub generate_db
173
200
chomp ($output );
174
201
my @libpaths = split (" \n " , $output );
175
202
176
- my $dump_data = slurp_file(" $tempdir /dump1.sql " );
203
+ my $dump_data = slurp_file($dump1_file );
177
204
178
205
my $newregresssrc = " $srcdir /src/test/regress" ;
179
206
foreach (@libpaths )
@@ -183,7 +210,7 @@ sub generate_db
183
210
$dump_data =~ s / $libpath/ $newregresssrc / g ;
184
211
}
185
212
186
- open my $fh , " >" , " $tempdir /dump1.sql " or die " could not open dump file" ;
213
+ open my $fh , " >" , $dump1_file or die " could not open dump file" ;
187
214
print $fh $dump_data ;
188
215
close $fh ;
189
216
@@ -284,24 +311,34 @@ sub generate_db
284
311
}
285
312
286
313
# Second dump from the upgraded instance.
287
- $newnode -> command_ok(
288
- [
289
- ' pg_dumpall' , ' --no-sync' ,
290
- ' -d' , $newnode -> connstr(' postgres' ),
291
- ' -f' , " $tempdir /dump2.sql"
292
- ],
293
- ' dump after running pg_upgrade' );
314
+ @dump_command = (
315
+ ' pg_dumpall' , ' --no-sync' , ' -d' , $newnode -> connstr(' postgres' ),
316
+ ' -f' , $dump2_file );
317
+ # --extra-float-digits is needed when upgrading from a version older than 11.
318
+ push (@dump_command , ' --extra-float-digits' , ' 0' )
319
+ if ($oldnode -> pg_version < 12);
320
+ $newnode -> command_ok(\@dump_command , ' dump after running pg_upgrade' );
321
+
322
+ # No need to apply filters on the dumps if working on the same version
323
+ # for the old and new nodes.
324
+ my $dump1_filtered = $dump1_file ;
325
+ my $dump2_filtered = $dump2_file ;
326
+ if ($oldnode -> pg_version != $newnode -> pg_version)
327
+ {
328
+ $dump1_filtered = filter_dump($oldnode , $dump1_file );
329
+ $dump2_filtered = filter_dump($newnode , $dump2_file );
330
+ }
294
331
295
332
# Compare the two dumps, there should be no differences.
296
- my $compare_res = compare(" $tempdir /dump1.sql " , " $tempdir /dump2.sql " );
333
+ my $compare_res = compare($dump1_filtered , $dump2_filtered );
297
334
is($compare_res , 0, ' old and new dumps match after pg_upgrade' );
298
335
299
336
# Provide more context if the dumps do not match.
300
337
if ($compare_res != 0)
301
338
{
302
339
my ($stdout , $stderr ) =
303
- run_command([ ' diff' , " $tempdir /dump1.sql " , " $tempdir /dump2.sql " ]);
304
- print " === diff of $tempdir /dump1.sql and $tempdir /dump2.sql \n " ;
340
+ run_command([ ' diff' , $dump1_filtered , $dump2_filtered ]);
341
+ print " === diff of $dump1_filtered and $dump2_filtered \n " ;
305
342
print " === stdout ===\n " ;
306
343
print $stdout ;
307
344
print " === stderr ===\n " ;
0 commit comments