SlideShare une entreprise Scribd logo
1  sur  111
Télécharger pour lire hors ligne
Mastering
                 PostgreSQL Administration

                                  BRUCE MOMJIAN,
                                   ENTERPRISEDB

                                       April, 2009




                               Abstract
   POSTGRESQL is an open-source, full-featured relational database.
   This presentation covers advanced administration topics.

Creative Commons Attribution License                 http://momjian.us/presentations
Introduction



    Installation
 




    Configuration
 




    Maintenance
 




    Monitoring
 




    Recovery
 




Mastering PostgreSQL Administration                  1
Installation

    Click-Through installers
 




    –   MS Windows
    –   Linux
    –   OS/X
    –   Solaris

    Ports
 




    –   RPM
    –   DEB
    –   PKG
    –   other packages

    Source
 




    – obtaining
    – build options
    – installing
Mastering PostgreSQL Administration                  2
Initialization (initdb)

    $ initdb
    The files belonging to this database system will be owned by user "postgres".
    This user must also own the server process.
    The database cluster will be initialized with locale C.
    The default database encoding has accordingly been set to SQL_ASCII.
    The default text search configuration will be set to "english".
    creating directory /u/pg/data ... ok
    creating subdirectories ... ok
    selecting default max_connections ... 100
    selecting default shared_buffers/max_fsm_pages ... 32MB/204800
    creating configuration files ... ok
    creating template1 database in /u/pg/data/base/1 ... ok
    initializing pg_authid ... ok
    initializing dependencies ... ok
    creating system views ... ok
    loading system objects’ descriptions ... ok
    creating conversions ... ok
    creating dictionaries ... ok
    setting privileges on built-in objects ... ok
    creating information schema ... ok
    vacuuming database template1 ... ok
    copying template1 to template0 ... ok
    copying template1 to postgres ... ok
Mastering PostgreSQL Administration                                                 3
Initialization (continued)

    WARNING: enabling "trust" authentication for local connections
    You can change this by editing pg_hba.conf or using the -A option the
    next time you run initdb.


    Success. You can now start the database server using:


         postgres -D /u/pg/data
    or
          pg_ctl -D /u/pg/data -l logfile start




Mastering PostgreSQL Administration                                         4
pg_controldata
    pg_control version number:              74
    Catalog version number:                 200502281
    Database system identifier:             4766833642862247929
    Database cluster state:                 shut down
    pg_control last modified:               03/03/05 10:49:18
    Current log file ID:                    0
    Next log file segment:                  1
    Latest checkpoint location:             0/A34010
    Prior checkpoint location:              0/A2D5C0
    Latest checkpoint’s REDO location:      0/A34010
    Latest checkpoint’s UNDO location:      0/0
    Latest checkpoint’s TimeLineID:         1
    Latest checkpoint’s NextXID:            545
    Latest checkpoint’s NextOID:            17233
    Time of latest checkpoint:              03/03/05 10:49:18
    Database block size:                    8192
    Blocks per segment of large relation:   131072
    Bytes per WAL segment:                  16777216
    Maximum length of identifiers:          64
    Maximum number of function arguments:   32
    Date/time type storage:                 floating-point numbers
    Maximum length of locale name:          128
    LC_COLLATE:                             C
    LC_CTYPE:                               C
Mastering PostgreSQL Administration                                  5
System Architecture

                                                    Main
                                                                                    Libpq

                                              Postmaster


                                               Postgres                            Postgres




                                           Parse Statement


                                                                  utility           Utility
                                              Traffic Cop
                                                                                  Command
                                                Query                        e.g. CREATE TABLE, COPY
                                      SELECT, INSERT, UPDATE, DELETE

                                            Rewrite Query


                                           Generate Paths
                                            Optimal Path

                                            Generate Plan
                                                Plan

                                             Execute Plan




                                        Utilities                      Catalog              Storage Managers


                                                Access Methods                   Nodes / Lists
Mastering PostgreSQL Administration                                                                            6
Starting Postmaster



    LOG:     database system was shut down at 2009-01-27 10:32:05 EST
    LOG:     database system is ready to accept connections
    LOG:     autovacuum launcher started


    manually
 




    pg_ctl
 




    on boot
 




Mastering PostgreSQL Administration                                     7
Stopping Postmaster



    LOG:     received smart shutdown request
    LOG:     autovacuum launcher shutting down
    LOG:     shutting down
    LOG:     database system is shut down


    manually
 




    pg_ctl
 




    on shutdown
 




Mastering PostgreSQL Administration                         8
Connections



    local — unix domain socket
 




    host —      TCP/IP,    both SSL or non-SSL
 




    hostssl — only          SSL
 




    hostnossl — never SSL
 




Mastering PostgreSQL Administration                 9
Authentication

    trust
 




    passwords
 




    – md5
    – crypt
    – password

    remote authentication
 




    –   host ident using pg_ident.conf
    –   kerberos
    –   gss
    –   sspi



Mastering PostgreSQL Administration                    10
Authentication (continued)



    local socket ident
 




    host ident using local identd
 




    socket permissions
 




    pam
 




    ldap
 




    reject
 




Mastering PostgreSQL Administration                       11
Access



    hostname and network mask
 




    database name
 




    role name (user or group)
 




    filename or list of databases, role
 




    IPv6
 




Mastering PostgreSQL Administration            12
Pg_hba.conf



    # TYPE DATABASE     USER        CIDR-ADDRESS           METHOD
    # "local" is for Unix domain socket connections only
    local   all         all                                trust
    # IPv4 local connections:
    host    all         all         127.0.0.1/32           trust
    # IPv6 local connections:
    host    all         all         ::1/128                trust




Mastering PostgreSQL Administration                                 13
Permissions



    host connection permissions
 




    role permissions
 




    – create roles
    – create databases
    – table permissions

    Database creation
 




    – template1 customization
    – system tables
    – disk space computations


Mastering PostgreSQL Administration                 14
Data Directory



    $ ls -CF
    PG_VERSION                        pg_ident.conf    pg_xlog/
    base/                             pg_multixact/    postgresql.conf
    global/                           pg_subtrans/     postmaster.opts
    pg_clog/                          pg_tblspc/       postmaster.pid
    pg_hba.conf                       pg_twophase/




Mastering PostgreSQL Administration                                      15
Database Directories

    $ ls -CF global/
    1136                              2397          2843
    1137                              2671          2844
    1213                              2672          2845
    1214                              2676          2846
    1232                              2677          2847
    1233                              2694          pg_auth
    1260                              2695          pg_control
    1261                              2697          pg_database
    1262                              2698          pgstat.stat
    2396                              2842

    $ ls -CF base/
    1/      11510/ 11511/ 16384/

    $ ls -CF base/16384
    11429                             2617          2696
    11431                             2618          2699
    ...
Mastering PostgreSQL Administration                               16
Transaction/WAL Directories



    $ ls -CF pg_xlog/
    000000010000000000000000          archive_status/
    $ ls -CF pg_clog/
    0000




Mastering PostgreSQL Administration                      17
Configuration Directories



    $ ls -CF share/
    conversion_create.sql             postgres.description     sql_features.txt
    information_schema.sql            postgres.shdescription   system_views.sql
    pg_hba.conf.sample                postgresql.conf.sample   timezone/
    pg_ident.conf.sample              psqlrc.sample            timezonesets/
    pg_service.conf.sample            recovery.conf.sample     tsearch_data/
    postgres.bki                      snowball_create.sql      unknown.pltcl




Mastering PostgreSQL Administration                                               18
Configuration Postgresql.conf




Mastering PostgreSQL Administration                      19
PostgreSQL.Conf



    #   -----------------------------
    #   PostgreSQL configuration file
    #   -----------------------------
    #
    #   This file consists of lines of the form:
    #
    #    name = value
    #
    #   (The "=" is optional.) Whitespace may be used. Comments are introduced with
    #   "#" anywhere on a line. The complete list of parameter names and allowed
    #   values can be found in the PostgreSQL documentation.
    #
    #   The commented-out settings shown in this file represent the default values.
    #   Re-commenting a setting is NOT sufficient to revert it to the default value;
    #   you need to reload the server.


Mastering PostgreSQL Administration                                                    20
PostgreSQL.Conf (Continued)




    #   This file is read on server startup and when the server receives a SIGHUP
    #   signal. If you edit the file on a running system, you have to SIGHUP the
    #   server for the changes to take effect, or use "pg_ctl reload". Some
    #   parameters, which are marked below, require a server shutdown and restart to
    #   take effect.
    #
    #   Any parameter can also be given as a command-line option to the server, e.g.,
    #   "postgres -c log_connections=on". Some paramters can be changed at run time
    #   with the "SET" SQL command.
    #
    #   Memory units: kB = kilobytes MB = megabytes GB = gigabytes
    #   Time units:   ms = milliseconds s = seconds min = minutes h = hours d = days




Mastering PostgreSQL Administration                                                     21
Configuration File Location



    #data_directory = ’ConfigDir’           # use data in another directory
                                            # (change requires restart)
    #hba_file = ’ConfigDir/pg_hba.conf’     # host-based authentication file
                                            # (change requires restart)
    #ident_file = ’ConfigDir/pg_ident.conf’ # ident configuration file
                                            # (change requires restart)
    # If external_pid_file is not explicitly set, no extra PID file is written.
    #external_pid_file = ’(none)’           # write an extra PID file
                                            # (change requires restart)




Mastering PostgreSQL Administration                                               22
Connections and Authentication



    #listen_addresses = ’localhost’         # what IP address(es) to listen on;
                                            # comma-separated list of addresses;
                                            # defaults to ’localhost’, ’*’ = all
                                            # (change requires restart)
    #port = 5432                            # (change requires restart)
    max_connections = 100                   # (change requires restart)
    # Note: Increasing max_connections costs ~400 bytes of shared memory per
    # connection slot, plus lock space (see max_locks_per_transaction). You might
    # also need to raise shared_buffers to support more connections.
    #superuser_reserved_connections = 3     # (change requires restart)
    #unix_socket_directory = ’’             # (change requires restart)
    #unix_socket_group = ’’                 # (change requires restart)
    #unix_socket_permissions = 0777         # begin with 0 to use octal notation
                                            # (change requires restart)
    #bonjour_name = ’’                      # defaults to the computer name
                                            # (change requires restart)

Mastering PostgreSQL Administration                                                 23
Security and Authentication



    #authentication_timeout = 1min          # 1s-600s
    #ssl = off                              # (change requires restart)
    #ssl_ciphers = ’ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH’      # allowed SSL ciphers
                                            # (change requires restart)
    #password_encryption = on
    #db_user_namespace = off
    # Kerberos and GSSAPI
    #krb_server_keyfile = ’’                # (change requires restart)
    #krb_-
    srvname = ’postgres’               # (change requires restart, Kerberos only)
    #krb_server_hostname = ’’               # empty string matches any keytab entry
                                            # (change requires restart, Ker-
    beros only)
    #krb_caseins_users = off                # (change requires restart)
    #krb_realm = ’’                         # (change requires restart)


Mastering PostgreSQL Administration                                                   24
TCP/IP Control



    # see "man 7 tcp" for details
    #tcp_keepalives_idle = 0                #   TCP_KEEPIDLE, in seconds;
                                            #   0 selects the system default
    #tcp_keepalives_interval = 0            #   TCP_KEEPINTVL, in seconds;
                                            #   0 selects the system default
    #tcp_keepalives_count = 0               #   TCP_KEEPCNT;
                                            #   0 selects the system default




Mastering PostgreSQL Administration                                            25
Memory Usage



    shared_buffers = 32MB                   # min 128kB or max_connections*16kB
                                            # (change requires restart)
    #temp_buffers = 8MB                     # min 800kB
    #max_prepared_transactions = 5          # can be 0 or more
                                            # (change requires restart)
    # Note: Increasing max_prepared_transactions costs ~600 bytes of shared memory
    # per transaction slot, plus lock space (see max_locks_per_transaction).
    #work_mem = 1MB                         # min 64kB
    #maintenance_work_mem = 16MB            # min 1MB
    #max_stack_depth = 2MB                 # min 100kB




Kernel changes often required.


Mastering PostgreSQL Administration                                                  26
Sizing Shared Memory


                                         Postgres Backend

                                         Postgres Backend

                                         Postgres Backend
           R
                                PostgreSQL Shared Buffer Cache
           A
                                      Kernel Disk Buffer Cache   Page Out
           M
                                                                            Swap
                                               Free
                                                                 Page In
                                              Kernel




Mastering PostgreSQL Administration                                                27
Free Space Map and Kernel Resources



    # - Free Space Map -
    max_fsm_pages = 204800            # min max_fsm_relations*16, 6 bytes each
                                      # (change requires restart)
    #max_fsm_relations = 1000         # min 100, ~70 bytes each
                                      # (change requires restart)


    # - Kernel Resource Usage -
    #max_files_per_process = 1000     # min 25
                                      # (change requires restart)
    #shared_preload_libraries = ’’    # (change requires restart)




Mastering PostgreSQL Administration                                              28
Vacuum and Background Writer



    # - Cost-Based Vacuum Delay -
    #vacuum_cost_delay = 0                 #   0-1000 milliseconds
    #vacuum_cost_page_hit = 1              #   0-10000 credits
    #vacuum_cost_page_miss = 10            #   0-10000 credits
    #vacuum_cost_page_dirty = 20           #   0-10000 credits
    #vacuum_cost_limit = 200               # 1-10000 credits


    # - Background Writer -
    #bgwriter_delay = 200ms                 # 10-10000ms between rounds
    #bgwriter_lru_maxpages = 100            # 0-1000 max buffers written/round
    #bgwriter_lru_multiplier = 2.0          # 0-
    10.0 multipler on buffers scanned/round




