pg_dbms_stats provies the following functions.
Operation | Function | Parameters | Target unit | Return |
---|---|---|---|---|
Backup | dbms_stats.backup_database_stats | comment | Database | int8 |
dbms_stats.backup_schema_stats | schemaname、comment | Schema | ||
dbms_stats.backup_table_stats | relname、comment | Table | ||
schemaname、tablename、comment | ||||
dbms_stats.backup_column_stats | relname、attname、comment | Column | ||
schemaname、tablename、attname、comment | ||||
Restore | dbms_stats.restore_database_stats | timestamp | Database | regclass |
dbms_stats.restore_schema_stats | schemaname、timestamp | Schema | ||
dbms_stats.restore_table_stats | relname、timestamp | Table | ||
schemaname、tablename、timestamp | ||||
dbms_stats.restore_column_stats | relname、attname、timestamp | Column | ||
schemaname、tablename、attname、timestamp | ||||
dbms_stats.restore_stats | backup_id | Backup | ||
Lock | dbms_stats.lock_database_stats | (None) | Database | regclass |
dbms_stats.lock_schema_stats | schemaname | Schema | ||
dbms_stats.lock_table_stats | relname | Table | ||
schemaname、tablename | ||||
dbms_stats.lock_column_stats | relname、attname | Column | ||
schemaname、tablename、attname | ||||
Unlock | dbms_stats.unlock_database_stats | (None) | Database | regclass |
dbms_stats.unlock_schema_stats | schemaname | Schema | ||
dbms_stats.unlock_table_stats | relname | Table | ||
schemaname、tablename | ||||
dbms_stats.unlock_column_stats | relname、attname | Column | ||
schemaname、tablename、attname | ||||
Import | dbms_stats.import_database_stats | src | Database | void |
dbms_stats.import_schema_stats | schemaname、src | Schema | ||
dbms_stats.import_table_stats | relname、src | Table | ||
schemaname、tablename、src | ||||
dbms_stats.import_column_stats | relname、attname、src | Column | ||
schemaname、tablename、attname、src | ||||
Purge | dbms_stats.purge_stats | backup_id、force | Backup | dbms_stats.backup_history |
Cleanup | dbms_stats.clean_up_stats | (Nnne) | Database | text |
The parameter name in the above table are below.
Parameter | Data type | Description |
---|---|---|
schemaname | text | The name of the target schema |
relname | regclass | The name of the target table, prefixed by a schema name. |
tablename | text | The name of the target tble. |
attname | text | The name of the target column. |
comment | text | The comment to identify the backup. |
as_of_timestamp | timestamptz | The timestamp of the target time. The functions restore the latest backups before the target time. Does nothing if no appropriate backup for the object is found. |
src | text | The absolute path of the file to be imported. |
backup_id | bigint | The backup ID that identifies the target of restore or purge operations. Restores the backup identified by the id, or purges the identified backup and all backups older than it. |
force | bool | Set true to purge the all matching backups even if no backup will be left. Leave the oldest database-wise backup and warn if false. Defaults to false. |
The export function is in the shape of SQL file.
Following are the description on each SQL files. The default name for the output file is export_stats.dmp.
File name | Output statictics | Description |
---|---|---|
export_effective_stats.<PG ver>.sql.sample | Statistics that planner actually sees | - |
export_plain_stats-<PG ver>.sql.sample | The real statistics | works without pg_dbms_stats installed |
pg_dbms_stats uses the following tables.
Table name | Column name | Data type | Description |
---|---|---|---|
dbms_stats.backup_history | id | int8 | An ID given on taking the backup. |
time | timestamptz | The time of taking the backup | |
unit | char(1) | Specified unit of the backup d:database、s:schema、t:table、c:column | |
comment | text | The comment given on taking the backup |
pg_dbms_stats defines and uses the following views.
View name | Description |
---|---|
dbms_stats.relation_stats_effective | The view used to internally retrieve table statistics passed to planner. Corresponds to pg_class catalog of PostgreSQL. |
dbms_stats.column_stats_effective | The view used to internally retrieve column statistics passed to planner. Corresponds to pg_statistic catalog of PostgreSQL. |
dbms_stats.stats | The view for users to see column statistics for planner. Corresponds to pg_stats view of PostgreSQL. |