|
| 1 | +--- |
| 2 | +icon: material/play-circle |
| 3 | +--- |
| 4 | +# Running queries |
| 5 | + |
| 6 | +PgDog EE provides a real-time view into queries currently executing on PostgreSQL connections. It is accessible in two places: |
| 7 | + |
| 8 | +1. [`SHOW ACTIVE_QUERIES`](#admin-database) admin command |
| 9 | +2. [Activity](#dashboard) view in the dashboard |
| 10 | + |
| 11 | +## How it works |
| 12 | + |
| 13 | +When a client sends a query to PgDog, it will first attempt to acquire a connection from the connection pool. Once acquired, it will register the query with the live query view. After the query finishes running, it's removed from the view. |
| 14 | + |
| 15 | +Only queries that are currently executing through PgDog are visible in this view. If your application doesn't connect to PgDog, its queries won't appear here. |
| 16 | + |
| 17 | +### Admin database |
| 18 | + |
| 19 | +You can see which queries are actually running on each instance by connecting to the admin database and running the `SHOW ACTIVE_QUERIES` command: |
| 20 | + |
| 21 | +=== "Command" |
| 22 | + ``` |
| 23 | + SHOW ACTIVE_QUERIES; |
| 24 | + ``` |
| 25 | + |
| 26 | +=== "Output" |
| 27 | + ``` |
| 28 | + query | protocol | database | user | running_time | |
| 29 | + -------------------------------------------------------+----------+----------+-------+--------------+ |
| 30 | + SELECT * FROM users WHERE id = $1 | extended | pgdog | pgdog | 15 | |
| 31 | + SELECT pg_sleep(50) | simple | pgdog | pgdog | 5 | |
| 32 | + INSERT INTO users (id, email) VALUES ($1, $2) | extended | pgdog | pgdog | 1 | |
| 33 | + ``` |
| 34 | + |
| 35 | +The following information is available in the running queries view: |
| 36 | + |
| 37 | +| Column | Description | |
| 38 | +|-|-| |
| 39 | +| `query` | The SQL statement currently executing on a PostgreSQL connection. | |
| 40 | +| `protocol` | What version of the query protocol is used. `simple` protocol injects parameters into text, while `extended` is used by prepared statements. | |
| 41 | +| `database` | The name of the connection pool database. | |
| 42 | +| `user` | The name of the user executing the query. | |
| 43 | +| `running_time` | For how long (in ms) has the query been running. | |
| 44 | + |
| 45 | +### Dashboard |
| 46 | + |
| 47 | +If you're running multiple instances of PgDog, active queries from all instances are aggregated and sent to the Dashboard application. They are then made available in the Activity tab, in real-time, with query plans automatically attached for slow queries. |
| 48 | + |
| 49 | +<center> |
| 50 | + <img src="/images/ee/activity.png" width="100%" alt="How PgDog works" class="screenshot" /> |
| 51 | + <i>Real-time view into running queries.</i> |
| 52 | +</center> |
0 commit comments