mirror of
https://github.com/jbranchaud/til
synced 2026-01-04 15:48:01 +00:00
Add Enable Logging Of Database Activity as a Postgres til
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||||
|
|
||||||
_1176 TILs and counting..._
|
_1177 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -571,6 +571,7 @@ _1176 TILs and counting..._
|
|||||||
- [Dump And Restore A Database](postgres/dump-and-restore-a-database.md)
|
- [Dump And Restore A Database](postgres/dump-and-restore-a-database.md)
|
||||||
- [Duplicate A Local Database](postgres/duplicate-a-local-database.md)
|
- [Duplicate A Local Database](postgres/duplicate-a-local-database.md)
|
||||||
- [Edit Existing Functions](postgres/edit-existing-functions.md)
|
- [Edit Existing Functions](postgres/edit-existing-functions.md)
|
||||||
|
- [Enable Logging Of Database Activity](postgres/enable-logging-of-database-activity.md)
|
||||||
- [Escaping A Quote In A String](postgres/escaping-a-quote-in-a-string.md)
|
- [Escaping A Quote In A String](postgres/escaping-a-quote-in-a-string.md)
|
||||||
- [Escaping String Literals With Dollar Quoting](postgres/escaping-string-literals-with-dollar-quoting.md)
|
- [Escaping String Literals With Dollar Quoting](postgres/escaping-string-literals-with-dollar-quoting.md)
|
||||||
- [Export Query Results To A CSV](postgres/export-query-results-to-a-csv.md)
|
- [Export Query Results To A CSV](postgres/export-query-results-to-a-csv.md)
|
||||||
|
|||||||
43
postgres/enable-logging-of-database-activity.md
Normal file
43
postgres/enable-logging-of-database-activity.md
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
# Enable Logging Of Database Activity
|
||||||
|
|
||||||
|
For logging to be enabled for a PostgreSQL server, it needs to be properly
|
||||||
|
configured. This means ensuring the `logging_collector` option is on. By
|
||||||
|
default I believe it is `off`.
|
||||||
|
|
||||||
|
This is configured in the `postgresql.conf` file and requires a server restart.
|
||||||
|
|
||||||
|
First, to find where the conf file is. I can answer that question in a `psql`
|
||||||
|
session.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
> show config_file;
|
||||||
|
config_file
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
/Users/jbranchaud/.asdf/installs/postgres/12.3/data/postgresql.conf
|
||||||
|
(1 row)
|
||||||
|
```
|
||||||
|
|
||||||
|
Now, I can open up that file and search for the line that has
|
||||||
|
`logging_collector`. I uncomment that line and change `off` to `on`.
|
||||||
|
|
||||||
|
```
|
||||||
|
# This is used when logging to stderr:
|
||||||
|
logging_collector = on # Enable capturing of stderr and csvlog
|
||||||
|
# into log files. Required to be on for
|
||||||
|
# csvlogs.
|
||||||
|
# (change requires restart)
|
||||||
|
```
|
||||||
|
|
||||||
|
This requires a restart of the Postgres server.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ ~/.asdf/installs/postgres/12.3/bin/pg_ctl -D ~/.asdf/installs/postgres/12.3/data restart
|
||||||
|
waiting for server to shut down.... done
|
||||||
|
server stopped
|
||||||
|
waiting for server to start...
|
||||||
|
done
|
||||||
|
server started
|
||||||
|
```
|
||||||
|
|
||||||
|
I can now adjust any further logging-related configurations on a server or
|
||||||
|
session basis. And then view those logs.
|
||||||
Reference in New Issue
Block a user