$Id: README,v 1.56 2004/06/26 14:13:29 jt Exp $

Abstract:

This is the README for the Cygwin PostgreSQL distribution.

PostgreSQL is an advanced Object-Relational database management system
(DBMS) that supports almost all SQL constructs (including transactions,
subselects and user-defined types and functions).

The Cygwin PostgreSQL package is very monolithic compared its RPM
counterparts and its contents is roughly analogous to the aggregation
of the following PostgreSQL RPMs:

    postgresql-contrib
    postgresql-devel
    postgresql-docs
    postgresql-jdbc
    postgresql-libs
    postgresql-perl
    postgresql-python
    postgresql-server

Requirements:

The following packages or later are required to build and/or execute
Cygwin PostgreSQL:

    crypt 1.1-1
    cygrunsrv 1.0-1
    cygwin 1.5.10-3
    gcc 3.3.1-3
    libncurses7 5.3-4
    libreadline5 4.3-5
    openssl 0.9.7d-1
    perl 5.8.2-1
    readline 4.3-5
    zlib 1.2.1-1

    Sun JDK 1.4.1
    Ant 1.5

Install:

There are two types of Cygwin PostgreSQL installations -- basic and NT
services.  The basic installation is good for casual use on any version of
Windows, but required on Windows 9x/Me.  The NT services installation is
good for a more production environment, but is only available on Windows
NT/2000/XP.  Note that this installation type is very similar to the normal
Unix installation with just some Cygwin/Windows variations.  You should
choose the type which best meets your needs and/or is constrained by your
platform.

Regardless of the installation type, the first step is to add "server" to
your CYGWIN environment variable setting and start cygserver.  See the
cygserver README:

    /usr/share/doc/cygwin/cygserver.README

for more details.  If the CYGWIN variable is not set correctly and/or
cygserver is not running then initdb and postmaster will fail to run
properly.

The following is the basic Cygwin PostgreSQL installation procedure (skip if
using the NT services installation below):

1. Install and configure cygserver:

    $ cygserver-config

2. Start cygserver:

    $ /usr/sbin/cygserver &

3. Initialize PostgreSQL:

    $ initdb -D /var/postgresql/data

4. Start the PostgreSQL postmaster:

    $ postmaster -D /var/postgresql/data &

5. Connect to PostgreSQL:

    $ psql template1

The following is the NT services Cygwin PostgreSQL installation procedure
(with footnotes designated by "[n]"):

1. Install and configure cygserver as a NT service:

    # cygserver-config

2. Create the "postgres" user account:

    # net user postgres $password /add /fullname:postgres /comment:'PostgreSQL user account' /homedir:"$(cygpath -w /home/postgres)" # [11]
    # mkpasswd -l -u postgres >>/etc/passwd

3. Grant the "postgres" user the "Log on as a service" user right:

    # cmd /c secpol.msc # [3] [4] [5] [12]

4. Install postmaster as a NT service:

    # cygrunsrv --install postmaster --path /usr/bin/postmaster --args "-D /var/postgresql/data -i" --dep cygserver --termsig INT --user postgres --shutdown # [6]

5. Create the PostgreSQL data directory:

    # mkdir -p /var/postgresql/data

6. Change ownership of the PostgreSQL data directory:

    # chown postgres /var/postgresql/data # [10]

7. Start cygserver:

    # cygrunsrv -S cygserver # [7]

8. Initialize PostgreSQL (*when running under the "postgres" account*):

    $ initdb -D /var/postgresql/data

9. Start postmaster:

    # cygrunsrv -S postmaster # [7]

10. Verify postmaster is running:

    # cygrunsrv -Q postmaster  [13]

11. Connect to PostgreSQL:

    # psql -U postgres template1 # [8] [9]

The following are the notes to the above:

[1] The "#" prompt indicates running as a user which is a member of the
    Local Administrators group under bash.
