1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-02 22:58:01 +00:00

Add Enable Logging Of Database Activity as a Postgres til

This commit is contained in:
jbranchaud
2022-01-05 09:36:44 -06:00
parent 7a61286a9f
commit 5b0af953d8
2 changed files with 45 additions and 1 deletions

View File

@@ -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).
_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)
- [Duplicate A Local Database](postgres/duplicate-a-local-database.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 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)

View 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.