more useful log output with row count for each table
This commit is contained in:
parent
a2f88a795c
commit
da37342332
|
@ -1,5 +1,5 @@
|
|||
#!/bin/bash
|
||||
# greate postgres backup and status log
|
||||
# postgres backup and log management
|
||||
|
||||
time_stamp=$(date '+%Y%m%d')
|
||||
time_date=$(date '+%Y%m%d_%H%M%S')
|
||||
|
@ -9,16 +9,23 @@ backup_dir="$HOME/backup"
|
|||
docker exec postgres pg_dump -U aqi | gzip > "$backup_dir/pg_$time_stamp.gz"
|
||||
|
||||
# log
|
||||
log_file="$backup_dir/pg_status_$time_stamp.log"
|
||||
log_file="$backup_dir/pg_status.log"
|
||||
|
||||
query="SELECT schemaname AS table_schema, \
|
||||
query1="SELECT schemaname AS table_schema, \
|
||||
relname AS table_name, \
|
||||
pg_size_pretty(pg_relation_size(relid)) AS data_size \
|
||||
FROM pg_catalog.pg_statio_user_tables \
|
||||
ORDER BY pg_relation_size(relid) DESC;"
|
||||
|
||||
query2="SELECT schemaname,relname,n_live_tup \
|
||||
FROM pg_stat_user_tables \
|
||||
ORDER BY n_live_tup DESC;"
|
||||
|
||||
echo "postgres dump run at $time_date" > "$log_file"
|
||||
docker exec postgres psql -U aqi -c "$query" >> "$log_file"
|
||||
echo "table size" >> "$log_file"
|
||||
docker exec postgres psql -U aqi -c "$query1" >> "$log_file"
|
||||
echo "row count" >> "$log_file"
|
||||
docker exec postgres psql -U aqi -c "$query2" >> "$log_file"
|
||||
|
||||
##
|
||||
exit 0
|
||||
|
|
Loading…
Reference in New Issue