static PGconn *conn = NULL;
/*
- * Relation files are fetched max CHUNKSIZE bytes at a time.
+ * Files are fetched max CHUNKSIZE bytes at a time.
+ *
+ * (This only applies to files that are copied in whole, or for truncated
+ * files where we copy the tail. Relation files, where we know the individual
+ * blocks that need to be fetched, are fetched in BLCKSZ chunks.)
*/
#define CHUNKSIZE 1000000
const char *sql;
int i;
+ /*
+ * Create a recursive directory listing of the whole data directory.
+ *
+ * The WITH RECURSIVE part does most of the work. The second part
+ * gets the targets of the symlinks in pg_tblspc directory.
+ *
+ * XXX: There is no backend function to get a symbolic link's target in
+ * general, so if the admin has put any custom symbolic links in the data
+ * directory, they won't be copied correctly.
+ */
sql =
- "-- Create a recursive directory listing of the whole data directory\n"
"WITH RECURSIVE files (path, filename, size, isdir) AS (\n"
" SELECT '' AS path, filename, size, isdir FROM\n"
" (SELECT pg_ls_dir('.') AS filename) AS fn,\n"
" pg_stat_file(parent.path || parent.filename || '/' || fn) AS this\n"
" WHERE parent.isdir = 't'\n"
")\n"
- "-- Using the cte, fetch a listing of the all the files.\n"
- "--\n"
- "-- For tablespaces, use pg_tablespace_location() function to fetch\n"
- "-- the link target (there is no backend function to get a symbolic\n"
- "-- link's target in general, so if the admin has put any custom\n"
- "-- symbolic links in the data directory, they won't be copied\n"
- "-- correctly)\n"
"SELECT path || filename, size, isdir,\n"
" pg_tablespace_location(pg_tablespace.oid) AS link_target\n"
"FROM files\n"
PQresultErrorMessage(res));
}
- /* Ok, we've sent the file list. Now receive the files. */
+ /*
+ * We've now copied the list of file ranges that we need to fetch to
+ * the temporary table. Now, actually fetch all of those ranges.
+ */
sql =
- "-- fetch all the blocks listed in the temp table.\n"
"SELECT path, begin, \n"
" pg_read_binary_file(path, begin, len) AS chunk\n"
"FROM fetchchunks\n";
receiveFileChunks(sql);
}
-
static void
execute_pagemap(datapagemap_t *pagemap, const char *path)
{