diff --git a/src/backup.c b/src/backup.c index 6f0a3cca..b215b121 100644 --- a/src/backup.c +++ b/src/backup.c @@ -2677,7 +2677,7 @@ pg_ptrack_get_block(Oid dbOid, PGresult *res_db; PGresult *res; const char *dbname; - char *params[3]; + char *params[4]; char *result; char *val; PGconn *tmp_conn; @@ -2685,47 +2685,51 @@ pg_ptrack_get_block(Oid dbOid, params[0] = palloc(64); params[1] = palloc(64); params[2] = palloc(64); + params[3] = palloc(64); - sprintf(params[0], "%i", dbOid); - res_db = pgut_execute(backup_conn, - "SELECT datname FROM pg_database WHERE oid=$1", - 1, (const char **) params, true); - /* - * If database is not found, it's not an error. - * It could have been deleted. - */ - if (PQntuples(res_db) != 1 || PQnfields(res_db) != 1) - { - //elog(LOG, "Database with oid %d is not found", dbOid); - return NULL; - } - - dbname = PQgetvalue(res_db, 0, 0); - if (strcmp(dbname, "template0") == 0) - { - /* - * There is no way to connect to the template0 database. - * But it's totally OK, since files there can never be changed. - */ - return NULL; - } - tmp_conn = pgut_connect(dbname); +// sprintf(params[0], "%i", dbOid); +// res_db = pgut_execute(backup_conn, +// "SELECT datname FROM pg_database WHERE oid=$1", +// 1, (const char **) params, true); +// /* +// * If database is not found, it's not an error. +// * It could have been deleted. +// */ +// if (PQntuples(res_db) != 1 || PQnfields(res_db) != 1) +// { +// //elog(LOG, "Database with oid %d is not found", dbOid); +// return NULL; +// } +// +// dbname = PQgetvalue(res_db, 0, 0); +// if (strcmp(dbname, "template0") == 0) +// { +// /* +// * There is no way to connect to the template0 database. +// * But it's totally OK, since files there can never be changed. +// */ +// return NULL; +// } +// tmp_conn = pgut_connect(dbname); /* * Use backup_conn, cause we can do it from any database. */ sprintf(params[0], "%i", tblsOid); - sprintf(params[1], "%i", relOid); - sprintf(params[2], "%u", blknum); + sprintf(params[1], "%i", dbOid); + 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); - - res = pgut_execute(tmp_conn, "SELECT pg_ptrack_get_block($1, $2, $3)", - 3, (const char **)params, true); + //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)", + 4, (const char **)params, true); 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); @@ -2735,12 +2739,14 @@ pg_ptrack_get_block(Oid dbOid, result = (char *) PQunescapeBytea((unsigned char *) PQgetvalue(res, 0, 0), result_size); - pgut_disconnect(tmp_conn); +// pgut_disconnect(tmp_conn); +// PQclear(res_db); + PQclear(res); - PQclear(res_db); pfree(params[0]); pfree(params[1]); pfree(params[2]); + pfree(params[3]); return result; } \ No newline at end of file