Monitor a database
The Observe tab of a database shows metrics and query statistics, so you can find slow queries and decide whether the database needs more resources before users notice.
Metrics and query statistics are available only for dedicated databases.
View metrics
Section titled “View metrics”- Open the database.
- Go to Observe > Metrics.
- Select a time range.
orchard db metrics <id>The Metrics view has the following panels:
| Section | Panels |
|---|---|
| Activity | Connections, Transactions, Cache hit |
| Replication & storage | Replication lag, Database size, Disk used |
| Resources | CPU, Memory, Network in, Network out |
| Health | Deadlocks. This panel appears only when the range contains a deadlock. |
The Disk used panel marks 80% full and 92% full. Writes pause at 92%, so grow the storage before the line reaches that mark.
Turn on query statistics
Section titled “Turn on query statistics”Query statistics use the pg_stat_statements extension. Turning on the extension restarts the database once.
- Open the database.
- Go to Observe > Queries.
- Select Enable.
Find slow queries
Section titled “Find slow queries”- Open the database.
- Go to Observe > Queries.
- In Rank queries by, select one of these options:
- Most time: Total time across all calls.
- Most frequent: Number of calls.
- Slowest: Mean time for each call.
- (Optional) In Filter queries, enter text to search for.
- Select a row to read the full query.
To clear the collected statistics, select Reset.
Read logs and restart history
Section titled “Read logs and restart history”The Overview tab of a database includes a console. In the console, Logs shows Postgres logs and Killed shows the output of containers that were killed.
To read this data from the CLI, run the following commands:
orchard db logs <id>orchard db killed list <id>To print a summary of database health, run the following command:
orchard db diagnose <dbId>Related resources
Section titled “Related resources”- Change Postgres parameters - Tune timeouts, memory, and slow query logging.
- Read logs and open a shell - Use the database console from the dashboard.
orchard dbreference - Review themetrics,logs,killed, anddiagnosecommands.