[2] The "$" prompt indicates running as the "postgres" user under bash.
    Log in as "postgres" or use ssh to emulate Unix's "su" command.
[3] Sorry, but I don't know of a generally available command line way of
    setting user rights.
[4] On Windows 2000 and XP Pro, this starts the "Local Security Settings"
    applet.  On Windows NT 4.0, start User Manager, select Policies, and then
    select User Rights...
[5] See http://support.microsoft.com/default.aspx?scid=KB;en-us;q259733 for
    a Microsoft KB article explaining how to configure user rights.
[6] Clean postmaster shutdown will only work with a post Cygwin 1.3.2
    snapshot from 2001-Jul-28 or later.
[7] Cygwin's bin directory (e.g., C:\Cygwin\bin) must be added to the
    Windows NT/2000's system PATH and the machine rebooted for the SCM
    to find cygwin1.dll.
[8] Actually, psql can run under any user account.
[9] One can use PostgreSQL's createuser command or set PGUSER to obviate
    the need to specify "-U postgres" on the psql command line.
[10] Assumes that ntsec is set via the CYGWIN environment variable.
[11] $password is the password for the postgres user account.
[12] On Windows XP Home, there is no built in way to assign user rights --
     use editrights instead:

         $ editrights -u postgres -a SeServiceLogonRight

[13] If postmaster fails to start, then examine /var/log/postmaster.log
     and/or the NT Event Log.

Source:

As configured, the PostgreSQL source builds OOTB under Cygwin.

I also added the following files to the source archive:

    CYGWIN-PATCHES/README
    CYGWIN-PATCHES/build.sh

and renamed the original source archive to match Cygwin's setup.exe
naming conventions.

Build:

This distribution has been configured as follows:

    configure --enable-multibyte --with-python --with-perl --with-java --with-CXX --with-openssl --prefix=/usr --sysconfdir=/etc --datadir=/usr/share --mandir=/usr/share/man --docdir=/usr/share/doc/postgresql-$version

where $version is the PostgreSQL version (e.g., 7.3).

See CYGWIN-PATCHES/build.sh in the source archive for my exact build
recipe for configuring, making, and packaging this distribution.

Test:

On NT/2000/XP, Cygwin PostgreSQL passes all regression tests.

On 9X/ME, it has been reported that Cygwin PostgreSQL hangs at random
places during the regression test.  Unfortunately, at the time of this
writing, no one has tracked down the root cause of these hangs.

Issues:

1. make check can generate spurious regression test failures due to
overflowing the listen() backlog queue which generates connection
refused errors.  One can workaround this (Winsock) limitation, by running
the regression test as follows:

    $ make MAX_CONNECTIONS=5 check

2. Cygwin PostgreSQL only supports the "C" locale because Cygwin itself
does not fully support locales.  This implies the LANG environment variable
must be unset or set to "C".  Otherwise, initdb will fail.

3. Cygwin PostgreSQL can fail to start or not function properly if certain
files and directories have incorrect permissions.  The following usually
solves these kinds of problems:

    $ chmod a+rwx /tmp
    $ chmod a+rx /usr/bin /usr/bin/*
    $ chmod a+rw /var/log # could adversely affect other daemons

4. It may be necessary to increase cygserver's system wide maximum number of
semaphores (SEMMNS).  This change is affected by editing /etc/cygserver.conf,
setting the following parameter:

    kern.ipc.semmns 100

and restarting cygserver.  Otherwise, PostgreSQL can fail to operate properly.
For example, initdb will fail if postmaster is already running.

Homepage:

The primary PostgreSQL web site is:

    http://www.postgresql.org

Download:

The primary PostgreSQL ftp site is:

    ftp://ftp.postgresql.org

Mailing Lists:

Please report problems, suggestions, etc. dependent on their nature to one of
the following:

    pgsql-cygwin@postgresql.org
    cygwin@cygwin.com

Maintainer:

    Jason Tishler <jason@tishler.net>
