081:114G Fall 2008
Data Base Management Systems(3 hours)
Motes on Running PostgreSQL under Cygwin and Vbox/Ubuntu
Last updated: September 14, 2008

  • Running PostgreSQL on Ubuntu and Cygwin:
    # Some of these commands are for Cygwin only while
    # others are for Ubuntu and/or both.
    
    # Postgresql should have been installed with
    # Cygwin if you followed my notes.
    
    # To get Postgresql in Ubuntu, go to System | Administration | Synaptic Package Manager.
    # Start the package manager then search for Postgresql. It will display many
    # line of packages that use the word Postgresql. Scroll down to the line that
    # begins with an Ubuntu logo and has the name postgresql.Click the line and
    # mark for installation.  This will cause a box to appear indicating additional
    # dependant software needed. Accept this. Several boxes will now be checked.
    # Notice the version number (8.3 at the moment). Scroll down and click
    # the line for the documentation corresponding to the highest version number.
    # Click Apply from the menu bar on the top and confirm the installation.
    # When done, the package manager will take some time to redisplay the
    # available packages. Do not kill it until it has finished.
    
    # create and set environment variable
    # do not do these next two lines for Linux installs
    
    CYGWIN=server (Cygwin)
    export CYGWIN (Cygwin)
    
    # start the server facility (not part of PostgreSQL but needed)
    # do not do the following command for Linux.
    
    /usr/sbin/cygserver.exe & (Cygwin)
    
    # Note: the above 3 commands must be executed everytime you start 
    # up Cygwin and use Postgresql. They do not apply to Ubuntu.
    
    # Cygwin installs the executables in /usr/sbin.  
    
    # Ubuntu puts the executables /usr/lib/postgres/8.2/bin. 
    
    # Other distros hide them elsewheres. Try /usr/local.
    
    # For Ubuntu, do not be root for the commands below. 
    # There is no such state as root for Cygwin.
    
    # In Ubuntu, go to your users and groups management utility 
    # and place your logon id in the same group as postgres.
    # if not, permissions will cause problems.
    
    # Go to: System | Administration | Users and Groups
    
    # Click Unlock button and enter password.
    
    # Click Manage Groups. Click postgres (scroll down)
    
    # Click Properties. Check the box next to your name.
    
    # This makes you a member of the postgres group.
    # exit from these boxes. Shutdown Ubuntu and restart
    # for these to take effect.
    
    # The above does not apply to Cygwin. The above is done only
    # once.
    
    # Create a PostgreSQL data base file cluster
    # you will be prompted to create a password.
    
    # the example creates the database cluster
    # in /usr/local/pgsql/data in Cygwin and
    # the directory DB in your home directory
    # in Ubuntu. 
    
    # Because the directory containing the PostgreSQL code
    # id not in your search path, you need to add this
    # directory it to your search path. To do this, in your
    # home directory, edit the file .bashrc (not normally
    # visible because it begins with a '.' character.
    # You may want to make a backup first:
    
    cd
    cp .bashrc .bashrc-backup
    
    # Add the following line to the end of the file:
    
    PATH=$PATH:.:/usr/sbin:                     (Cygwin)
    PATH=$PATH:.:/usr/lib/postgresql/8.3/bin:   (Ubuntu)
    
    Change 8.3 as needed for the release you have.
    
    Logout/logon to make it take effect.
    
    # by default, when you install PostgreSQL, Ubuntu will
    # configure a database in /var/lib/postgres/8.3/main and 
    # automatically start the server each time you logon.  
    # You can turn off the auto start by modifying the file :
    # /etc/postgresql/8.3/main/start.conf
    # other configureation opetions can be found here as well.
    
    # If you want to run the database manually, you need to
    # create your own and then start it. To do this,
    # type the following commands. Note: you must doe these
    # for Cygwin.  Skip the following if you will use the default 
    # Ubuntu install.
    
          initdb -D /usr/local/pgsql/data -W -E LATIN1 (Cygwin)
          initdb -D ~/DB/data -W  (Ubuntu)
    
          # The above commands are done only once. They are not repeated
          # unless you create a new database cluster.
    
          # Ubuntu only: modify the startup procedures. As root:
    
          cd /etc/postgresql/8.3/main
    
          # Edit start.conf's last line to read manual rather than auto.
          # Reboot your system for this to take effect.
          # This is done only once. The reboot is required.
    
          # The following commands start PostgreSQL:
    
          postmaster -D /usr/local/pgsql/data & (Cygwin)
          postmaster -D ~/DB/data & (Ubuntu)
    
          # The mmediately above commands are done each time you start postgresql.
          # They start the background deamon that will process requests.
    
    # Optional: Add users. change "username" as needed. This is
    # for multiuser systems.  Note: your login name is already an 
    # authorized user if you did the manual commands above.
    
    # To add users:
    # 1. As root, create a password for user postgres.
    # 2. login as postgres and do the following command:
    
          createuser username 
    
    # say yes to the super user question if you want to be able to
    # control PostgreSQL from your own account.
    
    # the above is done only once unless you want to add users again.
    
    # create a test data base named medical
    
          createdb medical
    
    # The above is done only once. It creates an empty database in the cluster.