File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010
1111For a steady stream of TILs, [ sign up for my newsletter] ( https://crafty-builder-6996.ck.page/e169c61186 ) .
1212
13- _ 1176 TILs and counting..._
13+ _ 1177 TILs and counting..._
1414
1515---
1616
@@ -571,6 +571,7 @@ _1176 TILs and counting..._
571571- [ Dump And Restore A Database] ( postgres/dump-and-restore-a-database.md )
572572- [ Duplicate A Local Database] ( postgres/duplicate-a-local-database.md )
573573- [ Edit Existing Functions] ( postgres/edit-existing-functions.md )
574+ - [ Enable Logging Of Database Activity] ( postgres/enable-logging-of-database-activity.md )
574575- [ Escaping A Quote In A String] ( postgres/escaping-a-quote-in-a-string.md )
575576- [ Escaping String Literals With Dollar Quoting] ( postgres/escaping-string-literals-with-dollar-quoting.md )
576577- [ Export Query Results To A CSV] ( postgres/export-query-results-to-a-csv.md )
Original file line number Diff line number Diff line change 1+ # Enable Logging Of Database Activity
2+
3+ For logging to be enabled for a PostgreSQL server, it needs to be properly
4+ configured. This means ensuring the ` logging_collector ` option is on. By
5+ default I believe it is ` off ` .
6+
7+ This is configured in the ` postgresql.conf ` file and requires a server restart.
8+
9+ First, to find where the conf file is. I can answer that question in a ` psql `
10+ session.
11+
12+ ``` sql
13+ > show config_file;
14+ config_file
15+ -- -------------------------------------------------------------------
16+ / Users/ jbranchaud/ .asdf/ installs/ postgres/ 12 .3 / data/ postgresql .conf
17+ (1 row)
18+ ```
19+
20+ Now, I can open up that file and search for the line that has
21+ ` logging_collector ` . I uncomment that line and change ` off ` to ` on ` .
22+
23+ ```
24+ # This is used when logging to stderr:
25+ logging_collector = on # Enable capturing of stderr and csvlog
26+ # into log files. Required to be on for
27+ # csvlogs.
28+ # (change requires restart)
29+ ```
30+
31+ This requires a restart of the Postgres server.
32+
33+ ``` bash
34+ $ ~ /.asdf/installs/postgres/12.3/bin/pg_ctl -D ~ /.asdf/installs/postgres/12.3/data restart
35+ waiting for server to shut down.... done
36+ server stopped
37+ waiting for server to start...
38+ done
39+ server started
40+ ```
41+
42+ I can now adjust any further logging-related configurations on a server or
43+ session basis. And then view those logs.
You can’t perform that action at this time.
0 commit comments