Setting up PostgreSQL



Similar documents
OpenGeo Suite for Linux Release 3.0

IUCLID 5 Guidance and support. Installation Guide Distributed Version. Linux - Apache Tomcat - PostgreSQL

PetaLinux SDK User Guide. Application Development Guide

XGenPlus Installation Guide

3. License Management - Unix & Linux

2015 Exelis Visual Information Solutions, Inc., a subsidiary of Harris Corporation

1. Product Information

Online Backup Client User Manual Linux

Net/FSE Installation Guide v1.0.1, 1/21/2008

Partek Flow Installation Guide

RecoveryVault Express Client User Manual

SAS 9.4 In-Database Products

System Resources. To keep your system in optimum shape, you need to be CHAPTER 16. System-Monitoring Tools IN THIS CHAPTER. Console-Based Monitoring

Online Backup Linux Client User Manual

Online Backup Client User Manual

SendMIME Pro Installation & Users Guide

LifeKeeper for Linux PostgreSQL Recovery Kit. Technical Documentation

How to Set Up pgagent for Postgres Plus. A Postgres Evaluation Quick Tutorial From EnterpriseDB

Unix Sampler. PEOPLE whoami id who

Online Backup Client User Manual

Using ORACLE in the CSLab

MySQL Backups: From strategy to Implementation

Incremental Backup Script. Jason Healy, Director of Networks and Systems

Table of Contents. V. UPGRADING LSTC License Manager Software for Microsoft Windows A. Run the Installation Program B. Verify the Installation

Introduction to Operating Systems

PMOD Installation on Linux Systems

Linux command line. An introduction to the Linux command line for genomics. Susan Fairley

AXIOM 4 AXIOM SERVER GUIDE

Installing IBM Websphere Application Server 7 and 8 on OS4 Enterprise Linux

MapGuide Open Source Repository Management Back up, restore, and recover your resource repository.

This presentation explains how to monitor memory consumption of DataStage processes during run time.

DiskPulse DISK CHANGE MONITOR

AlienVault Unified Security Management (USM) 4.x-5.x. Deploying HIDS Agents to Linux Hosts

SimbaEngine SDK 9.4. Build a C++ ODBC Driver for SQL-Based Data Sources in 5 Days. Last Revised: October Simba Technologies Inc.

Magento Search Extension TECHNICAL DOCUMENTATION

Secure File Transfer Installation. Sender Recipient Attached FIles Pages Date. Development Internal/External None 11 6/23/08

Thirty Useful Unix Commands

Code Estimation Tools Directions for a Services Engagement

CS 103 Lab Linux and Virtual Machines

PAYMENTVAULT TM LONG TERM DATA STORAGE

PuTTY/Cygwin Tutorial. By Ben Meister Written for CS 23, Winter 2007

TNM093 Practical Data Visualization and Virtual Reality Laboratory Platform

Hands-On UNIX Exercise:

NRPE Documentation CONTENTS. 1. Introduction... a) Purpose... b) Design Overview Example Uses... a) Direct Checks... b) Indirect Checks...

Security Correlation Server Backup and Recovery Guide

Monitoring PostgreSQL database with Verax NMS

Building and Using NX Open Source Components version 3.X

Windows PowerShell Cookbook

ADSMConnect Agent for Oracle Backup on Sun Solaris Installation and User's Guide

Basic C Shell. helpdesk@stat.rice.edu. 11th August 2003

Linux System Administration. System Administration Tasks

PostgreSQL 9.0 Streaming Replication under the hood Heikki Linnakangas

Secure Shell Demon setup under Windows XP / Windows Server 2003

LAE Enterprise Server Installation Guide

Table of Contents. The RCS MINI HOWTO

Lab 2: PostgreSQL Tutorial II: Command Line

SysPatrol - Server Security Monitor

UNIX / Linux commands Basic level. Magali COTTEVIEILLE - September 2009

Backup of ESXi Virtual Machines using Affa

SWsoft Plesk 8.3 for Linux/Unix Backup and Restore Utilities

Installing FEAR on Windows, Linux, and Mac Systems

Java Language Tools COPYRIGHTED MATERIAL. Part 1. In this part...

IBM WebSphere Application Server Version 7.0

HARFORD COMMUNITY COLLEGE 401 Thomas Run Road Bel Air, MD Course Outline CIS INTRODUCTION TO UNIX

BACKUP YOUR SENSITIVE DATA WITH BACKUP- MANAGER

Installing HSPICE on UNIX, Linux or Windows Platforms

Backup Agent. Backup Agent Guide

SQL Server Instance-Level Benchmarks with DVDStore

Leak Check Version 2.1 for Linux TM

SWsoft Plesk 8.2 for Linux/Unix Backup and Restore Utilities. Administrator's Guide

Cisco Setting Up PIX Syslog

