Skip to content

Commit 7151ea1

Browse files
committed
Add Include All Queries In The Log File as a Postgres til
1 parent 4c8832f commit 7151ea1

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
1212

13-
_1179 TILs and counting..._
13+
_1180 TILs and counting..._
1414

1515
---
1616

@@ -595,6 +595,7 @@ _1179 TILs and counting..._
595595
- [Get The Size Of An Index](postgres/get-the-size-of-an-index.md)
596596
- [Getting A Slice Of An Array](postgres/getting-a-slice-of-an-array.md)
597597
- [Group By The Result Of A Function Call](postgres/group-by-the-result-of-a-function-call.md)
598+
- [Include All Queries In The Log File](postgres/include-all-queries-in-the-log-file.md)
598599
- [Insert A Bunch Of Records With Generate Series](postgres/insert-a-bunch-of-records-with-generate-series.md)
599600
- [Insert Just The Defaults](postgres/insert-just-the-defaults.md)
600601
- [Install Postgres With uuid-ossp Using asdf](postgres/install-postgres-with-uuid-ossp-using-asdf.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Include All Queries In The Log File
2+
3+
The default log-level (`log_statement` setting) for a PostgreSQL server is
4+
`none`. Other valid log-levels for [that setting are `ddl`, `mod`, and
5+
`all`](https://www.postgresql.org/docs/13/runtime-config-logging.html).
6+
7+
If you want to see all the queries hitting a database, you'll want to set it to
8+
`all`. This can be set as a server-wide setting or it can be set on a
9+
per-session basis.
10+
11+
Because `all` is so noisy, I like to use it on a per-session basis when I'm in
12+
a situation where I know I'd like to see all queries.
13+
14+
```sql
15+
> set log_statement = 'all';
16+
```
17+
18+
After running that statement in my `psql` session, I can tail the log file to
19+
keep an eye on queries hitting the database.
20+
21+
Be sure that [logging is enabled via the
22+
`logging_collector`](enable-logging-of-database-activity.md) as well.

0 commit comments

Comments
 (0)