Split pgstat file in smaller pieces

We now write one file per database and one global file, instead of
having the whole thing in a single huge file.  This reduces the I/O that
must be done when partial data is required -- which is all the time,
because each process only needs information on its own database anyway.
Also, the autovacuum launcher does not need data about tables and
functions in each database; having the global stats for all DBs is
enough.

Catalog version bumped because we have a new subdir under PGDATA.

Author: Tomas Vondra.  Some rework by Álvaro
Testing by Jeff Janes
Other discussion by Heikki Linnakangas, Tom Lane.
This commit is contained in:
Alvaro Herrera 2013-02-18 17:56:08 -03:00
parent 9475db3a4e
commit 187492b6c2
5 changed files with 601 additions and 247 deletions

File diff suppressed because it is too large Load Diff

View File

@ -8705,14 +8705,23 @@ static void
assign_pgstat_temp_directory(const char *newval, void *extra)
{
/* check_canonical_path already canonicalized newval for us */
char *dname;
char *tname;
char *fname;
tname = guc_malloc(ERROR, strlen(newval) + 12); /* /pgstat.tmp */
sprintf(tname, "%s/pgstat.tmp", newval);
fname = guc_malloc(ERROR, strlen(newval) + 13); /* /pgstat.stat */
sprintf(fname, "%s/pgstat.stat", newval);
/* directory */
dname = guc_malloc(ERROR, strlen(newval) + 1); /* runtime dir */
sprintf(dname, "%s", newval);
/* global stats */
tname = guc_malloc(ERROR, strlen(newval) + 12); /* /global.tmp */
sprintf(tname, "%s/global.tmp", newval);
fname = guc_malloc(ERROR, strlen(newval) + 13); /* /global.stat */
sprintf(fname, "%s/global.stat", newval);
if (pgstat_stat_directory)
free(pgstat_stat_directory);
pgstat_stat_directory = dname;
if (pgstat_stat_tmpname)
free(pgstat_stat_tmpname);
pgstat_stat_tmpname = tname;

View File

@ -192,6 +192,7 @@ const char *subdirs[] = {
"base",
"base/1",
"pg_tblspc",
"pg_stat",
"pg_stat_tmp"
};

View File

@ -53,6 +53,6 @@
*/
/* yyyymmddN */
#define CATALOG_VERSION_NO 201302131
#define CATALOG_VERSION_NO 201302181
#endif

View File

@ -205,6 +205,7 @@ typedef struct PgStat_MsgInquiry
PgStat_MsgHdr m_hdr;
TimestampTz clock_time; /* observed local clock time */
TimestampTz cutoff_time; /* minimum acceptable file timestamp */
Oid databaseid; /* requested DB (InvalidOid => all DBs) */
} PgStat_MsgInquiry;
@ -514,7 +515,7 @@ typedef union PgStat_Msg
* ------------------------------------------------------------
*/
#define PGSTAT_FILE_FORMAT_ID 0x01A5BC9A
#define PGSTAT_FILE_FORMAT_ID 0x01A5BC9B
/* ----------
* PgStat_StatDBEntry The collector's data per database
@ -545,6 +546,7 @@ typedef struct PgStat_StatDBEntry
PgStat_Counter n_block_write_time;
TimestampTz stat_reset_timestamp;
TimestampTz stats_timestamp; /* time of db stats file update */
/*
* tables and functions must be last in the struct, because we don't write
@ -722,6 +724,7 @@ extern bool pgstat_track_activities;
extern bool pgstat_track_counts;
extern int pgstat_track_functions;
extern PGDLLIMPORT int pgstat_track_activity_query_size;
extern char *pgstat_stat_directory;
extern char *pgstat_stat_tmpname;
extern char *pgstat_stat_filename;