|
| 1 | +--- |
| 2 | +title: "postgres-list-database-stats" |
| 3 | +type: docs |
| 4 | +weight: 1 |
| 5 | +description: > |
| 6 | + The "postgres-list-database-stats" tool lists lists key performance and activity statistics of PostgreSQL databases. |
| 7 | +aliases: |
| 8 | +- /resources/tools/postgres-list-database-stats |
| 9 | +--- |
| 10 | + |
| 11 | +## About |
| 12 | + |
| 13 | +The `postgres-list-database-stats` lists the key performance and activity statistics for each PostgreSQL database in the instance, offering insights into cache efficiency, transaction throughput, row-level activity, temporary file usage, and contention. It's compatible with |
| 14 | +any of the following sources: |
| 15 | + |
| 16 | +- [alloydb-postgres](../../sources/alloydb-pg.md) |
| 17 | +- [cloud-sql-postgres](../../sources/cloud-sql-pg.md) |
| 18 | +- [postgres](../../sources/postgres.md) |
| 19 | + |
| 20 | +`postgres-list-database-stats` lists detailed information as JSON for each database. The tool |
| 21 | +takes the following input parameters: |
| 22 | + |
| 23 | +- `database_name` (optional): A text to filter results by database name. Default: `""` |
| 24 | +- `include_templates` (optional): Boolean, set to `true` to include template databases in the results. Default: `false` |
| 25 | +- `database_owner` (optional): A text to filter results by database owner. Default: `""` |
| 26 | +- `default_tablespace` (optional): A text to filter results by the default tablespace name. Default: `""` |
| 27 | +- `order_by` (optional): Specifies the sorting order. Valid values are `'size'` (descending) or `'commit'` (descending). Default: `database_name` ascending. |
| 28 | +- `limit` (optional): The maximum number of databases to return. Default: `10` |
| 29 | + |
| 30 | +## Example |
| 31 | + |
| 32 | +```yaml |
| 33 | +tools: |
| 34 | + list_database_stats: |
| 35 | + kind: postgres-list-database-stats |
| 36 | + source: postgres-source |
| 37 | + description: | |
| 38 | + Lists the key performance and activity statistics for each PostgreSQL |
| 39 | + database in the instance, offering insights into cache efficiency, |
| 40 | + transaction throughput row-level activity, temporary file usage, and |
| 41 | + contention. It returns: the database name, whether the database is |
| 42 | + connectable, database owner, default tablespace name, the percentage of |
| 43 | + data blocks found in the buffer cache rather than being read from disk |
| 44 | + (a higher value indicates better cache performance), the total number of |
| 45 | + disk blocks read from disk, the total number of times disk blocks were |
| 46 | + found already in the cache; the total number of committed transactions, |
| 47 | + the total number of rolled back transactions, the percentage of rolled |
| 48 | + back transactions compared to the total number of completed |
| 49 | + transactions, the total number of rows returned by queries, the total |
| 50 | + number of live rows fetched by scans, the total number of rows inserted, |
| 51 | + the total number of rows updated, the total number of rows deleted, the |
| 52 | + number of temporary files created by queries, the total size of |
| 53 | + temporary files used by queries in bytes, the number of query |
| 54 | + cancellations due to conflicts with recovery, the number of deadlocks |
| 55 | + detected, the current number of active backend connections, the |
| 56 | + timestamp when the database statistics were last reset, and the total |
| 57 | + database size in bytes. |
| 58 | +``` |
| 59 | +
|
| 60 | +The response is a json array with the following elements: |
| 61 | +
|
| 62 | +```json |
| 63 | +{ |
| 64 | + "database_name": "Name of the database", |
| 65 | + "is_connectable": "Boolean indicating Whether the database allows connections", |
| 66 | + "database_owner": "Username of the database owner", |
| 67 | + "default_tablespace": "Name of the default tablespace for the database", |
| 68 | + "cache_hit_ratio_percent": "The percentage of data blocks found in the buffer cache rather than being read from disk", |
| 69 | + "blocks_read_from_disk": "The total number of disk blocks read for this database", |
| 70 | + "blocks_hit_in_cache": "The total number of times disk blocks were found already in the cache.", |
| 71 | + "xact_commit": "The total number of committed transactions", |
| 72 | + "xact_rollback": "The total number of rolled back transactions", |
| 73 | + "rollback_ratio_percent": "The percentage of rolled back transactions compared to the total number of completed transactions", |
| 74 | + "rows_returned_by_queries": "The total number of rows returned by queries", |
| 75 | + "rows_fetched_by_scans": "The total number of live rows fetched by scans", |
| 76 | + "tup_inserted": "The total number of rows inserted", |
| 77 | + "tup_updated": "The total number of rows updated", |
| 78 | + "tup_deleted": "The total number of rows deleted", |
| 79 | + "temp_files": "The number of temporary files created by queries", |
| 80 | + "temp_size_bytes": "The total size of temporary files used by queries in bytes", |
| 81 | + "conflicts": "Number of query cancellations due to conflicts", |
| 82 | + "deadlocks": "Number of deadlocks detected", |
| 83 | + "active_connections": "The current number of active backend connections", |
| 84 | + "statistics_last_reset": "The timestamp when the database statistics were last reset", |
| 85 | + "database_size_bytes": "The total disk size of the database in bytes" |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +## Reference |
| 90 | + |
| 91 | +| **field** | **type** | **required** | **description** | |
| 92 | +|-------------|:--------:|:------------:|------------------------------------------------------| |
| 93 | +| kind | string | true | Must be "postgres-list-database-stats". | |
| 94 | +| source | string | true | Name of the source the SQL should execute on. | |
| 95 | +| description | string | false | Description of the tool that is passed to the agent. | |
0 commit comments