PostGreSQL Server Admin

Installation

FreeBSD

  1. Install the latest stable PostGreSQL server port:

    
    [tethys] ~% cd /usr/ports/databases/postgresql84-server/
    [tethys] postgresql84-server% sudo make install clean
    
    

  2. Verify that the install process created the pgsql user:

    
    [tethys] ~% grep pgsql /etc/passwd 
    pgsql:*:70:70:PostgreSQL Daemon:/usr/local/pgsql:/bin/sh
    
    

  3. In /etc/rc.conf, enable PostGreSQL:

    
    # vi /etc/rc.conf
    
    Add:
    
    postgresql_enable="YES"
    postgresql_data="/data/pgsql"
    
    

  4. Initialize the PostGreSQL databases:

    
    [tethys] ~% sudo /usr/local/etc/rc.d/postgresql initdb
    The files belonging to this database system will be owned by user "pgsql".
    This user must also own the server process.
    
    The database cluster will be initialized with locale C.
    The default text search configuration will be set to "english".
    
    creating directory /usr/local/pgsql/data ... ok
    creating subdirectories ... ok
    selecting default max_connections ... 40
    selecting default shared_buffers ... 28MB
    creating configuration files ... ok
    creating template1 database in /usr/local/pgsql/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
    
    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:
    
        /usr/local/bin/postgres -D /usr/local/pgsql/data
    or
        /usr/local/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
    
    

  5. Create a log directory:

    
    # mkdir /var/log/postgresql
    # chown pgsql /var/log/postgresql
    # chgrp pgsql /var/log/postgresql
    
    

  6. Edit the PostGreSQL configuration file:

    
    # vi /data/pgsql/postgresql.conf
    
    Set:
    
    # - Connection Settings -
    
    listen_addresses = '*'  # what IP address(es) to listen on;
    
    
    # - Where to Log -            
    
    #log_destination = 'syslog'
    log_destination = 'stderr'             # Valid values are combinations of
    
    logging_collector = on          # Enable capturing of stderr and csvlog
    
    # These are only used if logging_collector is on:
    log_directory = '/var/log/postgresql'   # directory where log files are written,
    
    log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern,
    
    log_rotation_size = 10MB                # Automatic rotation of logfiles will
    
    

  7. Edit the PostGreSQL Client Authentication Configuration File:

    
    # vi /data/pgsql/pg_hba.conf
    
    Add:
    
    #IPv4 cse connections:
    host    all         all         128.205.0.0/16        md5
    
    

  8. Replace the postgresql start-script with the postgresql distribution's contributed FreeBSD start-script:
    
    [lethe] % cd /src/util/postgresql-8.4.10/contrib/start-scripts
    [lethe] start-scripts% scp freebsd tethys:/tmp
    
    [tethys] ~% cd /usr/local/etc/rc.d
    [tethys] rc.d% sudo mv /tmp/freebsd .
    [tethys] rc.d% sudo chown root freebsd
    [tethys] rc.d% sudo mv freebsd postgresql
    [tethys] rc.d% sudo chmod 755 postgresql
    
    

    ... then edit the new postgresql start-script to suit our environment:

    
    ## EDIT FROM HERE
    
    # Installation prefix
    prefix=/usr/local/
    
    # Data directory
    PGDATA="/data/pgsql"              
    
    # Who to run the postmaster as, usually "postgres".  (NOT "root")
    PGUSER=pgsql
    
    # Where to keep a log file
    PGLOG="/var/log/postgresql"                 
    
    ## STOP EDITING HERE
    
    

    And change all instances of su -l to su.

  9. Manually start the PostGreSQL server:

    
    # /usr/local/etc/rc.d/postgresql start
    
    

  10. Add members to the pgsql group:

    
    # vi /etc/group
    
    pgsql:*:70:cwmiller,kensmith,kpcleary,mrf8