mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Handle OID's and unsigned values better in pg_autovacuum.
Matthew T. O'Connor
This commit is contained in:
@ -117,9 +117,9 @@ init_table_info(PGresult *res, int row, db_info * dbi)
|
|||||||
atol(PQgetvalue(res, row, PQfnumber(res, "n_tup_upd"))));
|
atol(PQgetvalue(res, row, PQfnumber(res, "n_tup_upd"))));
|
||||||
new_tbl->curr_vacuum_count = new_tbl->CountAtLastVacuum;
|
new_tbl->curr_vacuum_count = new_tbl->CountAtLastVacuum;
|
||||||
|
|
||||||
new_tbl->relid = atoi(PQgetvalue(res, row, PQfnumber(res, "oid")));
|
new_tbl->relid = atooid(PQgetvalue(res, row, PQfnumber(res, "oid")));
|
||||||
new_tbl->reltuples = atoi(PQgetvalue(res, row, PQfnumber(res, "reltuples")));
|
new_tbl->reltuples = atof(PQgetvalue(res, row, PQfnumber(res, "reltuples")));
|
||||||
new_tbl->relpages = atoi(PQgetvalue(res, row, PQfnumber(res, "relpages")));
|
new_tbl->relpages = atooid(PQgetvalue(res, row, PQfnumber(res, "relpages")));
|
||||||
|
|
||||||
if (strcmp("t", PQgetvalue(res, row, PQfnumber(res, "relisshared"))))
|
if (strcmp("t", PQgetvalue(res, row, PQfnumber(res, "relisshared"))))
|
||||||
new_tbl->relisshared = 0;
|
new_tbl->relisshared = 0;
|
||||||
@ -159,8 +159,8 @@ update_table_thresholds(db_info * dbi, tbl_info * tbl, int vacuum_type)
|
|||||||
if (res != NULL)
|
if (res != NULL)
|
||||||
{
|
{
|
||||||
tbl->reltuples =
|
tbl->reltuples =
|
||||||
atoi(PQgetvalue(res, 0, PQfnumber(res, "reltuples")));
|
atof(PQgetvalue(res, 0, PQfnumber(res, "reltuples")));
|
||||||
tbl->relpages = atoi(PQgetvalue(res, 0, PQfnumber(res, "relpages")));
|
tbl->relpages = atooid(PQgetvalue(res, 0, PQfnumber(res, "relpages")));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* update vacuum thresholds only of we just did a vacuum
|
* update vacuum thresholds only of we just did a vacuum
|
||||||
@ -237,7 +237,7 @@ update_table_list(db_info * dbi)
|
|||||||
for (i = 0; i < t; i++)
|
for (i = 0; i < t; i++)
|
||||||
{ /* loop through result set looking for a
|
{ /* loop through result set looking for a
|
||||||
* match */
|
* match */
|
||||||
if (tbl->relid == atoi(PQgetvalue(res, i, PQfnumber(res, "oid"))))
|
if (tbl->relid == atooid(PQgetvalue(res, i, PQfnumber(res, "oid"))))
|
||||||
{
|
{
|
||||||
found_match = 1;
|
found_match = 1;
|
||||||
break;
|
break;
|
||||||
@ -267,7 +267,7 @@ update_table_list(db_info * dbi)
|
|||||||
while (tbl_elem != NULL)
|
while (tbl_elem != NULL)
|
||||||
{
|
{
|
||||||
tbl = ((tbl_info *) DLE_VAL(tbl_elem));
|
tbl = ((tbl_info *) DLE_VAL(tbl_elem));
|
||||||
if (tbl->relid == atoi(PQgetvalue(res, i, PQfnumber(res, "oid"))))
|
if (tbl->relid == atooid(PQgetvalue(res, i, PQfnumber(res, "oid"))))
|
||||||
{
|
{
|
||||||
found_match = 1;
|
found_match = 1;
|
||||||
break;
|
break;
|
||||||
@ -361,9 +361,9 @@ print_table_info(tbl_info * tbl)
|
|||||||
{
|
{
|
||||||
sprintf(logbuffer, " table name: %s.%s", tbl->dbi->dbname, tbl->table_name);
|
sprintf(logbuffer, " table name: %s.%s", tbl->dbi->dbname, tbl->table_name);
|
||||||
log_entry(logbuffer);
|
log_entry(logbuffer);
|
||||||
sprintf(logbuffer, " relid: %i; relisshared: %i", tbl->relid, tbl->relisshared);
|
sprintf(logbuffer, " relid: %u; relisshared: %i", tbl->relid, tbl->relisshared);
|
||||||
log_entry(logbuffer);
|
log_entry(logbuffer);
|
||||||
sprintf(logbuffer, " reltuples: %i; relpages: %i", tbl->reltuples, tbl->relpages);
|
sprintf(logbuffer, " reltuples: %f; relpages: %u", tbl->reltuples, tbl->relpages);
|
||||||
log_entry(logbuffer);
|
log_entry(logbuffer);
|
||||||
sprintf(logbuffer, " curr_analyze_count: %li; cur_delete_count: %li",
|
sprintf(logbuffer, " curr_analyze_count: %li; cur_delete_count: %li",
|
||||||
tbl->curr_analyze_count, tbl->curr_vacuum_count);
|
tbl->curr_analyze_count, tbl->curr_vacuum_count);
|
||||||
@ -407,8 +407,8 @@ init_db_list()
|
|||||||
if (dbs->conn != NULL)
|
if (dbs->conn != NULL)
|
||||||
{
|
{
|
||||||
res = send_query(FROZENOID_QUERY, dbs);
|
res = send_query(FROZENOID_QUERY, dbs);
|
||||||
dbs->oid = atoi(PQgetvalue(res, 0, PQfnumber(res, "oid")));
|
dbs->oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "oid")));
|
||||||
dbs->age = atoi(PQgetvalue(res, 0, PQfnumber(res, "age")));
|
dbs->age = atol(PQgetvalue(res, 0, PQfnumber(res, "age")));
|
||||||
if (res)
|
if (res)
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
|
||||||
@ -421,7 +421,7 @@ init_db_list()
|
|||||||
/* Simple function to create an instance of the dbinfo struct
|
/* Simple function to create an instance of the dbinfo struct
|
||||||
Initalizes all the pointers and connects to the database */
|
Initalizes all the pointers and connects to the database */
|
||||||
db_info *
|
db_info *
|
||||||
init_dbinfo(char *dbname, int oid, int age)
|
init_dbinfo(char *dbname, Oid oid, long age)
|
||||||
{
|
{
|
||||||
db_info *newdbinfo = (db_info *) malloc(sizeof(db_info));
|
db_info *newdbinfo = (db_info *) malloc(sizeof(db_info));
|
||||||
|
|
||||||
@ -500,7 +500,7 @@ update_db_list(Dllist *db_list)
|
|||||||
for (i = 0; i < t; i++)
|
for (i = 0; i < t; i++)
|
||||||
{ /* loop through result set looking for a
|
{ /* loop through result set looking for a
|
||||||
* match */
|
* match */
|
||||||
if (dbi->oid == atoi(PQgetvalue(res, i, PQfnumber(res, "oid"))))
|
if (dbi->oid == atooid(PQgetvalue(res, i, PQfnumber(res, "oid"))))
|
||||||
{
|
{
|
||||||
found_match = 1;
|
found_match = 1;
|
||||||
|
|
||||||
@ -508,7 +508,7 @@ update_db_list(Dllist *db_list)
|
|||||||
* update the dbi->age so that we ensure
|
* update the dbi->age so that we ensure
|
||||||
* xid_wraparound won't happen
|
* xid_wraparound won't happen
|
||||||
*/
|
*/
|
||||||
dbi->age = atoi(PQgetvalue(res, i, PQfnumber(res, "age")));
|
dbi->age = atol(PQgetvalue(res, i, PQfnumber(res, "age")));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -536,7 +536,7 @@ update_db_list(Dllist *db_list)
|
|||||||
while (db_elem != NULL)
|
while (db_elem != NULL)
|
||||||
{
|
{
|
||||||
dbi = ((db_info *) DLE_VAL(db_elem));
|
dbi = ((db_info *) DLE_VAL(db_elem));
|
||||||
if (dbi->oid == atoi(PQgetvalue(res, i, PQfnumber(res, "oid"))))
|
if (dbi->oid == atooid(PQgetvalue(res, i, PQfnumber(res, "oid"))))
|
||||||
{
|
{
|
||||||
found_match = 1;
|
found_match = 1;
|
||||||
break;
|
break;
|
||||||
@ -548,8 +548,8 @@ update_db_list(Dllist *db_list)
|
|||||||
{
|
{
|
||||||
DLAddTail(db_list, DLNewElem(init_dbinfo
|
DLAddTail(db_list, DLNewElem(init_dbinfo
|
||||||
(PQgetvalue(res, i, PQfnumber(res, "datname")),
|
(PQgetvalue(res, i, PQfnumber(res, "datname")),
|
||||||
atoi(PQgetvalue(res, i, PQfnumber(res, "oid"))),
|
atooid(PQgetvalue(res, i, PQfnumber(res, "oid"))),
|
||||||
atoi(PQgetvalue(res, i, PQfnumber(res, "age"))))));
|
atol(PQgetvalue(res, i, PQfnumber(res, "age"))))));
|
||||||
if (args->debug >= 1)
|
if (args->debug >= 1)
|
||||||
{
|
{
|
||||||
sprintf(logbuffer, "added database: %s", ((db_info *) DLE_VAL(DLGetTail(db_list)))->dbname);
|
sprintf(logbuffer, "added database: %s", ((db_info *) DLE_VAL(DLGetTail(db_list)))->dbname);
|
||||||
@ -681,7 +681,7 @@ print_db_info(db_info * dbi, int print_tbl_list)
|
|||||||
sprintf(logbuffer, "dbname: %s Username %s Passwd %s", dbi->dbname,
|
sprintf(logbuffer, "dbname: %s Username %s Passwd %s", dbi->dbname,
|
||||||
dbi->username, dbi->password);
|
dbi->username, dbi->password);
|
||||||
log_entry(logbuffer);
|
log_entry(logbuffer);
|
||||||
sprintf(logbuffer, " oid %i InsertThresh: %i DeleteThresh: %i", dbi->oid,
|
sprintf(logbuffer, " oid %u InsertThresh: %li DeleteThresh: %li", dbi->oid,
|
||||||
dbi->analyze_threshold, dbi->vacuum_threshold);
|
dbi->analyze_threshold, dbi->vacuum_threshold);
|
||||||
log_entry(logbuffer);
|
log_entry(logbuffer);
|
||||||
if (dbi->conn != NULL)
|
if (dbi->conn != NULL)
|
||||||
@ -1072,7 +1072,7 @@ main(int argc, char *argv[])
|
|||||||
{ /* Loop through tables in list */
|
{ /* Loop through tables in list */
|
||||||
tbl = ((tbl_info *) DLE_VAL(tbl_elem)); /* set tbl_info =
|
tbl = ((tbl_info *) DLE_VAL(tbl_elem)); /* set tbl_info =
|
||||||
* current_table */
|
* current_table */
|
||||||
if (tbl->relid == atoi(PQgetvalue(res, j, PQfnumber(res, "oid"))))
|
if (tbl->relid == atooid(PQgetvalue(res, j, PQfnumber(res, "oid"))))
|
||||||
{
|
{
|
||||||
tbl->curr_analyze_count =
|
tbl->curr_analyze_count =
|
||||||
(atol(PQgetvalue(res, j, PQfnumber(res, "n_tup_ins"))) +
|
(atol(PQgetvalue(res, j, PQfnumber(res, "n_tup_ins"))) +
|
||||||
|
@ -37,10 +37,13 @@
|
|||||||
#define TABLE_STATS_QUERY "select a.oid,a.relname,a.relnamespace,a.relpages,a.relisshared,a.reltuples,b.schemaname,b.n_tup_ins,b.n_tup_upd,b.n_tup_del from pg_class a, pg_stat_all_tables b where a.oid=b.relid and a.relkind = 'r'"
|
#define TABLE_STATS_QUERY "select a.oid,a.relname,a.relnamespace,a.relpages,a.relisshared,a.reltuples,b.schemaname,b.n_tup_ins,b.n_tup_upd,b.n_tup_del from pg_class a, pg_stat_all_tables b where a.oid=b.relid and a.relkind = 'r'"
|
||||||
|
|
||||||
#define FRONTEND
|
#define FRONTEND
|
||||||
#define PAGES_QUERY "select oid,reltuples,relpages from pg_class where oid=%i"
|
#define PAGES_QUERY "select oid,reltuples,relpages from pg_class where oid=%u"
|
||||||
#define FROZENOID_QUERY "select oid,age(datfrozenxid) from pg_database where datname = 'template1'"
|
#define FROZENOID_QUERY "select oid,age(datfrozenxid) from pg_database where datname = 'template1'"
|
||||||
#define FROZENOID_QUERY2 "select oid,datname,age(datfrozenxid) from pg_database where datname!='template0'"
|
#define FROZENOID_QUERY2 "select oid,datname,age(datfrozenxid) from pg_database where datname!='template0'"
|
||||||
|
|
||||||
|
/* define atooid */
|
||||||
|
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
|
||||||
|
|
||||||
/* define cmd_args stucture */
|
/* define cmd_args stucture */
|
||||||
struct cmdargs
|
struct cmdargs
|
||||||
{
|
{
|
||||||
@ -67,9 +70,9 @@ cmd_args *args;
|
|||||||
I think we need to guarantee this happens approx every 1Million TX's */
|
I think we need to guarantee this happens approx every 1Million TX's */
|
||||||
struct dbinfo
|
struct dbinfo
|
||||||
{
|
{
|
||||||
int oid,
|
Oid oid;
|
||||||
age;
|
long age;
|
||||||
int analyze_threshold,
|
long analyze_threshold,
|
||||||
vacuum_threshold; /* Use these as defaults for table
|
vacuum_threshold; /* Use these as defaults for table
|
||||||
* thresholds */
|
* thresholds */
|
||||||
PGconn *conn;
|
PGconn *conn;
|
||||||
@ -84,9 +87,9 @@ struct tableinfo
|
|||||||
{
|
{
|
||||||
char *schema_name,
|
char *schema_name,
|
||||||
*table_name;
|
*table_name;
|
||||||
int relid,
|
float reltuples;
|
||||||
reltuples,
|
int relisshared;
|
||||||
relisshared,
|
Oid relid,
|
||||||
relpages;
|
relpages;
|
||||||
long analyze_threshold,
|
long analyze_threshold,
|
||||||
vacuum_threshold;
|
vacuum_threshold;
|
||||||
@ -111,7 +114,7 @@ static void usage(void);
|
|||||||
|
|
||||||
/* Functions for managing database lists */
|
/* Functions for managing database lists */
|
||||||
static Dllist *init_db_list(void);
|
static Dllist *init_db_list(void);
|
||||||
static db_info *init_dbinfo(char *dbname, int oid, int age);
|
static db_info *init_dbinfo(char *dbname, Oid oid, long age);
|
||||||
static void update_db_list(Dllist *db_list);
|
static void update_db_list(Dllist *db_list);
|
||||||
static void remove_db_from_list(Dlelem *db_to_remove);
|
static void remove_db_from_list(Dlelem *db_to_remove);
|
||||||
static void print_db_info(db_info * dbi, int print_table_list);
|
static void print_db_info(db_info * dbi, int print_table_list);
|
||||||
|
Reference in New Issue
Block a user