-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
002_pg_dump.pl
4983 lines (4628 loc) · 141 KB
/
002_pg_dump.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) 2021-2023, PostgreSQL Global Development Group
use strict;
use warnings;
use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
use Test::More;
my $tempdir = PostgreSQL::Test::Utils::tempdir;
###############################################################
# Definition of the pg_dump runs to make.
#
# Each of these runs are named and those names are used below
# to define how each test should (or shouldn't) treat a result
# from a given run.
#
# test_key indicates that a given run should simply use the same
# set of like/unlike tests as another run, and which run that is.
#
# compile_option indicates if the commands run depend on a compilation
# option, if any. This can be used to control if tests should be
# skipped when a build dependency is not satisfied.
#
# dump_cmd is the pg_dump command to run, which is an array of
# the full command and arguments to run. Note that this is run
# using $node->command_ok(), so the port does not need to be
# specified and is pulled from $PGPORT, which is set by the
# PostgreSQL::Test::Cluster system.
#
# compress_cmd is the utility command for (de)compression, if any.
# Note that this should generally be used on pg_dump's output
# either to generate a text file to run the through the tests, or
# to test pg_restore's ability to parse manually compressed files
# that otherwise pg_dump does not compress on its own (e.g. *.toc).
#
# glob_patterns is an optional array consisting of strings compilable
# with glob() to check the files generated after a dump.
#
# command_like is an optional utility that can be used to compare
# the output generated by a command on the contents of an existing
# dump, like the TOC description of a pg_restore command.
#
# restore_cmd is the pg_restore command to run, if any. Note
# that this should generally be used when the pg_dump goes to
# a non-text file and that the restore can then be used to
# generate a text file to run through the tests from the
# non-text file generated by pg_dump.
#
# TODO: Have pg_restore actually restore to an independent
# database and then pg_dump *that* database (or something along
# those lines) to validate that part of the process.
my $supports_icu = ($ENV{with_icu} eq 'yes');
my $supports_gzip = check_pg_config("#define HAVE_LIBZ 1");
my $supports_lz4 = check_pg_config("#define USE_LZ4 1");
my $supports_zstd = check_pg_config("#define USE_ZSTD 1");
my %pgdump_runs = (
binary_upgrade => {
dump_cmd => [
'pg_dump',
'--no-sync',
'--format=custom',
"--file=$tempdir/binary_upgrade.dump",
'-w',
'--schema-only',
'--binary-upgrade',
'-d', 'postgres', # alternative way to specify database
],
restore_cmd => [
'pg_restore', '-Fc', '--verbose',
"--file=$tempdir/binary_upgrade.sql",
"$tempdir/binary_upgrade.dump",
],
},
# Do not use --no-sync to give test coverage for data sync.
compression_gzip_custom => {
test_key => 'compression',
compile_option => 'gzip',
dump_cmd => [
'pg_dump', '--format=custom',
'--compress=1', "--file=$tempdir/compression_gzip_custom.dump",
'postgres',
],
restore_cmd => [
'pg_restore',
"--file=$tempdir/compression_gzip_custom.sql",
"$tempdir/compression_gzip_custom.dump",
],
command_like => {
command => [
'pg_restore', '-l', "$tempdir/compression_gzip_custom.dump",
],
expected => qr/Compression: gzip/,
name => 'data content is gzip-compressed'
},
},
# Do not use --no-sync to give test coverage for data sync.
compression_gzip_dir => {
test_key => 'compression',
compile_option => 'gzip',
dump_cmd => [
'pg_dump', '--jobs=2',
'--format=directory', '--compress=gzip:1',
"--file=$tempdir/compression_gzip_dir", 'postgres',
],
# Give coverage for manually compressed blob.toc files during
# restore.
compress_cmd => {
program => $ENV{'GZIP_PROGRAM'},
args => [ '-f', "$tempdir/compression_gzip_dir/blobs.toc", ],
},
# Verify that only data files were compressed
glob_patterns => [
"$tempdir/compression_gzip_dir/toc.dat",
"$tempdir/compression_gzip_dir/*.dat.gz",
],
restore_cmd => [
'pg_restore', '--jobs=2',
"--file=$tempdir/compression_gzip_dir.sql",
"$tempdir/compression_gzip_dir",
],
},
compression_gzip_plain => {
test_key => 'compression',
compile_option => 'gzip',
dump_cmd => [
'pg_dump', '--format=plain', '-Z1',
"--file=$tempdir/compression_gzip_plain.sql.gz", 'postgres',
],
# Decompress the generated file to run through the tests.
compress_cmd => {
program => $ENV{'GZIP_PROGRAM'},
args => [ '-d', "$tempdir/compression_gzip_plain.sql.gz", ],
},
},
# Do not use --no-sync to give test coverage for data sync.
compression_lz4_custom => {
test_key => 'compression',
compile_option => 'lz4',
dump_cmd => [
'pg_dump', '--format=custom',
'--compress=lz4', "--file=$tempdir/compression_lz4_custom.dump",
'postgres',
],
restore_cmd => [
'pg_restore',
"--file=$tempdir/compression_lz4_custom.sql",
"$tempdir/compression_lz4_custom.dump",
],
command_like => {
command =>
[ 'pg_restore', '-l', "$tempdir/compression_lz4_custom.dump", ],
expected => qr/Compression: lz4/,
name => 'data content is lz4 compressed'
},
},
# Do not use --no-sync to give test coverage for data sync.
compression_lz4_dir => {
test_key => 'compression',
compile_option => 'lz4',
dump_cmd => [
'pg_dump', '--jobs=2',
'--format=directory', '--compress=lz4:1',
"--file=$tempdir/compression_lz4_dir", 'postgres',
],
# Give coverage for manually compressed blob.toc files during
# restore.
compress_cmd => {
program => $ENV{'LZ4'},
args => [
'-z', '-f', '--rm',
"$tempdir/compression_lz4_dir/blobs.toc",
"$tempdir/compression_lz4_dir/blobs.toc.lz4",
],
},
# Verify that data files were compressed
glob_patterns => [
"$tempdir/compression_lz4_dir/toc.dat",
"$tempdir/compression_lz4_dir/*.dat.lz4",
],
restore_cmd => [
'pg_restore', '--jobs=2',
"--file=$tempdir/compression_lz4_dir.sql",
"$tempdir/compression_lz4_dir",
],
},
compression_lz4_plain => {
test_key => 'compression',
compile_option => 'lz4',
dump_cmd => [
'pg_dump', '--format=plain', '--compress=lz4',
"--file=$tempdir/compression_lz4_plain.sql.lz4", 'postgres',
],
# Decompress the generated file to run through the tests.
compress_cmd => {
program => $ENV{'LZ4'},
args => [
'-d', '-f',
"$tempdir/compression_lz4_plain.sql.lz4",
"$tempdir/compression_lz4_plain.sql",
],
},
},
compression_zstd_custom => {
test_key => 'compression',
compile_option => 'zstd',
dump_cmd => [
'pg_dump', '--format=custom',
'--compress=zstd', "--file=$tempdir/compression_zstd_custom.dump",
'postgres',
],
restore_cmd => [
'pg_restore',
"--file=$tempdir/compression_zstd_custom.sql",
"$tempdir/compression_zstd_custom.dump",
],
command_like => {
command => [
'pg_restore', '-l', "$tempdir/compression_zstd_custom.dump",
],
expected => qr/Compression: zstd/,
name => 'data content is zstd compressed'
},
},
compression_zstd_dir => {
test_key => 'compression',
compile_option => 'zstd',
dump_cmd => [
'pg_dump', '--jobs=2',
'--format=directory', '--compress=zstd:1',
"--file=$tempdir/compression_zstd_dir", 'postgres',
],
# Give coverage for manually compressed blob.toc files during
# restore.
compress_cmd => {
program => $ENV{'ZSTD'},
args => [
'-z', '-f',
'--rm', "$tempdir/compression_zstd_dir/blobs.toc",
"-o", "$tempdir/compression_zstd_dir/blobs.toc.zst",
],
},
# Verify that data files were compressed
glob_patterns => [
"$tempdir/compression_zstd_dir/toc.dat",
"$tempdir/compression_zstd_dir/*.dat.zst",
],
restore_cmd => [
'pg_restore', '--jobs=2',
"--file=$tempdir/compression_zstd_dir.sql",
"$tempdir/compression_zstd_dir",
],
},
# Exercise long mode for test coverage
compression_zstd_plain => {
test_key => 'compression',
compile_option => 'zstd',
dump_cmd => [
'pg_dump', '--format=plain', '--compress=zstd:long',
"--file=$tempdir/compression_zstd_plain.sql.zst", 'postgres',
],
# Decompress the generated file to run through the tests.
compress_cmd => {
program => $ENV{'ZSTD'},
args => [
'-d', '-f',
"$tempdir/compression_zstd_plain.sql.zst", "-o",
"$tempdir/compression_zstd_plain.sql",
],
},
},
clean => {
dump_cmd => [
'pg_dump',
'--no-sync',
"--file=$tempdir/clean.sql",
'-c',
'-d', 'postgres', # alternative way to specify database
],
},
clean_if_exists => {
dump_cmd => [
'pg_dump',
'--no-sync',
"--file=$tempdir/clean_if_exists.sql",
'-c',
'--if-exists',
'--encoding=UTF8', # no-op, just tests that option is accepted
'postgres',
],
},
column_inserts => {
dump_cmd => [
'pg_dump', '--no-sync',
"--file=$tempdir/column_inserts.sql", '-a',
'--column-inserts', 'postgres',
],
},
createdb => {
dump_cmd => [
'pg_dump',
'--no-sync',
"--file=$tempdir/createdb.sql",
'-C',
'-R', # no-op, just for testing
'-v',
'postgres',
],
},
data_only => {
dump_cmd => [
'pg_dump',
'--no-sync',
"--file=$tempdir/data_only.sql",
'-a',
'--superuser=test_superuser',
'--disable-triggers',
'-v', # no-op, just make sure it works
'postgres',
],
},
defaults => {
dump_cmd => [
'pg_dump', '--no-sync',
'-f', "$tempdir/defaults.sql",
'postgres',
],
},
defaults_no_public => {
database => 'regress_pg_dump_test',
dump_cmd => [
'pg_dump', '--no-sync', '-f', "$tempdir/defaults_no_public.sql",
'regress_pg_dump_test',
],
},
defaults_no_public_clean => {
database => 'regress_pg_dump_test',
dump_cmd => [
'pg_dump', '--no-sync', '-c', '-f',
"$tempdir/defaults_no_public_clean.sql",
'regress_pg_dump_test',
],
},
defaults_public_owner => {
database => 'regress_public_owner',
dump_cmd => [
'pg_dump', '--no-sync', '-f',
"$tempdir/defaults_public_owner.sql",
'regress_public_owner',
],
},
# Do not use --no-sync to give test coverage for data sync.
# By default, the custom format compresses its data file
# when the code is compiled with gzip support, and lets them
# uncompressed when not compiled with it.
defaults_custom_format => {
test_key => 'defaults',
dump_cmd => [
'pg_dump', '-Fc',
"--file=$tempdir/defaults_custom_format.dump", 'postgres',
],
restore_cmd => [
'pg_restore', '-Fc',
"--file=$tempdir/defaults_custom_format.sql",
"$tempdir/defaults_custom_format.dump",
],
command_like => {
command =>
[ 'pg_restore', '-l', "$tempdir/defaults_custom_format.dump", ],
expected => $supports_gzip
? qr/Compression: gzip/
: qr/Compression: none/,
name => 'data content is gzip-compressed by default if available',
},
},
# Do not use --no-sync to give test coverage for data sync.
# By default, the directory format compresses its data files
# when the code is compiled with gzip support, and lets them
# uncompressed when not compiled with it.
defaults_dir_format => {
test_key => 'defaults',
dump_cmd => [
'pg_dump', '-Fd',
"--file=$tempdir/defaults_dir_format", 'postgres',
],
restore_cmd => [
'pg_restore', '-Fd',
"--file=$tempdir/defaults_dir_format.sql",
"$tempdir/defaults_dir_format",
],
command_like => {
command =>
[ 'pg_restore', '-l', "$tempdir/defaults_dir_format", ],
expected => $supports_gzip ? qr/Compression: gzip/
: qr/Compression: none/,
name => 'data content is gzip-compressed by default',
},
glob_patterns => [
"$tempdir/defaults_dir_format/toc.dat",
"$tempdir/defaults_dir_format/blobs.toc",
$supports_gzip ? "$tempdir/defaults_dir_format/*.dat.gz"
: "$tempdir/defaults_dir_format/*.dat",
],
},
# Do not use --no-sync to give test coverage for data sync.
defaults_parallel => {
test_key => 'defaults',
dump_cmd => [
'pg_dump', '-Fd', '-j2', "--file=$tempdir/defaults_parallel",
'postgres',
],
restore_cmd => [
'pg_restore',
"--file=$tempdir/defaults_parallel.sql",
"$tempdir/defaults_parallel",
],
},
# Do not use --no-sync to give test coverage for data sync.
defaults_tar_format => {
test_key => 'defaults',
dump_cmd => [
'pg_dump', '-Ft',
"--file=$tempdir/defaults_tar_format.tar", 'postgres',
],
restore_cmd => [
'pg_restore',
'--format=tar',
"--file=$tempdir/defaults_tar_format.sql",
"$tempdir/defaults_tar_format.tar",
],
},
exclude_dump_test_schema => {
dump_cmd => [
'pg_dump', '--no-sync',
"--file=$tempdir/exclude_dump_test_schema.sql",
'--exclude-schema=dump_test', 'postgres',
],
},
exclude_test_table => {
dump_cmd => [
'pg_dump', '--no-sync',
"--file=$tempdir/exclude_test_table.sql",
'--exclude-table=dump_test.test_table', 'postgres',
],
},
exclude_measurement => {
dump_cmd => [
'pg_dump',
'--no-sync',
"--file=$tempdir/exclude_measurement.sql",
'--exclude-table-and-children=dump_test.measurement',
'postgres',
],
},
exclude_measurement_data => {
dump_cmd => [
'pg_dump',
'--no-sync',
"--file=$tempdir/exclude_measurement_data.sql",
'--exclude-table-data-and-children=dump_test.measurement',
'--no-unlogged-table-data',
'postgres',
],
},
exclude_test_table_data => {
dump_cmd => [
'pg_dump',
'--no-sync',
"--file=$tempdir/exclude_test_table_data.sql",
'--exclude-table-data=dump_test.test_table',
'--no-unlogged-table-data',
'postgres',
],
},
inserts => {
dump_cmd => [
'pg_dump', '--no-sync',
"--file=$tempdir/inserts.sql", '-a',
'--inserts', 'postgres',
],
},
pg_dumpall_globals => {
dump_cmd => [
'pg_dumpall', '-v', "--file=$tempdir/pg_dumpall_globals.sql",
'-g', '--no-sync',
],
},
pg_dumpall_globals_clean => {
dump_cmd => [
'pg_dumpall', "--file=$tempdir/pg_dumpall_globals_clean.sql",
'-g', '-c', '--no-sync',
],
},
pg_dumpall_dbprivs => {
dump_cmd => [
'pg_dumpall', '--no-sync',
"--file=$tempdir/pg_dumpall_dbprivs.sql",
],
},
pg_dumpall_exclude => {
dump_cmd => [
'pg_dumpall', '-v', "--file=$tempdir/pg_dumpall_exclude.sql",
'--exclude-database', '*dump_test*', '--no-sync',
],
},
no_toast_compression => {
dump_cmd => [
'pg_dump', '--no-sync',
"--file=$tempdir/no_toast_compression.sql",
'--no-toast-compression', 'postgres',
],
},
no_large_objects => {
dump_cmd => [
'pg_dump', '--no-sync', "--file=$tempdir/no_large_objects.sql",
'-B', 'postgres',
],
},
no_privs => {
dump_cmd => [
'pg_dump', '--no-sync',
"--file=$tempdir/no_privs.sql", '-x',
'postgres',
],
},
no_owner => {
dump_cmd => [
'pg_dump', '--no-sync',
"--file=$tempdir/no_owner.sql", '-O',
'postgres',
],
},
no_table_access_method => {
dump_cmd => [
'pg_dump', '--no-sync',
"--file=$tempdir/no_table_access_method.sql",
'--no-table-access-method', 'postgres',
],
},
only_dump_test_schema => {
dump_cmd => [
'pg_dump', '--no-sync',
"--file=$tempdir/only_dump_test_schema.sql",
'--schema=dump_test', 'postgres',
],
},
only_dump_test_table => {
dump_cmd => [
'pg_dump',
'--no-sync',
"--file=$tempdir/only_dump_test_table.sql",
'--table=dump_test.test_table',
'--lock-wait-timeout='
. (1000 * $PostgreSQL::Test::Utils::timeout_default),
'postgres',
],
},
only_dump_measurement => {
dump_cmd => [
'pg_dump',
'--no-sync',
"--file=$tempdir/only_dump_measurement.sql",
'--table-and-children=dump_test.measurement',
'--lock-wait-timeout='
. (1000 * $PostgreSQL::Test::Utils::timeout_default),
'postgres',
],
},
role => {
dump_cmd => [
'pg_dump',
'--no-sync',
"--file=$tempdir/role.sql",
'--role=regress_dump_test_role',
'--schema=dump_test_second_schema',
'postgres',
],
},
role_parallel => {
test_key => 'role',
dump_cmd => [
'pg_dump',
'--no-sync',
'--format=directory',
'--jobs=2',
"--file=$tempdir/role_parallel",
'--role=regress_dump_test_role',
'--schema=dump_test_second_schema',
'postgres',
],
restore_cmd => [
'pg_restore', "--file=$tempdir/role_parallel.sql",
"$tempdir/role_parallel",
],
},
rows_per_insert => {
dump_cmd => [
'pg_dump',
'--no-sync',
"--file=$tempdir/rows_per_insert.sql",
'-a',
'--rows-per-insert=4',
'--table=dump_test.test_table',
'--table=dump_test.test_fourth_table',
'postgres',
],
},
schema_only => {
dump_cmd => [
'pg_dump', '--format=plain',
"--file=$tempdir/schema_only.sql", '--no-sync',
'-s', 'postgres',
],
},
section_pre_data => {
dump_cmd => [
'pg_dump', "--file=$tempdir/section_pre_data.sql",
'--section=pre-data', '--no-sync',
'postgres',
],
},
section_data => {
dump_cmd => [
'pg_dump', "--file=$tempdir/section_data.sql",
'--section=data', '--no-sync',
'postgres',
],
},
section_post_data => {
dump_cmd => [
'pg_dump', "--file=$tempdir/section_post_data.sql",
'--section=post-data', '--no-sync', 'postgres',
],
},
test_schema_plus_large_objects => {
dump_cmd => [
'pg_dump', "--file=$tempdir/test_schema_plus_large_objects.sql",
'--schema=dump_test', '-b', '-B', '--no-sync', 'postgres',
],
},);
###############################################################
# Definition of the tests to run.
#
# Each test is defined using the log message that will be used.
#
# A regexp should be defined for each test which provides the
# basis for the test. That regexp will be run against the output
# file of each of the runs which the test is to be run against
# and the success of the result will depend on if the regexp
# result matches the expected 'like' or 'unlike' case.
#
# The runs listed as 'like' will be checked if they match the
# regexp and, if so, the test passes. All runs which are not
# listed as 'like' will be checked to ensure they don't match
# the regexp; if they do, the test will fail.
#
# The below hashes provide convenience sets of runs. Individual
# runs can be excluded from a general hash by placing that run
# into the 'unlike' section.
#
# For example, there is an 'exclude_test_table' run which runs a
# full pg_dump but with an exclude flag to not include the test
# table. The CREATE TABLE test which creates the test table is
# defined with %full_runs but then has 'exclude_test_table' in
# its 'unlike' list, excluding that test.
#
# There can then be a 'create_sql' and 'create_order' for a
# given test. The 'create_sql' commands are collected up in
# 'create_order' and then run against the database prior to any
# of the pg_dump runs happening. This is what "seeds" the
# system with objects to be dumped out.
#
# There can be a flag called 'lz4', which can be set if the test
# case depends on LZ4. Tests marked with this flag are skipped if
# the build used does not support LZ4.
#
# Building of this hash takes a bit of time as all of the regexps
# included in it are compiled. This greatly improves performance
# as the regexps are used for each run the test applies to.
# Tests which target the 'dump_test' schema, specifically.
my %dump_test_schema_runs = (
only_dump_test_schema => 1,
only_dump_measurement => 1,
test_schema_plus_large_objects => 1,);
# Tests which are considered 'full' dumps by pg_dump, but there
# are flags used to exclude specific items (ACLs, LOs, etc).
my %full_runs = (
binary_upgrade => 1,
clean => 1,
clean_if_exists => 1,
compression => 1,
createdb => 1,
defaults => 1,
exclude_dump_test_schema => 1,
exclude_test_table => 1,
exclude_test_table_data => 1,
exclude_measurement => 1,
exclude_measurement_data => 1,
no_toast_compression => 1,
no_large_objects => 1,
no_owner => 1,
no_privs => 1,
no_table_access_method => 1,
pg_dumpall_dbprivs => 1,
pg_dumpall_exclude => 1,
schema_only => 1,);
# This is where the actual tests are defined.
my %tests = (
'ALTER DEFAULT PRIVILEGES FOR ROLE regress_dump_test_role GRANT' => {
create_order => 14,
create_sql => 'ALTER DEFAULT PRIVILEGES
FOR ROLE regress_dump_test_role IN SCHEMA dump_test
GRANT SELECT ON TABLES TO regress_dump_test_role;',
regexp => qr/^
\QALTER DEFAULT PRIVILEGES \E
\QFOR ROLE regress_dump_test_role IN SCHEMA dump_test \E
\QGRANT SELECT ON TABLES TO regress_dump_test_role;\E
/xm,
like =>
{ %full_runs, %dump_test_schema_runs, section_post_data => 1, },
unlike => {
exclude_dump_test_schema => 1,
no_privs => 1,
only_dump_measurement => 1,
},
},
'ALTER DEFAULT PRIVILEGES FOR ROLE regress_dump_test_role GRANT EXECUTE ON FUNCTIONS'
=> {
create_order => 15,
create_sql => 'ALTER DEFAULT PRIVILEGES
FOR ROLE regress_dump_test_role IN SCHEMA dump_test
GRANT EXECUTE ON FUNCTIONS TO regress_dump_test_role;',
regexp => qr/^
\QALTER DEFAULT PRIVILEGES \E
\QFOR ROLE regress_dump_test_role IN SCHEMA dump_test \E
\QGRANT ALL ON FUNCTIONS TO regress_dump_test_role;\E
/xm,
like =>
{ %full_runs, %dump_test_schema_runs, section_post_data => 1, },
unlike => {
exclude_dump_test_schema => 1,
no_privs => 1,
only_dump_measurement => 1,
},
},
'ALTER DEFAULT PRIVILEGES FOR ROLE regress_dump_test_role REVOKE' => {
create_order => 55,
create_sql => 'ALTER DEFAULT PRIVILEGES
FOR ROLE regress_dump_test_role
REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;',
regexp => qr/^
\QALTER DEFAULT PRIVILEGES \E
\QFOR ROLE regress_dump_test_role \E
\QREVOKE ALL ON FUNCTIONS FROM PUBLIC;\E
/xm,
like => { %full_runs, section_post_data => 1, },
unlike => { no_privs => 1, },
},
'ALTER DEFAULT PRIVILEGES FOR ROLE regress_dump_test_role REVOKE SELECT'
=> {
create_order => 56,
create_sql => 'ALTER DEFAULT PRIVILEGES
FOR ROLE regress_dump_test_role
REVOKE SELECT ON TABLES FROM regress_dump_test_role;',
regexp => qr/^
\QALTER DEFAULT PRIVILEGES \E
\QFOR ROLE regress_dump_test_role \E
\QREVOKE ALL ON TABLES FROM regress_dump_test_role;\E\n
\QALTER DEFAULT PRIVILEGES \E
\QFOR ROLE regress_dump_test_role \E
\QGRANT INSERT,REFERENCES,DELETE,TRIGGER,TRUNCATE,UPDATE ON TABLES TO regress_dump_test_role;\E
/xm,
like => { %full_runs, section_post_data => 1, },
unlike => { no_privs => 1, },
},
'ALTER ROLE regress_dump_test_role' => {
regexp => qr/^
\QALTER ROLE regress_dump_test_role WITH \E
\QNOSUPERUSER INHERIT NOCREATEROLE NOCREATEDB NOLOGIN \E
\QNOREPLICATION NOBYPASSRLS;\E
/xm,
like => {
pg_dumpall_dbprivs => 1,
pg_dumpall_globals => 1,
pg_dumpall_globals_clean => 1,
pg_dumpall_exclude => 1,
},
},
'ALTER COLLATION test0 OWNER TO' => {
regexp => qr/^\QALTER COLLATION public.test0 OWNER TO \E.+;/m,
collation => 1,
like => { %full_runs, section_pre_data => 1, },
unlike => { %dump_test_schema_runs, no_owner => 1, },
},
'ALTER FOREIGN DATA WRAPPER dummy OWNER TO' => {
regexp => qr/^ALTER FOREIGN DATA WRAPPER dummy OWNER TO .+;/m,
like => { %full_runs, section_pre_data => 1, },
unlike => { no_owner => 1, },
},
'ALTER SERVER s1 OWNER TO' => {
regexp => qr/^ALTER SERVER s1 OWNER TO .+;/m,
like => { %full_runs, section_pre_data => 1, },
unlike => { no_owner => 1, },
},
'ALTER FUNCTION dump_test.pltestlang_call_handler() OWNER TO' => {
regexp => qr/^
\QALTER FUNCTION dump_test.pltestlang_call_handler() \E
\QOWNER TO \E
.+;/xm,
like =>
{ %full_runs, %dump_test_schema_runs, section_pre_data => 1, },
unlike => {
exclude_dump_test_schema => 1,
no_owner => 1,
only_dump_measurement => 1,
},
},
'ALTER OPERATOR FAMILY dump_test.op_family OWNER TO' => {
regexp => qr/^
\QALTER OPERATOR FAMILY dump_test.op_family USING btree \E
\QOWNER TO \E
.+;/xm,
like =>
{ %full_runs, %dump_test_schema_runs, section_pre_data => 1, },
unlike => {
exclude_dump_test_schema => 1,
no_owner => 1,
only_dump_measurement => 1,
},
},
'ALTER OPERATOR FAMILY dump_test.op_family USING btree' => {
create_order => 75,
create_sql =>
'ALTER OPERATOR FAMILY dump_test.op_family USING btree ADD
OPERATOR 1 <(bigint,int4),
OPERATOR 2 <=(bigint,int4),
OPERATOR 3 =(bigint,int4),
OPERATOR 4 >=(bigint,int4),
OPERATOR 5 >(bigint,int4),
FUNCTION 1 (int4, int4) btint4cmp(int4,int4),
FUNCTION 2 (int4, int4) btint4sortsupport(internal),
FUNCTION 4 (int4, int4) btequalimage(oid);',
# note: it's correct that btint8sortsupport and bigint btequalimage
# are included here:
regexp => qr/^
\QALTER OPERATOR FAMILY dump_test.op_family USING btree ADD\E\n\s+
\QOPERATOR 1 <(bigint,integer) ,\E\n\s+
\QOPERATOR 2 <=(bigint,integer) ,\E\n\s+
\QOPERATOR 3 =(bigint,integer) ,\E\n\s+
\QOPERATOR 4 >=(bigint,integer) ,\E\n\s+
\QOPERATOR 5 >(bigint,integer) ,\E\n\s+
\QFUNCTION 1 (integer, integer) btint4cmp(integer,integer) ,\E\n\s+
\QFUNCTION 2 (bigint, bigint) btint8sortsupport(internal) ,\E\n\s+
\QFUNCTION 2 (integer, integer) btint4sortsupport(internal) ,\E\n\s+
\QFUNCTION 4 (bigint, bigint) btequalimage(oid) ,\E\n\s+
\QFUNCTION 4 (integer, integer) btequalimage(oid);\E
/xm,
like =>
{ %full_runs, %dump_test_schema_runs, section_pre_data => 1, },
unlike => {
exclude_dump_test_schema => 1,
only_dump_measurement => 1,
},
},
'ALTER OPERATOR CLASS dump_test.op_class OWNER TO' => {
regexp => qr/^
\QALTER OPERATOR CLASS dump_test.op_class USING btree \E
\QOWNER TO \E
.+;/xm,
like =>
{ %full_runs, %dump_test_schema_runs, section_pre_data => 1, },
unlike => {
exclude_dump_test_schema => 1,
no_owner => 1,
only_dump_measurement => 1,
},
},
'ALTER PUBLICATION pub1 OWNER TO' => {
regexp => qr/^ALTER PUBLICATION pub1 OWNER TO .+;/m,
like => { %full_runs, section_post_data => 1, },
unlike => { no_owner => 1, },
},
'ALTER LARGE OBJECT ... OWNER TO' => {
regexp => qr/^ALTER LARGE OBJECT \d+ OWNER TO .+;/m,
like => {
%full_runs,
column_inserts => 1,
data_only => 1,
inserts => 1,
section_pre_data => 1,
test_schema_plus_large_objects => 1,
},
unlike => {
no_large_objects => 1,
no_owner => 1,
schema_only => 1,
},
},
'ALTER PROCEDURAL LANGUAGE pltestlang OWNER TO' => {
regexp => qr/^ALTER PROCEDURAL LANGUAGE pltestlang OWNER TO .+;/m,
like => { %full_runs, section_pre_data => 1, },
unlike => { no_owner => 1, },
},
'ALTER SCHEMA dump_test OWNER TO' => {
regexp => qr/^ALTER SCHEMA dump_test OWNER TO .+;/m,
like =>
{ %full_runs, %dump_test_schema_runs, section_pre_data => 1, },
unlike => {
exclude_dump_test_schema => 1,
no_owner => 1,
only_dump_measurement => 1,
},
},
'ALTER SCHEMA dump_test_second_schema OWNER TO' => {
regexp => qr/^ALTER SCHEMA dump_test_second_schema OWNER TO .+;/m,
like => {
%full_runs,
role => 1,
section_pre_data => 1,
},
unlike => { no_owner => 1, },
},
'ALTER SCHEMA public OWNER TO' => {
create_order => 15,
create_sql =>
'ALTER SCHEMA public OWNER TO "regress_quoted \"" role";',
regexp => qr/^ALTER SCHEMA public OWNER TO .+;/m,
like => {
%full_runs, section_pre_data => 1,
},
unlike => { no_owner => 1, },
},
'ALTER SCHEMA public OWNER TO (w/o ACL changes)' => {
database => 'regress_public_owner',
create_order => 100,
create_sql =>
'ALTER SCHEMA public OWNER TO "regress_quoted \"" role";',
regexp => qr/^(GRANT|REVOKE)/m,
unlike => { defaults_public_owner => 1 },
},
'ALTER SEQUENCE test_table_col1_seq' => {
regexp => qr/^
\QALTER SEQUENCE dump_test.test_table_col1_seq OWNED BY dump_test.test_table.col1;\E
/xm,
like => {
%full_runs,
%dump_test_schema_runs,
only_dump_test_table => 1,
section_pre_data => 1,
},
unlike => {
exclude_dump_test_schema => 1,
exclude_test_table => 1,
only_dump_measurement => 1,
},
},
'ALTER TABLE ONLY test_table ADD CONSTRAINT ... PRIMARY KEY' => {