mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2025-01-07 13:40:17 +02:00
use pg_ptrack_get_block_2 to read block by relfilenode without relcache
This commit is contained in:
parent
109b9968cc
commit
389c82fffb
76
src/backup.c
76
src/backup.c
@ -2677,7 +2677,7 @@ pg_ptrack_get_block(Oid dbOid,
|
|||||||
PGresult *res_db;
|
PGresult *res_db;
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
const char *dbname;
|
const char *dbname;
|
||||||
char *params[3];
|
char *params[4];
|
||||||
char *result;
|
char *result;
|
||||||
char *val;
|
char *val;
|
||||||
PGconn *tmp_conn;
|
PGconn *tmp_conn;
|
||||||
@ -2685,47 +2685,51 @@ pg_ptrack_get_block(Oid dbOid,
|
|||||||
params[0] = palloc(64);
|
params[0] = palloc(64);
|
||||||
params[1] = palloc(64);
|
params[1] = palloc(64);
|
||||||
params[2] = palloc(64);
|
params[2] = palloc(64);
|
||||||
|
params[3] = palloc(64);
|
||||||
|
|
||||||
sprintf(params[0], "%i", dbOid);
|
// sprintf(params[0], "%i", dbOid);
|
||||||
res_db = pgut_execute(backup_conn,
|
// res_db = pgut_execute(backup_conn,
|
||||||
"SELECT datname FROM pg_database WHERE oid=$1",
|
// "SELECT datname FROM pg_database WHERE oid=$1",
|
||||||
1, (const char **) params, true);
|
// 1, (const char **) params, true);
|
||||||
/*
|
// /*
|
||||||
* If database is not found, it's not an error.
|
// * If database is not found, it's not an error.
|
||||||
* It could have been deleted.
|
// * It could have been deleted.
|
||||||
*/
|
// */
|
||||||
if (PQntuples(res_db) != 1 || PQnfields(res_db) != 1)
|
// if (PQntuples(res_db) != 1 || PQnfields(res_db) != 1)
|
||||||
{
|
// {
|
||||||
//elog(LOG, "Database with oid %d is not found", dbOid);
|
// //elog(LOG, "Database with oid %d is not found", dbOid);
|
||||||
return NULL;
|
// return NULL;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
dbname = PQgetvalue(res_db, 0, 0);
|
// dbname = PQgetvalue(res_db, 0, 0);
|
||||||
if (strcmp(dbname, "template0") == 0)
|
// if (strcmp(dbname, "template0") == 0)
|
||||||
{
|
// {
|
||||||
/*
|
// /*
|
||||||
* There is no way to connect to the template0 database.
|
// * There is no way to connect to the template0 database.
|
||||||
* But it's totally OK, since files there can never be changed.
|
// * But it's totally OK, since files there can never be changed.
|
||||||
*/
|
// */
|
||||||
return NULL;
|
// return NULL;
|
||||||
}
|
// }
|
||||||
tmp_conn = pgut_connect(dbname);
|
// tmp_conn = pgut_connect(dbname);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Use backup_conn, cause we can do it from any database.
|
* Use backup_conn, cause we can do it from any database.
|
||||||
*/
|
*/
|
||||||
sprintf(params[0], "%i", tblsOid);
|
sprintf(params[0], "%i", tblsOid);
|
||||||
sprintf(params[1], "%i", relOid);
|
sprintf(params[1], "%i", dbOid);
|
||||||
sprintf(params[2], "%u", blknum);
|
sprintf(params[2], "%i", relOid);
|
||||||
|
sprintf(params[3], "%u", blknum);
|
||||||
|
|
||||||
//elog(WARNING, "db %i pg_ptrack_get_block(%i, %i, %u)",dbOid, tblsOid, relOid, blknum);
|
//elog(LOG, "db %i pg_ptrack_get_block(%i, %i, %u)",dbOid, tblsOid, relOid, blknum);
|
||||||
|
res = pgut_execute(backup_conn, "SELECT pg_ptrack_get_block_2($1, $2, $3, $4)",
|
||||||
res = pgut_execute(tmp_conn, "SELECT pg_ptrack_get_block($1, $2, $3)",
|
4, (const char **)params, true);
|
||||||
3, (const char **)params, true);
|
|
||||||
|
|
||||||
if (PQnfields(res) != 1)
|
if (PQnfields(res) != 1)
|
||||||
elog(WARNING, "cannot get file block for relation oid %u",
|
{
|
||||||
relOid);
|
elog(LOG, "cannot get file block for relation oid %u",
|
||||||
|
relOid);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
val = PQgetvalue(res, 0, 0);
|
val = PQgetvalue(res, 0, 0);
|
||||||
|
|
||||||
@ -2735,12 +2739,14 @@ pg_ptrack_get_block(Oid dbOid,
|
|||||||
result = (char *) PQunescapeBytea((unsigned char *) PQgetvalue(res, 0, 0),
|
result = (char *) PQunescapeBytea((unsigned char *) PQgetvalue(res, 0, 0),
|
||||||
result_size);
|
result_size);
|
||||||
|
|
||||||
pgut_disconnect(tmp_conn);
|
// pgut_disconnect(tmp_conn);
|
||||||
|
// PQclear(res_db);
|
||||||
|
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQclear(res_db);
|
|
||||||
pfree(params[0]);
|
pfree(params[0]);
|
||||||
pfree(params[1]);
|
pfree(params[1]);
|
||||||
pfree(params[2]);
|
pfree(params[2]);
|
||||||
|
pfree(params[3]);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user