summaryrefslogtreecommitdiff
path: root/src/backend/backup/basebackup.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2023-10-23 15:08:53 -0400
committerRobert Haas <rhaas@postgresql.org>2023-10-23 15:08:53 -0400
commit5c47c6546c413d5eb51c1626070a807026e6139d (patch)
treef9145164fda101e0fa454d2f8274526c3d559104 /src/backend/backup/basebackup.c
parentb6f1cca9ba3d24c8fcaa9facc30c96bcc50b37aa (diff)
Refactor parse_filename_for_nontemp_relation to parse more.
Instead of returning the number of characters in the RelFileNumber, return the RelFileNumber itself. Continue to return the fork number, as before, and additionally return the segment number. parse_filename_for_nontemp_relation now rejects a RelFileNumber or segment number that begins with a leading zero. Before, we accepted such cases as relation filenames, but if we continued to do so after this change, the function might return the same values for two different files (e.g. 1234.5 and 001234.5 or 1234.005) which could be annoying for callers. Since we don't actually ever generate filenames with leading zeroes in the names, any such files that we find must have been created by something other than PostgreSQL, and it is therefore reasonable to treat them as non-relation files. Along the way, change unlogged_relation_entry to store a RelFileNumber rather than an OID. This update should have been made in 851f4cc75cdd8c831f1baa9a7abf8c8248b65890, but it was overlooked. It's trivial to make the update as part of this commit, perhaps more trivial than it would have been without it, so do that. Patch by me, reviewed by David Steele. Discussion: http://postgr.es/m/CA+TgmoZNVeBzoqDL8xvr-nkaepq815jtDR4nJzPew7=3iEuM1g@mail.gmail.com
Diffstat (limited to 'src/backend/backup/basebackup.c')
-rw-r--r--src/backend/backup/basebackup.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 7d025bcf382..b126d9c8907 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -1197,9 +1197,9 @@ sendDir(bbsink *sink, const char *path, int basepathlen, bool sizeonly,
{
int excludeIdx;
bool excludeFound;
- ForkNumber relForkNum; /* Type of fork if file is a relation */
- int relnumchars; /* Chars in filename that are the
- * relnumber */
+ RelFileNumber relNumber;
+ ForkNumber relForkNum;
+ unsigned segno;
/* Skip special stuff */
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)
@@ -1249,23 +1249,20 @@ sendDir(bbsink *sink, const char *path, int basepathlen, bool sizeonly,
/* Exclude all forks for unlogged tables except the init fork */
if (isDbDir &&
- parse_filename_for_nontemp_relation(de->d_name, &relnumchars,
- &relForkNum))
+ parse_filename_for_nontemp_relation(de->d_name, &relNumber,
+ &relForkNum, &segno))
{
/* Never exclude init forks */
if (relForkNum != INIT_FORKNUM)
{
char initForkFile[MAXPGPATH];
- char relNumber[OIDCHARS + 1];
/*
* If any other type of fork, check if there is an init fork
* with the same RelFileNumber. If so, the file can be
* excluded.
*/
- memcpy(relNumber, de->d_name, relnumchars);
- relNumber[relnumchars] = '\0';
- snprintf(initForkFile, sizeof(initForkFile), "%s/%s_init",
+ snprintf(initForkFile, sizeof(initForkFile), "%s/%u_init",
path, relNumber);
if (lstat(initForkFile, &statbuf) == 0)