ConcourseSuite 7.0. Installation, Setup, Maintenance, and Upgrade

Integrating SNiFF+ with the Data Display Debugger (DDD)

Pervasive Backup Agent Guide

ODBC Driver User s Guide. Objectivity/SQL++ ODBC Driver User s Guide. Release 10.2

MatrixSSL Getting Started

ROUNDTABLE TSMS 11.5 Installation Guide

Workflow Templates Library

Configuring MailArchiva with Insight Server

KretchmarBook 2003/8/29 19:05 page 39 #51

Instructions for update installation of ElsaWin 5.00

SQL 2012 Installation Guide. Manually installing an SQL Server 2012 instance

Compiere ERP & CRM Installation Instructions Linux System - EnterpriseDB

Using Network Attached Storage with Linux. by Andy Pepperdine

This document presents the new features available in ngklast release 4.4 and KServer 4.2.

Site Configuration SETUP GUIDE. Windows Hosts Single Workstation Installation. May08. May 08

OroTimesheet 7 Installation Guide

24/08/2004. Introductory User Guide

vcenter Operations Management Pack for SAP HANA Installation and Configuration Guide

4PSA Total Backup User's Guide. for Plesk and newer versions

LSN 10 Linux Overview

How To Install An Aneka Cloud On A Windows 7 Computer (For Free)

Open-Xchange Server Backup Whitepaper

Forming a P2P System In order to form a P2P system, the 'central-server' should be created by the following command.

