Skip to content

Commit a5e8a54

Browse files
committed
do not throw an error if database is not found while performing ptrack backup
1 parent a42add5 commit a5e8a54

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/backup.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -826,8 +826,13 @@ pg_ptrack_get_and_clear(Oid tablespace_oid, Oid db_oid, Oid rel_oid,
826826
res_db = pgut_execute(backup_conn,
827827
"SELECT datname FROM pg_database WHERE oid=$1",
828828
1, (const char **) params);
829+
830+
/*
831+
* If database is not found, it's not an error.
832+
* It could have been deleted since previous backup.
833+
*/
829834
if (PQntuples(res_db) != 1 || PQnfields(res_db) != 1)
830-
elog(ERROR, "cannot find database by oid %u", db_oid);
835+
return NULL;
831836

832837
dbname = pstrdup(PQgetvalue(res_db, 0, 0));
833838
PQclear(res_db);
@@ -1877,22 +1882,24 @@ make_pagemap_from_ptrack(parray *files)
18771882
/* get ptrack map for all segments of the relation in a raw format */
18781883
ptrack_nonparsed = pg_ptrack_get_and_clear(tablespace_oid, db_oid,
18791884
rel_oid, &ptrack_nonparsed_size);
1885+
if (ptrack_nonparsed != NULL)
1886+
{
1887+
/*
1888+
* FIXME When do we cut VARHDR from ptrack_nonparsed?
1889+
* Compute the beginning of the ptrack map related to this segment
1890+
*/
1891+
start_addr = (RELSEG_SIZE/HEAPBLOCKS_PER_BYTE)*p->segno;
18801892

1881-
/*
1882-
* FIXME When do we cut VARHDR from ptrack_nonparsed?
1883-
* Compute the beginning of the ptrack map related to this segment
1884-
*/
1885-
start_addr = (RELSEG_SIZE/HEAPBLOCKS_PER_BYTE)*p->segno;
1886-
1887-
if (start_addr + RELSEG_SIZE/HEAPBLOCKS_PER_BYTE > ptrack_nonparsed_size)
1888-
p->pagemap.bitmapsize = ptrack_nonparsed_size - start_addr;
1889-
else
1890-
p->pagemap.bitmapsize = RELSEG_SIZE/HEAPBLOCKS_PER_BYTE;
1893+
if (start_addr + RELSEG_SIZE/HEAPBLOCKS_PER_BYTE > ptrack_nonparsed_size)
1894+
p->pagemap.bitmapsize = ptrack_nonparsed_size - start_addr;
1895+
else
1896+
p->pagemap.bitmapsize = RELSEG_SIZE/HEAPBLOCKS_PER_BYTE;
18911897

1892-
p->pagemap.bitmap = pg_malloc(p->pagemap.bitmapsize);
1893-
memcpy(p->pagemap.bitmap, ptrack_nonparsed+start_addr, p->pagemap.bitmapsize);
1898+
p->pagemap.bitmap = pg_malloc(p->pagemap.bitmapsize);
1899+
memcpy(p->pagemap.bitmap, ptrack_nonparsed+start_addr, p->pagemap.bitmapsize);
18941900

1895-
pg_free(ptrack_nonparsed);
1901+
pg_free(ptrack_nonparsed);
1902+
}
18961903
}
18971904
}
18981905
}

0 commit comments

Comments
 (0)