From: Heikki Linnakangas Date: Fri, 9 Jan 2015 09:39:54 +0000 (+0200) Subject: Uppercase SQL keywords. Remove spurious dot from error message. Improve comments X-Git-Url: http://git.postgresql.org/gitweb/review?a=commitdiff_plain;h=399cca9cbd9f27d69ca94949547ea561dd17be0c;p=users%2Fheikki%2Fpostgres.git Uppercase SQL keywords. Remove spurious dot from error message. Improve comments --- diff --git a/contrib/pg_rewind/filemap.c b/contrib/pg_rewind/filemap.c index 3d69100930..0e62d7971b 100644 --- a/contrib/pg_rewind/filemap.c +++ b/contrib/pg_rewind/filemap.c @@ -94,7 +94,7 @@ process_remote_file(const char *path, file_type_t type, size_t newsize, */ if (type != FILE_TYPE_REGULAR && isRelDataFile(path)) { - fprintf(stderr, "data file in source \"%s\" is a directory.\n", path); + fprintf(stderr, "data file in source \"%s\" is a directory\n", path); exit(1); } @@ -483,6 +483,11 @@ print_filemap(void) /* * Does it look like a relation data file? + * + * For our purposes, only files belonging to the main fork are considered + * relation files. Other forks are alwayes copied in toto, because we cannot + * reliably track changes to the, because WAL only contains block references + * for the main fork. */ static bool isRelDataFile(const char *path) diff --git a/contrib/pg_rewind/filemap.h b/contrib/pg_rewind/filemap.h index d806adff21..1ce82a433b 100644 --- a/contrib/pg_rewind/filemap.h +++ b/contrib/pg_rewind/filemap.h @@ -72,7 +72,7 @@ struct filemap_t /* * After processing all the remote files, the entries in the linked list - * are moved to this array. After processing local file, too, all the + * are moved to this array. After processing local files, too, all the * local entries are added to the array by filemap_finalize, and sorted * in the final order. After filemap_finalize, all the entries are in * the array, and the linked list is empty. diff --git a/contrib/pg_rewind/libpq_fetch.c b/contrib/pg_rewind/libpq_fetch.c index b5f5314a4a..a781b7aa4a 100644 --- a/contrib/pg_rewind/libpq_fetch.c +++ b/contrib/pg_rewind/libpq_fetch.c @@ -30,6 +30,9 @@ static PGconn *conn = NULL; +/* + * Relation files are fetched max CHUNKSIZE bytes at a time. + */ #define CHUNKSIZE 1000000 static void receiveFileChunks(const char *sql); @@ -62,17 +65,17 @@ libpqProcessFileList(void) 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(fn.filename) as this\n" - " union all\n" - " select parent.path || parent.filename || '/' as path,\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(fn.filename) AS this\n" + " UNION ALL\n" + " SELECT parent.path || parent.filename || '/' AS path,\n" " fn, this.size, this.isdir\n" - " from files as parent,\n" - " pg_ls_dir(parent.path || parent.filename) as fn,\n" - " pg_stat_file(parent.path || parent.filename || '/' || fn) as this\n" - " where parent.isdir = 't'\n" + " FROM files AS parent,\n" + " pg_ls_dir(parent.path || parent.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" @@ -81,11 +84,11 @@ libpqProcessFileList(void) "-- 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" - "left outer join pg_tablespace on files.path = 'pg_tblspc/'\n" - " and oid::text = files.filename\n"; + "SELECT path || filename, size, isdir,\n" + " pg_tablespace_location(pg_tablespace.oid) AS link_target\n" + "FROM files\n" + "LEFT OUTER JOIN pg_tablespace ON files.path = 'pg_tblspc/'\n" + " AND oid::text = files.filename\n"; res = PQexec(conn, sql); if (PQresultStatus(res) != PGRES_TUPLES_OK) @@ -235,7 +238,7 @@ libpqGetFile(const char *filename, size_t *filesize) const char *paramValues[1]; paramValues[0] = filename; - res = PQexecParams(conn, "select pg_read_binary_file($1)", + res = PQexecParams(conn, "SELECT pg_read_binary_file($1)", 1, NULL, paramValues, NULL, NULL, 1); if (PQresultStatus(res) != PGRES_TUPLES_OK) @@ -310,7 +313,7 @@ libpq_executeFileMap(filemap_t *map) * First create a temporary table, and load it with the blocks that * we need to fetch. */ - sql = "create temporary table fetchchunks(path text, begin int4, len int4);"; + sql = "CREATE TEMPORARY TABLE fetchchunks(path text, begin int4, len int4);"; res = PQexec(conn, sql); if (PQresultStatus(res) != PGRES_COMMAND_OK) @@ -385,9 +388,9 @@ libpq_executeFileMap(filemap_t *map) /* Ok, we've sent the file list. Now receive the files */ 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"; + "SELECT path, begin, \n" + " pg_read_binary_file(path, begin, len) AS chunk\n" + "FROM fetchchunks\n"; receiveFileChunks(sql); }