Mastering PostgreSQL Administration                                              29
Write-Ahead Log (WAL)

    #fsync = on                           #   turns forced synchronization on or off
    #synchronous_commit = on              #   immediate fsync at commit
    #wal_sync_method = fsync              #   the default is the first option
                                          #   supported by the operating system:
                                          #     open_datasync
                                          #     fdatasync
                                          #     fsync
                                          #     fsync_writethrough
                                          #     open_sync
    #full_page_writes = on                #   recover from partial page writes
    #wal_buffers = 64kB                   #   min 32kB
                                          #   (change requires restart)
    #wal_writer_delay = 200ms             #   1-10000 milliseconds
    #commit_delay = 0                     #   range 0-100000, in microseconds
    #commit_siblings = 5                  #   range 1-1000




Mastering PostgreSQL Administration                                                    30
Write-Ahead Logging (Continued)
                         Postgres              Postgres                Postgres
                         Backend               Backend                 Backend




                         PostgreSQL Shared Buffer Cache           Write−Ahead Log

                                                                       fsync


                                       Kernel Disk Buffer Cache

                                                                       fsync




                                             Disk Blocks




Mastering PostgreSQL Administration                                                 31
Checkpoints and Archiving

    # - Checkpoints -
    #checkpoint_segments = 3                   # in logfile segments, min 1, 16MB each
    #checkpoint_timeout = 5min                 # range 30s-1h
    #checkpoint_completion_target = 0.5        # checkpoint target duration, 0.0 - 1.0
    #checkpoint_warning = 30s                  # 0 is off


    # - Archiving -
    #archive_mode = off               #   allows archiving to be done
                                      #   (change requires restart)
    #archive_command = ’’             #   command to use to archive a logfile segment
    #archive_timeout = 0              #   force a logfile segment switch after this
                                      #   time; 0 is off




Mastering PostgreSQL Administration                                                      32
Query Tuning

    # - Planner Method Configuration -
    #enable_bitmapscan = on
    #enable_hashagg = on
    #enable_hashjoin = on
    #enable_indexscan = on
    #enable_mergejoin = on
    #enable_nestloop = on
    #enable_seqscan = on
    #enable_sort = on
    #enable_tidscan = on


    # - Planner Cost Constants -
    #seq_page_cost = 1.0                   #   measured on an arbitrary scale
    #random_page_cost = 4.0                #   same scale as above
    #cpu_tuple_cost = 0.01                 #   same scale as above
    #cpu_index_tuple_cost = 0.005          #   same scale as above
    #cpu_operator_cost = 0.0025            #   same scale as above
    #effective_cache_size = 128MB
Mastering PostgreSQL Administration                                             33
Query Tuning (Continued)



    #geqo = on
    #geqo_threshold = 12
    #geqo_effort = 5                    # range 1-10
    #geqo_pool_size = 0                 # selects default based on effort
    #geqo_generations = 0               # selects default based on effort
    #geqo_selection_bias = 2.0          # range 1.5-2.0


    # - Other Planner Options -
    #default_statistics_target = 10     # range 1-1000
    #constraint_exclusion = off
    #from_collapse_limit = 8
    #join_collapse_limit = 8            # 1 disables collapsing of explicit
                                        # JOIN clauses




Mastering PostgreSQL Administration                                           34
Where To Log



    #log_destination = ’stderr’            #   Valid values are combinations of
                                           #   stderr, csvlog, syslog and eventlog,
                                           #   depending on platform. csvlog
                                           #   requires logging_collector to be on.
    # This is used when logging to stderr:
    #logging_collector = off                # Enable capturing of stderr and csvlog
                                            # into log files. Required to be on for
                                            # csvlogs.
                                            # (change requires restart)
    # These are only used if logging_collector is on:
    #log_directory = ’pg_log’               # directory where log files are written,
                                            # can be absolute or relative to PGDATA
    #log_filename = ’postgresql-%Y-%m-%d_%H%M%S.log’        # log file name pattern,
                                            # can include strftime() escapes




Mastering PostgreSQL Administration                                                    35
Where To Log (Continued)


    #log_truncate_on_rotation = off        #   If on, an existing log file of the
                                           #   same name as the new log file will be
                                           #   truncated rather than appended to.
                                           #   But such truncation only occurs on
                                           #   time-driven rotation, not on restarts
                                           #   or size-driven rotation. Default is
                                           #   off, meaning append to existing files
                                           #   in all cases.
    #log_rotation_age = 1d                 #   Automatic rotation of logfiles will
                                           #   happen after that time. 0 to disable.
    #log_rotation_size = 10MB              #   Automatic rotation of logfiles will
                                           #   happen after that much log output.
                                            # 0 to disable.


    # These are relevant when logging to syslog:
    #syslog_facility = ’LOCAL0’
    #syslog_ident = ’postgres’
Mastering PostgreSQL Administration                                                    36
When to Log

    #client_min_messages = notice      # values in order of decreasing detail:
                                       # debug5
                                       # debug4
                                       # debug3
                                       # debug2
                                       # debug1
                                       # log
                                       # notice
                                       # warning
                                       # error
    #log_min_messages = notice         # values in order of decreasing detail:
                                       # debug5
                                       # debug4
                                       # debug3
                                       # debug2
                                       # debug1
                                       # info
                                       # notice
                                       # warning
                                       # error
                                       # log
                                       # fatal
                                       # panic
Mastering PostgreSQL Administration                                              37
When to Log (Continued)

    #log_error_verbosity = default     # terse, default, or verbose messages
    #log_min_error_statement = error   # values in order of decreasing detail:
                                       # debug5
                                       # debug4
                                       # debug3
                                       # debug2
                                       # debug1
                                       # info
                                       # notice
                                       # warning
                                       # error
                                       # log
                                       # fatal
                                       # panic (effectively off)
    #log_min_duration_statement = -1   # -1 is disabled, 0 logs all statements
                                       # and their durations, > 0 logs only
                                       # statements running at least this time.
    #silent_mode = off                 # DO NOT USE without syslog or
                                       # logging_collector
                                       # (change requires restart)



Mastering PostgreSQL Administration                                               38
What to Log



    #debug_print_parse = off
    #debug_print_rewritten = off
    #debug_print_plan = off
    #debug_pretty_print = off
    #log_checkpoints = off
    #log_connections = off
    #log_disconnections = off
    #log_duration = off
    #log_hostname = off




Mastering PostgreSQL Administration                 39
What To Log: Log_line_prefix


    #log_line_prefix = ’’              # special values:
                                       # %u = user name
                                       # %d = database name
                                       # %r = remote host and port
                                       # %h = remote host
                                       # %p = process ID
                                       # %t = timestamp without milliseconds
                                       # %m = timestamp with milliseconds
                                       # %i = command tag
                                       # %c = session ID
                                       # %l = session line number
                                       # %s = session start timestamp
                                       # %v = virtual transaction ID
                                       # %x = transaction ID (0 if none)
                                       # %q = stop here in non-session
                                       #        processes
                                       # %% = ’%’
                                       # e.g. ’<%u%%%d> ’
Mastering PostgreSQL Administration                                            40
What to Log (Continued)



    #log_lock_waits = off                #   log lock waits >= deadlock_timeout
    #log_statement = ’none’              #   none, ddl, mod, all
    #log_temp_files = -1                 #   log temporary files equal or larger
                                         #   than specified size;
                                         #   -1 disables, 0 logs all temp files
    #log_timezone = unknown              #   actually, defaults to TZ environment
                                         #   setting




Mastering PostgreSQL Administration                                                 41
Runtime Statistics



    # - Query/Index Statistics Collector -
    #track_activities = on
    #track_counts = on
    #update_process_title = on


    # - Statistics Monitoring -
    #log_parser_stats = off
    #log_planner_stats = off
    #log_executor_stats = off
    #log_statement_stats = off




Mastering PostgreSQL Administration                        42
Autovacuum

    #autovacuum = on                       # Enable autovacuum subprocess? ’on’
                                            # requires track_counts to also be on.
    #log_autovacuum_min_duration = -1      # -1 disables, 0 logs all actions and
                                            # their durations, > 0 logs only
                                            # actions running at least that time.
    #autovacuum_max_workers = 3            # max number of autovacuum subprocesses
    #autovacuum_naptime = 1min             # time between autovacuum runs
    #autovacuum_vacuum_threshold = 50      # min number of row updates before
                                            # vacuum
    #autovacuum_analyze_threshold = 50     # min number of row updates before
                                            # analyze
    #autovacuum_vacuum_scale_factor = 0.2 # fraction of table size before vacuum
    #autovacuum_analyze_scale_factor = 0.1 # fraction of table size before analyze
    #autovacuum_freeze_max_age = 200000000 # maximum XID age before forced vacuum
                                            # (change requires restart)
    #autovacuum_vacuum_cost_delay = 20     # default vacuum cost delay for
                                            # autovacuum, -1 means use
                                            # vacuum_cost_delay
    #autovacuum_vacuum_cost_limit = -1     # default vacuum cost limit for
                                            # autovacuum, -1 means use
                                            # vacuum_cost_limit


Mastering PostgreSQL Administration                                                  43
Statement Behavior



    #search_path = ’"$user",public’           #   schema names
    #default_tablespace = ’’                  #   a tablespace name, ’’ uses the default
    #temp_tablespaces = ’’                    #   a list of tablespace names, ’’ uses
                                              #   only default tablespace
    #check_function_bodies = on
    #default_transaction_isolation = ’read committed’
    #default_transaction_read_only = off
    #session_replication_role = ’origin’
    #statement_timeout = 0                  # 0 is disabled
    #vacuum_freeze_min_age = 100000000
    #xmlbinary = ’base64’
    #xmloption = ’content’




Mastering PostgreSQL Administration                                                        44
Locale and Formatting

    datestyle = ’iso, mdy’
    #timezone = unknown                     # actually, defaults to TZ environment
                                            # setting
    #timezone_abbreviations = ’Default’     # Select the set of available time zone
                                            # abbreviations. Currently, there are
                                            # Default
                                            # Australia
                                            # India
                                            # You can create your own file in
                                            # share/timezonesets/.
    #extra_float_digits = 0                 # min -15, max 2
    #client_encoding = sql_ascii            # actually, defaults to database
                                            # encoding
    # These settings are initialized by initdb, but they can be changed.
    lc_messages = ’C’                       # locale for system error message
                                            # strings
    lc_monetary = ’C’                       # locale for monetary formatting
    lc_numeric = ’C’                        # locale for number formatting
    lc_time = ’C’                           # locale for time formatting
Mastering PostgreSQL Administration                                                   45
Full Text Search



    # default configuration for text search
    default_text_search_config = ’pg_catalog.english’




Mastering PostgreSQL Administration                      46
Other Defaults



    #explain_pretty_print = on
    #dynamic_library_path = ’$libdir’
    #local_preload_libraries = ’’




Mastering PostgreSQL Administration                    47
Lock Management



    #deadlock_timeout = 1s
    #max_locks_per_transaction = 64         # min 10
                                            # (change requires restart)
    # Note: Each lock table slot uses ~270 bytes of shared memory, and there are
    # max_locks_per_transaction * (max_connections + max_prepared_transactions)
    # lock table slots.




Mastering PostgreSQL Administration                                                48
Version/Platform Compatibility



    # - Previous PostgreSQL Versions -
    #add_missing_from = off
    #array_nulls = on
    #backslash_quote = safe_encoding     # on, off, or safe_encoding
    #default_with_oids = off
    #escape_string_warning = on
    #regex_flavor = advanced             # advanced, extended, or basic
    #sql_inheritance = on
    #standard_conforming_strings = off
    #synchronize_seqscans = on


    # - Other Platforms and Clients -
    #transform_null_equals = off




Mastering PostgreSQL Administration                                       49
Customization



    #custom_variable_classes = ’’           # list of custom variable class names




Mastering PostgreSQL Administration                                                 50
Interfaces



    Installing
 




    – Compiled Languages (C, ecpg)
    – Scripting Language (Perl, Python)
    – SPI

    Connection Pooling
 




Mastering PostgreSQL Administration                51
Include Files



    $ ls -CF include/
    ecpg_config.h                     libpq/               pgtypes_interval.h
    ecpg_informix.h                   libpq-fe.h           pgtypes_numeric.h
    ecpgerrno.h                       pg_config.h          pgtypes_timestamp.h
    ecpglib.h                         pg_config_manual.h   postgres_ext.h
    ecpgtype.h                        pg_config_os.h       server/
    informix/                         pgtypes_date.h       sql3types.h
    internal/                         pgtypes_error.h      sqlca.h




Mastering PostgreSQL Administration                                              52
Library Files


    $ ls -CF lib/
    ascii_and_mic.so*                 libecpg_compat.so.3@     utf8_and_big5.so*
    cyrillic_and_mic.so*              libecpg_compat.so.3.0*   utf8_and_cyrillic.so*
    dict_snowball.so*                 libpgport.a              utf8_and_euc_cn.so*
    euc_cn_and_mic.so*                libpgtypes.a             utf8_and_euc_jis_2004.s
    euc_jis_2004_and_shift_           libpgtypes.so@           utf8_and_euc_jp.so*
    euc_jp_and_sjis.so*               libpgtypes.so.3@         utf8_and_euc_kr.so*
    euc_kr_and_mic.so*                libpgtypes.so.3.0*       utf8_and_euc_tw.so*
    euc_tw_and_big5.so*               libpq.a                  utf8_and_gb18030.so*
    latin2_and_win1250.so*            libpq.so@                utf8_and_gbk.so*
    latin_and_mic.so*                 libpq.so.5@              utf8_and_iso8859.so*
    libecpg.a                         libpq.so.5.1*            utf8_and_iso8859_1.so*
    libecpg.so@                       pgxs/                    utf8_and_johab.so*
    libecpg.so.6@                     plperl.so*               utf8_and_shift_jis_2004
    libecpg.so.6.0*                   plpgsql.so*              utf8_and_sjis.so*
    libecpg_compat.a                  pltcl.so*                utf8_and_uhc.so*
    libecpg_compat.so@                utf8_and_ascii.so*       utf8_and_win.so*
Mastering PostgreSQL Administration                                                      53
Maintenance




