Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Scaling the Wall of Text: Best Practices for Lo...

Scaling the Wall of Text: Best Practices for Logging in PostgreSQL

Something that many PostgreSQL users take for granted is the powerful logging features that it provides. With the right configuration, DBAs and sysadmins can quickly diagnose performance, security, and configuration issues, saving precious seconds of application uptime. This talk will cover the major logging parameters in `postgresql.conf`, as well as provide some tips and wisdom gleaned over years of parsing through gigabytes of logs. Presented at the 18th SoCal Linux Expo in Pasadena on March 5, 2020

Richard Yen

March 05, 2020
Tweet

More Decks by Richard Yen

Other Decks in Technology

Transcript

  1. Scaling the Wall of Text Best Practices for Logging in

    PostgreSQL SCaLE 18x | March 5, 2020 | Richard Yen
  2. About Me • Support Engineer at EnterpriseDB • Previously a

    DBA and Web Developer • Been using PostgreSQL since v. 7.4
  3. Setting Up a New Postgres Instance • listen_addresses • port

    • shared_buffers • work_mem • autovacuum (costs)
  4. Setting Up a New Postgres Instance • listen_addresses • port

    • shared_buffers • work_mem • autovacuum (costs) • random_page_cost
  5. What are the consequences? • Slows down diagnosis and recovery

    when there's an outage or performance problem
  6. What are the consequences? • Slows down diagnosis and recovery

    when there's an outage or performance problem • Reflects poorly when your boss asks you what happened last night when the database went down
  7. What are the consequences? • Slows down diagnosis and recovery

    when there's an outage or performance problem • Reflects poorly when your boss asks you what happened last night when the database went down • Prevents you from planning for the future
  8. What the log can tell you • When a query

    started, finished, and how long it took
  9. What the log can tell you • When a query

    started, finished, and how long it took • Indicators of data corruption
  10. What the log can tell you • When a query

    started, finished, and how long it took • Indicators of data corruption • Any errors with a query, or with a connection attempt
  11. What the log can tell you • When a query

    started, finished, and how long it took • Indicators of data corruption • Any errors with a query, or with a connection attempt • Statistics about queries and maintenance activity
  12. What the log can tell you • When a query

    started, finished, and how long it took • Indicators of data corruption • Any errors with a query, or with a connection attempt • Statistics about queries and maintenance activity • Information about temp files
  13. What the log can tell you • When a query

    started, finished, and how long it took • Indicators of data corruption • Any errors with a query, or with a connection attempt • Statistics about queries and maintenance activity • Information about temp files • Who connected to the database
  14. What the log can tell you • When a query

    started, finished, and how long it took • Indicators of data corruption • Any errors with a query, or with a connection attempt • Statistics about queries and maintenance activity • Information about temp files • Who connected to the database • Where the connection came from
  15. What the log can tell you • When a query

    started, finished, and how long it took • Indicators of data corruption • Any errors with a query, or with a connection attempt • Statistics about queries and maintenance activity • Information about temp files • Who connected to the database • Where the connection came from • What queries ran before a transaction was rolled back
  16. What the log can tell you • When a query

    started, finished, and how long it took • Indicators of data corruption • Any errors with a query, or with a connection attempt • Statistics about queries and maintenance activity • Information about temp files • Who connected to the database • Where the connection came from • What queries ran before a transaction was rolled back • And more!
  17. More log means… • Faster diagnosis • Faster time to

    recovery • More happy users • More sleep for DBAs
  18. More log means… • Faster diagnosis • Faster time to

    recovery • More happy users • More sleep for DBAs • Better auditing
  19. More log means… • Faster diagnosis • Faster time to

    recovery • More happy users • More sleep for DBAs • Better auditing • Better capacity planning
  20. PostgreSQL Logging Parameters • log_destination • log_directory • log_filename •

    log_file_mode • log_line_prefix • log_min_duration_statement • log_statement • log_connections • log_disconnections • log_rotation_age • log_rotation_size • log_autovacuum_min_duration • log_checkpoints • log_temp_files • log_truncate_on_rotation • log_min_messages • log_min_error_statement • log_error_verbosity • log_hostname • log_lock_waits • log_replication_commands • log_timezone • log_parser_stats • log_planner_stats • log_executor_stats • log_statement_stats
  21. log_line_prefix • printf-style string at the beginning of each log

    line • As of v.10, defaults to %m [%p] (timestamp + backend PID) • Before v.10, default is blank • The more you log, the more chances you can catch a culprit
  22. log_line_prefix • printf-style string at the beginning of each log

    line • As of v.10, defaults to %m [%p] (timestamp + backend PID) • Before v.10, default is blank • The more you log, the more chances you can catch a culprit
  23. In a sample of 130 confs • 5% of users

    don’t change log_line_prefix • 38% only log timestamps (and nothing else) • Why?
  24. The Wall of Text LOG: statement: BEGIN; LOG: statement: UPDATE

    pgbench_accounts SET abalance = abalance + -4410 WHERE aid = 19334; LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 19334; LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + -4410 WHERE tid = 8; LOG: statement: BEGIN; LOG: statement: BEGIN; LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + -4410 WHERE bid = 1; LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -1442 WHERE aid = 57806; LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (8, 1, 19334, -4410, CURRENT_TIMESTAMP); LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 4310 WHERE aid = 57894; LOG: statement: BEGIN; LOG: statement: END; LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 2644 WHERE aid = 75471; LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 57806; LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + -1442 WHERE tid = 8; LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + -1442 WHERE bid = 1; LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 75471; LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (8, 1, 57806, -1442, CURRENT_TIMESTAMP); LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 57894; LOG: statement: END; LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + 2644 WHERE tid = 9; LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + 2644 WHERE bid = 1; LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + 4310 WHERE tid = 8; LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (9, 1, 75471, 2644, CURRENT_TIMESTAMP); LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + 4310 WHERE bid = 1; LOG: statement: END; LOG: statement: drop table pgbench_accounts ; LOG: statement: BEGIN; LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 524 WHERE aid = 23231; LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (8, 1, 57894, 4310, CURRENT_TIMESTAMP); LOG: statement: BEGIN; LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 4798 WHERE aid = 30074; LOG: statement: END; LOG: statement: BEGIN; LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -4793 WHERE aid = 23424; ERROR: relation "pgbench_accounts" does not exist at character 8 STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + 524 WHERE aid = 23231; ERROR: relation "pgbench_accounts" does not exist at character 8 STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + 4798 WHERE aid = 30074; ERROR: relation "pgbench_accounts" does not exist at character 8 STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -4793 WHERE aid = 23424; LOG: statement: BEGIN; LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -118 WHERE aid = 37745; ERROR: relation "pgbench_accounts" does not exist at character 8 STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -118 WHERE aid = 37745; LOG: automatic vacuum of table "postgres.public.pgbench_branches": index scans: 0 LOG: automatic analyze of table "postgres.public.pgbench_branches" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.02 s LOG: automatic analyze of table "postgres.public.pgbench_history" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s LOG: automatic analyze of table "postgres.public.pgbench_tellers" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
  25. The Wall of Text (with '%m [%p]') 2020-02-29 00:11:15.330 UTC

    [2411] LOG: statement: BEGIN; 2020-02-29 00:11:15.331 UTC [2411] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -4410 WHERE aid = 19334; 2020-02-29 00:11:15.331 UTC [2411] LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 19334; 2020-02-29 00:11:15.331 UTC [2411] LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + -4410 WHERE tid = 8; 2020-02-29 00:11:15.332 UTC [2412] LOG: statement: BEGIN; 2020-02-29 00:11:15.332 UTC [2413] LOG: statement: BEGIN; 2020-02-29 00:11:15.332 UTC [2411] LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + -4410 WHERE bid = 1; 2020-02-29 00:11:15.332 UTC [2412] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -1442 WHERE aid = 57806; 2020-02-29 00:11:15.332 UTC [2411] LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (8, 1, 19334, -4410, CURRENT_TIMESTAMP); 2020-02-29 00:11:15.332 UTC [2413] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 4310 WHERE aid = 57894; 2020-02-29 00:11:15.332 UTC [2414] LOG: statement: BEGIN; 2020-02-29 00:11:15.332 UTC [2411] LOG: statement: END; 2020-02-29 00:11:15.333 UTC [2414] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 2644 WHERE aid = 75471; 2020-02-29 00:11:15.333 UTC [2412] LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 57806; 2020-02-29 00:11:15.333 UTC [2412] LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + -1442 WHERE tid = 8; 2020-02-29 00:11:15.333 UTC [2412] LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + -1442 WHERE bid = 1; 2020-02-29 00:11:15.334 UTC [2414] LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 75471; 2020-02-29 00:11:15.334 UTC [2412] LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (8, 1, 57806, -1442, CURRENT_TIMESTAMP); 2020-02-29 00:11:15.334 UTC [2413] LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 57894; 2020-02-29 00:11:15.334 UTC [2412] LOG: statement: END; 2020-02-29 00:11:15.334 UTC [2414] LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + 2644 WHERE tid = 9; 2020-02-29 00:11:15.335 UTC [2414] LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + 2644 WHERE bid = 1; 2020-02-29 00:11:15.335 UTC [2413] LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + 4310 WHERE tid = 8; 2020-02-29 00:11:15.336 UTC [2414] LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (9, 1, 75471, 2644, CURRENT_TIMESTAMP); 2020-02-29 00:11:15.336 UTC [2413] LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + 4310 WHERE bid = 1; 2020-02-29 00:11:15.337 UTC [2414] LOG: statement: END; 2020-02-29 00:11:15.337 UTC [658] LOG: statement: drop table pgbench_accounts ; 2020-02-29 00:11:15.339 UTC [2416] LOG: statement: BEGIN; 2020-02-29 00:11:15.340 UTC [2416] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 524 WHERE aid = 23231; 2020-02-29 00:11:15.340 UTC [2413] LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (8, 1, 57894, 4310, CURRENT_TIMESTAMP); 2020-02-29 00:11:15.340 UTC [2415] LOG: statement: BEGIN; 2020-02-29 00:11:15.341 UTC [2415] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 4798 WHERE aid = 30074; 2020-02-29 00:11:15.342 UTC [2413] LOG: statement: END; 2020-02-29 00:11:15.342 UTC [2417] LOG: statement: BEGIN; 2020-02-29 00:11:15.342 UTC [2417] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -4793 WHERE aid = 23424; 2020-02-29 00:11:15.345 UTC [2416] ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:11:15.345 UTC [2416] STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + 524 WHERE aid = 23231; 2020-02-29 00:11:15.345 UTC [2415] ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:11:15.345 UTC [2415] STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + 4798 WHERE aid = 30074; 2020-02-29 00:11:15.345 UTC [2417] ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:11:15.345 UTC [2417] STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -4793 WHERE aid = 23424; 2020-02-29 00:11:15.351 UTC [2418] LOG: statement: BEGIN; 2020-02-29 00:11:15.352 UTC [2418] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -118 WHERE aid = 37745; 2020-02-29 00:11:15.352 UTC [2418] ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:11:15.352 UTC [2418] STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -118 WHERE aid = 37745; 2020-02-29 00:11:21.566 UTC [2419] LOG: automatic vacuum of table "postgres.public.pgbench_branches": index scans: 0 2020-02-29 00:11:21.589 UTC [2419] LOG: automatic analyze of table "postgres.public.pgbench_branches" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.02 s 2020-02-29 00:11:21.603 UTC [2419] LOG: automatic analyze of table "postgres.public.pgbench_history" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s 2020-02-29 00:11:21.616 UTC [2419] LOG: automatic analyze of table "postgres.public.pgbench_tellers" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
  26. The Wall of Text (sorted) 2020-02-29 00:11:15.330 UTC [2411] LOG:

    statement: BEGIN; 2020-02-29 00:11:15.332 UTC [2411] LOG: statement: END; 2020-02-29 00:11:15.332 UTC [2411] LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (8, 1, 19334, -4410, CURRENT_TIMESTAMP); 2020-02-29 00:11:15.331 UTC [2411] LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 19334; 2020-02-29 00:11:15.331 UTC [2411] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -4410 WHERE aid = 19334; 2020-02-29 00:11:15.332 UTC [2411] LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + -4410 WHERE bid = 1; 2020-02-29 00:11:15.331 UTC [2411] LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + -4410 WHERE tid = 8; 2020-02-29 00:11:15.332 UTC [2412] LOG: statement: BEGIN; 2020-02-29 00:11:15.334 UTC [2412] LOG: statement: END; 2020-02-29 00:11:15.334 UTC [2412] LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (8, 1, 57806, -1442, CURRENT_TIMESTAMP); 2020-02-29 00:11:15.333 UTC [2412] LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 57806; 2020-02-29 00:11:15.332 UTC [2412] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -1442 WHERE aid = 57806; 2020-02-29 00:11:15.333 UTC [2412] LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + -1442 WHERE bid = 1; 2020-02-29 00:11:15.333 UTC [2412] LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + -1442 WHERE tid = 8; 2020-02-29 00:11:15.332 UTC [2413] LOG: statement: BEGIN; 2020-02-29 00:11:15.342 UTC [2413] LOG: statement: END; 2020-02-29 00:11:15.340 UTC [2413] LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (8, 1, 57894, 4310, CURRENT_TIMESTAMP); 2020-02-29 00:11:15.334 UTC [2413] LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 57894; 2020-02-29 00:11:15.332 UTC [2413] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 4310 WHERE aid = 57894; 2020-02-29 00:11:15.336 UTC [2413] LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + 4310 WHERE bid = 1; 2020-02-29 00:11:15.335 UTC [2413] LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + 4310 WHERE tid = 8; 2020-02-29 00:11:15.332 UTC [2414] LOG: statement: BEGIN; 2020-02-29 00:11:15.337 UTC [2414] LOG: statement: END; 2020-02-29 00:11:15.336 UTC [2414] LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (9, 1, 75471, 2644, CURRENT_TIMESTAMP); 2020-02-29 00:11:15.334 UTC [2414] LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 75471; 2020-02-29 00:11:15.333 UTC [2414] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 2644 WHERE aid = 75471; 2020-02-29 00:11:15.335 UTC [2414] LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + 2644 WHERE bid = 1; 2020-02-29 00:11:15.334 UTC [2414] LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + 2644 WHERE tid = 9; 2020-02-29 00:11:15.345 UTC [2415] ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:11:15.340 UTC [2415] LOG: statement: BEGIN; 2020-02-29 00:11:15.341 UTC [2415] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 4798 WHERE aid = 30074; 2020-02-29 00:11:15.345 UTC [2415] STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + 4798 WHERE aid = 30074; 2020-02-29 00:11:15.345 UTC [2416] ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:11:15.339 UTC [2416] LOG: statement: BEGIN; 2020-02-29 00:11:15.340 UTC [2416] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 524 WHERE aid = 23231; 2020-02-29 00:11:15.345 UTC [2416] STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + 524 WHERE aid = 23231; 2020-02-29 00:11:15.345 UTC [2417] ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:11:15.342 UTC [2417] LOG: statement: BEGIN; 2020-02-29 00:11:15.342 UTC [2417] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -4793 WHERE aid = 23424; 2020-02-29 00:11:15.345 UTC [2417] STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -4793 WHERE aid = 23424; 2020-02-29 00:11:15.352 UTC [2418] ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:11:15.351 UTC [2418] LOG: statement: BEGIN; 2020-02-29 00:11:15.352 UTC [2418] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -118 WHERE aid = 37745; 2020-02-29 00:11:15.352 UTC [2418] STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -118 WHERE aid = 37745; 2020-02-29 00:11:21.589 UTC [2419] LOG: automatic analyze of table "postgres.public.pgbench_branches" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.02 s 2020-02-29 00:11:21.603 UTC [2419] LOG: automatic analyze of table "postgres.public.pgbench_history" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s 2020-02-29 00:11:21.616 UTC [2419] LOG: automatic analyze of table "postgres.public.pgbench_tellers" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s 2020-02-29 00:11:21.566 UTC [2419] LOG: automatic vacuum of table "postgres.public.pgbench_branches": index scans: 0 2020-02-29 00:11:15.337 UTC [658] LOG: statement: drop table pgbench_accounts ;
  27. The Wall of Text (sorted) 2020-02-29 00:11:15.330 UTC [2411] LOG:

    statement: BEGIN; 2020-02-29 00:11:15.332 UTC [2411] LOG: statement: END; 2020-02-29 00:11:15.332 UTC [2411] LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (8, 1, 19334, -4410, CURRENT_TIMESTAMP); 2020-02-29 00:11:15.331 UTC [2411] LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 19334; 2020-02-29 00:11:15.331 UTC [2411] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -4410 WHERE aid = 19334; 2020-02-29 00:11:15.332 UTC [2411] LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + -4410 WHERE bid = 1; 2020-02-29 00:11:15.331 UTC [2411] LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + -4410 WHERE tid = 8; 2020-02-29 00:11:15.332 UTC [2412] LOG: statement: BEGIN; 2020-02-29 00:11:15.334 UTC [2412] LOG: statement: END; 2020-02-29 00:11:15.334 UTC [2412] LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (8, 1, 57806, -1442, CURRENT_TIMESTAMP); 2020-02-29 00:11:15.333 UTC [2412] LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 57806; 2020-02-29 00:11:15.332 UTC [2412] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -1442 WHERE aid = 57806; 2020-02-29 00:11:15.333 UTC [2412] LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + -1442 WHERE bid = 1; 2020-02-29 00:11:15.333 UTC [2412] LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + -1442 WHERE tid = 8; 2020-02-29 00:11:15.332 UTC [2413] LOG: statement: BEGIN; 2020-02-29 00:11:15.342 UTC [2413] LOG: statement: END; 2020-02-29 00:11:15.340 UTC [2413] LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (8, 1, 57894, 4310, CURRENT_TIMESTAMP); 2020-02-29 00:11:15.334 UTC [2413] LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 57894; 2020-02-29 00:11:15.332 UTC [2413] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 4310 WHERE aid = 57894; 2020-02-29 00:11:15.336 UTC [2413] LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + 4310 WHERE bid = 1; 2020-02-29 00:11:15.335 UTC [2413] LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + 4310 WHERE tid = 8; 2020-02-29 00:11:15.332 UTC [2414] LOG: statement: BEGIN; 2020-02-29 00:11:15.337 UTC [2414] LOG: statement: END; 2020-02-29 00:11:15.336 UTC [2414] LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (9, 1, 75471, 2644, CURRENT_TIMESTAMP); 2020-02-29 00:11:15.334 UTC [2414] LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 75471; 2020-02-29 00:11:15.333 UTC [2414] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 2644 WHERE aid = 75471; 2020-02-29 00:11:15.335 UTC [2414] LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + 2644 WHERE bid = 1; 2020-02-29 00:11:15.334 UTC [2414] LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + 2644 WHERE tid = 9; 2020-02-29 00:11:15.345 UTC [2415] ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:11:15.340 UTC [2415] LOG: statement: BEGIN; 2020-02-29 00:11:15.341 UTC [2415] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 4798 WHERE aid = 30074; 2020-02-29 00:11:15.345 UTC [2415] STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + 4798 WHERE aid = 30074; 2020-02-29 00:11:15.345 UTC [2416] ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:11:15.339 UTC [2416] LOG: statement: BEGIN; 2020-02-29 00:11:15.340 UTC [2416] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 524 WHERE aid = 23231; 2020-02-29 00:11:15.345 UTC [2416] STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + 524 WHERE aid = 23231; 2020-02-29 00:11:15.345 UTC [2417] ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:11:15.342 UTC [2417] LOG: statement: BEGIN; 2020-02-29 00:11:15.342 UTC [2417] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -4793 WHERE aid = 23424; 2020-02-29 00:11:15.345 UTC [2417] STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -4793 WHERE aid = 23424; 2020-02-29 00:11:15.352 UTC [2418] ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:11:15.351 UTC [2418] LOG: statement: BEGIN; 2020-02-29 00:11:15.352 UTC [2418] LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -118 WHERE aid = 37745; 2020-02-29 00:11:15.352 UTC [2418] STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -118 WHERE aid = 37745; 2020-02-29 00:11:21.589 UTC [2419] LOG: automatic analyze of table "postgres.public.pgbench_branches" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.02 s 2020-02-29 00:11:21.603 UTC [2419] LOG: automatic analyze of table "postgres.public.pgbench_history" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s 2020-02-29 00:11:21.616 UTC [2419] LOG: automatic analyze of table "postgres.public.pgbench_tellers" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s 2020-02-29 00:11:21.566 UTC [2419] LOG: automatic vacuum of table "postgres.public.pgbench_branches": index scans: 0 2020-02-29 00:11:15.337 UTC [658] LOG: statement: drop table pgbench_accounts ;
  28. My Personal Favorites • %a - Application Name - Allows

    quick reference and filtering • %u - User Name - Allows filter by user name
  29. My Personal Favorites • %a - Application Name - Allows

    quick reference and filtering • %u - User Name - Allows filter by user name • %d - Database Name - Allows filter by database name
  30. My Personal Favorites • %a - Application Name - Allows

    quick reference and filtering • %u - User Name - Allows filter by user name • %d - Database Name - Allows filter by database name • %r - Remote Host IP/Name (w/ port) - Helps identify suspicious activity from a host
  31. My Personal Favorites • %a - Application Name - Allows

    quick reference and filtering • %u - User Name - Allows filter by user name • %d - Database Name - Allows filter by database name • %r - Remote Host IP/Name (w/ port) - Helps identify suspicious activity from a host • %p - Process ID - Helps identify specific problematic sessions
  32. My Personal Favorites • %a - Application Name - Allows

    quick reference and filtering • %u - User Name - Allows filter by user name • %d - Database Name - Allows filter by database name • %r - Remote Host IP/Name (w/ port) - Helps identify suspicious activity from a host • %p - Process ID - Helps identify specific problematic sessions • %l - Session/Process Log Line - Helps identify what a session has done
  33. My Personal Favorites • %a - Application Name - Allows

    quick reference and filtering • %u - User Name - Allows filter by user name • %d - Database Name - Allows filter by database name • %r - Remote Host IP/Name (w/ port) - Helps identify suspicious activity from a host • %p - Process ID - Helps identify specific problematic sessions • %l - Session/Process Log Line - Helps identify what a session has done • %v/%x - Transaction IDs - Helps identify what queries a transaction ran
  34. Other Useful Parameters • log_min_duration_statement -- helpful in identifying slow

    queries • log_statement -- good for auditing purposes • log_[dis]connections -- good for auditing purposes • log_rotation_age/log_rotation_size -- good for organization • log_autovacuum_min_duration -- gives insight into autovacuum behavior • log_checkpoints -- know what queries happened between checkpoints • log_temp_files -- helps identify work_mem shortages, I/O spikes
  35. The Wall of Text (with log_connections) LOG: connection received: host=127.0.0.1

    port=45214 LOG: connection authorized: user=postgres database=postgres LOG: statement: END; LOG: connection authorized: user=postgres database=postgres LOG: statement: BEGIN; LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 4305 WHERE aid = 47364; LOG: statement: BEGIN; LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 47364; LOG: connection authorized: user=postgres database=postgres LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -2684 WHERE aid = 53855; LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + 4305 WHERE tid = 10; LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + 4305 WHERE bid = 1; LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (10, 1, 47364, 4305, CURRENT_TIMESTAMP); LOG: statement: END; LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 53855; LOG: connection received: host=127.0.0.1 port=45216 LOG: statement: drop table pgbench_accounts LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + -2684 WHERE tid = 10; LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + -2684 WHERE bid = 1; LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (10, 1, 53855, -2684, CURRENT_TIMESTAMP); LOG: statement: END; LOG: connection authorized: user=postgres database=postgres LOG: connection received: host=127.0.0.1 port=45218 LOG: connection authorized: user=postgres database=postgres LOG: statement: BEGIN; LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -3198 WHERE aid = 51840; LOG: statement: BEGIN; LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 4395 WHERE aid = 62616; ERROR: relation "pgbench_accounts" does not exist at character 8 STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + 4395 WHERE aid = 62616; ERROR: relation "pgbench_accounts" does not exist at character 8 STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -3198 WHERE aid = 51840; LOG: connection received: host=127.0.0.1 port=45220 LOG: connection received: host=127.0.0.1 port=45222 LOG: connection authorized: user=postgres database=postgres LOG: connection authorized: user=postgres database=postgres LOG: statement: BEGIN; LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -148 WHERE aid = 98357; ERROR: relation "pgbench_accounts" does not exist at character 8 STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -148 WHERE aid = 98357; LOG: statement: BEGIN; LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -3241 WHERE aid = 26657; ERROR: relation "pgbench_accounts" does not exist at character 8 STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -3241 WHERE aid = 26657; LOG: automatic vacuum of table "postgres.public.pgbench_branches": index scans: 0 LOG: automatic analyze of table "postgres.public.pgbench_branches" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.02 s LOG: automatic analyze of table "postgres.public.pgbench_history" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s LOG: automatic vacuum of table "postgres.public.pgbench_tellers": index scans: 0 LOG: automatic analyze of table "postgres.public.pgbench_tellers" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
  36. The Wall of Text (with '%m [%p]: [%l] [txid=%x] user=%u,db=%d,app%a,client=%r

    ') 2020-02-29 00:37:42.791 UTC [5194]: [1] [txid=0] user=[unknown],db=[unknown],app[unknown],client=127.0.0.1(45214) LOG: connection received: host=127.0.0.1 port=45214 2020-02-29 00:37:42.791 UTC [5192]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=127.0.0.1(45210) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.792 UTC [5191]: [9] [txid=100155] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45208) LOG: statement: END; 2020-02-29 00:37:42.792 UTC [5194]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=127.0.0.1(45214) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.794 UTC [5194]: [3] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: BEGIN; 2020-02-29 00:37:42.795 UTC [5194]: [4] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 4305 WHERE aid = 47364; 2020-02-29 00:37:42.796 UTC [5192]: [3] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: BEGIN; 2020-02-29 00:37:42.796 UTC [5194]: [5] [txid=100157] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 47364; 2020-02-29 00:37:42.796 UTC [5193]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=172.17.0.3(44698) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.796 UTC [5192]: [4] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -2684 WHERE aid = 53855; 2020-02-29 00:37:42.796 UTC [5194]: [6] [txid=100157] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + 4305 WHERE tid = 10; 2020-02-29 00:37:42.796 UTC [5194]: [7] [txid=100157] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + 4305 WHERE bid = 1; 2020-02-29 00:37:42.796 UTC [5194]: [8] [txid=100157] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (10, 1, 47364, 2020-02-29 00:37:42.797 UTC [5194]: [9] [txid=100157] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: END; 2020-02-29 00:37:42.797 UTC [5192]: [5] [txid=100158] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 53855; 2020-02-29 00:37:42.797 UTC [5195]: [1] [txid=0] user=[unknown],db=[unknown],app[unknown],client=127.0.0.1(45216) LOG: connection received: host=127.0.0.1 port=45216 2020-02-29 00:37:42.797 UTC [5193]: [3] [txid=0] user=postgres,db=postgres,apppsql,client=172.17.0.3(44698) LOG: statement: drop table pgbench_accounts 2020-02-29 00:37:42.797 UTC [5192]: [6] [txid=100158] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + -2684 WHERE tid = 10; 2020-02-29 00:37:42.798 UTC [5192]: [7] [txid=100158] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + -2684 WHERE bid = 1; 2020-02-29 00:37:42.798 UTC [5192]: [8] [txid=100158] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (10, 1, 53855, 2020-02-29 00:37:42.798 UTC [5192]: [9] [txid=100158] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: END; 2020-02-29 00:37:42.799 UTC [5195]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=127.0.0.1(45216) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.799 UTC [5196]: [1] [txid=0] user=[unknown],db=[unknown],app[unknown],client=127.0.0.1(45218) LOG: connection received: host=127.0.0.1 port=45218 2020-02-29 00:37:42.800 UTC [5196]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=127.0.0.1(45218) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.800 UTC [5195]: [3] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45216) LOG: statement: BEGIN; 2020-02-29 00:37:42.800 UTC [5195]: [4] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45216) LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -3198 WHERE aid = 51840; 2020-02-29 00:37:42.801 UTC [5196]: [3] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45218) LOG: statement: BEGIN; 2020-02-29 00:37:42.801 UTC [5196]: [4] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45218) LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 4395 WHERE aid = 62616; 2020-02-29 00:37:42.801 UTC [5196]: [5] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45218) ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:37:42.801 UTC [5196]: [6] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45218) STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + 4395 WHERE aid = 62616; 2020-02-29 00:37:42.802 UTC [5195]: [5] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45216) ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:37:42.802 UTC [5195]: [6] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45216) STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -3198 WHERE aid = 51840; 2020-02-29 00:37:42.804 UTC [5197]: [1] [txid=0] user=[unknown],db=[unknown],app[unknown],client=127.0.0.1(45220) LOG: connection received: host=127.0.0.1 port=45220 2020-02-29 00:37:42.804 UTC [5198]: [1] [txid=0] user=[unknown],db=[unknown],app[unknown],client=127.0.0.1(45222) LOG: connection received: host=127.0.0.1 port=45222 2020-02-29 00:37:42.805 UTC [5197]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=127.0.0.1(45220) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.807 UTC [5198]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=127.0.0.1(45222) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.807 UTC [5197]: [3] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45220) LOG: statement: BEGIN; 2020-02-29 00:37:42.808 UTC [5197]: [4] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45220) LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -148 WHERE aid = 98357; 2020-02-29 00:37:42.808 UTC [5197]: [5] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45220) ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:37:42.808 UTC [5197]: [6] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45220) STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -148 WHERE aid = 98357; 2020-02-29 00:37:42.808 UTC [5198]: [3] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45222) LOG: statement: BEGIN; 2020-02-29 00:37:42.809 UTC [5198]: [4] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45222) LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -3241 WHERE aid = 26657; 2020-02-29 00:37:42.809 UTC [5198]: [5] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45222) ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:37:42.809 UTC [5198]: [6] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45222) STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -3241 WHERE aid = 26657; 2020-02-29 00:37:47.480 UTC [5199]: [1] [txid=0] user=,db=,app,client= LOG: automatic vacuum of table "postgres.public.pgbench_branches": index scans: 0 2020-02-29 00:37:47.501 UTC [5199]: [2] [txid=100160] user=,db=,app,client= LOG: automatic analyze of table "postgres.public.pgbench_branches" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.02 s 2020-02-29 00:37:47.515 UTC [5199]: [3] [txid=100161] user=,db=,app,client= LOG: automatic analyze of table "postgres.public.pgbench_history" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s 2020-02-29 00:37:47.527 UTC [5199]: [4] [txid=0] user=,db=,app,client= LOG: automatic vacuum of table "postgres.public.pgbench_tellers": index scans: 0 2020-02-29 00:37:47.527 UTC [5199]: [5] [txid=100162] user=,db=,app,client= LOG: automatic analyze of table "postgres.public.pgbench_tellers" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
  37. The Wall of Text (sorted) 2020-02-29 00:37:42.792 UTC [5191]: [9]

    [txid=100155] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45208) LOG: statement: END; 2020-02-29 00:37:42.791 UTC [5192]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=127.0.0.1(45210) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.796 UTC [5192]: [3] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: BEGIN; 2020-02-29 00:37:42.796 UTC [5192]: [4] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -2684 WHERE aid = 53855; 2020-02-29 00:37:42.797 UTC [5192]: [5] [txid=100158] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 53855; 2020-02-29 00:37:42.797 UTC [5192]: [6] [txid=100158] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + -2684 WHERE tid = 10; 2020-02-29 00:37:42.798 UTC [5192]: [7] [txid=100158] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + -2684 WHERE bid = 1; 2020-02-29 00:37:42.798 UTC [5192]: [8] [txid=100158] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (10, 1, 53855, 2020-02-29 00:37:42.798 UTC [5192]: [9] [txid=100158] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: END; 2020-02-29 00:37:42.796 UTC [5193]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=172.17.0.3(44698) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.797 UTC [5193]: [3] [txid=0] user=postgres,db=postgres,apppsql,client=172.17.0.3(44698) LOG: statement: drop table pgbench_accounts 2020-02-29 00:37:42.791 UTC [5194]: [1] [txid=0] user=[unknown],db=[unknown],app[unknown],client=127.0.0.1(45214) LOG: connection received: host=127.0.0.1 port=45214 2020-02-29 00:37:42.792 UTC [5194]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=127.0.0.1(45214) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.794 UTC [5194]: [3] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: BEGIN; 2020-02-29 00:37:42.795 UTC [5194]: [4] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 4305 WHERE aid = 47364; 2020-02-29 00:37:42.796 UTC [5194]: [5] [txid=100157] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 47364; 2020-02-29 00:37:42.796 UTC [5194]: [6] [txid=100157] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + 4305 WHERE tid = 10; 2020-02-29 00:37:42.796 UTC [5194]: [7] [txid=100157] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + 4305 WHERE bid = 1; 2020-02-29 00:37:42.796 UTC [5194]: [8] [txid=100157] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (10, 1, 47364, 2020-02-29 00:37:42.797 UTC [5194]: [9] [txid=100157] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: END; 2020-02-29 00:37:42.797 UTC [5195]: [1] [txid=0] user=[unknown],db=[unknown],app[unknown],client=127.0.0.1(45216) LOG: connection received: host=127.0.0.1 port=45216 2020-02-29 00:37:42.799 UTC [5195]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=127.0.0.1(45216) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.800 UTC [5195]: [3] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45216) LOG: statement: BEGIN; 2020-02-29 00:37:42.800 UTC [5195]: [4] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45216) LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -3198 WHERE aid = 51840; 2020-02-29 00:37:42.802 UTC [5195]: [5] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45216) ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:37:42.802 UTC [5195]: [6] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45216) STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -3198 WHERE aid = 51840; 2020-02-29 00:37:42.799 UTC [5196]: [1] [txid=0] user=[unknown],db=[unknown],app[unknown],client=127.0.0.1(45218) LOG: connection received: host=127.0.0.1 port=45218 2020-02-29 00:37:42.800 UTC [5196]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=127.0.0.1(45218) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.801 UTC [5196]: [3] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45218) LOG: statement: BEGIN; 2020-02-29 00:37:42.801 UTC [5196]: [4] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45218) LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 4395 WHERE aid = 62616; 2020-02-29 00:37:42.801 UTC [5196]: [5] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45218) ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:37:42.801 UTC [5196]: [6] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45218) STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + 4395 WHERE aid = 62616; 2020-02-29 00:37:42.804 UTC [5197]: [1] [txid=0] user=[unknown],db=[unknown],app[unknown],client=127.0.0.1(45220) LOG: connection received: host=127.0.0.1 port=45220 2020-02-29 00:37:42.805 UTC [5197]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=127.0.0.1(45220) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.807 UTC [5197]: [3] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45220) LOG: statement: BEGIN; 2020-02-29 00:37:42.808 UTC [5197]: [4] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45220) LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -148 WHERE aid = 98357; 2020-02-29 00:37:42.808 UTC [5197]: [5] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45220) ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:37:42.808 UTC [5197]: [6] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45220) STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -148 WHERE aid = 98357; 2020-02-29 00:37:42.804 UTC [5198]: [1] [txid=0] user=[unknown],db=[unknown],app[unknown],client=127.0.0.1(45222) LOG: connection received: host=127.0.0.1 port=45222 2020-02-29 00:37:42.807 UTC [5198]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=127.0.0.1(45222) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.808 UTC [5198]: [3] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45222) LOG: statement: BEGIN; 2020-02-29 00:37:42.809 UTC [5198]: [4] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45222) LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -3241 WHERE aid = 26657; 2020-02-29 00:37:42.809 UTC [5198]: [5] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45222) ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:37:42.809 UTC [5198]: [6] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45222) STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -3241 WHERE aid = 26657; 2020-02-29 00:37:47.480 UTC [5199]: [1] [txid=0] user=,db=,app,client= LOG: automatic vacuum of table "postgres.public.pgbench_branches": index scans: 0 2020-02-29 00:37:47.501 UTC [5199]: [2] [txid=100160] user=,db=,app,client= LOG: automatic analyze of table "postgres.public.pgbench_branches" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.02 s 2020-02-29 00:37:47.515 UTC [5199]: [3] [txid=100161] user=,db=,app,client= LOG: automatic analyze of table "postgres.public.pgbench_history" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s 2020-02-29 00:37:47.527 UTC [5199]: [4] [txid=0] user=,db=,app,client= LOG: automatic vacuum of table "postgres.public.pgbench_tellers": index scans: 0 2020-02-29 00:37:47.527 UTC [5199]: [5] [txid=100162] user=,db=,app,client= LOG: automatic analyze of table "postgres.public.pgbench_tellers" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
  38. Found the culprit! 2020-02-29 00:37:42.792 UTC [5191]: [9] [txid=100155] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45208)

    LOG: statement: END; 2020-02-29 00:37:42.791 UTC [5192]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=127.0.0.1(45210) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.796 UTC [5192]: [3] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: BEGIN; 2020-02-29 00:37:42.796 UTC [5192]: [4] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -2684 WHERE aid = 53855; 2020-02-29 00:37:42.797 UTC [5192]: [5] [txid=100158] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 53855; 2020-02-29 00:37:42.797 UTC [5192]: [6] [txid=100158] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + -2684 WHERE tid = 10; 2020-02-29 00:37:42.798 UTC [5192]: [7] [txid=100158] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + -2684 WHERE bid = 1; 2020-02-29 00:37:42.798 UTC [5192]: [8] [txid=100158] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (10, 1, 53855, 2020-02-29 00:37:42.798 UTC [5192]: [9] [txid=100158] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45210) LOG: statement: END; 2020-02-29 00:37:42.796 UTC [5193]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=172.17.0.3(44698) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.797 UTC [5193]: [3] [txid=0] user=postgres,db=postgres,apppsql,client=172.17.0.3(44698) LOG: statement: drop table pgbench_accounts 2020-02-29 00:37:42.791 UTC [5194]: [1] [txid=0] user=[unknown],db=[unknown],app[unknown],client=127.0.0.1(45214) LOG: connection received: host=127.0.0.1 port=45214 2020-02-29 00:37:42.792 UTC [5194]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=127.0.0.1(45214) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.794 UTC [5194]: [3] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: BEGIN; 2020-02-29 00:37:42.795 UTC [5194]: [4] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 4305 WHERE aid = 47364; 2020-02-29 00:37:42.796 UTC [5194]: [5] [txid=100157] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: SELECT abalance FROM pgbench_accounts WHERE aid = 47364; 2020-02-29 00:37:42.796 UTC [5194]: [6] [txid=100157] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: UPDATE pgbench_tellers SET tbalance = tbalance + 4305 WHERE tid = 10; 2020-02-29 00:37:42.796 UTC [5194]: [7] [txid=100157] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: UPDATE pgbench_branches SET bbalance = bbalance + 4305 WHERE bid = 1; 2020-02-29 00:37:42.796 UTC [5194]: [8] [txid=100157] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (10, 1, 47364, 2020-02-29 00:37:42.797 UTC [5194]: [9] [txid=100157] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45214) LOG: statement: END; 2020-02-29 00:37:42.797 UTC [5195]: [1] [txid=0] user=[unknown],db=[unknown],app[unknown],client=127.0.0.1(45216) LOG: connection received: host=127.0.0.1 port=45216 2020-02-29 00:37:42.799 UTC [5195]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=127.0.0.1(45216) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.800 UTC [5195]: [3] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45216) LOG: statement: BEGIN; 2020-02-29 00:37:42.800 UTC [5195]: [4] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45216) LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -3198 WHERE aid = 51840; 2020-02-29 00:37:42.802 UTC [5195]: [5] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45216) ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:37:42.802 UTC [5195]: [6] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45216) STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -3198 WHERE aid = 51840; 2020-02-29 00:37:42.799 UTC [5196]: [1] [txid=0] user=[unknown],db=[unknown],app[unknown],client=127.0.0.1(45218) LOG: connection received: host=127.0.0.1 port=45218 2020-02-29 00:37:42.800 UTC [5196]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=127.0.0.1(45218) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.801 UTC [5196]: [3] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45218) LOG: statement: BEGIN; 2020-02-29 00:37:42.801 UTC [5196]: [4] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45218) LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + 4395 WHERE aid = 62616; 2020-02-29 00:37:42.801 UTC [5196]: [5] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45218) ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:37:42.801 UTC [5196]: [6] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45218) STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + 4395 WHERE aid = 62616; 2020-02-29 00:37:42.804 UTC [5197]: [1] [txid=0] user=[unknown],db=[unknown],app[unknown],client=127.0.0.1(45220) LOG: connection received: host=127.0.0.1 port=45220 2020-02-29 00:37:42.805 UTC [5197]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=127.0.0.1(45220) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.807 UTC [5197]: [3] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45220) LOG: statement: BEGIN; 2020-02-29 00:37:42.808 UTC [5197]: [4] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45220) LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -148 WHERE aid = 98357; 2020-02-29 00:37:42.808 UTC [5197]: [5] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45220) ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:37:42.808 UTC [5197]: [6] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45220) STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -148 WHERE aid = 98357; 2020-02-29 00:37:42.804 UTC [5198]: [1] [txid=0] user=[unknown],db=[unknown],app[unknown],client=127.0.0.1(45222) LOG: connection received: host=127.0.0.1 port=45222 2020-02-29 00:37:42.807 UTC [5198]: [2] [txid=0] user=postgres,db=postgres,app[unknown],client=127.0.0.1(45222) LOG: connection authorized: user=postgres database=postgres 2020-02-29 00:37:42.808 UTC [5198]: [3] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45222) LOG: statement: BEGIN; 2020-02-29 00:37:42.809 UTC [5198]: [4] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45222) LOG: statement: UPDATE pgbench_accounts SET abalance = abalance + -3241 WHERE aid = 26657; 2020-02-29 00:37:42.809 UTC [5198]: [5] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45222) ERROR: relation "pgbench_accounts" does not exist at character 8 2020-02-29 00:37:42.809 UTC [5198]: [6] [txid=0] user=postgres,db=postgres,apppgbench,client=127.0.0.1(45222) STATEMENT: UPDATE pgbench_accounts SET abalance = abalance + -3241 WHERE aid = 26657; 2020-02-29 00:37:47.480 UTC [5199]: [1] [txid=0] user=,db=,app,client= LOG: automatic vacuum of table "postgres.public.pgbench_branches": index scans: 0 2020-02-29 00:37:47.501 UTC [5199]: [2] [txid=100160] user=,db=,app,client= LOG: automatic analyze of table "postgres.public.pgbench_branches" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.02 s 2020-02-29 00:37:47.515 UTC [5199]: [3] [txid=100161] user=,db=,app,client= LOG: automatic analyze of table "postgres.public.pgbench_history" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s 2020-02-29 00:37:47.527 UTC [5199]: [4] [txid=0] user=,db=,app,client= LOG: automatic vacuum of table "postgres.public.pgbench_tellers": index scans: 0 2020-02-29 00:37:47.527 UTC [5199]: [5] [txid=100162] user=,db=,app,client= LOG: automatic analyze of table "postgres.public.pgbench_tellers" system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
  39. How much is too much? • Log as much, as

    long, as your system can handle
  40. How much is too much? • Log as much, as

    long, as your system can handle • Most logging params can be turned on/off with a HUP/reload
  41. How much is too much? • Log as much, as

    long, as your system can handle • Most logging params can be turned on/off with a HUP/reload • Use a separate partition
  42. How much is too much? • Log as much, as

    long, as your system can handle • Most logging params can be turned on/off with a HUP/reload • Use a separate partition • Get familiar with grep and awk (or even sed)
  43. How much is too much? • Log as much, as

    long, as your system can handle • Most logging params can be turned on/off with a HUP/reload • Use a separate partition • Get familiar with grep and awk (or even sed) • Compress your log files (using a cronjob)
  44. How much is too much? • Log as much, as

    long, as your system can handle • Most logging params can be turned on/off with a HUP/reload • Use a separate partition • Get familiar with grep and awk (or even sed) • Compress your log files (using a cronjob) • If you know what to look for, you can filter out the noise
  45. A word on verbosity • log_min_messages • This indicates *generally*

    how much to log. • Valid values are : • DEBUG{5,4,3,2,1} • INFO • NOTICE • WARNING • ERROR • LOG • FATAL • PANIC • WARNING is the default, but you shouldn’t ever have to do more than INFO
  46. What to look for: Logging Levels • WARNING • Not

    necessarily urgent, but a proactive notice from PG • ERROR • Failure to execute a command; often a syntax error, but can indicate worse (i.e., corruption) • FATAL • Session terminated due to some error (ex., wrong password, bad auth) • PANIC • Some anomaly encountered in the database engine (segfault, corruption, etc.) • All sessions terminated for safety
  47. What to look for: Common Issues • Don’t ignore DETAIL

    and HINT messages • A spike in FATAL messages often correlates to misconfigured application • A spike in ERROR messages often correlates to an application bug • A spike in ERROR messages can indicate broken replication • Autovacuum problems? Look for long-running idle transactions
  48. What to look for: hints 2016-03-04 10:13:51.746 CET [15340]: [80091-1]

    user=postgres,db=postgres,10.0.1.1(49015) WARNING: database "postgres" must be vacuumed within 9763669 transactions 2016-03-04 10:13:51.746 CET [15340]: [80092-1] user=postgres,db=postgres,10.0.1.1(49015) HINT: To avoid a database shutdown, execute a database-wide VACUUM in that database. You might also need to commit or roll back old prepared transactions. 2016-03-04 10:13:51.746 CET [15337]: [79775-1] user=postgres,db=postgres,10.0.1.1(49012) WARNING: database "postgres" must be vacuumed within 9763668 transactions 2016-03-04 10:13:51.746 CET [15337]: [79776-1] user=postgres,db=postgres,10.0.1.1(49012) HINT: To avoid a database shutdown, execute a database-wide VACUUM in that database. You might also need to commit or roll back old prepared transactions. 2016-03-04 10:13:51.746 CET [15332]: [80655-1] user=postgres,db=postgres,10.0.1.1(49007) WARNING: database "postgres" must be vacuumed within 9763667 transactions 2016-03-04 10:13:51.746 CET [15332]: [80656-1] user=postgres,db=postgres,10.0.1.1(49007) HINT: To avoid a database shutdown, execute a database-wide VACUUM in that database. You might also need to commit or roll back old prepared transactions.
  49. What to look for: Application Configuration/Downtime 2017-01-11 16:19:24 IST FATAL:

    the database system is starting up 2017-01-11 16:19:25 IST FATAL: the database system is starting up 2017-01-11 16:19:26 IST FATAL: the database system is starting up 2017-01-11 16:19:27 IST FATAL: the database system is starting up 2017-01-11 16:19:28 IST FATAL: the database system is starting up 2017-01-11 16:19:29 IST FATAL: the database system is starting up 2017-01-11 16:19:30 IST FATAL: the database system is starting up 2017-01-11 16:19:31 IST FATAL: the database system is starting up 2017-01-11 16:19:32 IST FATAL: the database system is starting up 2017-01-11 16:19:33 IST FATAL: the database system is starting up 2017-01-11 16:19:33 IST LOG: startup process (PID 15153) was terminated by signal 6: Aborted 2017-01-11 16:19:33 IST LOG: aborting startup due to startup process failure 2017-01-11 16:20:00 IST LOG: database system was shut down at 2017-01-11 15:34:43 IST 2017-01-11 16:20:00 IST FATAL: the database system is starting up 2017-01-11 16:20:00 IST FATAL: the database system is starting up 2017-01-11 16:20:00 IST FATAL: the database system is starting up 2017-01-11 16:20:00 IST LOG: could not send data to client: Broken pipe 2017-01-11 16:20:00 IST LOG: could not open file "pg_xlog/00000001000000E3000000B9" (log file 227, segment 185): No such file or directory 2017-01-11 16:20:00 IST LOG: invalid primary checkpoint record 2017-01-11 16:20:00 IST LOG: could not open file "pg_xlog/00000001000000E3000000B9" (log file 227, segment 185): No such file or directory 2017-01-11 16:20:00 IST LOG: invalid secondary checkpoint record 2017-01-11 16:20:00 IST PANIC: could not locate a valid checkpoint record 2017-01-11 16:20:00 IST FATAL: the database system is starting up 2017-01-11 16:20:00 IST FATAL: the database system is starting up 2017-01-11 16:20:00 IST FATAL: the database system is starting up 2017-01-11 16:20:00 IST FATAL: the database system is starting up 2017-01-11 16:20:00 IST FATAL: the database system is starting up 2017-01-11 16:20:00 IST FATAL: the database system is starting up 2017-01-11 16:20:00 IST FATAL: the database system is starting up
  50. What to look for: Application Bugs 2017-01-11 00:02:18 IST WARNING:

    there is no transaction in progress 2017-01-11 00:02:18 IST WARNING: there is no transaction in progress 2017-01-11 00:02:18 IST WARNING: there is no transaction in progress 2017-01-11 00:02:18 IST WARNING: there is no transaction in progress 2017-01-11 00:15:07 IST WARNING: there is no transaction in progress 2017-01-11 00:16:48 IST WARNING: there is no transaction in progress 2017-01-11 00:25:11 IST WARNING: there is no transaction in progress 2017-01-11 00:45:01 IST WARNING: there is no transaction in progress 2017-01-11 00:48:33 IST WARNING: there is no transaction in progress 2017-01-11 00:56:23 IST WARNING: there is no transaction in progress 2017-01-11 01:01:04 IST LOG: unexpected EOF on client connection 2017-01-11 01:01:04 IST LOG: unexpected EOF on client connection 2017-01-11 01:01:04 IST LOG: unexpected EOF on client connection 2017-01-11 01:01:04 IST LOG: unexpected EOF on client connection 2017-01-11 01:01:04 IST LOG: unexpected EOF on client connection 2017-01-11 01:01:04 IST LOG: unexpected EOF on client connection 2017-01-11 01:01:04 IST LOG: unexpected EOF on client connection 2017-01-11 01:05:14 IST WARNING: there is no transaction in progress 2017-01-11 01:15:10 IST WARNING: there is no transaction in progress 2017-01-11 01:25:29 IST WARNING: there is no transaction in progress 2017-01-11 01:45:01 IST WARNING: there is no transaction in progress
  51. What to look for: Broken Replication 2019-02-19 19:35:57.222 UTC >

    ERROR: requested WAL segment 000000010000000000000009 has already been removed 2019-02-19 19:36:02.217 UTC > ERROR: requested WAL segment 000000010000000000000009 has already been removed 2019-02-19 19:36:07.235 UTC > ERROR: requested WAL segment 000000010000000000000009 has already been removed 2019-02-19 19:36:12.232 UTC > ERROR: requested WAL segment 000000010000000000000009 has already been removed 2019-02-19 19:36:17.235 UTC > ERROR: requested WAL segment 000000010000000000000009 has already been removed
  52. What to look for: autovacuum 2020-02-25 00:29:29.062 UTC [66340] LOG:

    automatic vacuum of table "postgres.public.pgbench_accounts": index scans: 1 pages: 0 removed, 8694 remain, 0 skipped due to pins, 0 skipped frozen tuples: 198 removed, 125983 remain, 99944 are dead but not yet removable, oldest xmin: 95278 buffer usage: 25163 hits, 0 misses, 0 dirtied avg read rate: 0.000 MB/s, avg write rate: 0.000 MB/s system usage: CPU: user: 0.17 s, system: 0.01 s, elapsed: 3.00 s
  53. What to look for: temp files 2020-02-14 09:20:23 EST [63408]:

    [3-1] db=,user=,app=,client=LOG: temporary file: path "base/pgsql_tmp/ pgsql_tmp63408.0", size 8216576 2020-02-14 09:20:23 EST [63410]: [3-1] db=,user=,app=,client=LOG: temporary file: path "base/pgsql_tmp/ pgsql_tmp63410.0", size 11018240 2020-02-14 09:20:23 EST [63411]: [3-1] db=,user=,app=,client=LOG: temporary file: path "base/pgsql_tmp/ pgsql_tmp63411.0", size 13869056 2020-02-14 09:20:23 EST [63409]: [3-1] db=,user=,app=,client=LOG: temporary file: path "base/pgsql_tmp/ pgsql_tmp63409.0", size 10616832
  54. What to look for: locking & blocking 2020-02-14 09:20:24 EST

    [43118]: [64706-1] db=immcare,user=svc-mmpphmp,app=PostgreSQL JDBC Driver,client=10.8.37.178LOG: process 43118 still waiting for AccessExclusiveLock on tuple (0,2) of relation 17305 of database 16493 after 1000.117 ms 2020-02-14 09:20:24 EST [43118]: [64707-1] db=immcare,user=svc-mmpphmp,app=PostgreSQL JDBC Driver,client=10.8.37.178DETAIL: Process holding the lock: 29558. Wait queue: 59904, 45056, 19684, 60331, 45055, 43385, 45544, 29400, 43383, 55077, 45197, 50943, 43549, 29401, 43548, 59877, 43550, 29076, 35322, 50944, 25466, 29078, 19683, 43119, 54837, 10518, 43118. ——————- 2019-02-07 01:01:36.253 EST,"postgres","dbname",6652,"10.161.66.46:64171",5c5bc869.19fc,2,"SELECT",2019-02-07 00:55:53 EST,15/2674841,579153561,ERROR,40P01,"deadlock detected","Process 6652 waits for AccessExclusiveLock on relation 34670713 of database 9122478; blocked by process 7715. Process 7715 waits for AccessShareLock on relation 34670707 of database 9122478; blocked by process 6652. Process 6652: SELECT * FROM myschema.proc_mv_refresh() Process 7715: SELECT c.relname AS view_name, c.relkind AS view_type, c.relispopulated AS ispopulated, spc.spcname AS tablespace_name, pg_get_userbyid(c.relowner) AS view_owner, pg_get_viewdef(c.oid, true) AS definition FROM pg_catalog.pg_class c LEFT OUTER JOIN pg_tablespace spc on spc.oid=c.reltablespace LEFT OUTER JOIN pg_namespace n on n.oid=c.relnamespace WHERE (c.relkind = 'v' OR c.relkind = 'm') AND c.relnamespace = n.oid AND n.nspname = $1","See server log for query details.",,,"SQL statement ""REFRESH MATERIALIZED VIEW ENTRP_SERVS.MV_8001_AU_PRSN""
  55. Digesting the log: pgbadger • Analyzes your logs • Generates

    statistics of your query traffic • Helps identify problematic queries
  56. More Knowledge, More Power • auto_explain • Adds EXPLAIN output

    to your log • Can show the runtimes of each plan node • Can show caching behavior and memory usage • pg_stat_statements • Logs statistics on each statement executed • Doesn’t go into your log, but in a table within Postgres • Can help alleviate log traffic (YMMV)
  57. Some gotchas • logging_collector • needs to be turned on

    if you want separate log files (i.e., not using syslog) • log_filename • needs to include the relevant escapes for notation to happen • otherwise, it just appends (unless log_truncate_on_rotation is turned on)
  58. Some gotchas • log_min_duration_statement v log_duration • log_duration • only

    logs the time it took for a query to run • does not log the query • Applies to all queries • log_min_duration_statement • logs the time it took for a query to run • logs the query • Applies to only queries exceeding the threshold • Why log_duration? • Allows you to gather stats on high-workload environments, without the added overhead of printing the full query
  59. Some gotchas • log_min_duration_statement v log_statement • log_min_duration_statement • logs

    the statement and duration AFTER the query has finished • does not log parameters • log_statement • logs the statement BEFORE the query is executed • logs parameters
  60. Summary • Be sure to set your log_line_prefix • Turn

    on log_connections to track down the origin of your queries
  61. Summary • Be sure to set your log_line_prefix • Turn

    on log_connections to track down the origin of your queries • Log as much as you can, for as long as you can
  62. Summary • Be sure to set your log_line_prefix • Turn

    on log_connections to track down the origin of your queries • Log as much as you can, for as long as you can • Run your logs through pgbadger for visibility and forecasting
  63. Summary • Be sure to set your log_line_prefix • Turn

    on log_connections to track down the origin of your queries • Log as much as you can, for as long as you can • Run your logs through pgbadger for visibility and forecasting • Monitor for spikes in FATAL/ERROR/WARNING messages