@ -135,6 +135,7 @@ static int disable_dollar_quoting = 0;
static int dump_inserts = 0 ;
static int dump_inserts = 0 ;
static int column_inserts = 0 ;
static int column_inserts = 0 ;
static int no_security_labels = 0 ;
static int no_security_labels = 0 ;
static int no_synchronized_snapshots = 0 ;
static int no_unlogged_table_data = 0 ;
static int no_unlogged_table_data = 0 ;
static int serializable_deferrable = 0 ;
static int serializable_deferrable = 0 ;
@ -243,8 +244,6 @@ static Oid findLastBuiltinOid_V70(Archive *fout);
static void selectSourceSchema ( Archive * fout , const char * schemaName ) ;
static void selectSourceSchema ( Archive * fout , const char * schemaName ) ;
static char * getFormattedTypeName ( Archive * fout , Oid oid , OidOptions opts ) ;
static char * getFormattedTypeName ( Archive * fout , Oid oid , OidOptions opts ) ;
static char * myFormatType ( const char * typname , int32 typmod ) ;
static char * myFormatType ( const char * typname , int32 typmod ) ;
static const char * fmtQualifiedId ( Archive * fout ,
const char * schema , const char * id ) ;
static void getBlobs ( Archive * fout ) ;
static void getBlobs ( Archive * fout ) ;
static void dumpBlob ( Archive * fout , BlobInfo * binfo ) ;
static void dumpBlob ( Archive * fout , BlobInfo * binfo ) ;
static int dumpBlobs ( Archive * fout , void * arg ) ;
static int dumpBlobs ( Archive * fout , void * arg ) ;
@ -262,8 +261,10 @@ static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer,
DumpableObject * dobj ,
DumpableObject * dobj ,
const char * objlabel ) ;
const char * objlabel ) ;
static const char * getAttrName ( int attrnum , TableInfo * tblInfo ) ;
static const char * getAttrName ( int attrnum , TableInfo * tblInfo ) ;
static const char * fmtCopyColumnList ( const TableInfo * ti ) ;
static const char * fmtCopyColumnList ( const TableInfo * ti , PQExpBuffer buffer ) ;
static char * get_synchronized_snapshot ( Archive * fout ) ;
static PGresult * ExecuteSqlQueryForSingleRow ( Archive * fout , char * query ) ;
static PGresult * ExecuteSqlQueryForSingleRow ( Archive * fout , char * query ) ;
static void setupDumpWorker ( Archive * AHX , RestoreOptions * ropt ) ;
int
int
@ -284,6 +285,7 @@ main(int argc, char **argv)
int numObjs ;
int numObjs ;
DumpableObject * boundaryObjs ;
DumpableObject * boundaryObjs ;
int i ;
int i ;
int numWorkers = 1 ;
enum trivalue prompt_password = TRI_DEFAULT ;
enum trivalue prompt_password = TRI_DEFAULT ;
int compressLevel = - 1 ;
int compressLevel = - 1 ;
int plainText = 0 ;
int plainText = 0 ;
@ -314,6 +316,7 @@ main(int argc, char **argv)
{ " format " , required_argument , NULL , ' F ' } ,
{ " format " , required_argument , NULL , ' F ' } ,
{ " host " , required_argument , NULL , ' h ' } ,
{ " host " , required_argument , NULL , ' h ' } ,
{ " ignore-version " , no_argument , NULL , ' i ' } ,
{ " ignore-version " , no_argument , NULL , ' i ' } ,
{ " jobs " , 1 , NULL , ' j ' } ,
{ " no-reconnect " , no_argument , NULL , ' R ' } ,
{ " no-reconnect " , no_argument , NULL , ' R ' } ,
{ " oids " , no_argument , NULL , ' o ' } ,
{ " oids " , no_argument , NULL , ' o ' } ,
{ " no-owner " , no_argument , NULL , ' O ' } ,
{ " no-owner " , no_argument , NULL , ' O ' } ,
@ -353,6 +356,7 @@ main(int argc, char **argv)
{ " serializable-deferrable " , no_argument , & serializable_deferrable , 1 } ,
{ " serializable-deferrable " , no_argument , & serializable_deferrable , 1 } ,
{ " use-set-session-authorization " , no_argument , & use_setsessauth , 1 } ,
{ " use-set-session-authorization " , no_argument , & use_setsessauth , 1 } ,
{ " no-security-labels " , no_argument , & no_security_labels , 1 } ,
{ " no-security-labels " , no_argument , & no_security_labels , 1 } ,
{ " no-synchronized-snapshots " , no_argument , & no_synchronized_snapshots , 1 } ,
{ " no-unlogged-table-data " , no_argument , & no_unlogged_table_data , 1 } ,
{ " no-unlogged-table-data " , no_argument , & no_unlogged_table_data , 1 } ,
{ NULL , 0 , NULL , 0 }
{ NULL , 0 , NULL , 0 }
@ -360,6 +364,12 @@ main(int argc, char **argv)
set_pglocale_pgservice ( argv [ 0 ] , PG_TEXTDOMAIN ( " pg_dump " ) ) ;
set_pglocale_pgservice ( argv [ 0 ] , PG_TEXTDOMAIN ( " pg_dump " ) ) ;
/*
* Initialize what we need for parallel execution , especially for thread
* support on Windows .
*/
init_parallel_dump_utils ( ) ;
g_verbose = false ;
g_verbose = false ;
strcpy ( g_comment_start , " -- " ) ;
strcpy ( g_comment_start , " -- " ) ;
@ -390,7 +400,7 @@ main(int argc, char **argv)
}
}
}
}
while ( ( c = getopt_long ( argc , argv , " abcCd:E:f:F:h:iK:n:N:oOp:RsS:t:T:U:vwWxZ: " ,
while ( ( c = getopt_long ( argc , argv , " abcCd:E:f:F:h:ij: K:n:N:oOp:RsS:t:T:U:vwWxZ: " ,
long_options , & optindex ) ) ! = - 1 )
long_options , & optindex ) ) ! = - 1 )
{
{
switch ( c )
switch ( c )
@ -435,6 +445,10 @@ main(int argc, char **argv)
/* ignored, deprecated option */
/* ignored, deprecated option */
break ;
break ;
case ' j ' : /* number of dump jobs */
numWorkers = atoi ( optarg ) ;
break ;
case ' n ' : /* include schema(s) */
case ' n ' : /* include schema(s) */
simple_string_list_append ( & schema_include_patterns , optarg ) ;
simple_string_list_append ( & schema_include_patterns , optarg ) ;
include_everything = false ;
include_everything = false ;
@ -577,8 +591,25 @@ main(int argc, char **argv)
compressLevel = 0 ;
compressLevel = 0 ;
}
}
/*
* On Windows we can only have at most MAXIMUM_WAIT_OBJECTS ( = 64 usually )
* parallel jobs because that ' s the maximum limit for the
* WaitForMultipleObjects ( ) call .
*/
if ( numWorkers < = 0
# ifdef WIN32
| | numWorkers > MAXIMUM_WAIT_OBJECTS
# endif
)
exit_horribly ( NULL , " %s: invalid number of parallel jobs \n " , progname ) ;
/* Parallel backup only in the directory archive format so far */
if ( archiveFormat ! = archDirectory & & numWorkers > 1 )
exit_horribly ( NULL , " parallel backup only supported by the directory format \n " ) ;
/* Open the output file */
/* Open the output file */
fout = CreateArchive ( filename , archiveFormat , compressLevel , archiveMode ) ;
fout = CreateArchive ( filename , archiveFormat , compressLevel , archiveMode ,
setupDumpWorker ) ;
/* Register the cleanup hook */
/* Register the cleanup hook */
on_exit_close_archive ( fout ) ;
on_exit_close_archive ( fout ) ;
@ -600,6 +631,8 @@ main(int argc, char **argv)
fout - > minRemoteVersion = 70000 ;
fout - > minRemoteVersion = 70000 ;
fout - > maxRemoteVersion = ( my_version / 100 ) * 100 + 99 ;
fout - > maxRemoteVersion = ( my_version / 100 ) * 100 + 99 ;
fout - > numWorkers = numWorkers ;
/*
/*
* Open the database using the Archiver , so it knows about it . Errors mean
* Open the database using the Archiver , so it knows about it . Errors mean
* death .
* death .
@ -621,6 +654,7 @@ main(int argc, char **argv)
if ( fout - > remoteVersion > = 90000 )
if ( fout - > remoteVersion > = 90000 )
{
{
PGresult * res = ExecuteSqlQueryForSingleRow ( fout , " SELECT pg_catalog.pg_is_in_recovery() " ) ;
PGresult * res = ExecuteSqlQueryForSingleRow ( fout , " SELECT pg_catalog.pg_is_in_recovery() " ) ;
if ( strcmp ( PQgetvalue ( res , 0 , 0 ) , " t " ) = = 0 )
if ( strcmp ( PQgetvalue ( res , 0 , 0 ) , " t " ) = = 0 )
{
{
/*
/*
@ -632,32 +666,6 @@ main(int argc, char **argv)
PQclear ( res ) ;
PQclear ( res ) ;
}
}
/*
* Start transaction - snapshot mode transaction to dump consistent data .
*/
ExecuteSqlStatement ( fout , " BEGIN " ) ;
if ( fout - > remoteVersion > = 90100 )
{
if ( serializable_deferrable )
ExecuteSqlStatement ( fout ,
" SET TRANSACTION ISOLATION LEVEL "
" SERIALIZABLE, READ ONLY, DEFERRABLE " ) ;
else
ExecuteSqlStatement ( fout ,
" SET TRANSACTION ISOLATION LEVEL "
" REPEATABLE READ, READ ONLY " ) ;
}
else if ( fout - > remoteVersion > = 70400 )
{
/* note: comma was not accepted in SET TRANSACTION before 8.0 */
ExecuteSqlStatement ( fout ,
" SET TRANSACTION ISOLATION LEVEL "
" SERIALIZABLE READ ONLY " ) ;
}
else
ExecuteSqlStatement ( fout ,
" SET TRANSACTION ISOLATION LEVEL SERIALIZABLE " ) ;
/* Select the appropriate subquery to convert user IDs to names */
/* Select the appropriate subquery to convert user IDs to names */
if ( fout - > remoteVersion > = 80100 )
if ( fout - > remoteVersion > = 80100 )
username_subquery = " SELECT rolname FROM pg_catalog.pg_roles WHERE oid = " ;
username_subquery = " SELECT rolname FROM pg_catalog.pg_roles WHERE oid = " ;
@ -666,6 +674,14 @@ main(int argc, char **argv)
else
else
username_subquery = " SELECT usename FROM pg_user WHERE usesysid = " ;
username_subquery = " SELECT usename FROM pg_user WHERE usesysid = " ;
/* check the version for the synchronized snapshots feature */
if ( numWorkers > 1 & & fout - > remoteVersion < 90200
& & ! no_synchronized_snapshots )
exit_horribly ( NULL ,
" No synchronized snapshots available in this server version. \n "
" Run with --no-synchronized-snapshots instead if you do not \n "
" need synchronized snapshots. \n " ) ;
/* Find the last built-in OID, if needed */
/* Find the last built-in OID, if needed */
if ( fout - > remoteVersion < 70300 )
if ( fout - > remoteVersion < 70300 )
{
{
@ -763,6 +779,10 @@ main(int argc, char **argv)
else
else
sortDumpableObjectsByTypeOid ( dobjs , numObjs ) ;
sortDumpableObjectsByTypeOid ( dobjs , numObjs ) ;
/* If we do a parallel dump, we want the largest tables to go first */
if ( archiveFormat = = archDirectory & & numWorkers > 1 )
sortDataAndIndexObjectsBySize ( dobjs , numObjs ) ;
sortDumpableObjects ( dobjs , numObjs ,
sortDumpableObjects ( dobjs , numObjs ,
boundaryObjs [ 0 ] . dumpId , boundaryObjs [ 1 ] . dumpId ) ;
boundaryObjs [ 0 ] . dumpId , boundaryObjs [ 1 ] . dumpId ) ;
@ -810,9 +830,9 @@ main(int argc, char **argv)
SetArchiveRestoreOptions ( fout , ropt ) ;
SetArchiveRestoreOptions ( fout , ropt ) ;
/*
/*
* The archive ' s TOC entries are now marked as to which ones will
* The archive ' s TOC entries are now marked as to which ones will actually
* actually be output , so we can set up their dependency lists properly .
* be output , so we can set up their dependency lists properly . This isn ' t
* This isn ' t necessary for plain - text output , though .
* necessary for plain - text output , though .
*/
*/
if ( ! plainText )
if ( ! plainText )
BuildArchiveDependencies ( fout ) ;
BuildArchiveDependencies ( fout ) ;
@ -844,6 +864,7 @@ help(const char *progname)
printf ( _ ( " -f, --file=FILENAME output file or directory name \n " ) ) ;
printf ( _ ( " -f, --file=FILENAME output file or directory name \n " ) ) ;
printf ( _ ( " -F, --format=c|d|t|p output file format (custom, directory, tar, \n "
printf ( _ ( " -F, --format=c|d|t|p output file format (custom, directory, tar, \n "
" plain text (default)) \n " ) ) ;
" plain text (default)) \n " ) ) ;
printf ( _ ( " -j, --jobs=NUM use this many parallel jobs to dump \n " ) ) ;
printf ( _ ( " -v, --verbose verbose mode \n " ) ) ;
printf ( _ ( " -v, --verbose verbose mode \n " ) ) ;
printf ( _ ( " -V, --version output version information, then exit \n " ) ) ;
printf ( _ ( " -V, --version output version information, then exit \n " ) ) ;
printf ( _ ( " -Z, --compress=0-9 compression level for compressed formats \n " ) ) ;
printf ( _ ( " -Z, --compress=0-9 compression level for compressed formats \n " ) ) ;
@ -873,6 +894,7 @@ help(const char *progname)
printf ( _ ( " --exclude-table-data=TABLE do NOT dump data for the named table(s) \n " ) ) ;
printf ( _ ( " --exclude-table-data=TABLE do NOT dump data for the named table(s) \n " ) ) ;
printf ( _ ( " --inserts dump data as INSERT commands, rather than COPY \n " ) ) ;
printf ( _ ( " --inserts dump data as INSERT commands, rather than COPY \n " ) ) ;
printf ( _ ( " --no-security-labels do not dump security label assignments \n " ) ) ;
printf ( _ ( " --no-security-labels do not dump security label assignments \n " ) ) ;
printf ( _ ( " --no-synchronized-snapshots parallel processes should not use synchronized snapshots \n " ) ) ;
printf ( _ ( " --no-tablespaces do not dump tablespace assignments \n " ) ) ;
printf ( _ ( " --no-tablespaces do not dump tablespace assignments \n " ) ) ;
printf ( _ ( " --no-unlogged-table-data do not dump unlogged table data \n " ) ) ;
printf ( _ ( " --no-unlogged-table-data do not dump unlogged table data \n " ) ) ;
printf ( _ ( " --quote-all-identifiers quote all identifiers, even if not key words \n " ) ) ;
printf ( _ ( " --quote-all-identifiers quote all identifiers, even if not key words \n " ) ) ;
@ -902,7 +924,12 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role)
PGconn * conn = GetConnection ( AH ) ;
PGconn * conn = GetConnection ( AH ) ;
const char * std_strings ;
const char * std_strings ;
/* Set the client encoding if requested */
/*
* Set the client encoding if requested . If dumpencoding = = NULL then
* either it hasn ' t been requested or we ' re a cloned connection and then
* this has already been set in CloneArchive according to the original
* connection encoding .
*/
if ( dumpencoding )
if ( dumpencoding )
{
{
if ( PQsetClientEncoding ( conn , dumpencoding ) < 0 )
if ( PQsetClientEncoding ( conn , dumpencoding ) < 0 )
@ -919,6 +946,10 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role)
std_strings = PQparameterStatus ( conn , " standard_conforming_strings " ) ;
std_strings = PQparameterStatus ( conn , " standard_conforming_strings " ) ;
AH - > std_strings = ( std_strings & & strcmp ( std_strings , " on " ) = = 0 ) ;
AH - > std_strings = ( std_strings & & strcmp ( std_strings , " on " ) = = 0 ) ;
/* Set the role if requested */
if ( ! use_role & & AH - > use_role )
use_role = AH - > use_role ;
/* Set the role if requested */
/* Set the role if requested */
if ( use_role & & AH - > remoteVersion > = 80100 )
if ( use_role & & AH - > remoteVersion > = 80100 )
{
{
@ -927,6 +958,10 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role)
appendPQExpBuffer ( query , " SET ROLE %s " , fmtId ( use_role ) ) ;
appendPQExpBuffer ( query , " SET ROLE %s " , fmtId ( use_role ) ) ;
ExecuteSqlStatement ( AH , query - > data ) ;
ExecuteSqlStatement ( AH , query - > data ) ;
destroyPQExpBuffer ( query ) ;
destroyPQExpBuffer ( query ) ;
/* save this for later use on parallel connections */
if ( ! AH - > use_role )
AH - > use_role = strdup ( use_role ) ;
}
}
/* Set the datestyle to ISO to ensure the dump's portability */
/* Set the datestyle to ISO to ensure the dump's portability */
@ -965,6 +1000,68 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role)
*/
*/
if ( quote_all_identifiers & & AH - > remoteVersion > = 90100 )
if ( quote_all_identifiers & & AH - > remoteVersion > = 90100 )
ExecuteSqlStatement ( AH , " SET quote_all_identifiers = true " ) ;
ExecuteSqlStatement ( AH , " SET quote_all_identifiers = true " ) ;
/*
* Start transaction - snapshot mode transaction to dump consistent data .
*/
ExecuteSqlStatement ( AH , " BEGIN " ) ;
if ( AH - > remoteVersion > = 90100 )
{
if ( serializable_deferrable )
ExecuteSqlStatement ( AH ,
" SET TRANSACTION ISOLATION LEVEL "
" SERIALIZABLE, READ ONLY, DEFERRABLE " ) ;
else
ExecuteSqlStatement ( AH ,
" SET TRANSACTION ISOLATION LEVEL "
" REPEATABLE READ, READ ONLY " ) ;
}
else if ( AH - > remoteVersion > = 70400 )
{
/* note: comma was not accepted in SET TRANSACTION before 8.0 */
ExecuteSqlStatement ( AH ,
" SET TRANSACTION ISOLATION LEVEL "
" SERIALIZABLE READ ONLY " ) ;
}
else
ExecuteSqlStatement ( AH ,
" SET TRANSACTION ISOLATION LEVEL SERIALIZABLE " ) ;
if ( AH - > numWorkers > 1 & & AH - > remoteVersion > = 90200 & & ! no_synchronized_snapshots )
{
if ( AH - > sync_snapshot_id )
{
PQExpBuffer query = createPQExpBuffer ( ) ;
appendPQExpBuffer ( query , " SET TRANSACTION SNAPSHOT " ) ;
appendStringLiteralConn ( query , AH - > sync_snapshot_id , conn ) ;
destroyPQExpBuffer ( query ) ;
}
else
AH - > sync_snapshot_id = get_synchronized_snapshot ( AH ) ;
}
}
static void
setupDumpWorker ( Archive * AHX , RestoreOptions * ropt )
{
setup_connection ( AHX , NULL , NULL ) ;
}
static char *
get_synchronized_snapshot ( Archive * fout )
{
char * query = " SELECT pg_export_snapshot() " ;
char * result ;
PGresult * res ;
res = ExecuteSqlQueryForSingleRow ( fout , query ) ;
result = strdup ( PQgetvalue ( res , 0 , 0 ) ) ;
PQclear ( res ) ;
return result ;
}
}
static ArchiveFormat
static ArchiveFormat
@ -1282,6 +1379,12 @@ dumpTableData_copy(Archive *fout, void *dcontext)
const bool hasoids = tbinfo - > hasoids ;
const bool hasoids = tbinfo - > hasoids ;
const bool oids = tdinfo - > oids ;
const bool oids = tdinfo - > oids ;
PQExpBuffer q = createPQExpBuffer ( ) ;
PQExpBuffer q = createPQExpBuffer ( ) ;
/*
* Note : can ' t use getThreadLocalPQExpBuffer ( ) here , we ' re calling fmtId
* which uses it already .
*/
PQExpBuffer clistBuf = createPQExpBuffer ( ) ;
PGconn * conn = GetConnection ( fout ) ;
PGconn * conn = GetConnection ( fout ) ;
PGresult * res ;
PGresult * res ;
int ret ;
int ret ;
@ -1306,14 +1409,14 @@ dumpTableData_copy(Archive *fout, void *dcontext)
* cases involving ADD COLUMN and inheritance . )
* cases involving ADD COLUMN and inheritance . )
*/
*/
if ( fout - > remoteVersion > = 70300 )
if ( fout - > remoteVersion > = 70300 )
column_list = fmtCopyColumnList ( tbinfo ) ;
column_list = fmtCopyColumnList ( tbinfo , clistBuf ) ;
else
else
column_list = " " ; /* can't select columns in COPY */
column_list = " " ; /* can't select columns in COPY */
if ( oids & & hasoids )
if ( oids & & hasoids )
{
{
appendPQExpBuffer ( q , " COPY %s %s WITH OIDS TO stdout; " ,
appendPQExpBuffer ( q , " COPY %s %s WITH OIDS TO stdout; " ,
fmtQualifiedId ( fout ,
fmtQualifiedId ( fout - > remoteVersion ,
tbinfo - > dobj . namespace - > dobj . name ,
tbinfo - > dobj . namespace - > dobj . name ,
classname ) ,
classname ) ,
column_list ) ;
column_list ) ;
@ -1331,7 +1434,7 @@ dumpTableData_copy(Archive *fout, void *dcontext)
else
else
appendPQExpBufferStr ( q , " * " ) ;
appendPQExpBufferStr ( q , " * " ) ;
appendPQExpBuffer ( q , " FROM %s %s) TO stdout; " ,
appendPQExpBuffer ( q , " FROM %s %s) TO stdout; " ,
fmtQualifiedId ( fout ,
fmtQualifiedId ( fout - > remoteVersion ,
tbinfo - > dobj . namespace - > dobj . name ,
tbinfo - > dobj . namespace - > dobj . name ,
classname ) ,
classname ) ,
tdinfo - > filtercond ) ;
tdinfo - > filtercond ) ;
@ -1339,13 +1442,14 @@ dumpTableData_copy(Archive *fout, void *dcontext)
else
else
{
{
appendPQExpBuffer ( q , " COPY %s %s TO stdout; " ,
appendPQExpBuffer ( q , " COPY %s %s TO stdout; " ,
fmtQualifiedId ( fout ,
fmtQualifiedId ( fout - > remoteVersion ,
tbinfo - > dobj . namespace - > dobj . name ,
tbinfo - > dobj . namespace - > dobj . name ,
classname ) ,
classname ) ,
column_list ) ;
column_list ) ;
}
}
res = ExecuteSqlQuery ( fout , q - > data , PGRES_COPY_OUT ) ;
res = ExecuteSqlQuery ( fout , q - > data , PGRES_COPY_OUT ) ;
PQclear ( res ) ;
PQclear ( res ) ;
destroyPQExpBuffer ( clistBuf ) ;
for ( ; ; )
for ( ; ; )
{
{
@ -1464,7 +1568,7 @@ dumpTableData_insert(Archive *fout, void *dcontext)
{
{
appendPQExpBuffer ( q , " DECLARE _pg_dump_cursor CURSOR FOR "
appendPQExpBuffer ( q , " DECLARE _pg_dump_cursor CURSOR FOR "
" SELECT * FROM ONLY %s " ,
" SELECT * FROM ONLY %s " ,
fmtQualifiedId ( fout ,
fmtQualifiedId ( fout - > remoteVersion ,
tbinfo - > dobj . namespace - > dobj . name ,
tbinfo - > dobj . namespace - > dobj . name ,
classname ) ) ;
classname ) ) ;
}
}
@ -1472,7 +1576,7 @@ dumpTableData_insert(Archive *fout, void *dcontext)
{
{
appendPQExpBuffer ( q , " DECLARE _pg_dump_cursor CURSOR FOR "
appendPQExpBuffer ( q , " DECLARE _pg_dump_cursor CURSOR FOR "
" SELECT * FROM %s " ,
" SELECT * FROM %s " ,
fmtQualifiedId ( fout ,
fmtQualifiedId ( fout - > remoteVersion ,
tbinfo - > dobj . namespace - > dobj . name ,
tbinfo - > dobj . namespace - > dobj . name ,
classname ) ) ;
classname ) ) ;
}
}
@ -1604,6 +1708,7 @@ dumpTableData(Archive *fout, TableDataInfo *tdinfo)
{
{
TableInfo * tbinfo = tdinfo - > tdtable ;
TableInfo * tbinfo = tdinfo - > tdtable ;
PQExpBuffer copyBuf = createPQExpBuffer ( ) ;
PQExpBuffer copyBuf = createPQExpBuffer ( ) ;
PQExpBuffer clistBuf = createPQExpBuffer ( ) ;
DataDumperPtr dumpFn ;
DataDumperPtr dumpFn ;
char * copyStmt ;
char * copyStmt ;
@ -1615,7 +1720,7 @@ dumpTableData(Archive *fout, TableDataInfo *tdinfo)
appendPQExpBuffer ( copyBuf , " COPY %s " ,
appendPQExpBuffer ( copyBuf , " COPY %s " ,
fmtId ( tbinfo - > dobj . name ) ) ;
fmtId ( tbinfo - > dobj . name ) ) ;
appendPQExpBuffer ( copyBuf , " %s %sFROM stdin; \n " ,
appendPQExpBuffer ( copyBuf , " %s %sFROM stdin; \n " ,
fmtCopyColumnList ( tbinfo ) ,
fmtCopyColumnList ( tbinfo , clistBuf ) ,
( tdinfo - > oids & & tbinfo - > hasoids ) ? " WITH OIDS " : " " ) ;
( tdinfo - > oids & & tbinfo - > hasoids ) ? " WITH OIDS " : " " ) ;
copyStmt = copyBuf - > data ;
copyStmt = copyBuf - > data ;
}
}
@ -1640,6 +1745,7 @@ dumpTableData(Archive *fout, TableDataInfo *tdinfo)
dumpFn , tdinfo ) ;
dumpFn , tdinfo ) ;
destroyPQExpBuffer ( copyBuf ) ;
destroyPQExpBuffer ( copyBuf ) ;
destroyPQExpBuffer ( clistBuf ) ;
}
}
/*
/*
@ -4122,6 +4228,7 @@ getTables(Archive *fout, int *numTables)
int i_reloptions ;
int i_reloptions ;
int i_toastreloptions ;
int i_toastreloptions ;
int i_reloftype ;
int i_reloftype ;
int i_relpages ;
/* Make sure we are in proper schema */
/* Make sure we are in proper schema */
selectSourceSchema ( fout , " pg_catalog " ) ;
selectSourceSchema ( fout , " pg_catalog " ) ;
@ -4161,6 +4268,7 @@ getTables(Archive *fout, int *numTables)
" c.relfrozenxid, tc.oid AS toid, "
" c.relfrozenxid, tc.oid AS toid, "
" tc.relfrozenxid AS tfrozenxid, "
" tc.relfrozenxid AS tfrozenxid, "
" c.relpersistence, pg_relation_is_scannable(c.oid) as isscannable, "
" c.relpersistence, pg_relation_is_scannable(c.oid) as isscannable, "
" c.relpages, "
" CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, "
" CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, "
" d.refobjid AS owning_tab, "
" d.refobjid AS owning_tab, "
" d.refobjsubid AS owning_col, "
" d.refobjsubid AS owning_col, "
@ -4233,6 +4341,7 @@ getTables(Archive *fout, int *numTables)
" c.relfrozenxid, tc.oid AS toid, "
" c.relfrozenxid, tc.oid AS toid, "
" tc.relfrozenxid AS tfrozenxid, "
" tc.relfrozenxid AS tfrozenxid, "
" 'p' AS relpersistence, 't'::bool as isscannable, "
" 'p' AS relpersistence, 't'::bool as isscannable, "
" c.relpages, "
" CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, "
" CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, "
" d.refobjid AS owning_tab, "
" d.refobjid AS owning_tab, "
" d.refobjsubid AS owning_col, "
" d.refobjsubid AS owning_col, "
@ -4268,6 +4377,7 @@ getTables(Archive *fout, int *numTables)
" c.relfrozenxid, tc.oid AS toid, "
" c.relfrozenxid, tc.oid AS toid, "
" tc.relfrozenxid AS tfrozenxid, "
" tc.relfrozenxid AS tfrozenxid, "
" 'p' AS relpersistence, 't'::bool as isscannable, "
" 'p' AS relpersistence, 't'::bool as isscannable, "
" c.relpages, "
" NULL AS reloftype, "
" NULL AS reloftype, "
" d.refobjid AS owning_tab, "
" d.refobjid AS owning_tab, "
" d.refobjsubid AS owning_col, "
" d.refobjsubid AS owning_col, "
@ -4303,6 +4413,7 @@ getTables(Archive *fout, int *numTables)
" c.relfrozenxid, tc.oid AS toid, "
" c.relfrozenxid, tc.oid AS toid, "
" tc.relfrozenxid AS tfrozenxid, "
" tc.relfrozenxid AS tfrozenxid, "
" 'p' AS relpersistence, 't'::bool as isscannable, "
" 'p' AS relpersistence, 't'::bool as isscannable, "
" c.relpages, "
" NULL AS reloftype, "
" NULL AS reloftype, "
" d.refobjid AS owning_tab, "
" d.refobjid AS owning_tab, "
" d.refobjsubid AS owning_col, "
" d.refobjsubid AS owning_col, "
@ -4339,6 +4450,7 @@ getTables(Archive *fout, int *numTables)
" 0 AS toid, "
" 0 AS toid, "
" 0 AS tfrozenxid, "
" 0 AS tfrozenxid, "
" 'p' AS relpersistence, 't'::bool as isscannable, "
" 'p' AS relpersistence, 't'::bool as isscannable, "
" relpages, "
" NULL AS reloftype, "
" NULL AS reloftype, "
" d.refobjid AS owning_tab, "
" d.refobjid AS owning_tab, "
" d.refobjsubid AS owning_col, "
" d.refobjsubid AS owning_col, "
@ -4374,6 +4486,7 @@ getTables(Archive *fout, int *numTables)
" 0 AS toid, "
" 0 AS toid, "
" 0 AS tfrozenxid, "
" 0 AS tfrozenxid, "
" 'p' AS relpersistence, 't'::bool as isscannable, "
" 'p' AS relpersistence, 't'::bool as isscannable, "
" relpages, "
" NULL AS reloftype, "
" NULL AS reloftype, "
" d.refobjid AS owning_tab, "
" d.refobjid AS owning_tab, "
" d.refobjsubid AS owning_col, "
" d.refobjsubid AS owning_col, "
@ -4405,6 +4518,7 @@ getTables(Archive *fout, int *numTables)
" 0 AS toid, "
" 0 AS toid, "
" 0 AS tfrozenxid, "
" 0 AS tfrozenxid, "
" 'p' AS relpersistence, 't'::bool as isscannable, "
" 'p' AS relpersistence, 't'::bool as isscannable, "
" relpages, "
" NULL AS reloftype, "
" NULL AS reloftype, "
" NULL::oid AS owning_tab, "
" NULL::oid AS owning_tab, "
" NULL::int4 AS owning_col, "
" NULL::int4 AS owning_col, "
@ -4431,6 +4545,7 @@ getTables(Archive *fout, int *numTables)
" 0 AS toid, "
" 0 AS toid, "
" 0 AS tfrozenxid, "
" 0 AS tfrozenxid, "
" 'p' AS relpersistence, 't'::bool as isscannable, "
" 'p' AS relpersistence, 't'::bool as isscannable, "
" relpages, "
" NULL AS reloftype, "
" NULL AS reloftype, "
" NULL::oid AS owning_tab, "
" NULL::oid AS owning_tab, "
" NULL::int4 AS owning_col, "
" NULL::int4 AS owning_col, "
@ -4467,6 +4582,7 @@ getTables(Archive *fout, int *numTables)
" 0 AS toid, "
" 0 AS toid, "
" 0 AS tfrozenxid, "
" 0 AS tfrozenxid, "
" 'p' AS relpersistence, 't'::bool as isscannable, "
" 'p' AS relpersistence, 't'::bool as isscannable, "
" 0 AS relpages, "
" NULL AS reloftype, "
" NULL AS reloftype, "
" NULL::oid AS owning_tab, "
" NULL::oid AS owning_tab, "
" NULL::int4 AS owning_col, "
" NULL::int4 AS owning_col, "
@ -4515,6 +4631,7 @@ getTables(Archive *fout, int *numTables)
i_toastfrozenxid = PQfnumber ( res , " tfrozenxid " ) ;
i_toastfrozenxid = PQfnumber ( res , " tfrozenxid " ) ;
i_relpersistence = PQfnumber ( res , " relpersistence " ) ;
i_relpersistence = PQfnumber ( res , " relpersistence " ) ;
i_isscannable = PQfnumber ( res , " isscannable " ) ;
i_isscannable = PQfnumber ( res , " isscannable " ) ;
i_relpages = PQfnumber ( res , " relpages " ) ;
i_owning_tab = PQfnumber ( res , " owning_tab " ) ;
i_owning_tab = PQfnumber ( res , " owning_tab " ) ;
i_owning_col = PQfnumber ( res , " owning_col " ) ;
i_owning_col = PQfnumber ( res , " owning_col " ) ;
i_reltablespace = PQfnumber ( res , " reltablespace " ) ;
i_reltablespace = PQfnumber ( res , " reltablespace " ) ;
@ -4557,6 +4674,7 @@ getTables(Archive *fout, int *numTables)
tblinfo [ i ] . hastriggers = ( strcmp ( PQgetvalue ( res , i , i_relhastriggers ) , " t " ) = = 0 ) ;
tblinfo [ i ] . hastriggers = ( strcmp ( PQgetvalue ( res , i , i_relhastriggers ) , " t " ) = = 0 ) ;
tblinfo [ i ] . hasoids = ( strcmp ( PQgetvalue ( res , i , i_relhasoids ) , " t " ) = = 0 ) ;
tblinfo [ i ] . hasoids = ( strcmp ( PQgetvalue ( res , i , i_relhasoids ) , " t " ) = = 0 ) ;
tblinfo [ i ] . isscannable = ( strcmp ( PQgetvalue ( res , i , i_isscannable ) , " t " ) = = 0 ) ;
tblinfo [ i ] . isscannable = ( strcmp ( PQgetvalue ( res , i , i_isscannable ) , " t " ) = = 0 ) ;
tblinfo [ i ] . relpages = atoi ( PQgetvalue ( res , i , i_relpages ) ) ;
tblinfo [ i ] . frozenxid = atooid ( PQgetvalue ( res , i , i_relfrozenxid ) ) ;
tblinfo [ i ] . frozenxid = atooid ( PQgetvalue ( res , i , i_relfrozenxid ) ) ;
tblinfo [ i ] . toast_oid = atooid ( PQgetvalue ( res , i , i_toastoid ) ) ;
tblinfo [ i ] . toast_oid = atooid ( PQgetvalue ( res , i , i_toastoid ) ) ;
tblinfo [ i ] . toast_frozenxid = atooid ( PQgetvalue ( res , i , i_toastfrozenxid ) ) ;
tblinfo [ i ] . toast_frozenxid = atooid ( PQgetvalue ( res , i , i_toastfrozenxid ) ) ;
@ -4606,7 +4724,7 @@ getTables(Archive *fout, int *numTables)
resetPQExpBuffer ( query ) ;
resetPQExpBuffer ( query ) ;
appendPQExpBuffer ( query ,
appendPQExpBuffer ( query ,
" LOCK TABLE %s IN ACCESS SHARE MODE " ,
" LOCK TABLE %s IN ACCESS SHARE MODE " ,
fmtQualifiedId ( fout ,
fmtQualifiedId ( fout - > remoteVersion ,
tblinfo [ i ] . dobj . namespace - > dobj . name ,
tblinfo [ i ] . dobj . namespace - > dobj . name ,
tblinfo [ i ] . dobj . name ) ) ;
tblinfo [ i ] . dobj . name ) ) ;
ExecuteSqlStatement ( fout , query - > data ) ;
ExecuteSqlStatement ( fout , query - > data ) ;
@ -4745,7 +4863,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
i_conoid ,
i_conoid ,
i_condef ,
i_condef ,
i_tablespace ,
i_tablespace ,
i_options ;
i_options ,
i_relpages ;
int ntups ;
int ntups ;
for ( i = 0 ; i < numTables ; i + + )
for ( i = 0 ; i < numTables ; i + + )
@ -4790,6 +4909,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
" pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
" pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
" t.relnatts AS indnkeys, "
" t.relnatts AS indnkeys, "
" i.indkey, i.indisclustered, "
" i.indkey, i.indisclustered, "
" t.relpages, "
" c.contype, c.conname, "
" c.contype, c.conname, "
" c.condeferrable, c.condeferred, "
" c.condeferrable, c.condeferred, "
" c.tableoid AS contableoid, "
" c.tableoid AS contableoid, "
@ -4815,6 +4935,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
" pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
" pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
" t.relnatts AS indnkeys, "
" t.relnatts AS indnkeys, "
" i.indkey, i.indisclustered, "
" i.indkey, i.indisclustered, "
" t.relpages, "
" c.contype, c.conname, "
" c.contype, c.conname, "
" c.condeferrable, c.condeferred, "
" c.condeferrable, c.condeferred, "
" c.tableoid AS contableoid, "
" c.tableoid AS contableoid, "
@ -4843,6 +4964,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
" pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
" pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
" t.relnatts AS indnkeys, "
" t.relnatts AS indnkeys, "
" i.indkey, i.indisclustered, "
" i.indkey, i.indisclustered, "
" t.relpages, "
" c.contype, c.conname, "
" c.contype, c.conname, "
" c.condeferrable, c.condeferred, "
" c.condeferrable, c.condeferred, "
" c.tableoid AS contableoid, "
" c.tableoid AS contableoid, "
@ -4871,6 +4993,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
" pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
" pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
" t.relnatts AS indnkeys, "
" t.relnatts AS indnkeys, "
" i.indkey, i.indisclustered, "
" i.indkey, i.indisclustered, "
" t.relpages, "
" c.contype, c.conname, "
" c.contype, c.conname, "
" c.condeferrable, c.condeferred, "
" c.condeferrable, c.condeferred, "
" c.tableoid AS contableoid, "
" c.tableoid AS contableoid, "
@ -4899,6 +5022,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
" pg_get_indexdef(i.indexrelid) AS indexdef, "
" pg_get_indexdef(i.indexrelid) AS indexdef, "
" t.relnatts AS indnkeys, "
" t.relnatts AS indnkeys, "
" i.indkey, false AS indisclustered, "
" i.indkey, false AS indisclustered, "
" t.relpages, "
" CASE WHEN i.indisprimary THEN 'p'::char "
" CASE WHEN i.indisprimary THEN 'p'::char "
" ELSE '0'::char END AS contype, "
" ELSE '0'::char END AS contype, "
" t.relname AS conname, "
" t.relname AS conname, "
@ -4925,6 +5049,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
" pg_get_indexdef(i.indexrelid) AS indexdef, "
" pg_get_indexdef(i.indexrelid) AS indexdef, "
" t.relnatts AS indnkeys, "
" t.relnatts AS indnkeys, "
" i.indkey, false AS indisclustered, "
" i.indkey, false AS indisclustered, "
" t.relpages, "
" CASE WHEN i.indisprimary THEN 'p'::char "
" CASE WHEN i.indisprimary THEN 'p'::char "
" ELSE '0'::char END AS contype, "
" ELSE '0'::char END AS contype, "
" t.relname AS conname, "
" t.relname AS conname, "
@ -4953,6 +5078,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
i_indnkeys = PQfnumber ( res , " indnkeys " ) ;
i_indnkeys = PQfnumber ( res , " indnkeys " ) ;
i_indkey = PQfnumber ( res , " indkey " ) ;
i_indkey = PQfnumber ( res , " indkey " ) ;
i_indisclustered = PQfnumber ( res , " indisclustered " ) ;
i_indisclustered = PQfnumber ( res , " indisclustered " ) ;
i_relpages = PQfnumber ( res , " relpages " ) ;
i_contype = PQfnumber ( res , " contype " ) ;
i_contype = PQfnumber ( res , " contype " ) ;
i_conname = PQfnumber ( res , " conname " ) ;
i_conname = PQfnumber ( res , " conname " ) ;
i_condeferrable = PQfnumber ( res , " condeferrable " ) ;
i_condeferrable = PQfnumber ( res , " condeferrable " ) ;
@ -4995,6 +5121,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
parseOidArray ( PQgetvalue ( res , j , i_indkey ) ,
parseOidArray ( PQgetvalue ( res , j , i_indkey ) ,
indxinfo [ j ] . indkeys , INDEX_MAX_KEYS ) ;
indxinfo [ j ] . indkeys , INDEX_MAX_KEYS ) ;
indxinfo [ j ] . indisclustered = ( PQgetvalue ( res , j , i_indisclustered ) [ 0 ] = = ' t ' ) ;
indxinfo [ j ] . indisclustered = ( PQgetvalue ( res , j , i_indisclustered ) [ 0 ] = = ' t ' ) ;
indxinfo [ j ] . relpages = atoi ( PQgetvalue ( res , j , i_relpages ) ) ;
contype = * ( PQgetvalue ( res , j , i_contype ) ) ;
contype = * ( PQgetvalue ( res , j , i_contype ) ) ;
if ( contype = = ' p ' | | contype = = ' u ' | | contype = = ' x ' )
if ( contype = = ' p ' | | contype = = ' u ' | | contype = = ' x ' )
@ -12793,9 +12920,10 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
for ( j = 0 ; j < tbinfo - > numatts ; j + + )
for ( j = 0 ; j < tbinfo - > numatts ; j + + )
{
{
/*
/*
* Normally , dump if it ' s locally defined in this table , and not
* Normally , dump if it ' s locally defined in this table , and
* dropped . But for binary upgrade , we ' ll dump all the columns ,
* not dropped . But for binary upgrade , we ' ll dump all the
* and then fix up the dropped and nonlocal cases below .
* columns , and then fix up the dropped and nonlocal cases
* below .
*/
*/
if ( shouldPrintColumn ( tbinfo , j ) )
if ( shouldPrintColumn ( tbinfo , j ) )
{
{
@ -12806,8 +12934,8 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
! tbinfo - > attrdefs [ j ] - > separate ) ;
! tbinfo - > attrdefs [ j ] - > separate ) ;
/*
/*
* Not Null constraint - - - suppress if inherited , except in
* Not Null constraint - - - suppress if inherited , except
* binary - upgrade case where that won ' t work .
* in binary - upgrade case where that won ' t work .
*/
*/
bool has_notnull = ( tbinfo - > notnull [ j ] & &
bool has_notnull = ( tbinfo - > notnull [ j ] & &
( ! tbinfo - > inhNotNull [ j ] | |
( ! tbinfo - > inhNotNull [ j ] | |
@ -12833,9 +12961,10 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
if ( tbinfo - > attisdropped [ j ] )
if ( tbinfo - > attisdropped [ j ] )
{
{
/*
/*
* ALTER TABLE DROP COLUMN clears pg_attribute . atttypid ,
* ALTER TABLE DROP COLUMN clears
* so we will not have gotten a valid type name ; insert
* pg_attribute . atttypid , so we will not have gotten a
* INTEGER as a stopgap . We ' ll clean things up later .
* valid type name ; insert INTEGER as a stopgap . We ' ll
* clean things up later .
*/
*/
appendPQExpBuffer ( q , " INTEGER /* dummy */ " ) ;
appendPQExpBuffer ( q , " INTEGER /* dummy */ " ) ;
/* Skip all the rest, too */
/* Skip all the rest, too */
@ -12912,8 +13041,8 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
else if ( ! ( tbinfo - > reloftype & & ! binary_upgrade ) )
else if ( ! ( tbinfo - > reloftype & & ! binary_upgrade ) )
{
{
/*
/*
* We must have a parenthesized attribute list , even though empty ,
* We must have a parenthesized attribute list , even though
* when not using the OF TYPE syntax .
* empty , when not using the OF TYPE syntax .
*/
*/
appendPQExpBuffer ( q , " ( \n ) " ) ;
appendPQExpBuffer ( q , " ( \n ) " ) ;
}
}
@ -13853,8 +13982,8 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
/*
/*
* If the sequence is owned by a table column , emit the ALTER for it as a
* If the sequence is owned by a table column , emit the ALTER for it as a
* separate TOC entry immediately following the sequence ' s own entry .
* separate TOC entry immediately following the sequence ' s own entry . It ' s
* It ' s OK to do this rather than using full sorting logic , because the
* OK to do this rather than using full sorting logic , because the
* dependency that tells us it ' s owned will have forced the table to be
* dependency that tells us it ' s owned will have forced the table to be
* created first . We can ' t just include the ALTER in the TOC entry
* created first . We can ' t just include the ALTER in the TOC entry
* because it will fail if we haven ' t reassigned the sequence owner to
* because it will fail if we haven ' t reassigned the sequence owner to
@ -14859,9 +14988,9 @@ findDumpableDependencies(ArchiveHandle *AH, DumpableObject *dobj,
else
else
{
{
/*
/*
* Object will not be dumped , so recursively consider its deps .
* Object will not be dumped , so recursively consider its deps . We
* We rely on the assumption that sortDumpableObjects already
* rely on the assumption that sortDumpableObjects already broke
* broke any dependency loops , else we might recurse infinitely .
* any dependency loops , else we might recurse infinitely .
*/
*/
DumpableObject * otherdobj = findObjectByDumpId ( depid ) ;
DumpableObject * otherdobj = findObjectByDumpId ( depid ) ;
@ -14884,22 +15013,21 @@ findDumpableDependencies(ArchiveHandle *AH, DumpableObject *dobj,
*
*
* Whenever the selected schema is not pg_catalog , be careful to qualify
* Whenever the selected schema is not pg_catalog , be careful to qualify
* references to system catalogs and types in our emitted commands !
* references to system catalogs and types in our emitted commands !
*
* This function is called only from selectSourceSchemaOnAH and
* selectSourceSchema .
*/
*/
static void
static void
selectSourceSchema ( Archive * fout , const char * schemaName )
selectSourceSchema ( Archive * fout , const char * schemaName )
{
{
static char * curSchemaName = NULL ;
PQExpBuffer query ;
PQExpBuffer query ;
/* This is checked by the callers already */
Assert ( schemaName ! = NULL & & * schemaName ! = ' \0 ' ) ;
/* Not relevant if fetching from pre-7.3 DB */
/* Not relevant if fetching from pre-7.3 DB */
if ( fout - > remoteVersion < 70300 )
if ( fout - > remoteVersion < 70300 )
return ;
return ;
/* Ignore null schema names */
if ( schemaName = = NULL | | * schemaName = = ' \0 ' )
return ;
/* Optimize away repeated selection of same schema */
if ( curSchemaName & & strcmp ( curSchemaName , schemaName ) = = 0 )
return ;
query = createPQExpBuffer ( ) ;
query = createPQExpBuffer ( ) ;
appendPQExpBuffer ( query , " SET search_path = %s " ,
appendPQExpBuffer ( query , " SET search_path = %s " ,
@ -14910,9 +15038,6 @@ selectSourceSchema(Archive *fout, const char *schemaName)
ExecuteSqlStatement ( fout , query - > data ) ;
ExecuteSqlStatement ( fout , query - > data ) ;
destroyPQExpBuffer ( query ) ;
destroyPQExpBuffer ( query ) ;
if ( curSchemaName )
free ( curSchemaName ) ;
curSchemaName = pg_strdup ( schemaName ) ;
}
}
/*
/*
@ -15049,34 +15174,6 @@ myFormatType(const char *typname, int32 typmod)
return result ;
return result ;
}
}
/*
* fmtQualifiedId - convert a qualified name to the proper format for
* the source database .
*
* Like fmtId , use the result before calling again .
*/
static const char *
fmtQualifiedId ( Archive * fout , const char * schema , const char * id )
{
static PQExpBuffer id_return = NULL ;
if ( id_return ) /* first time through? */
resetPQExpBuffer ( id_return ) ;
else
id_return = createPQExpBuffer ( ) ;
/* Suppress schema name if fetching from pre-7.3 DB */
if ( fout - > remoteVersion > = 70300 & & schema & & * schema )
{
appendPQExpBuffer ( id_return , " %s. " ,
fmtId ( schema ) ) ;
}
appendPQExpBuffer ( id_return , " %s " ,
fmtId ( id ) ) ;
return id_return - > data ;
}
/*
/*
* Return a column list clause for the given relation .
* Return a column list clause for the given relation .
*
*
@ -15084,37 +15181,31 @@ fmtQualifiedId(Archive *fout, const char *schema, const char *id)
* " " , not an invalid " () " column list .
* " " , not an invalid " () " column list .
*/
*/
static const char *
static const char *
fmtCopyColumnList ( const TableInfo * ti )
fmtCopyColumnList ( const TableInfo * ti , PQExpBuffer buffer )
{
{
static PQExpBuffer q = NULL ;
int numatts = ti - > numatts ;
int numatts = ti - > numatts ;
char * * attnames = ti - > attnames ;
char * * attnames = ti - > attnames ;
bool * attisdropped = ti - > attisdropped ;
bool * attisdropped = ti - > attisdropped ;
bool needComma ;
bool needComma ;
int i ;
int i ;
if ( q ) /* first time through? */
appendPQExpBuffer ( buffer , " ( " ) ;
resetPQExpBuffer ( q ) ;
else
q = createPQExpBuffer ( ) ;
appendPQExpBuffer ( q , " ( " ) ;
needComma = false ;
needComma = false ;
for ( i = 0 ; i < numatts ; i + + )
for ( i = 0 ; i < numatts ; i + + )
{
{
if ( attisdropped [ i ] )
if ( attisdropped [ i ] )
continue ;
continue ;
if ( needComma )
if ( needComma )
appendPQExpBuffer ( q , " , " ) ;
appendPQExpBuffer ( buffer , " , " ) ;
appendPQExpBuffer ( q , " %s " , fmtId ( attnames [ i ] ) ) ;
appendPQExpBuffer ( buffer , " %s " , fmtId ( attnames [ i ] ) ) ;
needComma = true ;
needComma = true ;
}
}
if ( ! needComma )
if ( ! needComma )
return " " ; /* no undropped columns */
return " " ; /* no undropped columns */
appendPQExpBuffer ( q , " ) " ) ;
appendPQExpBuffer ( buffer , " ) " ) ;
return q - > data ;
return buffer - > data ;
}
}
/*
/*