PostgreSQL Administration for System Administrators

6,823 views

Published on

Spencer Christensen

There are many aspects to managing an RDBMS. Some of these are handled by an experienced DBA, but there are a good many things that any sys admin should be able to take care of if they know what to look for.

This presentation will cover basics of managing Postgres, including creating database clusters, overview of configuration, and logging. We will also look at tools to help monitor Postgres and keep an eye on what is going on. Some of the tools we will review are:

* pgtop

* pg_top

* pgfouine

* check_postgres.pl.

Check_postgres.pl is a great tool that can plug into your Nagios or Cacti monitoring systems, giving you even better visibility into your databases.

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,823
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
280
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • History of Postgres: Developed at UC Berkely, called Ingres Academic project Business Ingres Corp formed Forks: Informix, Sybase Then creator decided on different implimentation: Postgres Postgres95 (1994-1995) SQL became popular/standard PostgreSQL (1996-now)
  • Top line output for postgres: User, database, host connected from, PID, command type
  • PostgreSQL Administration for System Administrators

    1. 1. Postgres Administration for Sysadmins Spencer Christensen Backcountry.com PostgreSQL Conference East, Philadelphia March 26, 2010
    2. 2. PostgreSQL <ul><li>How do you pronounce “PostgreSQL”?
    3. 3. The Q and L are silent </li></ul>
    4. 4. How do you pronounce Thule? <ul><li>“Yakima” </li></ul>
    5. 5. Audience <ul><li>Linux/Unix system administrator
    6. 6. Familiar with databases
    7. 7. Want to understand Postgres better </li></ul>
    8. 8. What we'll cover <ul><li>Management
    9. 9. Monitoring </li></ul>
    10. 10. What we'll cover <ul><li>Management </li><ul><li>Creating a cluster
    11. 11. Highlights of postgresql.conf
    12. 12. Logging options, review of log output
    13. 13. pg_hba.conf
    14. 14. Starting, stopping, restarts
    15. 15. Connecting with psql </li></ul></ul>
    16. 16. What we'll cover <ul><li>Monitoring </li><ul><li>top
    17. 17. ps
    18. 18. du
    19. 19. pgtop
    20. 20. pg_top
    21. 21. check_postgres.pl
    22. 22. Pgfouine </li></ul></ul>
    23. 23. Management <ul><li>Install by rpm/deb/source
    24. 24. Multiple installs
    25. 25. Multiple instances (different ports, different ip addresses, etc) </li></ul>
    26. 26. Creating a cluster <ul><li>Initdb -D /path/to/data/dir [options] </li><ul><li>-U postgres </li></ul></ul>[schristensen@small_db ~]$ initdb -U postgres -D cluster1/data The files belonging to this database system will be owned by user &quot;schristensen&quot;. This user must also own the server process. The database cluster will be initialized with locale en_US.UTF-8. The default database encoding has accordingly been set to UTF8. The default text search configuration will be set to &quot;english&quot;.
    27. 27. Postgresql.conf <ul><li>Located at $PGDATA/postgresql.conf
    28. 28. Helpful comments
    29. 29. Default values commented out
    30. 30. Some changes require a restart (others can be picked up with a reload) </li></ul>
    31. 31. Postgresql.conf <ul><li>port = 5432
    32. 32. listen_addresses = 'localhost'
    33. 33. max_connections = 10
    34. 34. statement_timeout = 0 # microseconds </li></ul>
    35. 35. Postgresql.conf <ul><li>port = 5432 </li><ul><li>port = 54321 </li></ul><li>listen_addresses = 'localhost' </li><ul><li>listen_addresses = '*' </li></ul><li>max_connections = 10 </li><ul><li>max_connections = 100 </li></ul><li>statement_timeout = 0 # microseconds </li><ul><li>statement_timeout = 1800000 </li></ul></ul>
    36. 36. pg_ctl <ul><li>pg_ctl -D /path/to/data/dir
    37. 37. -l /path/to/logfile [start|stop|reload|restart|status]
    38. 38. Run as owner of data files (created by initdb)
    39. 39. -m [smart|fast|immediate] stop </li></ul>Start cluster1
    40. 40. Logging options <ul><li>log_destination = 'stderr' # or syslog
    41. 41. log_directory = 'pg_log'
    42. 42. syslog_facility = 'LOCAL0'
    43. 43. log_connections = off
    44. 44. log_disconnections = off
    45. 45. log_duration = off
    46. 46. log_statement = 'none' # or all, ddl, mod </li></ul>
    47. 47. Log output samples LOG: connection received: host=192.168.56.1 port=44738 LOG: connection authorized: user=training database=training LOG: duration: 18.301 ms LOG: duration: 0.898 ms LOG: duration: 1428.301 ms LOG: duration: 2038.301 ms LOG: disconnection: session time: 0:00:12.543 user=training database=training host=192.168.56.1 port=44738
    48. 48. Log output samples LOG: connection received: host=192.168.56.1 port=33185 LOG: duration: 23.469 ms LOG: connection authorized: user=training database=training LOG: statement: select * from emusic.sales_item LOG: duration: 0.706 ms LOG: statement: select * from emusic.stores LOG: duration: 0.447 ms LOG: disconnection: session time: 0:00:12.084 user=training database=training host=192.168.56.1 port=33185
    49. 49. pg_hba.conf HOST DATABASE USER CIDR-ADDRESS METHOD [OPTION] local all pgmonitor trust host all all 10.41.8.21/32 md5 host all all 10.12.12.0/24 md5 <ul><li>Need to reload to take effect </li></ul>H
    50. 50. Postgres Env vars <ul><li>$PGDATA – data directory
    51. 51. $PGPORT – port
    52. 52. $PGHOST – host
    53. 53. $PGUSER – user
    54. 54. pg_ctl -l /tmp/pg.log start
    55. 55. psql </li></ul>
    56. 56. psql <ul><li>psql [-h $host] [-p $port] [-U $user] $db </li></ul>d – list tables, views, sequences dt – list tables only d my_awesome_table – describe table, view q – exit out of psql l – list databases in cluster du – list users in cluster h – help
    57. 57. Monitoring
    58. 58. top <ul><li>Example of running queries </li></ul>
    59. 59. Du <ul><li>Example of disk space usage </li></ul>
    60. 60. Pgtop <ul><li>http://search.cpan.org/~cosimo/pgtop-0.05/pgtop
    61. 61. Based on mytop
    62. 62. Example of running pgtop </li></ul>
    63. 63. pg_top <ul><li>http://ptop.projects.postgresql.org/
    64. 64. More like system top </li><ul><li>Can view running queries, locks, EXPLAIN </li></ul><li>Example of running pg_top </li></ul>
    65. 65. check_postgres.pl <ul><li>http://bucardo.org/check_postgres/
    66. 66. Disk space
    67. 67. Backends
    68. 68. Index size
    69. 69. Table size
    70. 70. Bloat
    71. 71. Last vacuum
    72. 72. Locks
    73. 73. txn_wraparound </li></ul>
    74. 74. Pgfouine <ul><li>http://pgfouine.projects.postgresql.org/
    75. 75. Log files </li><ul><li>Connections, disconnections, durations, statements </li></ul><li>Vacuum verbose output
    76. 76. Example </li></ul>
    77. 77. Wrap up <ul><li>Initdb, postgresql.conf, pg_hba.conf
    78. 78. pg_ctl -D $datadir start|stop|reload|status
    79. 79. psql
    80. 80. Top, du
    81. 81. pg_top, pgtop
    82. 82. check_postgres.pl
    83. 83. Pgfouine </li></ul>
    84. 84. Me <ul><li>Spencer Christensen
    85. 85. Backcountry.com
    86. 86. [email_address]
    87. 87. [email_address] </li></ul>

    ×