Mastering PostgreSQL Administration                 54
Backup



    File system-level
 




    – tar, cpio while shutdown
    – file system snapshot
    – rsync, shutdown, rsync, restart

    pg_dump/pg_dumpall
 




    restore/pg_restore with custom format
 




Mastering PostgreSQL Administration            55
Continuous Archiving /
                         Point-In-Time Recovery (PITR)
           00




                                                00




                                                              00




                                                                    00
        02




                                               09




                                                          11




                                                                   13
                                 WAL
                                                AL       AL
                                               W     W




       File System-             Continuous
      Level Backup                    Backup
Mastering PostgreSQL Administration                                      56
PITR Backup Procedures



1. archive_command = ’cp %p /mnt/server/pgsql/%f ’

2. SELECT pg_start_backup(’label’);

3. Perform file system-level backup (can be inconsistent)

4. SELECT pg_stop_backup();




Mastering PostgreSQL Administration                        57
PITR Recovery
           00




                                                   30




                                                                  40




                                                                        55
        17




                                                  17




                                                              17




                                                                       17
                                       WAL
                                                   AL        AL
                                                  W      W




       File System-             Continuous
      Level Backup                    Backup

Mastering PostgreSQL Administration                                          58
PITR Recovery Procecdures



1. Stop postmaster

2. Restore file system-level backup

3. Make adjustments as outlined in the documentation

4. Create recovery.conf

5. Add restore_command = ’cp /mnt/server/pgsql/%f %p’

6. Start the postmaster



