-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathpostgres-log
executable file
·51 lines (43 loc) · 1 KB
/
postgres-log
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh
# postgres: tail postgresql logs, ensuring logging is enabled (with optional
# restart and restore).
conf=/var/lib/postgres/data/postgresql.conf
log_statement="log_statement = 'all'"
if ! sudo grep -Eq "^(# )?$log_statement" "$conf"; then
echo "Expected log_statement line in $conf not found."
exit 1
fi
_on() {
if sudo grep -q "^# $log_statement" "$conf"; then
echo "Enabling log_statement."
sudo sed -i "s/# $log_statement/$log_statement/" "$conf"
sudo systemctl restart postgresql.service
return 1
fi
return 0
}
_off() {
if sudo grep -q "^$log_statement" "$conf"; then
echo "Disabling log_statement."
sudo sed -i "s/$log_statement/# $log_statement/" "$conf"
sudo systemctl restart postgresql.service
return 1
fi
return 0
}
if [ -n "$1" ]; then
if [ "$1" = 0 ] || [ "$1" = off ]; then
_off
else
_on
fi
exit 0
fi
restore=0
_restore() {
[ "$restore" = 1 ] && _off
}
trap '_restore && exit $?' INT
_on
restore=$?
sudo journalctl -t postgres -f