How To Run A Standby On Postgres (Postgres) On A Slave Server On A Standby Server On Your Computer (Mysql) On Your Server (Myscientific) (Mysberry) (

insync Installation Guide

SAS Scalable Performance Data Server 5.1

Using ESXi with PowerChute Business Edition

WS_FTP Server. User s Guide. Software Version 3.1. Ipswitch, Inc.

Transcription:

Setting up PostgreSQL 1 Introduction to PostgreSQL PostgreSQL is an object-relational database management system based on POSTGRES, which was developed at the University of California at Berkeley. PostgreSQL is an open-source descendant of this original Berkeley code. 2 Installation of PostgreSQL This section describes how to download, install and use PostgreSQL version 8.1.4. This is the version that will be used for all assignments in this course. A compressed tar archive containing the PostgreSQL version 8.1.4 source code can be found in the CS448 course account as /u/cs448/public/postgresql-8.1.4.tgz. This same archive can be downloaded via the Web though the link that can be found on the CS448 course web page. For a more complete installation guide, refer to the INSTALL file, which is included with the PostgreSQL source code. You can install PostgreSQL on your own machine, or in your account in the CS student computing environment. 2.1 Installing PostgreSQL in the CS Student Computing Environment First, log in to a Linux server in the student.cs computing environment. The simplest way to do this is to log in to linux.student.cs.uwaterloo.ca. This is a load balancing alias which will automatically choose a specific Linux server to log you into. Alternatively, you can choose a specific Linux server and log in directly to that server. A list of available Linux servers in the student computing environment can be found at http://www.cs.uwaterloo.ca/cscf/student/hosts.shtml. Make sure you choose a Linux server. Next, from your home directory, extract a copy of the PostgreSQL source from the course account: tar xzf /u/cs448/public/postgresql-8.1.4.tgz This may take a few minutes. It should create a new directory called postgresql-8.1.4 containing a complete copy of the PostgreSQL source code. PostgreSQL is large. You will need about 70MB of space to hold the unpacked source code. By the time you have built and installed PostgreSQL, you will be consuming about 200MB of space. If you are registered for CS448/648, you should have plenty of disk quota to allow you to work with PostgreSQL, provided that you did not filled your quota with unrelated stuff! You can check your disk quota and disk usage using the diskquota command. In your home directory, do mkdir pgbuild This creates a pgbuild directory in which the PostgreSQL binaries and libraries will be placed once they have been built. Next, cd into the postgresql-8.1.4 directory, which was created when you unpacked the PostgreSQL distribution, and configure PostgreSQL like this:./configure --prefix=$home/pgbuild CFLAGS= -g -O0 --enable-debug --enable-cassert --with-maxbackends=3 The two configuration arguments, --enable-debug and --enable-cassert, are used to enable debugging of PostgreSQL code and assertions, respectively. The CFLAGS setting also simplifies debugging by turning off compiler optimizations. Note that in the -O0 in the CFLAGS setting, the first character is an upper-case letter O, and the second is the digit 0 (zero). 1

make Then, build PostgreSQL by running Again, this make take a few minutes. You may see warnings during the build, but it should complete successfully. Next, install PostgreSQL into your pgbuild directory by running: make install At this point, PostgreSQL has been built and installed in your $HOME/pgbuild directory. Before running PostgreSQL commands, you will need to set your PATH and LD LIBRARY PATH environment variables so that the PostgreSQL binaries and libraries can be found. csh and tcsh users should do this in their.cshrc file. Look for a line like this: setenv PATH /bin/showpath $HOME/bin standard and add $HOME/pgbuild/bin to the list, similar to this: setenv PATH /bin/showpath $HOME/bin $HOME/pgbuild/bin standard Assuming LD LIBRARY PATH is not already being defined somewhere in the file, you should also define that variable using a line like this: setenv LD LIBRARY PATH $HOME/pgbuild/lib Users of sh or bash should make similar changes in their.profile or.bashrc file. The syntax is slightly different, but should be self-explanatory. You may need to log out and log back in again to get these environment variable settings to take effect. The next step is to create a directory in which to host the database and related server state: initdb -D $HOME/pgdb This will initialize the database in a pgdb directory under your home directory. If you wish, you can choose a different directory name. Last but not least, you should ensure that your copy of the PostgreSQL code is not visible to others. In your home directory, issue the following command: chmod 700 postgresql-8.1.4 You should now be able to start the database server. The most convenient way to run PostgreSQL is to use two separate shell command windows. In one window, you will launch the server. In the other window, you will run programs that issue commands to the server. To use this method, you must be logged in to the same Linux machine in both windows. You can check which machine you are logged into in a particular window by running the hostname command. Once you have two command windows on the same machine, launch the PostgreSQL server in one window using the following command: postmaster -p <port-number> -D $HOME/pgdb Note that because you are running the PostgreSQL server on a shared host, you have to use a port number other than the default one to avoid conflicts with other instances of PostgreSQL initiated by other students. This is the purpose of the -p flag. Legitimate port numbers are greater than 1024 and less than or equal to 65536. To minimize the likelihood of conflicts, choose a random port number with 5 digits (i.e., greater than 10000). In the other window, you can now run PostgreSQL client programs and utilities that issue commands to the PostgreSQL server that you just launched. You tell these client progams how to find the server by specifying, as a command line parameter to the client, the port number that is being used by your server. For example, you can use the createdb utility to create a new database. To create a new database named mytest, you would use the command 2

createdb -p <port-number> mytest Here, the port number that you specify must match the one with which you launched your server. One client that you will need to use is psql, which gives you a simple, text-based command interface that you can use to issue SQL commands to the database server, and view the results of those commands. If you created a test database called mytest, you can launch psql on your test database like this: psql -p <port-number> mytest You can now use the psql client to interactively create tables, insert data, and issue queries. A sample script that creates two tables and performs a number of queries can be found at postgresql-8.1.4/src/tutorial/basics.source To quit the interactive client, use the psql command \q. psql also has on-line help available, which you can access using the \? psql command. Further documentation for psql, as well as all of the other PostgreSQL clients, can be found in Section VI-II of the on-line PostgreSQL documentation, which is linked to by the course web page. When you are finished running PostgreSQL client programs, please shut down your PostgreSQL server, so that unused servers do not clog up the student.cs Linux machines. You can shut down your PostgreSQL server by simply typing control-c in the server s window. The server should output some log information indicating that it is shutting down, like this ^CLOG: received fast shutdown request LOG: shutting down LOG: database system is shut down That s all that s necessary. You can double-check that you have no PostgreSQL servers running by using the ps command, which can show all of the processes that you have running on a machine: ps ux This should give you a list of processes, like this: USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND kmsalem 4721 0.0 0.0 69528 2700? S 12:44 0:00 sshd: kmsalem@p kmsalem 5007 0.0 0.0 21944 2516 pts/0 Ss 12:44 0:00 -tcsh kmsalem 6259 0.0 0.0 69012 2156? S 12:57 0:00 sshd: kmsalem@p kmsalem 6347 0.0 0.0 21944 2488 pts/4 Ss 12:57 0:00 -tcsh kmsalem 9523 0.0 0.0 7228 1468 pts/0 R+ 13:20 0:00 ps ux kmsalem 27552 0.6 0.0 39772 3324 pts/4 S+ 13:19 0:00 postmaster -p 4 kmsalem 27793 0.0 0.0 39772 984 pts/4 S+ 13:19 0:00 postgres: write kmsalem 27794 0.0 0.0 29952 752 pts/4 S+ 13:19 0:00 postgres: stats kmsalem 27795 0.0 0.0 29140 940 pts/4 S+ 13:19 0:00 postgres: stats If you see any postmaster processes (as in the above example), you have a PostgreSQL server running. You can kill any such servers using the kill command, specifying the process ID (PID) of the postmaster process. In the example above, the PID of postmaster is 27552, so you can kill it with: kill -INT 27552 You can use ps again to make sure that PostgreSQL is really dead. 2.2 Installing PostgreSQL on Your Own Linux Machine You should be able to install CS448 s version of PostgreSQL on your own Linux machine by following the instructions for installation in the student.cs computing environment. You will not be able to extract the PostgreSQL code directly from the course account. Instead, you can download a compressed tar archive of the PostgreSQL source code using the link on the course web page, and then unpack your copy of the archive using tar: 3

tar xzf postgresql-8.1.4.tgz This will create the postgresql-8.1.4 directory, in which you can configure and build PostgreSQL. If PostgreSQL fails to configure or make, it may because you are missing software packages required by PostgreSQL. One common problem is missing readline packages. On Ubuntu, make sure you have both libreadline and libreadline-dev installed. Other package-based Linux distributions should have similar packages. Support for zlib may also be missing. On Ubuntu, make sure that zlib1g-dev is installed if the PostgreSQL configuration complains about lack of zlib support. 3 Modifying PostgreSQL Source Code Course assignments will require that you add or modify PostgreSQL source files. Before modifying PostgreSQL files, make sure that you have a backup copy of the original file so that you can always undo your modifications. Note that after making changes to PostgreSQL files, you should clean the built version using make clean before rebuilding from the modified source code. This is particularly important if you have modified header files. Before each assignment, you should start with a fresh copy of the PostgreSQL source code. Each assignment is standalone, i.e. the assignments are not incremental. 4 Debugging PostgreSQL PostgreSQL is a client/server system, meaning that a user runs a client process, like the psql command interpreter, which talks to a postgres server process. The main PostgreSQL server, called postmaster, spawns a separate postgres server process for each client connection. There are two main methods that can be used for debugging. The first method is to print out debugging information (e.g. variables values) from within the server process. The second method is to use a debugging facility to insert breakpoints at interesting locations and inspect the variables values and the flow of control. 4.1 Printing Server Debugging Information To insert debugging statements into PostgreSQL server code, use the elog() function, with the first argument being DEBUG1. Note that elog() takes a message string as its main argument; to construct such a string you may want to use the sprintf() routine. You ll find examples of the use of elog() in the nbtinsert.c file, which you will be working on for Assignment 1. To get elog() messages to be displayed by the server, you should use the -d 1 flag when you launch the postmaster, e.g., postmaster -d 1 -p <port-number> -D $HOME/pgdb The server will display your debug messages in its log, which is normally sent to the server process s stderr output. 4.2 Using a Debugger You may use any available debugger, such as gdb, to debug PostgreSQL server code. To start debugging a PostgreSQL server process on a local machine, you first need to startup the server (i.e., postmaster), and the client (i.e., psql). Then, you must attach the debugger to the PostgreSQL server process that is serving your psql client. To do this using gdb, open another shell window on the same host on which your PostgreSQL server is running. This should leave you with three separate windows: one for the server, one for the client program (e.g., psql), and one for the debugger. In the debugger window, enter the command: ps ux grep post 4

This will give you a list of your PostgreSQL server processes. Assuming you have launched the PostgreSQL server and one psql client connected to a database called mytest, your process list should look something like this. kmsalem 13052 0.2 0.0 40448 2132 pts/4 S+ 14:00 0:00 postgres: kmsalem mytest [local] idle kmsalem 14019 0.0 0.0 39772 3328 pts/4 S+ 13:57 0:00 postmaster -p 45454 -D /u5/kmsalem/pgdb kmsalem 14601 0.0 0.0 39772 912 pts/4 S+ 13:57 0:00 postgres: writer process kmsalem 14603 0.0 0.0 29952 732 pts/4 S+ 13:57 0:00 postgres: stats buffer process kmsalem 14605 0.0 0.0 29140 936 pts/4 S+ 13:57 0:00 postgres: stats collector process kmsalem 16064 0.0 0.0 7344 864 pts/6 S+ 14:01 0:00 grep post Each line corresponds to a process, and the second entry on each line is a process id. The process labeled: postgres: kmsalem mytest [local] idle is the PostgreSQL server process that is serving your psql client. This is the process you want to connect the debugger to. In this case, its process ID (PID) is 13052. Once you have identified the correct process id, launch the debugger: gdb postgres At the gdb command prompt, enter attach <process-id> where <process-id> is the PostgreSQL server process id that you just identified: 13052 in the example above. Attaching gdb to the PostgreSQL server process will cause the server process to pause, so that you can use the debugger to inspect code and variables, set breakpoints, and so on. Issue gdb s continue command when you are ready to let the server process continue running. If you wish to exit gdb without killing the PostgreSQL server process, you can issue a detach command to gdb. 5 Documentation The main source for PostgreSQL information is the official documentation, to which there is a link from the course web page. In the source code, you will find README files within each component directory (e.g. parser, executor and optimizer components). Comments found in the PostgreSQL code are particularly helpful in understanding how PostgreSQL functions are implemented. 5