Mastering PostgreSQL Administration                     59
60
Master-Slave Replication - Slony




                                                                                              54 54 32 32 32 0 10 10 10 10 10                  )( )( & '& '& '& $ %$ %$ %$ %$ %$
                                                                                             B777723B 7723B 7723B 77777777B1 @A0
                                                                                              5 7B 5 7B 7@7@7@7B 7B 7B 7B1 7B1 7B1 7B1 7
                                                                                                @7@7@7A A A @777@7@777
                                                                                                 A4 A4 A           A @A @A0 A0 A0 @A0 @A0     9777&77&'9 77&'9 77&'9 777777779% 8$
                                                                                                                                               ) 79 ) 79 8 8 8 8 9 79 79 79% 79% 79% 79% 7
                                                                                                                                                  8( 8(                    8 8 8$ 8$ 8$ 8$ 8$
                                                                                               54 54 32 32 32 0 10 10 10 10 10                  ) 7) 77' 7' 7' 7777% 7% 7% 7% 7% 6$
                                                                                                                                                  6 ( 6 ( 6 & 6 & 6 & 6 & 6 6 6$ 6$ 6$ 6$ 6$
                                                                                               54 54 32 32 32 0 10 10 10 10 10                   )( )( & '& '& '& $ %$ %$ %$ %$ %$
                                                                                                                           0 10 10 10 10 10                                      $ %$ %$ %$ %$ %$
                                     #" #" ! ! !                            
                                   H7# G7H7# G7H7H7H7H7H7H7H7H7H7H7H7H G
                                                   G7! G7! G7! G7G7G7G7 G7 G7 G7 G7
                                                                            
                                    T7# S7T7# S7T7T7T7T7T7T7T7T7T7T7T7T S
                                                    S7! S7! S7! S7S7S7S7 S7 S7 S7 S7
                                                                             
                                                                                                                                        ¨ ©¨ ©¨ ©¨ ¦ §¦ §¦ §¦ §¦ §¦
                                     # # ! ! !                                                                                                   ¨ ©¨ ©¨ ©¨ ¦ §¦ §¦ §¦ §¦ §¦
                                                                                                                                              R  7R  7R Q Q Q Q R 7R 7R 7R§ 7R§ 7R§ 7R§ 7
                                                                                                                                               777¨77¨©R 77¨©R 77¨©R 77777777R§ Q¦
                                                                                                                                                  Q Q               Q Q Q¦ Q¦ Q¦ Q¦ Q¦
                                                                                                                                                   ¨ ©¨ ©¨ ©¨ ¦ §¦ §¦ §¦ §¦ §¦
                                                                                                ¥¤ ¥¤ £¢ £¢ £¢      
                                                                                             ¥D7777¢£D 77¢£D 77¢£D 77777777D C
                                                                                                 7D ¥ 7D 7C C C D 7D 7D 7D 7D 7D 7D 7
                                                                                                 C¤ C¤ C            C C C C C C C
                                                                                             F ¥ 7F ¥ 7F 7E E E F 7F 7F 7F 7F 7F 7F 7
                                                                                              7777¢£F 77¢£F 77¢£F 77777777F E
                                                                                                 E¤ E¤ E             E E E E E E E
                                                                                                ¥¤ ¥¤ £¢ £¢ £¢      
                                                                                                                                                 ¡  ¡           
                                                                                                                                                 ¡  ¡           
                                                                                                                                              P ¡ 7P ¡ 7P I I I I P 7P 7P 7P 7P 7P 7P 7
                                                                                                                                               77777P 77P 77P 77777777P I
                                                                                                                                                  I  I                I I I I I I I
                                                                                                                                                 ¡  ¡           




                                                                                                                                                                                                    Mastering PostgreSQL Administration
Other Solutions



    Mutli-master replication: pgcluster, bacardo
 




    Pooling: pgpool
 




Mastering PostgreSQL Administration                     61
Data Maintenance



    VACUUM        (nonblocking), free space map
 




    VACUUM FULL
 




    ANALYZE
 




Mastering PostgreSQL Administration                      62
Vacuum

                                                  Free Space Map


                                      Table       Block #       Block #   Block #


   DB oid
 Relfilenode                          Table       Block #       Block #



                                      Table       Block #       Block #   Block #

                     Hashed

                                                     Shared Memory




Mastering PostgreSQL Administration                                             63
Vacuum Full

                                      A   A   E   A   A   A   E   A   A   A   A   A
         Original Heap                C   C   X   C   C   C   X   C   C   C   C   C
                                      T   T   P   T   T   T   P   T   T   T   T   T
         With Expired                 I   I   I   I   I   I   I   I   I   I   I   I
                                      V   V   R   V   V   V   R   V   V   V   V   V
         Rows Identified              E   E   E   E   E   E   E   E   E   E   E   E




                                      A   A       A   A   A       A   A   A   A   A
         Move Trailing                C   C       C   C   C       C   C   C   C   C
                                      T   T       T   T   T       T   T   T   T   T
         Rows Into Expired            I   I       I   I   I       I   I   I   I   I
                                      V   V       V   V   V       V   V   V   V   V
         Slots                        E   E       E   E   E       E   E   E   E   E




                                      A   A   A   A   A   A   A   A   A   A
                                      C   C   C   C   C   C   C   C   C   C
                                      T   T   T   T   T   T   T   T   T   T
         Truncate File                I   I   I   I   I   I   I   I   I   I
                                      V   V   V   V   V   V   V   V   V   V
                                      E   E   E   E   E   E   E   E   E   E


Mastering PostgreSQL Administration                                                   64
Checkpoints



    Write all dirty shared buffers
 




    Sync all dirty kernel buffers
 




    Recycle WAL files
 




    Check for server messages indicating too-frequent checkpoints
 




    If so, increase checkpoint_segments
 




Mastering PostgreSQL Administration                                 65
Automating Tasks



    0 3 * * * root psql -c ’VACUUM FULL;’ test
    0 3 * * * root vacuumdb -a -f


Autovacuum usually makes vacuum administration unnecessary.




Mastering PostgreSQL Administration                           66
Monitoring Active Sessions




Mastering PostgreSQL Administration                       67
ps



    $ ps -Upostgres
      PID TT STAT              TIME COMMAND
     2125      ??    Ss         0:00.26   ./bin/postmaster -i
     2142      ??    S          0:00.03   stats buffer process    (postmaster)
     2143      ??    S          0:00.06   stats collector process    (postmaster)
     3341      ??    I          0:00.07   postgres test [local] idle (postmaster)
     3340      p6    I+         0:00.03   psql test




Mastering PostgreSQL Administration                                                 68
top



    $ top
    load averages: 0.56, 0.39, 0.36                                     18:25:58
    138 processes: 5 running, 130 sleeping, 3 zombie
    CPU states: 50.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 50.0% idle
    Memory: Real: 96M/133M Virt: 535M/1267M Free: 76M

      PID USERNAME PRI NICE SIZE RES STATE    TIME WCPU      CPU COMMAND
    23785 postgres 57     0 11M 5336K run/0   0:07 30.75% 30.66% postmaster
    23784 postgres 2      0 10M 11M sleep     0:00 2.25% 2.25% psql




Mastering PostgreSQL Administration                                                69
pgmonitor




Mastering PostgreSQL Administration               70
Query Monitoring



    test= SELECT * FROM pg_stat_activity;
    -[ RECORD 1 ]-+--------------------------------
    datid         | 16384
    datname       | test
    procpid       | 2373
    usesysid      | 10
    usename       | postgres
    current_query | select * from pg_stat_activity;
    waiting       | f
    xact_start    | 2009-01-27 12:12:59.917695-05
    query_start   | 2009-01-27 12:12:59.917695-05
    backend_start | 2009-01-27 12:12:33.422001-05
    client_addr   |
    client_port   | -1

Mastering PostgreSQL Administration                      71
pgmonitor




Mastering PostgreSQL Administration               72
Access Statistics



     pg_stat_all_indexes              |   view   |   postgres
     pg_stat_all_tables               |   view   |   postgres
     pg_stat_database                 |   view   |   postgres
     pg_stat_sys_indexes              |   view   |   postgres
     pg_stat_sys_tables               |   view   |   postgres
     pg_stat_user_indexes             |   view   |   postgres
     pg_stat_user_tables              |   view   |   postgres
     pg_statio_all_indexes            |   view   |   postgres
     pg_statio_all_sequences          |   view   |   postgres
     pg_statio_all_tables             |   view   |   postgres
     pg_statio_sys_indexes            |   view   |   postgres
     pg_statio_sys_sequences          |   view   |   postgres
     pg_statio_sys_tables             |   view   |   postgres
     pg_statio_user_indexes           |   view   |   postgres
     pg_statio_user_sequences         |   view   |   postgres
     pg_statio_user_tables            |   view   |   postgres

Mastering PostgreSQL Administration                             73
Database Statistics


    test= SELECT * FROM pg_stat_database;
    ...
    -[ RECORD 4 ]-+----------
    datid         | 16384
    datname       | test
    numbackends   | 1
    xact_commit   | 188
    xact_rollback | 0
    blks_read     | 95
    blks_hit      | 11832
    tup_returned | 64389
    tup_fetched   | 2938
    tup_inserted | 0
    tup_updated   | 0
    tup_deleted   | 0
Mastering PostgreSQL Administration                         74
Table Activity



    test= SELECT * FROM pg_stat_all_tables;
    ...
    -[ RECORD 10 ]---+------------------------
    relid            | 2616
    schemaname       | pg_catalog
    relname          | pg_opclass
    seq_scan         | 2
    seq_tup_read     | 2
    idx_scan         | 99
    idx_tup_fetch    | 99
    n_tup_ins        | 0
    n_tup_upd        | 0
    n_tup_del        | 0
    n_tup_hot_upd    | 0
    n_live_tup       | 0
Mastering PostgreSQL Administration                    75
n_dead_tup                | 0
    last_vacuum               |
    last_autovacuum           |
    last_analyze              |
    last_autoanalyze          |




Mastering PostgreSQL Administration   76
Table Block Activity



    test= SELECT * FROM pg_statio_all_tables;
    -[ RECORD 50 ]--+------------------------
    relid           | 2602
    schemaname      | pg_catalog
    relname         | pg_amop
    heap_blks_read | 3
    heap_blks_hit   | 114
    idx_blks_read   | 5
    idx_blks_hit    | 303
    toast_blks_read |
    toast_blks_hit |
    tidx_blks_read |
    tidx_blks_hit   |


Mastering PostgreSQL Administration                          77
Analyzing Activity



    Heavily used tables
 




    Unnecessary indexes
 




    Additional indexes
 




    Index usage
 




    TOAST      usage
 




Mastering PostgreSQL Administration                        78
CPU




    $ vmstat 5
     procs     memory             page                    disks      faults        cpu
     r b w     avm    fre         flt re    pi po fr sr   s0 s0    in sy cs      us sy   id
     1 0 0 501820 48520          1234 86     2  0 0 3      5 0    263 2881 599   10 4    86
     3 0 0 512796 46812          1422 201   12 0 0 0       3 0    259 6483 827    4 7    88
     3 0 0 542260 44356           788 137    6  0 0 0      8 0    286 5698 741    2 5    94
     4 0 0 539708 41868           576 65    13 0 0 0       4 0    273 5721 819   16 4    80
     4 0 0 547200 32964           454 0      0  0 0 0      5 0    253 5736 948   50 4    46
     4 0 0 556140 23884           461 0      0  0 0 0      2 0    249 5917 959   52 3    44
     1 0 0 535136 46280          1056 141   25 0 0 0       2 0    261 6417 890   24 6    70




Mastering PostgreSQL Administration                                                           79
I/O



    $ iostat 5
          tty          sd0                       sd1              sd2               %   cpu
     tin tout sps tps msps            sps tps   msps   sps tps   msps usr nic sys int   idl
       7 119 244 11 6.1                 0   0   27.3     0   0   18.1   9 1 4       0    86
       0 86    20   1 1.4               0   0    0.0     0   0    0.0   2 0 2       0    96
       0 82    61   4 3.6               0   0    0.0     0   0    0.0   2 0 2       0    97
       0 65     6   0 0.0               0   0    0.0     0   0    0.0   1 0 2       0    97
      12 90    31   2 5.4               0   0    0.0     0   0    0.0   4 0 3       0    93
      24 173    6   0 4.9               0   0    0.0     0   0    0.0 48 0 3        0    49
       0 91 3594 63 4.6                 0   0    0.0     0   0    0.0 11 0 4        0    85




Mastering PostgreSQL Administration                                                           80
Disk Usage



    play=# SELECT relfilenode, relpages * 8 AS kilobytes
    play-# FROM pg_class
    play-# WHERE relname = ’customer’;
    relfilenode | kilobytes
    -------------+----------
            16806 |      480
    (1 row)




Vacuum required. dbsize available.




Mastering PostgreSQL Administration                        81
TOAST Usage



    play=# SELECT relname, relpages * 8 AS kilobytes
    play-# FROM pg_class
    play-# WHERE relname = ’pg_toast_16806’ OR
    play-#       relname = ’pg_toast_16806_index’
    play-# ORDER BY relname;
           relname        | kilobytes
    ----------------------+----------
     pg_toast_16806       |        0
     pg_toast_16806_index |        1




Mastering PostgreSQL Administration                    82
Index Usage



    play=# SELECT c2.relname, c2.relpages * 8 AS kilobytes
    play-# FROM pg_class c, pg_class c2, pg_index i
    play-# WHERE c.relname = ’customer’ AND
    play-#       c.oid = i.indrelid AND
    play-#       c2.oid = i.indexrelid
    play-# ORDER BY c2.relname;
           relname        | kilobytes
    ----------------------+----------
     customer_id_indexdex |       26




Mastering PostgreSQL Administration                          83
Largest Tables



    play=# SELECT relname, relpages * 8
    play-# FROM pg_class
    play-# ORDER BY relpages DESC;
           relname        | kilobytes
    ----------------------+----------
     bigtable             |     3290
     customer             |     3144




Mastering PostgreSQL Administration                    84
Database File Mapping - oid2name



    $ oid2name
    All databases:
    ---------------------------------
    18720 = test1
    1      = template1
    18719 = template0
    18721 = test
    18735 = postgres
    18736 = cssi




Mastering PostgreSQL Administration                     85
Table File Mapping



    $ cd /usr/local/pgsql/data/base
    $ oid2name
    All databases:
    ---------------------------------
    16817 = test2
    16578 = x
    16756 = test
    1      = template1
    16569 = template0
    16818 = test3
    16811 = floattest

    $ cd 16756
    $ ls 1873*
    18730 18731          18732        18735   18736   18737   18738   18739


Mastering PostgreSQL Administration                                           86
$ oid2name -d test -o 18737
    Tablename of oid 18737 from database test:
    ---------------------------------
    18737 = ips

    $ oid2name -d test -t ips
    Oid of table ips from database test:
    ---------------------------------
    18737 = ips

    $ # show disk space for every db object
    $ du * | while read SIZE RELFILENODE
     do
           echo $SIZE      ‘oid2name -q -d test -o $RELFILENODE‘
     done
    24      18737 = ips
    36      18722 = cities
    ...

Mastering PostgreSQL Administration                                   87
$ # same as above, but sort by largest first
    $ du * | while read SIZE OID
     do
           echo $SIZE      ‘oid2name -q -d test -o $OID‘
     done |
     sort -rn
    2048    19324 = bigtable
    1950    23903 = customers
    ...

    $ # show disk usage per database
    $ cd /usr/local/pgsql/data/base
    $ du -s * |
     while read SIZE OID
     do
           echo $SIZE      ‘oid2name -q | grep ^$OID’ ’‘
     done |
     sort -rn
    2256        18721 = test
    2135        18735 = postgres
Mastering PostgreSQL Administration                           88
Disk Balancing



    Move pg_xlog to another drive using symlinks
 




    Tablespaces
 




Mastering PostgreSQL Administration                    89
Per-Database Tablespaces


                       DB1            DB2     DB3    DB4




                   Disk 1                   Disk 2         Disk 3
Mastering PostgreSQL Administration                                 90
Per-Object Tablespaces


                       tab1           tab2    index constraint




                   Disk 1                    Disk 2          Disk 3
Mastering PostgreSQL Administration                                   91
Analyzing Locking

    $ ps -Upostgres
      PID TT STAT             TIME    COMMAND
     9874 ?? I             0:00.07    postgres test [local] idle in transaction (postmaster)
     9835 ?? S             0:00.05    postgres test [local] UPDATE waiting (postmaster)
    10295 ?? S             0:00.05    postgres test [local] DELETE waiting (postmaster)


    test= SELECT * FROM pg_locks;
     relation | database | transaction | pid |        mode       | granted
    ----------+----------+-------------+------+------------------+---------
        17143 |    17142 |             | 9173 | AccessShareLock | t
        17143 |    17142 |             | 9173 | RowExclusiveLock | t
              |          |         472 | 9380 | ExclusiveLock    | t
              |          |         468 | 9338 | ShareLock        | f
              |          |         470 | 9338 | ExclusiveLock    | t
        16759 |    17142 |             | 9380 | AccessShareLock | t
        17143 |    17142 |             | 9338 | AccessShareLock | t
        17143 |    17142 |             | 9338 | RowExclusiveLock | t
              |          |         468 | 9173 | ExclusiveLock    | t
    (9 rows)
Mastering PostgreSQL Administration                                                            92
Miscellaneous Tasks



    Log file rotation, syslog
 




    Upgrading
 




    Migration
 




Mastering PostgreSQL Administration                         93
Administration Tools



    pgadmin
 




    phppgadmin
 




Mastering PostgreSQL Administration                          94
Recovery




Mastering PostgreSQL Administration              95
Client Application Crash


Nothing Required. Transactions in progress are rolled back.




Mastering PostgreSQL Administration                           96
Graceful Server Crash


Nothing Required. Transactions in progress are rolled back.




Mastering PostgreSQL Administration                           97
Abrupt Server Crash


Nothing Required. Transactions in progress are rolled back.




Mastering PostgreSQL Administration                           98
Operating System Crash


Nothing Required. Transactions in progress are rolled back. Partial page
writes are repaired.




Mastering PostgreSQL Administration                                    99
Disk Failure


Restore from previous backup or use PITR.




Mastering PostgreSQL Administration                  100
Accidental DELETE


Recover table from previous backup, perhaps using pg_restore. It is
possible to modify the backend code to make deleted tuples visible,
dump out the deleted table and restore the original code. All tuples in
the table since the previous vacuum will be visible. It is possible to
restrict that so only tuples deleted by a specific transaction are visible.




Mastering PostgreSQL Administration                                          101
Write-Ahead Log (WAL) Corruption


See pg_resetxlog. Review recent transactions and identify any damage,
including partially committed transactions.




Mastering PostgreSQL Administration                                 102
File Deletion


It may be necessary to create an empty file with the deleted file name so
the object can be deleted, and then the object restored from backup.




Mastering PostgreSQL Administration                                  103
Accidental DROP TABLE


Restore from previous backup.




Mastering PostgreSQL Administration                    104
Accidental DROP INDEX


Recreate index.




Mastering PostgreSQL Administration                   105
Accidental DROP DATABASE


Restore from previous backup.




Mastering PostgreSQL Administration                  106
Non-Starting Installation


Restart problems are usually caused by write-ahead log problems. See
pg_resetxlog. Review recent transactions and identify any damage,
including partially committed transactions.




Mastering PostgreSQL Administration                                    107
Index Corruption


Use REINDEX.




Mastering PostgreSQL Administration                      108
Table Corruption


Try reindexing the table. Try identifying the corrupt OID of the row and
transfer the valid rows into another table using SELECT…INTO…WHERE
oid != ###. Use http://sources.redhat.com/rhdb/tools.html to analyze
the internal structure of the table.




Mastering PostgreSQL Administration                                   109
Conclusion




Mastering PostgreSQL Administration                110

Contenu connexe

Tendances

Getting started with postgresql
Getting started with postgresqlGetting started with postgresql
Getting started with postgresqlbotsplash.com
 
Introduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparoundIntroduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparoundMasahiko Sawada
 
Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Mydbops
 
Optimizing MariaDB for maximum performance
Optimizing MariaDB for maximum performanceOptimizing MariaDB for maximum performance
Optimizing MariaDB for maximum performanceMariaDB plc
 
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015PostgreSQL-Consulting
 
PostgreSql query planning and tuning
PostgreSql query planning and tuningPostgreSql query planning and tuning
PostgreSql query planning and tuningFederico Campoli
 
MySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxMySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxNeoClova
 
PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuningelliando dias
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Alexey Lesovsky
 
Troubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming ReplicationTroubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming ReplicationAlexey Lesovsky
 
Patroni - HA PostgreSQL made easy
Patroni - HA PostgreSQL made easyPatroni - HA PostgreSQL made easy
Patroni - HA PostgreSQL made easyAlexander Kukushkin
 
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdfOracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdfSrirakshaSrinivasan2
 
PostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsPostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsMydbops
 
Oracle data guard for beginners
Oracle data guard for beginnersOracle data guard for beginners
Oracle data guard for beginnersPini Dibask
 
PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep InternalEXEM
 
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱PgDay.Seoul
 
Histograms in MariaDB, MySQL and PostgreSQL
Histograms in MariaDB, MySQL and PostgreSQLHistograms in MariaDB, MySQL and PostgreSQL
Histograms in MariaDB, MySQL and PostgreSQLSergey Petrunya
 

Tendances (20)

PostgreSQL replication
PostgreSQL replicationPostgreSQL replication
PostgreSQL replication
 
Getting started with postgresql
Getting started with postgresqlGetting started with postgresql
Getting started with postgresql
 
Introduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparoundIntroduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparound
 
Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0
 
Optimizing MariaDB for maximum performance
Optimizing MariaDB for maximum performanceOptimizing MariaDB for maximum performance
Optimizing MariaDB for maximum performance
 
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
 
Postgresql tutorial
Postgresql tutorialPostgresql tutorial
Postgresql tutorial
 
PostgreSql query planning and tuning
PostgreSql query planning and tuningPostgreSql query planning and tuning
PostgreSql query planning and tuning
 
MySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxMySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptx
 
5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance
 
PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuning
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.
 
Troubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming ReplicationTroubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming Replication
 
Patroni - HA PostgreSQL made easy
Patroni - HA PostgreSQL made easyPatroni - HA PostgreSQL made easy
Patroni - HA PostgreSQL made easy
 
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdfOracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
 
PostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsPostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability Methods
 
Oracle data guard for beginners
Oracle data guard for beginnersOracle data guard for beginners
Oracle data guard for beginners
 
PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep Internal
 
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱
 
Histograms in MariaDB, MySQL and PostgreSQL
Histograms in MariaDB, MySQL and PostgreSQLHistograms in MariaDB, MySQL and PostgreSQL
Histograms in MariaDB, MySQL and PostgreSQL
 

En vedette

Best Practices for Becoming an Exceptional Postgres DBA
Best Practices for Becoming an Exceptional Postgres DBA Best Practices for Becoming an Exceptional Postgres DBA
Best Practices for Becoming an Exceptional Postgres DBA EDB
 
Postgres in Production - Best Practices 2014
Postgres in Production - Best Practices 2014Postgres in Production - Best Practices 2014
Postgres in Production - Best Practices 2014EDB
 
The Magic of Tuning in PostgreSQL
The Magic of Tuning in PostgreSQLThe Magic of Tuning in PostgreSQL
The Magic of Tuning in PostgreSQLAshnikbiz
 
PostgreSQL Replication in 10 Minutes - SCALE
PostgreSQL Replication in 10  Minutes - SCALEPostgreSQL Replication in 10  Minutes - SCALE
PostgreSQL Replication in 10 Minutes - SCALEPostgreSQL Experts, Inc.
 
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized EnvironmentsBest Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized EnvironmentsJignesh Shah
 
Linux tuning for PostgreSQL at Secon 2015
Linux tuning for PostgreSQL at Secon 2015Linux tuning for PostgreSQL at Secon 2015
Linux tuning for PostgreSQL at Secon 2015Alexey Lesovsky
 
淺入淺出 MySQL & PostgreSQL
淺入淺出 MySQL & PostgreSQL淺入淺出 MySQL & PostgreSQL
淺入淺出 MySQL & PostgreSQLYi-Feng Tzeng
 
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 ViennaAutovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 ViennaPostgreSQL-Consulting
 
Data Processing Inside PostgreSQL
Data Processing Inside PostgreSQLData Processing Inside PostgreSQL
Data Processing Inside PostgreSQLEDB
 
PostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability ImprovementsPostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability ImprovementsPGConf APAC
 
Streaming replication in practice
Streaming replication in practiceStreaming replication in practice
Streaming replication in practiceAlexey Lesovsky
 
Lessons PostgreSQL learned from commercial databases, and didn’t
Lessons PostgreSQL learned from commercial databases, and didn’tLessons PostgreSQL learned from commercial databases, and didn’t
Lessons PostgreSQL learned from commercial databases, and didn’tPGConf APAC
 
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLTen Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLanandology
 
Becoming a Command Line Expert with the AWS CLI (TLS304) | AWS re:Invent 2013
Becoming a Command Line Expert with the AWS CLI (TLS304) | AWS re:Invent 2013Becoming a Command Line Expert with the AWS CLI (TLS304) | AWS re:Invent 2013
Becoming a Command Line Expert with the AWS CLI (TLS304) | AWS re:Invent 2013Amazon Web Services
 
GPGPU Accelerates PostgreSQL (English)
GPGPU Accelerates PostgreSQL (English)GPGPU Accelerates PostgreSQL (English)
GPGPU Accelerates PostgreSQL (English)Kohei KaiGai
 
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014Amazon Web Services
 
12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQL12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQLKonstantin Gredeskoul
 
PostgreSQL performance improvements in 9.5 and 9.6
PostgreSQL performance improvements in 9.5 and 9.6PostgreSQL performance improvements in 9.5 and 9.6
PostgreSQL performance improvements in 9.5 and 9.6Tomas Vondra
 

En vedette (20)

Best Practices for Becoming an Exceptional Postgres DBA
Best Practices for Becoming an Exceptional Postgres DBA Best Practices for Becoming an Exceptional Postgres DBA
Best Practices for Becoming an Exceptional Postgres DBA
 
Postgres in Production - Best Practices 2014
Postgres in Production - Best Practices 2014Postgres in Production - Best Practices 2014
Postgres in Production - Best Practices 2014
 
The Magic of Tuning in PostgreSQL
The Magic of Tuning in PostgreSQLThe Magic of Tuning in PostgreSQL
The Magic of Tuning in PostgreSQL
 
PostgreSQL Replication in 10 Minutes - SCALE
PostgreSQL Replication in 10  Minutes - SCALEPostgreSQL Replication in 10  Minutes - SCALE
PostgreSQL Replication in 10 Minutes - SCALE
 
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized EnvironmentsBest Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
 
Linux tuning for PostgreSQL at Secon 2015
Linux tuning for PostgreSQL at Secon 2015Linux tuning for PostgreSQL at Secon 2015
Linux tuning for PostgreSQL at Secon 2015
 
淺入淺出 MySQL & PostgreSQL
淺入淺出 MySQL & PostgreSQL淺入淺出 MySQL & PostgreSQL
淺入淺出 MySQL & PostgreSQL
 
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 ViennaAutovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
 
Data Processing Inside PostgreSQL
Data Processing Inside PostgreSQLData Processing Inside PostgreSQL
Data Processing Inside PostgreSQL
 
PostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability ImprovementsPostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability Improvements
 
Streaming replication in practice
Streaming replication in practiceStreaming replication in practice
Streaming replication in practice
 
Lessons PostgreSQL learned from commercial databases, and didn’t
Lessons PostgreSQL learned from commercial databases, and didn’tLessons PostgreSQL learned from commercial databases, and didn’t
Lessons PostgreSQL learned from commercial databases, and didn’t
 
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLTen Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
 
Full Text Search In PostgreSQL
Full Text Search In PostgreSQLFull Text Search In PostgreSQL
Full Text Search In PostgreSQL
 
Becoming a Command Line Expert with the AWS CLI (TLS304) | AWS re:Invent 2013
Becoming a Command Line Expert with the AWS CLI (TLS304) | AWS re:Invent 2013Becoming a Command Line Expert with the AWS CLI (TLS304) | AWS re:Invent 2013
Becoming a Command Line Expert with the AWS CLI (TLS304) | AWS re:Invent 2013
 
GPGPU Accelerates PostgreSQL (English)
GPGPU Accelerates PostgreSQL (English)GPGPU Accelerates PostgreSQL (English)
GPGPU Accelerates PostgreSQL (English)
 
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
 
12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQL12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQL
 
PostgreSQL and RAM usage
PostgreSQL and RAM usagePostgreSQL and RAM usage
PostgreSQL and RAM usage
 
PostgreSQL performance improvements in 9.5 and 9.6
PostgreSQL performance improvements in 9.5 and 9.6PostgreSQL performance improvements in 9.5 and 9.6
PostgreSQL performance improvements in 9.5 and 9.6
 

Similaire à Mastering PostgreSQL Administration with Advanced Topics

9 steps to install and configure postgre sql from source on linux
9 steps to install and configure postgre sql from source on linux9 steps to install and configure postgre sql from source on linux
9 steps to install and configure postgre sql from source on linuxchinkshady
 
Grabbing the PostgreSQL Elephant by the Trunk
Grabbing the PostgreSQL Elephant by the TrunkGrabbing the PostgreSQL Elephant by the Trunk
Grabbing the PostgreSQL Elephant by the TrunkHarold Giménez
 
Introduction to PostgreSQL for System Administrators
Introduction to PostgreSQL for System AdministratorsIntroduction to PostgreSQL for System Administrators
Introduction to PostgreSQL for System AdministratorsJignesh Shah
 
Database Tools by Skype
Database Tools by SkypeDatabase Tools by Skype
Database Tools by Skypeelliando dias
 
Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Michael Renner
 
Oracle rac 10g best practices
Oracle rac 10g best practicesOracle rac 10g best practices
Oracle rac 10g best practicesHaseeb Alam
 
plProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancerplProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancerelliando dias
 
Common Sense Performance Indicators in the Cloud
Common Sense Performance Indicators in the CloudCommon Sense Performance Indicators in the Cloud
Common Sense Performance Indicators in the CloudNick Gerner
 
Planning for-high-performance-web-application
Planning for-high-performance-web-applicationPlanning for-high-performance-web-application
Planning for-high-performance-web-applicationNguyễn Duy Nhân
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpen Gurukul
 
Planning For High Performance Web Application
Planning For High Performance Web ApplicationPlanning For High Performance Web Application
Planning For High Performance Web ApplicationYue Tian
 
Large Scale Crawling with Apache Nutch and Friends
Large Scale Crawling with Apache Nutch and FriendsLarge Scale Crawling with Apache Nutch and Friends
Large Scale Crawling with Apache Nutch and FriendsJulien Nioche
 
Large Scale Crawling with Apache Nutch and Friends
Large Scale Crawling with Apache Nutch and FriendsLarge Scale Crawling with Apache Nutch and Friends
Large Scale Crawling with Apache Nutch and Friendslucenerevolution
 
Inside PostgreSQL Shared Memory
Inside PostgreSQL Shared MemoryInside PostgreSQL Shared Memory
Inside PostgreSQL Shared MemoryEDB
 
Making Distributed Data Persistent Services Elastic (Without Losing All Your ...
Making Distributed Data Persistent Services Elastic (Without Losing All Your ...Making Distributed Data Persistent Services Elastic (Without Losing All Your ...
Making Distributed Data Persistent Services Elastic (Without Losing All Your ...Joe Stein
 
Large scale crawling with Apache Nutch
Large scale crawling with Apache NutchLarge scale crawling with Apache Nutch
Large scale crawling with Apache NutchJulien Nioche
 

Similaire à Mastering PostgreSQL Administration with Advanced Topics (20)

A Practical Multi-Tenant Cluster
A Practical Multi-Tenant ClusterA Practical Multi-Tenant Cluster
A Practical Multi-Tenant Cluster
 
9 steps to install and configure postgre sql from source on linux
9 steps to install and configure postgre sql from source on linux9 steps to install and configure postgre sql from source on linux
9 steps to install and configure postgre sql from source on linux
 
Grabbing the PostgreSQL Elephant by the Trunk
Grabbing the PostgreSQL Elephant by the TrunkGrabbing the PostgreSQL Elephant by the Trunk
Grabbing the PostgreSQL Elephant by the Trunk
 
Introduction to PostgreSQL for System Administrators
Introduction to PostgreSQL for System AdministratorsIntroduction to PostgreSQL for System Administrators
Introduction to PostgreSQL for System Administrators
 
PostgreSQL Prologue
PostgreSQL ProloguePostgreSQL Prologue
PostgreSQL Prologue
 
Database Tools by Skype
Database Tools by SkypeDatabase Tools by Skype
Database Tools by Skype
 
Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014
 
Get to know PostgreSQL!
Get to know PostgreSQL!Get to know PostgreSQL!
Get to know PostgreSQL!
 
Oracle rac 10g best practices
Oracle rac 10g best practicesOracle rac 10g best practices
Oracle rac 10g best practices
 
plProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancerplProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancer
 
Common Sense Performance Indicators in the Cloud
Common Sense Performance Indicators in the CloudCommon Sense Performance Indicators in the Cloud
Common Sense Performance Indicators in the Cloud
 
Planning for-high-performance-web-application
Planning for-high-performance-web-applicationPlanning for-high-performance-web-application
Planning for-high-performance-web-application
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQL
 
Planning For High Performance Web Application
Planning For High Performance Web ApplicationPlanning For High Performance Web Application
Planning For High Performance Web Application
 
Perl Programming - 04 Programming Database
Perl Programming - 04 Programming DatabasePerl Programming - 04 Programming Database
Perl Programming - 04 Programming Database
 
Large Scale Crawling with Apache Nutch and Friends
Large Scale Crawling with Apache Nutch and FriendsLarge Scale Crawling with Apache Nutch and Friends
Large Scale Crawling with Apache Nutch and Friends
 
Large Scale Crawling with Apache Nutch and Friends
Large Scale Crawling with Apache Nutch and FriendsLarge Scale Crawling with Apache Nutch and Friends
Large Scale Crawling with Apache Nutch and Friends
 
Inside PostgreSQL Shared Memory
Inside PostgreSQL Shared MemoryInside PostgreSQL Shared Memory
Inside PostgreSQL Shared Memory
 
Making Distributed Data Persistent Services Elastic (Without Losing All Your ...
Making Distributed Data Persistent Services Elastic (Without Losing All Your ...Making Distributed Data Persistent Services Elastic (Without Losing All Your ...
Making Distributed Data Persistent Services Elastic (Without Losing All Your ...
 
Large scale crawling with Apache Nutch
Large scale crawling with Apache NutchLarge scale crawling with Apache Nutch
Large scale crawling with Apache Nutch
 

Plus de EDB

Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
Cloud Migration Paths: Kubernetes, IaaS, or DBaaSCloud Migration Paths: Kubernetes, IaaS, or DBaaS
Cloud Migration Paths: Kubernetes, IaaS, or DBaaSEDB
 
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr UnternehmenDie 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr UnternehmenEDB
 
Migre sus bases de datos Oracle a la nube
Migre sus bases de datos Oracle a la nube Migre sus bases de datos Oracle a la nube
Migre sus bases de datos Oracle a la nube EDB
 
EFM Office Hours - APJ - July 29, 2021
EFM Office Hours - APJ - July 29, 2021EFM Office Hours - APJ - July 29, 2021
EFM Office Hours - APJ - July 29, 2021EDB
 
Benchmarking Cloud Native PostgreSQL
Benchmarking Cloud Native PostgreSQLBenchmarking Cloud Native PostgreSQL
Benchmarking Cloud Native PostgreSQLEDB
 
Las Variaciones de la Replicación de PostgreSQL
Las Variaciones de la Replicación de PostgreSQLLas Variaciones de la Replicación de PostgreSQL
Las Variaciones de la Replicación de PostgreSQLEDB
 
NoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQLNoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQLEDB
 
Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?EDB
 
Data Analysis with TensorFlow in PostgreSQL
Data Analysis with TensorFlow in PostgreSQLData Analysis with TensorFlow in PostgreSQL
Data Analysis with TensorFlow in PostgreSQLEDB
 
Practical Partitioning in Production with Postgres
Practical Partitioning in Production with PostgresPractical Partitioning in Production with Postgres
Practical Partitioning in Production with PostgresEDB
 
A Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAINA Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAINEDB
 
IOT with PostgreSQL
IOT with PostgreSQLIOT with PostgreSQL
IOT with PostgreSQLEDB
 
A Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQLA Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQLEDB
 
Psql is awesome!
Psql is awesome!Psql is awesome!
Psql is awesome!EDB
 
EDB 13 - New Enhancements for Security and Usability - APJ
EDB 13 - New Enhancements for Security and Usability - APJEDB 13 - New Enhancements for Security and Usability - APJ
EDB 13 - New Enhancements for Security and Usability - APJEDB
 
Comment sauvegarder correctement vos données
Comment sauvegarder correctement vos donnéesComment sauvegarder correctement vos données
Comment sauvegarder correctement vos donnéesEDB
 
Cloud Native PostgreSQL - Italiano
Cloud Native PostgreSQL - ItalianoCloud Native PostgreSQL - Italiano
Cloud Native PostgreSQL - ItalianoEDB
 
New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13EDB
 
Best Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLBest Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLEDB
 
Cloud Native PostgreSQL - APJ
Cloud Native PostgreSQL - APJCloud Native PostgreSQL - APJ
Cloud Native PostgreSQL - APJEDB
 

Plus de EDB (20)

Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
Cloud Migration Paths: Kubernetes, IaaS, or DBaaSCloud Migration Paths: Kubernetes, IaaS, or DBaaS
Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
 
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr UnternehmenDie 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
 
Migre sus bases de datos Oracle a la nube
Migre sus bases de datos Oracle a la nube Migre sus bases de datos Oracle a la nube
Migre sus bases de datos Oracle a la nube
 
EFM Office Hours - APJ - July 29, 2021
EFM Office Hours - APJ - July 29, 2021EFM Office Hours - APJ - July 29, 2021
EFM Office Hours - APJ - July 29, 2021
 
Benchmarking Cloud Native PostgreSQL
Benchmarking Cloud Native PostgreSQLBenchmarking Cloud Native PostgreSQL
Benchmarking Cloud Native PostgreSQL
 
Las Variaciones de la Replicación de PostgreSQL
Las Variaciones de la Replicación de PostgreSQLLas Variaciones de la Replicación de PostgreSQL
Las Variaciones de la Replicación de PostgreSQL
 
NoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQLNoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQL
 
Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?
 
Data Analysis with TensorFlow in PostgreSQL
Data Analysis with TensorFlow in PostgreSQLData Analysis with TensorFlow in PostgreSQL
Data Analysis with TensorFlow in PostgreSQL
 
Practical Partitioning in Production with Postgres
Practical Partitioning in Production with PostgresPractical Partitioning in Production with Postgres
Practical Partitioning in Production with Postgres
 
A Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAINA Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAIN
 
IOT with PostgreSQL
IOT with PostgreSQLIOT with PostgreSQL
IOT with PostgreSQL
 
A Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQLA Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQL
 
Psql is awesome!
Psql is awesome!Psql is awesome!
Psql is awesome!
 
EDB 13 - New Enhancements for Security and Usability - APJ
EDB 13 - New Enhancements for Security and Usability - APJEDB 13 - New Enhancements for Security and Usability - APJ
EDB 13 - New Enhancements for Security and Usability - APJ
 
Comment sauvegarder correctement vos données
Comment sauvegarder correctement vos donnéesComment sauvegarder correctement vos données
Comment sauvegarder correctement vos données
 
Cloud Native PostgreSQL - Italiano
Cloud Native PostgreSQL - ItalianoCloud Native PostgreSQL - Italiano
Cloud Native PostgreSQL - Italiano
 
New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13
 
Best Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLBest Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQL
 
Cloud Native PostgreSQL - APJ
Cloud Native PostgreSQL - APJCloud Native PostgreSQL - APJ
Cloud Native PostgreSQL - APJ
 

Dernier

Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 

Dernier (20)

Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 

Mastering PostgreSQL Administration with Advanced Topics

  • 1. Mastering PostgreSQL Administration BRUCE MOMJIAN, ENTERPRISEDB April, 2009 Abstract POSTGRESQL is an open-source, full-featured relational database. This presentation covers advanced administration topics. Creative Commons Attribution License http://momjian.us/presentations
  • 2. Introduction Installation   Configuration   Maintenance   Monitoring   Recovery   Mastering PostgreSQL Administration 1
  • 3. Installation Click-Through installers   – MS Windows – Linux – OS/X – Solaris Ports   – RPM – DEB – PKG – other packages Source   – obtaining – build options – installing Mastering PostgreSQL Administration 2
  • 4. Initialization (initdb) $ initdb The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale C. The default database encoding has accordingly been set to SQL_ASCII. The default text search configuration will be set to "english". creating directory /u/pg/data ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers/max_fsm_pages ... 32MB/204800 creating configuration files ... ok creating template1 database in /u/pg/data/base/1 ... ok initializing pg_authid ... ok initializing dependencies ... ok creating system views ... ok loading system objects’ descriptions ... ok creating conversions ... ok creating dictionaries ... ok setting privileges on built-in objects ... ok creating information schema ... ok vacuuming database template1 ... ok copying template1 to template0 ... ok copying template1 to postgres ... ok Mastering PostgreSQL Administration 3
  • 5. Initialization (continued) WARNING: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the -A option the next time you run initdb. Success. You can now start the database server using: postgres -D /u/pg/data or pg_ctl -D /u/pg/data -l logfile start Mastering PostgreSQL Administration 4
  • 6. pg_controldata pg_control version number: 74 Catalog version number: 200502281 Database system identifier: 4766833642862247929 Database cluster state: shut down pg_control last modified: 03/03/05 10:49:18 Current log file ID: 0 Next log file segment: 1 Latest checkpoint location: 0/A34010 Prior checkpoint location: 0/A2D5C0 Latest checkpoint’s REDO location: 0/A34010 Latest checkpoint’s UNDO location: 0/0 Latest checkpoint’s TimeLineID: 1 Latest checkpoint’s NextXID: 545 Latest checkpoint’s NextOID: 17233 Time of latest checkpoint: 03/03/05 10:49:18 Database block size: 8192 Blocks per segment of large relation: 131072 Bytes per WAL segment: 16777216 Maximum length of identifiers: 64 Maximum number of function arguments: 32 Date/time type storage: floating-point numbers Maximum length of locale name: 128 LC_COLLATE: C LC_CTYPE: C Mastering PostgreSQL Administration 5
  • 7. System Architecture Main Libpq Postmaster Postgres Postgres Parse Statement utility Utility Traffic Cop Command Query e.g. CREATE TABLE, COPY SELECT, INSERT, UPDATE, DELETE Rewrite Query Generate Paths Optimal Path Generate Plan Plan Execute Plan Utilities Catalog Storage Managers Access Methods Nodes / Lists Mastering PostgreSQL Administration 6
  • 8. Starting Postmaster LOG: database system was shut down at 2009-01-27 10:32:05 EST LOG: database system is ready to accept connections LOG: autovacuum launcher started manually   pg_ctl   on boot   Mastering PostgreSQL Administration 7
  • 9. Stopping Postmaster LOG: received smart shutdown request LOG: autovacuum launcher shutting down LOG: shutting down LOG: database system is shut down manually   pg_ctl   on shutdown   Mastering PostgreSQL Administration 8
  • 10. Connections local — unix domain socket   host — TCP/IP, both SSL or non-SSL   hostssl — only SSL   hostnossl — never SSL   Mastering PostgreSQL Administration 9
  • 11. Authentication trust   passwords   – md5 – crypt – password remote authentication   – host ident using pg_ident.conf – kerberos – gss – sspi Mastering PostgreSQL Administration 10
  • 12. Authentication (continued) local socket ident   host ident using local identd   socket permissions   pam   ldap   reject   Mastering PostgreSQL Administration 11
  • 13. Access hostname and network mask   database name   role name (user or group)   filename or list of databases, role   IPv6   Mastering PostgreSQL Administration 12
  • 14. Pg_hba.conf # TYPE DATABASE USER CIDR-ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 trust Mastering PostgreSQL Administration 13
  • 15. Permissions host connection permissions   role permissions   – create roles – create databases – table permissions Database creation   – template1 customization – system tables – disk space computations Mastering PostgreSQL Administration 14
  • 16. Data Directory $ ls -CF PG_VERSION pg_ident.conf pg_xlog/ base/ pg_multixact/ postgresql.conf global/ pg_subtrans/ postmaster.opts pg_clog/ pg_tblspc/ postmaster.pid pg_hba.conf pg_twophase/ Mastering PostgreSQL Administration 15
  • 17. Database Directories $ ls -CF global/ 1136 2397 2843 1137 2671 2844 1213 2672 2845 1214 2676 2846 1232 2677 2847 1233 2694 pg_auth 1260 2695 pg_control 1261 2697 pg_database 1262 2698 pgstat.stat 2396 2842 $ ls -CF base/ 1/ 11510/ 11511/ 16384/ $ ls -CF base/16384 11429 2617 2696 11431 2618 2699 ... Mastering PostgreSQL Administration 16
  • 18. Transaction/WAL Directories $ ls -CF pg_xlog/ 000000010000000000000000 archive_status/ $ ls -CF pg_clog/ 0000 Mastering PostgreSQL Administration 17
  • 19. Configuration Directories $ ls -CF share/ conversion_create.sql postgres.description sql_features.txt information_schema.sql postgres.shdescription system_views.sql pg_hba.conf.sample postgresql.conf.sample timezone/ pg_ident.conf.sample psqlrc.sample timezonesets/ pg_service.conf.sample recovery.conf.sample tsearch_data/ postgres.bki snowball_create.sql unknown.pltcl Mastering PostgreSQL Administration 18
  • 21. PostgreSQL.Conf # ----------------------------- # PostgreSQL configuration file # ----------------------------- # # This file consists of lines of the form: # # name = value # # (The "=" is optional.) Whitespace may be used. Comments are introduced with # "#" anywhere on a line. The complete list of parameter names and allowed # values can be found in the PostgreSQL documentation. # # The commented-out settings shown in this file represent the default values. # Re-commenting a setting is NOT sufficient to revert it to the default value; # you need to reload the server. Mastering PostgreSQL Administration 20
  • 22. PostgreSQL.Conf (Continued) # This file is read on server startup and when the server receives a SIGHUP # signal. If you edit the file on a running system, you have to SIGHUP the # server for the changes to take effect, or use "pg_ctl reload". Some # parameters, which are marked below, require a server shutdown and restart to # take effect. # # Any parameter can also be given as a command-line option to the server, e.g., # "postgres -c log_connections=on". Some paramters can be changed at run time # with the "SET" SQL command. # # Memory units: kB = kilobytes MB = megabytes GB = gigabytes # Time units: ms = milliseconds s = seconds min = minutes h = hours d = days Mastering PostgreSQL Administration 21
  • 23. Configuration File Location #data_directory = ’ConfigDir’ # use data in another directory # (change requires restart) #hba_file = ’ConfigDir/pg_hba.conf’ # host-based authentication file # (change requires restart) #ident_file = ’ConfigDir/pg_ident.conf’ # ident configuration file # (change requires restart) # If external_pid_file is not explicitly set, no extra PID file is written. #external_pid_file = ’(none)’ # write an extra PID file # (change requires restart) Mastering PostgreSQL Administration 22
  • 24. Connections and Authentication #listen_addresses = ’localhost’ # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to ’localhost’, ’*’ = all # (change requires restart) #port = 5432 # (change requires restart) max_connections = 100 # (change requires restart) # Note: Increasing max_connections costs ~400 bytes of shared memory per # connection slot, plus lock space (see max_locks_per_transaction). You might # also need to raise shared_buffers to support more connections. #superuser_reserved_connections = 3 # (change requires restart) #unix_socket_directory = ’’ # (change requires restart) #unix_socket_group = ’’ # (change requires restart) #unix_socket_permissions = 0777 # begin with 0 to use octal notation # (change requires restart) #bonjour_name = ’’ # defaults to the computer name # (change requires restart) Mastering PostgreSQL Administration 23
  • 25. Security and Authentication #authentication_timeout = 1min # 1s-600s #ssl = off # (change requires restart) #ssl_ciphers = ’ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH’ # allowed SSL ciphers # (change requires restart) #password_encryption = on #db_user_namespace = off # Kerberos and GSSAPI #krb_server_keyfile = ’’ # (change requires restart) #krb_- srvname = ’postgres’ # (change requires restart, Kerberos only) #krb_server_hostname = ’’ # empty string matches any keytab entry # (change requires restart, Ker- beros only) #krb_caseins_users = off # (change requires restart) #krb_realm = ’’ # (change requires restart) Mastering PostgreSQL Administration 24
  • 26. TCP/IP Control # see "man 7 tcp" for details #tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds; # 0 selects the system default #tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds; # 0 selects the system default #tcp_keepalives_count = 0 # TCP_KEEPCNT; # 0 selects the system default Mastering PostgreSQL Administration 25
  • 27. Memory Usage shared_buffers = 32MB # min 128kB or max_connections*16kB # (change requires restart) #temp_buffers = 8MB # min 800kB #max_prepared_transactions = 5 # can be 0 or more # (change requires restart) # Note: Increasing max_prepared_transactions costs ~600 bytes of shared memory # per transaction slot, plus lock space (see max_locks_per_transaction). #work_mem = 1MB # min 64kB #maintenance_work_mem = 16MB # min 1MB #max_stack_depth = 2MB # min 100kB Kernel changes often required. Mastering PostgreSQL Administration 26
  • 28. Sizing Shared Memory Postgres Backend Postgres Backend Postgres Backend R PostgreSQL Shared Buffer Cache A Kernel Disk Buffer Cache Page Out M Swap Free Page In Kernel Mastering PostgreSQL Administration 27
  • 29. Free Space Map and Kernel Resources # - Free Space Map - max_fsm_pages = 204800 # min max_fsm_relations*16, 6 bytes each # (change requires restart) #max_fsm_relations = 1000 # min 100, ~70 bytes each # (change requires restart) # - Kernel Resource Usage - #max_files_per_process = 1000 # min 25 # (change requires restart) #shared_preload_libraries = ’’ # (change requires restart) Mastering PostgreSQL Administration 28
  • 30. Vacuum and Background Writer # - Cost-Based Vacuum Delay - #vacuum_cost_delay = 0 # 0-1000 milliseconds #vacuum_cost_page_hit = 1 # 0-10000 credits #vacuum_cost_page_miss = 10 # 0-10000 credits #vacuum_cost_page_dirty = 20 # 0-10000 credits #vacuum_cost_limit = 200 # 1-10000 credits # - Background Writer - #bgwriter_delay = 200ms # 10-10000ms between rounds #bgwriter_lru_maxpages = 100 # 0-1000 max buffers written/round #bgwriter_lru_multiplier = 2.0 # 0- 10.0 multipler on buffers scanned/round Mastering PostgreSQL Administration 29
  • 31. Write-Ahead Log (WAL) #fsync = on # turns forced synchronization on or off #synchronous_commit = on # immediate fsync at commit #wal_sync_method = fsync # the default is the first option # supported by the operating system: # open_datasync # fdatasync # fsync # fsync_writethrough # open_sync #full_page_writes = on # recover from partial page writes #wal_buffers = 64kB # min 32kB # (change requires restart) #wal_writer_delay = 200ms # 1-10000 milliseconds #commit_delay = 0 # range 0-100000, in microseconds #commit_siblings = 5 # range 1-1000 Mastering PostgreSQL Administration 30
  • 32. Write-Ahead Logging (Continued) Postgres Postgres Postgres Backend Backend Backend PostgreSQL Shared Buffer Cache Write−Ahead Log fsync Kernel Disk Buffer Cache fsync Disk Blocks Mastering PostgreSQL Administration 31
  • 33. Checkpoints and Archiving # - Checkpoints - #checkpoint_segments = 3 # in logfile segments, min 1, 16MB each #checkpoint_timeout = 5min # range 30s-1h #checkpoint_completion_target = 0.5 # checkpoint target duration, 0.0 - 1.0 #checkpoint_warning = 30s # 0 is off # - Archiving - #archive_mode = off # allows archiving to be done # (change requires restart) #archive_command = ’’ # command to use to archive a logfile segment #archive_timeout = 0 # force a logfile segment switch after this # time; 0 is off Mastering PostgreSQL Administration 32
  • 34. Query Tuning # - Planner Method Configuration - #enable_bitmapscan = on #enable_hashagg = on #enable_hashjoin = on #enable_indexscan = on #enable_mergejoin = on #enable_nestloop = on #enable_seqscan = on #enable_sort = on #enable_tidscan = on # - Planner Cost Constants - #seq_page_cost = 1.0 # measured on an arbitrary scale #random_page_cost = 4.0 # same scale as above #cpu_tuple_cost = 0.01 # same scale as above #cpu_index_tuple_cost = 0.005 # same scale as above #cpu_operator_cost = 0.0025 # same scale as above #effective_cache_size = 128MB Mastering PostgreSQL Administration 33
  • 35. Query Tuning (Continued) #geqo = on #geqo_threshold = 12 #geqo_effort = 5 # range 1-10 #geqo_pool_size = 0 # selects default based on effort #geqo_generations = 0 # selects default based on effort #geqo_selection_bias = 2.0 # range 1.5-2.0 # - Other Planner Options - #default_statistics_target = 10 # range 1-1000 #constraint_exclusion = off #from_collapse_limit = 8 #join_collapse_limit = 8 # 1 disables collapsing of explicit # JOIN clauses Mastering PostgreSQL Administration 34
  • 36. Where To Log #log_destination = ’stderr’ # Valid values are combinations of # stderr, csvlog, syslog and eventlog, # depending on platform. csvlog # requires logging_collector to be on. # This is used when logging to stderr: #logging_collector = off # Enable capturing of stderr and csvlog # into log files. Required to be on for # csvlogs. # (change requires restart) # These are only used if logging_collector is on: #log_directory = ’pg_log’ # directory where log files are written, # can be absolute or relative to PGDATA #log_filename = ’postgresql-%Y-%m-%d_%H%M%S.log’ # log file name pattern, # can include strftime() escapes Mastering PostgreSQL Administration 35
  • 37. Where To Log (Continued) #log_truncate_on_rotation = off # If on, an existing log file of the # same name as the new log file will be # truncated rather than appended to. # But such truncation only occurs on # time-driven rotation, not on restarts # or size-driven rotation. Default is # off, meaning append to existing files # in all cases. #log_rotation_age = 1d # Automatic rotation of logfiles will # happen after that time. 0 to disable. #log_rotation_size = 10MB # Automatic rotation of logfiles will # happen after that much log output. # 0 to disable. # These are relevant when logging to syslog: #syslog_facility = ’LOCAL0’ #syslog_ident = ’postgres’ Mastering PostgreSQL Administration 36
  • 38. When to Log #client_min_messages = notice # values in order of decreasing detail: # debug5 # debug4 # debug3 # debug2 # debug1 # log # notice # warning # error #log_min_messages = notice # values in order of decreasing detail: # debug5 # debug4 # debug3 # debug2 # debug1 # info # notice # warning # error # log # fatal # panic Mastering PostgreSQL Administration 37
  • 39. When to Log (Continued) #log_error_verbosity = default # terse, default, or verbose messages #log_min_error_statement = error # values in order of decreasing detail: # debug5 # debug4 # debug3 # debug2 # debug1 # info # notice # warning # error # log # fatal # panic (effectively off) #log_min_duration_statement = -1 # -1 is disabled, 0 logs all statements # and their durations, > 0 logs only # statements running at least this time. #silent_mode = off # DO NOT USE without syslog or # logging_collector # (change requires restart) Mastering PostgreSQL Administration 38
  • 40. What to Log #debug_print_parse = off #debug_print_rewritten = off #debug_print_plan = off #debug_pretty_print = off #log_checkpoints = off #log_connections = off #log_disconnections = off #log_duration = off #log_hostname = off Mastering PostgreSQL Administration 39
  • 41. What To Log: Log_line_prefix #log_line_prefix = ’’ # special values: # %u = user name # %d = database name # %r = remote host and port # %h = remote host # %p = process ID # %t = timestamp without milliseconds # %m = timestamp with milliseconds # %i = command tag # %c = session ID # %l = session line number # %s = session start timestamp # %v = virtual transaction ID # %x = transaction ID (0 if none) # %q = stop here in non-session # processes # %% = ’%’ # e.g. ’<%u%%%d> ’ Mastering PostgreSQL Administration 40
  • 42. What to Log (Continued) #log_lock_waits = off # log lock waits >= deadlock_timeout #log_statement = ’none’ # none, ddl, mod, all #log_temp_files = -1 # log temporary files equal or larger # than specified size; # -1 disables, 0 logs all temp files #log_timezone = unknown # actually, defaults to TZ environment # setting Mastering PostgreSQL Administration 41
  • 43. Runtime Statistics # - Query/Index Statistics Collector - #track_activities = on #track_counts = on #update_process_title = on # - Statistics Monitoring - #log_parser_stats = off #log_planner_stats = off #log_executor_stats = off #log_statement_stats = off Mastering PostgreSQL Administration 42
  • 44. Autovacuum #autovacuum = on # Enable autovacuum subprocess? ’on’ # requires track_counts to also be on. #log_autovacuum_min_duration = -1 # -1 disables, 0 logs all actions and # their durations, > 0 logs only # actions running at least that time. #autovacuum_max_workers = 3 # max number of autovacuum subprocesses #autovacuum_naptime = 1min # time between autovacuum runs #autovacuum_vacuum_threshold = 50 # min number of row updates before # vacuum #autovacuum_analyze_threshold = 50 # min number of row updates before # analyze #autovacuum_vacuum_scale_factor = 0.2 # fraction of table size before vacuum #autovacuum_analyze_scale_factor = 0.1 # fraction of table size before analyze #autovacuum_freeze_max_age = 200000000 # maximum XID age before forced vacuum # (change requires restart) #autovacuum_vacuum_cost_delay = 20 # default vacuum cost delay for # autovacuum, -1 means use # vacuum_cost_delay #autovacuum_vacuum_cost_limit = -1 # default vacuum cost limit for # autovacuum, -1 means use # vacuum_cost_limit Mastering PostgreSQL Administration 43
  • 45. Statement Behavior #search_path = ’"$user",public’ # schema names #default_tablespace = ’’ # a tablespace name, ’’ uses the default #temp_tablespaces = ’’ # a list of tablespace names, ’’ uses # only default tablespace #check_function_bodies = on #default_transaction_isolation = ’read committed’ #default_transaction_read_only = off #session_replication_role = ’origin’ #statement_timeout = 0 # 0 is disabled #vacuum_freeze_min_age = 100000000 #xmlbinary = ’base64’ #xmloption = ’content’ Mastering PostgreSQL Administration 44
  • 46. Locale and Formatting datestyle = ’iso, mdy’ #timezone = unknown # actually, defaults to TZ environment # setting #timezone_abbreviations = ’Default’ # Select the set of available time zone # abbreviations. Currently, there are # Default # Australia # India # You can create your own file in # share/timezonesets/. #extra_float_digits = 0 # min -15, max 2 #client_encoding = sql_ascii # actually, defaults to database # encoding # These settings are initialized by initdb, but they can be changed. lc_messages = ’C’ # locale for system error message # strings lc_monetary = ’C’ # locale for monetary formatting lc_numeric = ’C’ # locale for number formatting lc_time = ’C’ # locale for time formatting Mastering PostgreSQL Administration 45
  • 47. Full Text Search # default configuration for text search default_text_search_config = ’pg_catalog.english’ Mastering PostgreSQL Administration 46
  • 48. Other Defaults #explain_pretty_print = on #dynamic_library_path = ’$libdir’ #local_preload_libraries = ’’ Mastering PostgreSQL Administration 47
  • 49. Lock Management #deadlock_timeout = 1s #max_locks_per_transaction = 64 # min 10 # (change requires restart) # Note: Each lock table slot uses ~270 bytes of shared memory, and there are # max_locks_per_transaction * (max_connections + max_prepared_transactions) # lock table slots. Mastering PostgreSQL Administration 48
  • 50. Version/Platform Compatibility # - Previous PostgreSQL Versions - #add_missing_from = off #array_nulls = on #backslash_quote = safe_encoding # on, off, or safe_encoding #default_with_oids = off #escape_string_warning = on #regex_flavor = advanced # advanced, extended, or basic #sql_inheritance = on #standard_conforming_strings = off #synchronize_seqscans = on # - Other Platforms and Clients - #transform_null_equals = off Mastering PostgreSQL Administration 49
  • 51. Customization #custom_variable_classes = ’’ # list of custom variable class names Mastering PostgreSQL Administration 50
  • 52. Interfaces Installing   – Compiled Languages (C, ecpg) – Scripting Language (Perl, Python) – SPI Connection Pooling   Mastering PostgreSQL Administration 51
  • 53. Include Files $ ls -CF include/ ecpg_config.h libpq/ pgtypes_interval.h ecpg_informix.h libpq-fe.h pgtypes_numeric.h ecpgerrno.h pg_config.h pgtypes_timestamp.h ecpglib.h pg_config_manual.h postgres_ext.h ecpgtype.h pg_config_os.h server/ informix/ pgtypes_date.h sql3types.h internal/ pgtypes_error.h sqlca.h Mastering PostgreSQL Administration 52
  • 54. Library Files $ ls -CF lib/ ascii_and_mic.so* libecpg_compat.so.3@ utf8_and_big5.so* cyrillic_and_mic.so* libecpg_compat.so.3.0* utf8_and_cyrillic.so* dict_snowball.so* libpgport.a utf8_and_euc_cn.so* euc_cn_and_mic.so* libpgtypes.a utf8_and_euc_jis_2004.s euc_jis_2004_and_shift_ libpgtypes.so@ utf8_and_euc_jp.so* euc_jp_and_sjis.so* libpgtypes.so.3@ utf8_and_euc_kr.so* euc_kr_and_mic.so* libpgtypes.so.3.0* utf8_and_euc_tw.so* euc_tw_and_big5.so* libpq.a utf8_and_gb18030.so* latin2_and_win1250.so* libpq.so@ utf8_and_gbk.so* latin_and_mic.so* libpq.so.5@ utf8_and_iso8859.so* libecpg.a libpq.so.5.1* utf8_and_iso8859_1.so* libecpg.so@ pgxs/ utf8_and_johab.so* libecpg.so.6@ plperl.so* utf8_and_shift_jis_2004 libecpg.so.6.0* plpgsql.so* utf8_and_sjis.so* libecpg_compat.a pltcl.so* utf8_and_uhc.so* libecpg_compat.so@ utf8_and_ascii.so* utf8_and_win.so* Mastering PostgreSQL Administration 53
  • 56. Backup File system-level   – tar, cpio while shutdown – file system snapshot – rsync, shutdown, rsync, restart pg_dump/pg_dumpall   restore/pg_restore with custom format   Mastering PostgreSQL Administration 55
  • 57. Continuous Archiving / Point-In-Time Recovery (PITR) 00 00 00 00 02 09 11 13 WAL AL AL W W File System- Continuous Level Backup Backup Mastering PostgreSQL Administration 56
  • 58. PITR Backup Procedures 1. archive_command = ’cp %p /mnt/server/pgsql/%f ’ 2. SELECT pg_start_backup(’label’); 3. Perform file system-level backup (can be inconsistent) 4. SELECT pg_stop_backup(); Mastering PostgreSQL Administration 57
  • 59. PITR Recovery 00 30 40 55 17 17 17 17 WAL AL AL W W File System- Continuous Level Backup Backup Mastering PostgreSQL Administration 58
  • 60. PITR Recovery Procecdures 1. Stop postmaster 2. Restore file system-level backup 3. Make adjustments as outlined in the documentation 4. Create recovery.conf 5. Add restore_command = ’cp /mnt/server/pgsql/%f %p’ 6. Start the postmaster Mastering PostgreSQL Administration 59
  • 61. 60 Master-Slave Replication - Slony 54 54 32 32 32 0 10 10 10 10 10 )( )( & '& '& '& $ %$ %$ %$ %$ %$ B777723B 7723B 7723B 77777777B1 @A0 5 7B 5 7B 7@7@7@7B 7B 7B 7B1 7B1 7B1 7B1 7 @7@7@7A A A @777@7@777 A4 A4 A A @A @A0 A0 A0 @A0 @A0 9777&77&'9 77&'9 77&'9 777777779% 8$ ) 79 ) 79 8 8 8 8 9 79 79 79% 79% 79% 79% 7 8( 8( 8 8 8$ 8$ 8$ 8$ 8$ 54 54 32 32 32 0 10 10 10 10 10 ) 7) 77' 7' 7' 7777% 7% 7% 7% 7% 6$ 6 ( 6 ( 6 & 6 & 6 & 6 & 6 6 6$ 6$ 6$ 6$ 6$ 54 54 32 32 32 0 10 10 10 10 10 )( )( & '& '& '& $ %$ %$ %$ %$ %$ 0 10 10 10 10 10 $ %$ %$ %$ %$ %$ #" #" ! ! ! H7# G7H7# G7H7H7H7H7H7H7H7H7H7H7H7H G G7! G7! G7! G7G7G7G7 G7 G7 G7 G7 T7# S7T7# S7T7T7T7T7T7T7T7T7T7T7T7T S S7! S7! S7! S7S7S7S7 S7 S7 S7 S7 ¨ ©¨ ©¨ ©¨ ¦ §¦ §¦ §¦ §¦ §¦ # # ! ! ! ¨ ©¨ ©¨ ©¨ ¦ §¦ §¦ §¦ §¦ §¦ R 7R 7R Q Q Q Q R 7R 7R 7R§ 7R§ 7R§ 7R§ 7 777¨77¨©R 77¨©R 77¨©R 77777777R§ Q¦ Q Q Q Q Q¦ Q¦ Q¦ Q¦ Q¦ ¨ ©¨ ©¨ ©¨ ¦ §¦ §¦ §¦ §¦ §¦ ¥¤ ¥¤ £¢ £¢ £¢ ¥D7777¢£D 77¢£D 77¢£D 77777777D C 7D ¥ 7D 7C C C D 7D 7D 7D 7D 7D 7D 7 C¤ C¤ C C C C C C C C F ¥ 7F ¥ 7F 7E E E F 7F 7F 7F 7F 7F 7F 7 7777¢£F 77¢£F 77¢£F 77777777F E E¤ E¤ E E E E E E E E ¥¤ ¥¤ £¢ £¢ £¢ ¡  ¡  ¡  ¡  P ¡ 7P ¡ 7P I I I I P 7P 7P 7P 7P 7P 7P 7 77777P 77P 77P 77777777P I I  I  I I I I I I I ¡  ¡  Mastering PostgreSQL Administration
  • 62. Other Solutions Mutli-master replication: pgcluster, bacardo   Pooling: pgpool   Mastering PostgreSQL Administration 61
  • 63. Data Maintenance VACUUM (nonblocking), free space map   VACUUM FULL   ANALYZE   Mastering PostgreSQL Administration 62
  • 64. Vacuum Free Space Map Table Block # Block # Block # DB oid Relfilenode Table Block # Block # Table Block # Block # Block # Hashed Shared Memory Mastering PostgreSQL Administration 63
  • 65. Vacuum Full A A E A A A E A A A A A Original Heap C C X C C C X C C C C C T T P T T T P T T T T T With Expired I I I I I I I I I I I I V V R V V V R V V V V V Rows Identified E E E E E E E E E E E E A A A A A A A A A A Move Trailing C C C C C C C C C C T T T T T T T T T T Rows Into Expired I I I I I I I I I I V V V V V V V V V V Slots E E E E E E E E E E A A A A A A A A A A C C C C C C C C C C T T T T T T T T T T Truncate File I I I I I I I I I I V V V V V V V V V V E E E E E E E E E E Mastering PostgreSQL Administration 64
  • 66. Checkpoints Write all dirty shared buffers   Sync all dirty kernel buffers   Recycle WAL files   Check for server messages indicating too-frequent checkpoints   If so, increase checkpoint_segments   Mastering PostgreSQL Administration 65
  • 67. Automating Tasks 0 3 * * * root psql -c ’VACUUM FULL;’ test 0 3 * * * root vacuumdb -a -f Autovacuum usually makes vacuum administration unnecessary. Mastering PostgreSQL Administration 66
  • 68. Monitoring Active Sessions Mastering PostgreSQL Administration 67
  • 69. ps $ ps -Upostgres PID TT STAT TIME COMMAND 2125 ?? Ss 0:00.26 ./bin/postmaster -i 2142 ?? S 0:00.03 stats buffer process (postmaster) 2143 ?? S 0:00.06 stats collector process (postmaster) 3341 ?? I 0:00.07 postgres test [local] idle (postmaster) 3340 p6 I+ 0:00.03 psql test Mastering PostgreSQL Administration 68
  • 70. top $ top load averages: 0.56, 0.39, 0.36 18:25:58 138 processes: 5 running, 130 sleeping, 3 zombie CPU states: 50.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 50.0% idle Memory: Real: 96M/133M Virt: 535M/1267M Free: 76M PID USERNAME PRI NICE SIZE RES STATE TIME WCPU CPU COMMAND 23785 postgres 57 0 11M 5336K run/0 0:07 30.75% 30.66% postmaster 23784 postgres 2 0 10M 11M sleep 0:00 2.25% 2.25% psql Mastering PostgreSQL Administration 69
  • 72. Query Monitoring test= SELECT * FROM pg_stat_activity; -[ RECORD 1 ]-+-------------------------------- datid | 16384 datname | test procpid | 2373 usesysid | 10 usename | postgres current_query | select * from pg_stat_activity; waiting | f xact_start | 2009-01-27 12:12:59.917695-05 query_start | 2009-01-27 12:12:59.917695-05 backend_start | 2009-01-27 12:12:33.422001-05 client_addr | client_port | -1 Mastering PostgreSQL Administration 71
  • 74. Access Statistics pg_stat_all_indexes | view | postgres pg_stat_all_tables | view | postgres pg_stat_database | view | postgres pg_stat_sys_indexes | view | postgres pg_stat_sys_tables | view | postgres pg_stat_user_indexes | view | postgres pg_stat_user_tables | view | postgres pg_statio_all_indexes | view | postgres pg_statio_all_sequences | view | postgres pg_statio_all_tables | view | postgres pg_statio_sys_indexes | view | postgres pg_statio_sys_sequences | view | postgres pg_statio_sys_tables | view | postgres pg_statio_user_indexes | view | postgres pg_statio_user_sequences | view | postgres pg_statio_user_tables | view | postgres Mastering PostgreSQL Administration 73
  • 75. Database Statistics test= SELECT * FROM pg_stat_database; ... -[ RECORD 4 ]-+---------- datid | 16384 datname | test numbackends | 1 xact_commit | 188 xact_rollback | 0 blks_read | 95 blks_hit | 11832 tup_returned | 64389 tup_fetched | 2938 tup_inserted | 0 tup_updated | 0 tup_deleted | 0 Mastering PostgreSQL Administration 74
  • 76. Table Activity test= SELECT * FROM pg_stat_all_tables; ... -[ RECORD 10 ]---+------------------------ relid | 2616 schemaname | pg_catalog relname | pg_opclass seq_scan | 2 seq_tup_read | 2 idx_scan | 99 idx_tup_fetch | 99 n_tup_ins | 0 n_tup_upd | 0 n_tup_del | 0 n_tup_hot_upd | 0 n_live_tup | 0 Mastering PostgreSQL Administration 75
  • 77. n_dead_tup | 0 last_vacuum | last_autovacuum | last_analyze | last_autoanalyze | Mastering PostgreSQL Administration 76
  • 78. Table Block Activity test= SELECT * FROM pg_statio_all_tables; -[ RECORD 50 ]--+------------------------ relid | 2602 schemaname | pg_catalog relname | pg_amop heap_blks_read | 3 heap_blks_hit | 114 idx_blks_read | 5 idx_blks_hit | 303 toast_blks_read | toast_blks_hit | tidx_blks_read | tidx_blks_hit | Mastering PostgreSQL Administration 77
  • 79. Analyzing Activity Heavily used tables   Unnecessary indexes   Additional indexes   Index usage   TOAST usage   Mastering PostgreSQL Administration 78
  • 80. CPU $ vmstat 5 procs memory page disks faults cpu r b w avm fre flt re pi po fr sr s0 s0 in sy cs us sy id 1 0 0 501820 48520 1234 86 2 0 0 3 5 0 263 2881 599 10 4 86 3 0 0 512796 46812 1422 201 12 0 0 0 3 0 259 6483 827 4 7 88 3 0 0 542260 44356 788 137 6 0 0 0 8 0 286 5698 741 2 5 94 4 0 0 539708 41868 576 65 13 0 0 0 4 0 273 5721 819 16 4 80 4 0 0 547200 32964 454 0 0 0 0 0 5 0 253 5736 948 50 4 46 4 0 0 556140 23884 461 0 0 0 0 0 2 0 249 5917 959 52 3 44 1 0 0 535136 46280 1056 141 25 0 0 0 2 0 261 6417 890 24 6 70 Mastering PostgreSQL Administration 79
  • 81. I/O $ iostat 5 tty sd0 sd1 sd2 % cpu tin tout sps tps msps sps tps msps sps tps msps usr nic sys int idl 7 119 244 11 6.1 0 0 27.3 0 0 18.1 9 1 4 0 86 0 86 20 1 1.4 0 0 0.0 0 0 0.0 2 0 2 0 96 0 82 61 4 3.6 0 0 0.0 0 0 0.0 2 0 2 0 97 0 65 6 0 0.0 0 0 0.0 0 0 0.0 1 0 2 0 97 12 90 31 2 5.4 0 0 0.0 0 0 0.0 4 0 3 0 93 24 173 6 0 4.9 0 0 0.0 0 0 0.0 48 0 3 0 49 0 91 3594 63 4.6 0 0 0.0 0 0 0.0 11 0 4 0 85 Mastering PostgreSQL Administration 80
  • 82. Disk Usage play=# SELECT relfilenode, relpages * 8 AS kilobytes play-# FROM pg_class play-# WHERE relname = ’customer’; relfilenode | kilobytes -------------+---------- 16806 | 480 (1 row) Vacuum required. dbsize available. Mastering PostgreSQL Administration 81
  • 83. TOAST Usage play=# SELECT relname, relpages * 8 AS kilobytes play-# FROM pg_class play-# WHERE relname = ’pg_toast_16806’ OR play-# relname = ’pg_toast_16806_index’ play-# ORDER BY relname; relname | kilobytes ----------------------+---------- pg_toast_16806 | 0 pg_toast_16806_index | 1 Mastering PostgreSQL Administration 82
  • 84. Index Usage play=# SELECT c2.relname, c2.relpages * 8 AS kilobytes play-# FROM pg_class c, pg_class c2, pg_index i play-# WHERE c.relname = ’customer’ AND play-# c.oid = i.indrelid AND play-# c2.oid = i.indexrelid play-# ORDER BY c2.relname; relname | kilobytes ----------------------+---------- customer_id_indexdex | 26 Mastering PostgreSQL Administration 83
  • 85. Largest Tables play=# SELECT relname, relpages * 8 play-# FROM pg_class play-# ORDER BY relpages DESC; relname | kilobytes ----------------------+---------- bigtable | 3290 customer | 3144 Mastering PostgreSQL Administration 84
  • 86. Database File Mapping - oid2name $ oid2name All databases: --------------------------------- 18720 = test1 1 = template1 18719 = template0 18721 = test 18735 = postgres 18736 = cssi Mastering PostgreSQL Administration 85
  • 87. Table File Mapping $ cd /usr/local/pgsql/data/base $ oid2name All databases: --------------------------------- 16817 = test2 16578 = x 16756 = test 1 = template1 16569 = template0 16818 = test3 16811 = floattest $ cd 16756 $ ls 1873* 18730 18731 18732 18735 18736 18737 18738 18739 Mastering PostgreSQL Administration 86
  • 88. $ oid2name -d test -o 18737 Tablename of oid 18737 from database test: --------------------------------- 18737 = ips $ oid2name -d test -t ips Oid of table ips from database test: --------------------------------- 18737 = ips $ # show disk space for every db object $ du * | while read SIZE RELFILENODE do echo $SIZE ‘oid2name -q -d test -o $RELFILENODE‘ done 24 18737 = ips 36 18722 = cities ... Mastering PostgreSQL Administration 87
  • 89. $ # same as above, but sort by largest first $ du * | while read SIZE OID do echo $SIZE ‘oid2name -q -d test -o $OID‘ done | sort -rn 2048 19324 = bigtable 1950 23903 = customers ... $ # show disk usage per database $ cd /usr/local/pgsql/data/base $ du -s * | while read SIZE OID do echo $SIZE ‘oid2name -q | grep ^$OID’ ’‘ done | sort -rn 2256 18721 = test 2135 18735 = postgres Mastering PostgreSQL Administration 88
  • 90. Disk Balancing Move pg_xlog to another drive using symlinks   Tablespaces   Mastering PostgreSQL Administration 89
  • 91. Per-Database Tablespaces DB1 DB2 DB3 DB4 Disk 1 Disk 2 Disk 3 Mastering PostgreSQL Administration 90
  • 92. Per-Object Tablespaces tab1 tab2 index constraint Disk 1 Disk 2 Disk 3 Mastering PostgreSQL Administration 91
  • 93. Analyzing Locking $ ps -Upostgres PID TT STAT TIME COMMAND 9874 ?? I 0:00.07 postgres test [local] idle in transaction (postmaster) 9835 ?? S 0:00.05 postgres test [local] UPDATE waiting (postmaster) 10295 ?? S 0:00.05 postgres test [local] DELETE waiting (postmaster) test= SELECT * FROM pg_locks; relation | database | transaction | pid | mode | granted ----------+----------+-------------+------+------------------+--------- 17143 | 17142 | | 9173 | AccessShareLock | t 17143 | 17142 | | 9173 | RowExclusiveLock | t | | 472 | 9380 | ExclusiveLock | t | | 468 | 9338 | ShareLock | f | | 470 | 9338 | ExclusiveLock | t 16759 | 17142 | | 9380 | AccessShareLock | t 17143 | 17142 | | 9338 | AccessShareLock | t 17143 | 17142 | | 9338 | RowExclusiveLock | t | | 468 | 9173 | ExclusiveLock | t (9 rows) Mastering PostgreSQL Administration 92
  • 94. Miscellaneous Tasks Log file rotation, syslog   Upgrading   Migration   Mastering PostgreSQL Administration 93
  • 95. Administration Tools pgadmin   phppgadmin   Mastering PostgreSQL Administration 94
  • 97. Client Application Crash Nothing Required. Transactions in progress are rolled back. Mastering PostgreSQL Administration 96
  • 98. Graceful Server Crash Nothing Required. Transactions in progress are rolled back. Mastering PostgreSQL Administration 97
  • 99. Abrupt Server Crash Nothing Required. Transactions in progress are rolled back. Mastering PostgreSQL Administration 98
  • 100. Operating System Crash Nothing Required. Transactions in progress are rolled back. Partial page writes are repaired. Mastering PostgreSQL Administration 99
  • 101. Disk Failure Restore from previous backup or use PITR. Mastering PostgreSQL Administration 100
  • 102. Accidental DELETE Recover table from previous backup, perhaps using pg_restore. It is possible to modify the backend code to make deleted tuples visible, dump out the deleted table and restore the original code. All tuples in the table since the previous vacuum will be visible. It is possible to restrict that so only tuples deleted by a specific transaction are visible. Mastering PostgreSQL Administration 101
  • 103. Write-Ahead Log (WAL) Corruption See pg_resetxlog. Review recent transactions and identify any damage, including partially committed transactions. Mastering PostgreSQL Administration 102
  • 104. File Deletion It may be necessary to create an empty file with the deleted file name so the object can be deleted, and then the object restored from backup. Mastering PostgreSQL Administration 103
  • 105. Accidental DROP TABLE Restore from previous backup. Mastering PostgreSQL Administration 104
  • 106. Accidental DROP INDEX Recreate index. Mastering PostgreSQL Administration 105
  • 107. Accidental DROP DATABASE Restore from previous backup. Mastering PostgreSQL Administration 106
  • 108. Non-Starting Installation Restart problems are usually caused by write-ahead log problems. See pg_resetxlog. Review recent transactions and identify any damage, including partially committed transactions. Mastering PostgreSQL Administration 107
  • 109. Index Corruption Use REINDEX. Mastering PostgreSQL Administration 108
  • 110. Table Corruption Try reindexing the table. Try identifying the corrupt OID of the row and transfer the valid rows into another table using SELECT…INTO…WHERE oid != ###. Use http://sources.redhat.com/rhdb/tools.html to analyze the internal structure of the table. Mastering PostgreSQL Administration 109