@ -390,6 +390,7 @@ static bool nonemptyReloptions(const char *reloptions);
static void appendReloptionsArrayAH ( PQExpBuffer buffer , const char * reloptions ,
static void appendReloptionsArrayAH ( PQExpBuffer buffer , const char * reloptions ,
const char * prefix , Archive * fout ) ;
const char * prefix , Archive * fout ) ;
static char * get_synchronized_snapshot ( Archive * fout ) ;
static char * get_synchronized_snapshot ( Archive * fout ) ;
static void set_restrict_relation_kind ( Archive * AH , const char * value ) ;
static void setupDumpWorker ( Archive * AH ) ;
static void setupDumpWorker ( Archive * AH ) ;
static TableInfo * getRootTableInfo ( const TableInfo * tbinfo ) ;
static TableInfo * getRootTableInfo ( const TableInfo * tbinfo ) ;
static bool forcePartitionRootLoad ( const TableInfo * tbinfo ) ;
static bool forcePartitionRootLoad ( const TableInfo * tbinfo ) ;
@ -1354,6 +1355,13 @@ setup_connection(Archive *AH, const char *dumpencoding,
ExecuteSqlStatement ( AH , " SET row_security = off " ) ;
ExecuteSqlStatement ( AH , " SET row_security = off " ) ;
}
}
/*
* For security reasons , we restrict the expansion of non - system views and
* access to foreign tables during the pg_dump process . This restriction
* is adjusted when dumping foreign table data .
*/
set_restrict_relation_kind ( AH , " view, foreign-table " ) ;
/*
/*
* Initialize prepared - query state to " nothing prepared " . We do this here
* Initialize prepared - query state to " nothing prepared " . We do this here
* so that a parallel dump worker will have its own state .
* so that a parallel dump worker will have its own state .
@ -2222,6 +2230,10 @@ dumpTableData_copy(Archive *fout, const void *dcontext)
*/
*/
if ( tdinfo - > filtercond | | tbinfo - > relkind = = RELKIND_FOREIGN_TABLE )
if ( tdinfo - > filtercond | | tbinfo - > relkind = = RELKIND_FOREIGN_TABLE )
{
{
/* Temporary allows to access to foreign tables to dump data */
if ( tbinfo - > relkind = = RELKIND_FOREIGN_TABLE )
set_restrict_relation_kind ( fout , " view " ) ;
appendPQExpBufferStr ( q , " COPY (SELECT " ) ;
appendPQExpBufferStr ( q , " COPY (SELECT " ) ;
/* klugery to get rid of parens in column list */
/* klugery to get rid of parens in column list */
if ( strlen ( column_list ) > 2 )
if ( strlen ( column_list ) > 2 )
@ -2333,6 +2345,11 @@ dumpTableData_copy(Archive *fout, const void *dcontext)
classname ) ;
classname ) ;
destroyPQExpBuffer ( q ) ;
destroyPQExpBuffer ( q ) ;
/* Revert back the setting */
if ( tbinfo - > relkind = = RELKIND_FOREIGN_TABLE )
set_restrict_relation_kind ( fout , " view, foreign-table " ) ;
return 1 ;
return 1 ;
}
}
@ -2359,6 +2376,10 @@ dumpTableData_insert(Archive *fout, const void *dcontext)
int rows_per_statement = dopt - > dump_inserts ;
int rows_per_statement = dopt - > dump_inserts ;
int rows_this_statement = 0 ;
int rows_this_statement = 0 ;
/* Temporary allows to access to foreign tables to dump data */
if ( tbinfo - > relkind = = RELKIND_FOREIGN_TABLE )
set_restrict_relation_kind ( fout , " view " ) ;
/*
/*
* If we ' re going to emit INSERTs with column names , the most efficient
* If we ' re going to emit INSERTs with column names , the most efficient
* way to deal with generated columns is to exclude them entirely . For
* way to deal with generated columns is to exclude them entirely . For
@ -2598,6 +2619,10 @@ dumpTableData_insert(Archive *fout, const void *dcontext)
destroyPQExpBuffer ( insertStmt ) ;
destroyPQExpBuffer ( insertStmt ) ;
free ( attgenerated ) ;
free ( attgenerated ) ;
/* Revert back the setting */
if ( tbinfo - > relkind = = RELKIND_FOREIGN_TABLE )
set_restrict_relation_kind ( fout , " view, foreign-table " ) ;
return 1 ;
return 1 ;
}
}
@ -4771,6 +4796,28 @@ is_superuser(Archive *fout)
return false ;
return false ;
}
}
/*
* Set the given value to restrict_nonsystem_relation_kind value . Since
* restrict_nonsystem_relation_kind is introduced in minor version releases ,
* the setting query is effective only where available .
*/
static void
set_restrict_relation_kind ( Archive * AH , const char * value )
{
PQExpBuffer query = createPQExpBuffer ( ) ;
PGresult * res ;
appendPQExpBuffer ( query ,
" SELECT set_config(name, '%s', false) "
" FROM pg_settings "
" WHERE name = 'restrict_nonsystem_relation_kind' " ,
value ) ;
res = ExecuteSqlQuery ( AH , query - > data , PGRES_TUPLES_OK ) ;
PQclear ( res ) ;
destroyPQExpBuffer ( query ) ;
}
/*
/*
* getSubscriptions
* getSubscriptions
* get information about subscriptions
* get information about subscriptions