@@ -126,7 +126,8 @@ static const CatalogId nilCatalogId = {0, 0};
126
126
127
127
static void help (const char * progname );
128
128
static void setup_connection (Archive * AH , DumpOptions * dopt ,
129
- const char * dumpencoding , char * use_role );
129
+ const char * dumpencoding , const char * dumpsnapshot ,
130
+ char * use_role );
130
131
static ArchiveFormat parseArchiveFormat (const char * format , ArchiveMode * mode );
131
132
static void expand_schema_name_patterns (Archive * fout ,
132
133
SimpleStringList * patterns ,
@@ -269,6 +270,7 @@ main(int argc, char **argv)
269
270
RestoreOptions * ropt ;
270
271
Archive * fout ; /* the script file */
271
272
const char * dumpencoding = NULL ;
273
+ const char * dumpsnapshot = NULL ;
272
274
char * use_role = NULL ;
273
275
int numWorkers = 1 ;
274
276
trivalue prompt_password = TRI_DEFAULT ;
@@ -329,6 +331,7 @@ main(int argc, char **argv)
329
331
{"role" , required_argument , NULL , 3 },
330
332
{"section" , required_argument , NULL , 5 },
331
333
{"serializable-deferrable" , no_argument , & dopt -> serializable_deferrable , 1 },
334
+ {"snapshot" , required_argument , NULL , 6 },
332
335
{"use-set-session-authorization" , no_argument , & dopt -> use_setsessauth , 1 },
333
336
{"no-security-labels" , no_argument , & dopt -> no_security_labels , 1 },
334
337
{"no-synchronized-snapshots" , no_argument , & dopt -> no_synchronized_snapshots , 1 },
@@ -506,6 +509,10 @@ main(int argc, char **argv)
506
509
set_dump_section (optarg , & dopt -> dumpSections );
507
510
break ;
508
511
512
+ case 6 : /* snapshot */
513
+ dumpsnapshot = pg_strdup (optarg );
514
+ break ;
515
+
509
516
default :
510
517
fprintf (stderr , _ ("Try \"%s --help\" for more information.\n" ), progname );
511
518
exit_nicely (1 );
@@ -614,7 +621,7 @@ main(int argc, char **argv)
614
621
* death.
615
622
*/
616
623
ConnectDatabase (fout , dopt -> dbname , dopt -> pghost , dopt -> pgport , dopt -> username , prompt_password );
617
- setup_connection (fout , dopt , dumpencoding , use_role );
624
+ setup_connection (fout , dopt , dumpencoding , dumpsnapshot , use_role );
618
625
619
626
/*
620
627
* Disable security label support if server version < v9.1.x (prevents
@@ -658,6 +665,11 @@ main(int argc, char **argv)
658
665
"Run with --no-synchronized-snapshots instead if you do not need\n"
659
666
"synchronized snapshots.\n" );
660
667
668
+ /* check the version when a snapshot is explicitly specified by user */
669
+ if (dumpsnapshot && fout -> remoteVersion < 90200 )
670
+ exit_horribly (NULL ,
671
+ "Exported snapshots are not supported by this server version.\n" );
672
+
661
673
/* Find the last built-in OID, if needed */
662
674
if (fout -> remoteVersion < 70300 )
663
675
{
@@ -888,6 +900,7 @@ help(const char *progname)
888
900
printf (_ (" --quote-all-identifiers quote all identifiers, even if not key words\n" ));
889
901
printf (_ (" --section=SECTION dump named section (pre-data, data, or post-data)\n" ));
890
902
printf (_ (" --serializable-deferrable wait until the dump can run without anomalies\n" ));
903
+ printf (_ (" --snapshot=SNAPSHOT use given synchronous snapshot for the dump\n" ));
891
904
printf (_ (" --use-set-session-authorization\n"
892
905
" use SET SESSION AUTHORIZATION commands instead of\n"
893
906
" ALTER OWNER commands to set ownership\n" ));
@@ -907,7 +920,8 @@ help(const char *progname)
907
920
}
908
921
909
922
static void
910
- setup_connection (Archive * AH , DumpOptions * dopt , const char * dumpencoding , char * use_role )
923
+ setup_connection (Archive * AH , DumpOptions * dopt , const char * dumpencoding ,
924
+ const char * dumpsnapshot , char * use_role )
911
925
{
912
926
PGconn * conn = GetConnection (AH );
913
927
const char * std_strings ;
@@ -1015,22 +1029,25 @@ setup_connection(Archive *AH, DumpOptions *dopt, const char *dumpencoding, char
1015
1029
ExecuteSqlStatement (AH ,
1016
1030
"SET TRANSACTION ISOLATION LEVEL SERIALIZABLE" );
1017
1031
1032
+ /*
1033
+ * define an export snapshot, either chosen by user or needed for
1034
+ * parallel dump.
1035
+ */
1036
+ if (dumpsnapshot )
1037
+ AH -> sync_snapshot_id = strdup (dumpsnapshot );
1018
1038
1019
-
1020
- if (AH -> numWorkers > 1 && AH -> remoteVersion >= 90200 && !dopt -> no_synchronized_snapshots )
1039
+ if (AH -> sync_snapshot_id )
1021
1040
{
1022
- if (AH -> sync_snapshot_id )
1023
- {
1024
- PQExpBuffer query = createPQExpBuffer ();
1025
-
1026
- appendPQExpBufferStr (query , "SET TRANSACTION SNAPSHOT " );
1027
- appendStringLiteralConn (query , AH -> sync_snapshot_id , conn );
1028
- ExecuteSqlStatement (AH , query -> data );
1029
- destroyPQExpBuffer (query );
1030
- }
1031
- else
1032
- AH -> sync_snapshot_id = get_synchronized_snapshot (AH );
1041
+ PQExpBuffer query = createPQExpBuffer ();
1042
+ appendPQExpBuffer (query , "SET TRANSACTION SNAPSHOT " );
1043
+ appendStringLiteralConn (query , AH -> sync_snapshot_id , conn );
1044
+ ExecuteSqlStatement (AH , query -> data );
1045
+ destroyPQExpBuffer (query );
1033
1046
}
1047
+ else if (AH -> numWorkers > 1 &&
1048
+ AH -> remoteVersion >= 90200 &&
1049
+ !dopt -> no_synchronized_snapshots )
1050
+ AH -> sync_snapshot_id = get_synchronized_snapshot (AH );
1034
1051
1035
1052
if (AH -> remoteVersion >= 90500 )
1036
1053
{
@@ -1044,7 +1061,7 @@ setup_connection(Archive *AH, DumpOptions *dopt, const char *dumpencoding, char
1044
1061
static void
1045
1062
setupDumpWorker (Archive * AHX , DumpOptions * dopt , RestoreOptions * ropt )
1046
1063
{
1047
- setup_connection (AHX , dopt , NULL , NULL );
1064
+ setup_connection (AHX , dopt , NULL , NULL , NULL );
1048
1065
}
1049
1066
1050
1067
static char *
0 commit comments