head	1.15;
access;
symbols
	REL7_0_PATCHES:1.14.0.2
	REL7_0:1.14
	REL6_5_PATCHES:1.3.0.2
	REL6_5:1.3;
locks; strict;
comment	@# @;


1.15
date	2000.06.02.02.27.59;	author momjian;	state dead;
branches;
next	1.14;

1.14
date	2000.02.14.12.29.58;	author momjian;	state Exp;
branches;
next	1.13;

1.13
date	99.12.29.22.57.16;	author momjian;	state Exp;
branches;
next	1.12;

1.12
date	99.12.29.10.27.59;	author momjian;	state Exp;
branches;
next	1.11;

1.11
date	99.11.12.17.05.08;	author momjian;	state Exp;
branches;
next	1.10;

1.10
date	99.09.28.13.08.10;	author momjian;	state Exp;
branches;
next	1.9;

1.9
date	99.09.28.01.43.00;	author momjian;	state Exp;
branches;
next	1.8;

1.8
date	99.09.27.19.55.48;	author momjian;	state Exp;
branches;
next	1.7;

1.7
date	99.09.27.18.32.58;	author momjian;	state Exp;
branches;
next	1.6;

1.6
date	99.09.24.05.58.42;	author inoue;	state Exp;
branches;
next	1.5;

1.5
date	99.08.01.14.48.50;	author momjian;	state Exp;
branches;
next	1.4;

1.4
date	99.07.18.18.03.48;	author momjian;	state Exp;
branches;
next	1.3;

1.3
date	99.07.09.21.46.13;	author momjian;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	99.07.07.16.41.18;	author momjian;	state Exp;
branches;
next	1.1;

1.1
date	99.06.16.18.09.59;	author momjian;	state Exp;
branches;
next	;

1.3.2.1
date	99.07.19.05.08.23;	author momjian;	state Exp;
branches;
next	1.3.2.2;

1.3.2.2
date	99.09.27.18.33.21;	author momjian;	state Exp;
branches;
next	1.3.2.3;

1.3.2.3
date	99.09.27.19.56.02;	author momjian;	state Exp;
branches;
next	1.3.2.4;

1.3.2.4
date	99.09.28.01.43.20;	author momjian;	state Exp;
branches;
next	1.3.2.5;

1.3.2.5
date	99.09.28.13.08.27;	author momjian;	state Exp;
branches;
next	1.3.2.6;

1.3.2.6
date	99.11.12.17.05.24;	author momjian;	state Exp;
branches;
next	1.3.2.7;

1.3.2.7
date	2000.01.02.01.38.47;	author momjian;	state Exp;
branches;
next	;


desc
@@


1.15
log
@Update faq's.
@
text
@Installing PostgreSQL on NT:

---------------------------------------------------------------------------

It can be done by done by typing configure, make and make install.

1. Install the Cygwin package
2. Update to EGCS 1.1.2
   (This may be optional.)

---------------------------------------------------------------------------

				OPTIONAL

1. Install the Andy Piper Tools (http://www.xemacs.freeserve.co.uk/)
   (This may be optional.)
   You need at least the crypt library (also available as
   ftp://sourceware.cygnus.com/pub/cygwin/xfree/libcrypt-cygwin-b20.1.tar.bz2)

---------------------------------------------------------------------------

			  CYGWIN32 INSTALLATION

1. Download the Cygwin32 IPC Package by Ludovic LANGE 
   http://penguin.cz/~horak/cygwin32_ipc-1.03.tar.gz
2. Untar the package and follow the readme instructions.
3. Apply the patch at the end of this file to the cygipc sources
   before compiling the library.
4. I tested 1.03.
5. I used the \cygwin-b20\h-i568-cygwin32\i586-cygwin32\lib and
\cygwin-b20\h-i568-cygwin32\i586-cygwin32\include\sys instead of the
/usr/local/lib and usr/local/include/sys.

NOTE:
Also, the cygnus-bindir has to be placed in the path before the
NT-directories, because the sort.exe has to be taken for cygnus, not
NT.

---------------------------------------------------------------------------

		   POSTGRESQL INSTALL WITH NT SPECIFICS

1. Download the current version of PostgreSQL.
2. Untar the package.
3. Copy the files from \pgsql\src\win32 according to the readme file.
4. Edit \pgsql\src\template\cygwin32 if needed (I had to adjust the YFLAGS
path).
5. ./configure
6. make
7. create the directory /usr/local/pgsql manually: the mkdir cannot create a
directory 2 levels deep in one step.
8. make install
9. cd /usr/lical/pgsql/doc
10. make install
11. Set the environmental data
12. Initdb --username=jkr (do not run this command as administrator)

13. Open a new Cygwin command prompt
14. Start "ipc-deamon&" (background proces)
15. Start "postmaster -i 2>&1 > /tmp/postgres.log &" (background proces)
16. Start "tail -f /tmp/postgres.log" to see the messages

17. cd /usr/src/pgsql/src/test/regress
18. make all runtest

All test should be run.

NOTE:
By default, PostgreSQL clients like psql communicate using unix domain
sockets, which don't work on NT.  Start the postmaster with -i, and 
when connecting to the database from a client, set the PGHOST
environment variable to 'localhost' or supply the hostname on the
command line.

Joost

PS: If you still have problems you can mail to Dan Horak <dan.horak@@email.cz>
    who is the maintainer for the win32 port

---------------------------------------------------------------------------

*** ./ipc-daemon.c.orig	Tue Dec 01 00:04:24 1998
--- ./ipc-daemon.c	Fri Sep 24 13:34:16 1999
***************
*** 270,285 ****
         {
          itoa(100*id+Index, LBuff) ;
          LHandle = OpenSemaphore(SEMAPHORE_ALL_ACCESS, FALSE, LBuff) ;
! 	while (LAdrSem->current_nb[id].current_nb[Index] > 0 )
! 	{
!     	 WaitForSingleObject(LHandle, 0) ;
! 	 LAdrSem->current_nb[id].current_nb[Index]-- ;
! 	}
! 	CloseHandle(LHandle) ;
         }
         LAdrSem->semary[id] = IPC_UNUSED ;
         LAdrSem->state[id]  = 0 ;
        }
        else
        {
         for (Index = 0; Index < sma->sem_nsems; Index++)
--- 270,284 ----
         {
          itoa(100*id+Index, LBuff) ;
          LHandle = OpenSemaphore(SEMAPHORE_ALL_ACCESS, FALSE, LBuff) ;
!         while (WaitForSingleObject(LHandle, 0) == WAIT_OBJECT_0)
!           ;
!         LAdrSem->current_nb[id].current_nb[Index] = 0;
!         CloseHandle(LHandle) ;
         }
         LAdrSem->semary[id] = IPC_UNUSED ;
         LAdrSem->state[id]  = 0 ;
        }
+ /*
        else
        {
         for (Index = 0; Index < sma->sem_nsems; Index++)
***************
*** 288,293 ****
--- 287,293 ----
          LHandle = OpenSemaphore(SEMAPHORE_ALL_ACCESS, FALSE, LBuff) ;
         }
        }
+ */
       }
      }
  
*** ./msg.c.orig	Tue Dec 01 00:16:09 1998
--- ./msg.c	Fri Sep 17 12:50:50 1999
***************
*** 57,62 ****
--- 57,77 ----
  static int		  GFirstMsg	 = 0;		/*PCPC*/
  static int		  GFdMsg	    ;		/*PCPC*/
  
+ /*****************************************/
+ /*	Initialization of static variables   */
+ /*****************************************/
+ static pid_t GProcessId = 0;
+ static void init_globals(void)
+ {
+ 	pid_t pid;
+ 
+ 	if (pid=getpid(), pid != GProcessId)
+ 	{
+ 		GFirstMsg = 0;
+ 		msgbytes = msghdrs = msg_seq = used_queues = max_msqid = 0;
+ 		GProcessId = pid;
+ 	}
+ }
  /************************************************************************/
  /* Demande d'acces a la zone partagee de gestion des semaphores		*/
  /************************************************************************/
***************
*** 79,84 ****
--- 94,100 ----
  {
   int LRet ;
  
+  init_globals();
   if( GFirstMsg == 0 )
   {
    if( IsGSemMsgExist() )
*** ./sem.c.orig	Tue Dec 01 00:16:25 1998
--- ./sem.c	Fri Sep 17 12:47:11 1999
***************
*** 58,63 ****
--- 58,78 ----
  static int		  GFirstSem	 = 0;		/*PCPC*/
  static int		  GFdSem	    ;		/*PCPC*/
  
+ static pid_t	GProcessId = 0;
+ 
+ static void	init_globals(void)
+ {
+ 	pid_t pid;
+ 
+ 	if (pid=getpid(), pid != GProcessId)
+ 	{
+ 		GFirstSem = 0;
+ 		used_sems = used_semids = max_semid = 0;
+ 		sem_seq = 0;
+ 		GProcessId = pid;
+ 	}
+ }
+ 
  /************************************************************************/
  /* Demande d'acces a la zone partagee de gestion des semaphores		*/
  /************************************************************************/
***************
*** 77,82 ****
--- 92,98 ----
  {
      int LRet ;
  
+ 	init_globals();
      if( GFirstSem == 0 )
      {
  	if( IsGSemSemExist() )
***************
*** 187,193 ****
      {
  	CloseHandle ( LHandle ) ;
      }
!     LHandle = CreateSemaphore(NULL, 0, 0x7FFFFFFF, LBuff) ;
      if( LHandle == NULL )
      {
  	printf( "Creation de Semaphore \"Sem\" impossible\n" ) ;
--- 203,209 ----
      {
  	CloseHandle ( LHandle ) ;
      }
!     LHandle = CreateSemaphore(NULL, 0, 1, LBuff) ;
      if( LHandle == NULL )
      {
  	printf( "Creation de Semaphore \"Sem\" impossible\n" ) ;
***************
*** 357,371 ****
  debug_printf("do_semop : return -EACCES\n");
  			CYGWIN32_IPCNT_RETURN (-EACCES) ;
  		    }
! 		    ReleaseSemaphore(LHandle, sop->sem_op, &LVal) ;
! 	    	    shareadrsem->current_nb[id].current_nb[sop->sem_num] +=
! 					sop->sem_op ;
  		    sem_deconnect() ;
  		} else {
  		    if( sop->sem_flg == IPC_NOWAIT )
  		    {
! 			LRet = WaitForSingleObject(LHandle, 0) ;
! 			if( LRet == WAIT_TIMEOUT )
  			{
  debug_printf("do_semop : return -EAGAIN\n");
  			    CYGWIN32_IPCNT_RETURN (-EAGAIN) ;
--- 373,386 ----
  debug_printf("do_semop : return -EACCES\n");
  			CYGWIN32_IPCNT_RETURN (-EACCES) ;
  		    }
!     	    shareadrsem->current_nb[id].current_nb[sop->sem_num] +=
! 				sop->sem_op ;
  		    sem_deconnect() ;
+ 		    ReleaseSemaphore(LHandle, 1 , &LVal) ;
  		} else {
  		    if( sop->sem_flg == IPC_NOWAIT )
  		    {
! 			if( sop->sem_op + shareadrsem->current_nb[id].current_nb[sop->sem_num] <0 )
  			{
  debug_printf("do_semop : return -EAGAIN\n");
  			    CYGWIN32_IPCNT_RETURN (-EAGAIN) ;
***************
*** 375,390 ****
  debug_printf("do_semop : return -EACCES\n");
  			    CYGWIN32_IPCNT_RETURN (-EACCES) ;
  			}
! 	    		shareadrsem->current_nb[id].current_nb[sop->sem_num] -= 1 ;
  			sem_deconnect() ;
  		    } else {
! 			LRet = WaitForSingleObject(LHandle, INFINITE) ;
  			if (sem_connect() == 0)
  			{
  debug_printf("do_semop : return -EACCES\n");
  			    CYGWIN32_IPCNT_RETURN (-EACCES) ;
  			}
! 			    shareadrsem->current_nb[id].current_nb[sop->sem_num] -= 1 ;
  			    sem_deconnect() ;
  		    }
  		}
--- 390,407 ----
  debug_printf("do_semop : return -EACCES\n");
  			    CYGWIN32_IPCNT_RETURN (-EACCES) ;
  			}
! 	    		shareadrsem->current_nb[id].current_nb[sop->sem_num] += sop->sem_op;
  			sem_deconnect() ;
  		    } else {
! 		    while(sop->sem_op + shareadrsem->current_nb[id].current_nb[sop->sem_num] <0)
! 				LRet = WaitForSingleObject(LHandle, INFINITE) ;
! 		    
  			if (sem_connect() == 0)
  			{
  debug_printf("do_semop : return -EACCES\n");
  			    CYGWIN32_IPCNT_RETURN (-EACCES) ;
  			}
! 			    shareadrsem->current_nb[id].current_nb[sop->sem_num] += sop->sem_op ;
  			    sem_deconnect() ;
  		    }
  		}
***************
*** 435,441 ****
  	char LBuff[100] ;
  	HANDLE LHandle ;
  	long LPrevious ;
- 	int LIndex;
  
  debug_printf("semctl : semid=%X semnum=%X cmd=0x%02X arg=%p\n",semid,semnum,cmd,arg);
  	if (semid < 0 || semnum < 0 || cmd < 0)
--- 452,457 ----
***************
*** 568,589 ****
  		if( LHandle != NULL )
  		{
  		    if( arg.val > shareadrsem->current_nb[id].current_nb[semnum] )
! 		    {
! 			ReleaseSemaphore(LHandle,
! 			arg.val-shareadrsem->current_nb[id].current_nb[semnum],
! 			&LPrevious) ;
! 		    }
! 		    else if (arg.val <
! 		             shareadrsem->current_nb[id].current_nb[semnum] )
! 		    {
! 			for( LIndex = arg.val;
! 			LIndex < shareadrsem->current_nb[id].current_nb[semnum];
! 			LIndex++ )
! 			{
! 			    WaitForSingleObject(LHandle, 0) ;
! 			}
! 		    }
!             	    shareadrsem->current_nb[id].current_nb[semnum] = arg.val ;
  		}
  debug_printf("semctl : SETVAL : return 0\n");
  		CYGWIN32_IPCNT_RETURN_DECONNECT (0);
--- 584,591 ----
  		if( LHandle != NULL )
  		{
  		    if( arg.val > shareadrsem->current_nb[id].current_nb[semnum] )
! 				ReleaseSemaphore(LHandle,1,&LPrevious) ;
!             shareadrsem->current_nb[id].current_nb[semnum] = arg.val ;
  		}
  debug_printf("semctl : SETVAL : return 0\n");
  		CYGWIN32_IPCNT_RETURN_DECONNECT (0);
*** ./shm.c.orig	Fri Sep 17 12:46:24 1999
--- ./shm.c	Fri Sep 17 12:47:11 1999
***************
*** 59,64 ****
--- 59,81 ----
  static int		  GFirstShm	 = 0;		/*PCPC*/
  static int		  GFdShm	    ;		/*PCPC*/
  
+ /*****************************************/
+ /*	Initialization of static variables   */
+ /*****************************************/
+ static pid_t GProcessId = 0;
+ static void init_globals(void)
+ {
+ 	pid_t pid;
+ 
+ 	if (pid=getpid(), pid != GProcessId)
+ 	{
+ 		GFirstShm = 0;
+ 		shm_rss = shm_swp = max_shmid = 0;
+ 		shm_seq = 0;
+ 		GProcessId = pid;
+ 	}
+ }
+ 
  /************************************************************************/
  /* Demande d'acces a la zone partagee de gestion des shm		*/
  /************************************************************************/
***************
*** 82,87 ****
--- 99,105 ----
  {
   int LRet ;
  
+  init_globals();
   if( GFirstShm == 0 )
   {
    if( IsGSemShmExist() )

@


1.14
log
@Update README.NT with new NT ipc location.
@
text
@@


1.13
log
@Improve subquery error message, now says "More than one tuple returned
by subselect used as expression."
@
text
@d25 1
a25 1
   http://www.multione.capgemini.fr:80/tools/pack_ipc/current.tar.gz
@


1.12
log
@Move ipc patch into README.NT.
@
text
@a0 7
From: "Joost Kraaijeveld" <JKraaijeveld@@askesis.nl>
To: "Pgsql-Ports@@Postgresql. Org" <pgsql-ports@@postgreSQL.org>
Subject: RE: [PORTS] Re: psql under win32
Date: Wed, 21 Apr 1999 07:07:47 +0200
Message-ID: <000001be8bb4$e59b0ab0$0300a8c0@@abraracourcix.askesis.nl>
MIME-Version: 1.0

@


1.11
log
@Update NT readme with new name.
@
text
@d34 1
a34 1
3. Apply the patch pgsql/src/win32/ipc.patch to the cygipc sources
d86 289
@


1.10
log
@Update README.NT
@
text
@d73 1
a73 2
All test should be run, allthought the latest snapshot I tested (18-4)
appears to have some problems with locking.
d83 3
@


1.9
log
@Update NT readme.
@
text
@d24 2
d34 2
a35 2
3. Apply the patch pgsql/src/win32/ipc.patch to the CygWin32 sources
   before compiling CygWin32.
@


1.8
log
@Update README.NT
@
text
@d32 2
a33 1
3. Apply the patch from the file.
a81 166


---------------------------------------------------------------------------

FIX FOR POSTGRESQL FREEZING ON NT MACHINES - EVERYONE SHOULD APPLY THIS PATCH


From: "Hiroshi Inoue" <Inoue@@tpf.co.jp>
To: "Horak Daniel" <horak@@mmp.plzen-city.cz>, "'Tom Lane'" <tgl@@sss.pgh.pa.us>
Cc: <pgsql-hackers@@postgreSQL.org>
Subject: RE: [HACKERS] backend freezeing on win32 fixed (I hope ;-) ) 
Date: Wed, 18 Aug 1999 08:45:28 +0900
Message-ID: <000301bee90a$95d40f00$2801007e@@cadzone.tpf.co.jp>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
In-reply-to: <2E7F82FAC1FCD2118E1500A024B3BF907DED3F@@exchange.mmp.plzen-city.cz>
Importance: Normal
Sender: owner-pgsql-hackers@@postgreSQL.org
Precedence: bulk
Status: RO

> -----Original Message-----
> From: owner-pgsql-hackers@@postgreSQL.org
> [mailto:owner-pgsql-hackers@@postgreSQL.org]On Behalf Of Horak Daniel
> Sent: Tuesday, August 17, 1999 9:06 PM
> To: 'Tom Lane'
> Cc: 'pgsql-hackers@@postgreSQL.org'
> Subject: RE: [HACKERS] backend freezeing on win32 fixed (I hope ;-) )

Yutaka Tanida [yutaka@@marin.or.jp] and I have examined IPC
library.

We found that postmaster doesn't call exec() after fork() since v6.4.

The value of static/extern variables which cygipc library holds may
be different from their initial values when postmaster fork()s child
backend processes.

I made the following patch for cygipc library on trial.
This patch was effective for Yutaka's test case.

Regards.

Hiroshi Inoue
Inoue@@tpf.co.jp

*** sem.c.orig	Tue Dec 01 00:16:25 1998
--- sem.c	Tue Aug 17 13:22:06 1999
***************
*** 58,63 ****
--- 58,78 ----
  static int		  GFirstSem	 = 0;		/*PCPC*/
  static int		  GFdSem	    ;		/*PCPC*/

+ static pid_t	GProcessId = 0;
+
+ static void	init_globals(void)
+ {
+ 	pid_t pid;
+
+ 	if (pid=getpid(), pid != GProcessId)
+ 	{
+ 		GFirstSem = 0;
+ 		used_sems = used_semids = max_semid = 0;
+ 		sem_seq = 0;
+ 		GProcessId = pid;
+ 	}
+ }
+
  /************************************************************************/
  /* Demande d'acces a la zone partagee de gestion des semaphores		*/
  /************************************************************************/
***************
*** 77,82 ****
--- 92,98 ----
  {
      int LRet ;

+ 	init_globals();
      if( GFirstSem == 0 )
      {
  	if( IsGSemSemExist() )
*** shm.c.orig	Tue Dec 01 01:04:57 1998
--- shm.c	Tue Aug 17 13:22:27 1999
***************
*** 59,64 ****
--- 59,81 ----
  static int		  GFirstShm	 = 0;		/*PCPC*/
  static int		  GFdShm	    ;		/*PCPC*/

+ /*****************************************/
+ /*	Initialization of static variables   */
+ /*****************************************/
+ static pid_t GProcessId = 0;
+ static void init_globals(void)
+ {
+ 	pid_t pid;
+
+ 	if (pid=getpid(), pid != GProcessId)
+ 	{
+ 		GFirstShm = 0;
+ 		shm_rss = shm_swp = max_shmid = 0;
+ 		shm_seq = 0;
+ 		GProcessId = pid;
+ 	}
+ }
+
  /************************************************************************/
  /* Demande d'acces a la zone partagee de gestion des shm		*/
  /************************************************************************/
***************
*** 82,87 ****
--- 99,105 ----
  {
   int LRet ;

+  init_globals();
   if( GFirstShm == 0 )
   {
    if( IsGSemShmExist() )
*** msg.c.orig	Tue Dec 01 00:16:09 1998
--- msg.c	Tue Aug 17 13:20:04 1999
***************
*** 57,62 ****
--- 57,77 ----
  static int		  GFirstMsg	 = 0;		/*PCPC*/
  static int		  GFdMsg	    ;		/*PCPC*/

+ /*****************************************/
+ /*	Initialization of static variables   */
+ /*****************************************/
+ static pid_t GProcessId = 0;
+ static void init_globals(void)
+ {
+ 	pid_t pid;
+
+ 	if (pid=getpid(), pid != GProcessId)
+ 	{
+ 		GFirstMsg = 0;
+ 		msgbytes = msghdrs = msg_seq = used_queues = max_msqid = 0;
+ 		GProcessId = pid;
+ 	}
+ }
  /************************************************************************/
  /* Demande d'acces a la zone partagee de gestion des semaphores		*/
  /************************************************************************/
***************
*** 79,84 ****
--- 94,100 ----
  {
   int LRet ;

+  init_globals();
   if( GFirstMsg == 0 )
   {
    if( IsGSemMsgExist() )




@


1.7
log
@Update README.NT with patch.
@
text
@d18 4
d25 4
d32 3
a34 3
2a. Apply the patch from src/win32/ipc.patch
3. I tested 1.03.
4. I used the \cygwin-b20\h-i568-cygwin32\i586-cygwin32\lib and
d38 9
d50 1
a50 1
3. Edit \pgsql\src\template\cygwin32 if needed (I had to adjust the YFLAGS
d52 3
a54 3
4. ./configure
5. make
6. create the directory /usr/local/pgsql manually: the mkdir cannot create a
d56 10
a65 10
7. make install
8. cd /usr/lical/pgsql/doc
9. make install
10. Set the environmental data
11. Initdb --username=jkr (do not run this command as administrator)

12. Open a new Cygwin command prompt
13. Start "ipc-deamon&" (background proces)
14. Start "postmaster -i 2>&1 > /tmp/postgres.log &" (background proces)
15. Start "tail -f /tmp/postgres.log" to see the messages
d67 2
a68 2
16. cd /usr/src/pgsql/src/test/regress
17. make all runtest
d73 4
a76 7
Joost

[Added by bjm]

By default, PostgreSQL clients like psql communicate by default using
unix domain sockets, which don't work on NT.  Start the postmaster with
-i, and when connecting to the database from a client, set the PGHOST
d80 2
a81 3
Also, the cygnus-bindir has to be placed in the path before the
NT-directories, because the sort.exe has to be take for cygnus, not
NT.
d85 1
a85 1
FIX FOR POSTGRESQL FREEZING ON NT MACHINES
@


1.6
log
@
This is a patch for cygipc library provided by Yutaka Tanida.
This is necessary to prevent freezing in cygwin port.
@
text
@d70 164
@


1.5
log
@Update NT readme.
@
text
@d24 1
@


1.4
log
@configure cleanup
@
text
@d65 4
@


1.3
log
@update readme.nt
@
text
@d22 1
a22 1
   (http://www.multione.capgemini.fr/tools/pack_ipc/
@


1.3.2.1
log
@Update README.NT.
@
text
@d22 1
a22 1
   http://www.multione.capgemini.fr:80/tools/pack_ipc/current.tar.gz
@


1.3.2.2
log
@Update README.NT with patch.
@
text
@a23 1
2a. Apply the patch from src/win32/ipc.patch
a63 168

Also, the cygnus-bindir has to be placed in the path before the
NT-directories, because the sort.exe has to be take for cygnus, not
NT.

---------------------------------------------------------------------------

FIX FOR POSTGRESQL FREEZING ON NT MACHINES


From: "Hiroshi Inoue" <Inoue@@tpf.co.jp>
To: "Horak Daniel" <horak@@mmp.plzen-city.cz>, "'Tom Lane'" <tgl@@sss.pgh.pa.us>
Cc: <pgsql-hackers@@postgreSQL.org>
Subject: RE: [HACKERS] backend freezeing on win32 fixed (I hope ;-) ) 
Date: Wed, 18 Aug 1999 08:45:28 +0900
Message-ID: <000301bee90a$95d40f00$2801007e@@cadzone.tpf.co.jp>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
In-reply-to: <2E7F82FAC1FCD2118E1500A024B3BF907DED3F@@exchange.mmp.plzen-city.cz>
Importance: Normal
Sender: owner-pgsql-hackers@@postgreSQL.org
Precedence: bulk
Status: RO

> -----Original Message-----
> From: owner-pgsql-hackers@@postgreSQL.org
> [mailto:owner-pgsql-hackers@@postgreSQL.org]On Behalf Of Horak Daniel
> Sent: Tuesday, August 17, 1999 9:06 PM
> To: 'Tom Lane'
> Cc: 'pgsql-hackers@@postgreSQL.org'
> Subject: RE: [HACKERS] backend freezeing on win32 fixed (I hope ;-) )

Yutaka Tanida [yutaka@@marin.or.jp] and I have examined IPC
library.

We found that postmaster doesn't call exec() after fork() since v6.4.

The value of static/extern variables which cygipc library holds may
be different from their initial values when postmaster fork()s child
backend processes.

I made the following patch for cygipc library on trial.
This patch was effective for Yutaka's test case.

Regards.

Hiroshi Inoue
Inoue@@tpf.co.jp

*** sem.c.orig	Tue Dec 01 00:16:25 1998
--- sem.c	Tue Aug 17 13:22:06 1999
***************
*** 58,63 ****
--- 58,78 ----
  static int		  GFirstSem	 = 0;		/*PCPC*/
  static int		  GFdSem	    ;		/*PCPC*/

+ static pid_t	GProcessId = 0;
+
+ static void	init_globals(void)
+ {
+ 	pid_t pid;
+
+ 	if (pid=getpid(), pid != GProcessId)
+ 	{
+ 		GFirstSem = 0;
+ 		used_sems = used_semids = max_semid = 0;
+ 		sem_seq = 0;
+ 		GProcessId = pid;
+ 	}
+ }
+
  /************************************************************************/
  /* Demande d'acces a la zone partagee de gestion des semaphores		*/
  /************************************************************************/
***************
*** 77,82 ****
--- 92,98 ----
  {
      int LRet ;

+ 	init_globals();
      if( GFirstSem == 0 )
      {
  	if( IsGSemSemExist() )
*** shm.c.orig	Tue Dec 01 01:04:57 1998
--- shm.c	Tue Aug 17 13:22:27 1999
***************
*** 59,64 ****
--- 59,81 ----
  static int		  GFirstShm	 = 0;		/*PCPC*/
  static int		  GFdShm	    ;		/*PCPC*/

+ /*****************************************/
+ /*	Initialization of static variables   */
+ /*****************************************/
+ static pid_t GProcessId = 0;
+ static void init_globals(void)
+ {
+ 	pid_t pid;
+
+ 	if (pid=getpid(), pid != GProcessId)
+ 	{
+ 		GFirstShm = 0;
+ 		shm_rss = shm_swp = max_shmid = 0;
+ 		shm_seq = 0;
+ 		GProcessId = pid;
+ 	}
+ }
+
  /************************************************************************/
  /* Demande d'acces a la zone partagee de gestion des shm		*/
  /************************************************************************/
***************
*** 82,87 ****
--- 99,105 ----
  {
   int LRet ;

+  init_globals();
   if( GFirstShm == 0 )
   {
    if( IsGSemShmExist() )
*** msg.c.orig	Tue Dec 01 00:16:09 1998
--- msg.c	Tue Aug 17 13:20:04 1999
***************
*** 57,62 ****
--- 57,77 ----
  static int		  GFirstMsg	 = 0;		/*PCPC*/
  static int		  GFdMsg	    ;		/*PCPC*/

+ /*****************************************/
+ /*	Initialization of static variables   */
+ /*****************************************/
+ static pid_t GProcessId = 0;
+ static void init_globals(void)
+ {
+ 	pid_t pid;
+
+ 	if (pid=getpid(), pid != GProcessId)
+ 	{
+ 		GFirstMsg = 0;
+ 		msgbytes = msghdrs = msg_seq = used_queues = max_msqid = 0;
+ 		GProcessId = pid;
+ 	}
+ }
  /************************************************************************/
  /* Demande d'acces a la zone partagee de gestion des semaphores		*/
  /************************************************************************/
***************
*** 79,84 ****
--- 94,100 ----
  {
   int LRet ;

+  init_globals();
   if( GFirstMsg == 0 )
   {
    if( IsGSemMsgExist() )



@


1.3.2.3
log
@Update README.NT
@
text
@a17 4
---------------------------------------------------------------------------

				OPTIONAL

a20 4
---------------------------------------------------------------------------

			  CYGWIN32 INSTALLATION

d24 3
a26 3
3. Apply the patch from the file.
4. I tested 1.03.
5. I used the \cygwin-b20\h-i568-cygwin32\i586-cygwin32\lib and
a29 9
NOTE:
Also, the cygnus-bindir has to be placed in the path before the
NT-directories, because the sort.exe has to be taken for cygnus, not
NT.

---------------------------------------------------------------------------

		   POSTGRESQL INSTALL WITH NT SPECIFICS

d33 1
a33 1
4. Edit \pgsql\src\template\cygwin32 if needed (I had to adjust the YFLAGS
d35 3
a37 3
5. ./configure
6. make
7. create the directory /usr/local/pgsql manually: the mkdir cannot create a
d39 10
a48 10
8. make install
9. cd /usr/lical/pgsql/doc
10. make install
11. Set the environmental data
12. Initdb --username=jkr (do not run this command as administrator)

13. Open a new Cygwin command prompt
14. Start "ipc-deamon&" (background proces)
15. Start "postmaster -i 2>&1 > /tmp/postgres.log &" (background proces)
16. Start "tail -f /tmp/postgres.log" to see the messages
d50 2
a51 2
17. cd /usr/src/pgsql/src/test/regress
18. make all runtest
d56 7
a62 4
NOTE:
By default, PostgreSQL clients like psql communicate using unix domain
sockets, which don't work on NT.  Start the postmaster with -i, and 
when connecting to the database from a client, set the PGHOST
d66 3
a68 2
Joost

d72 1
a72 1
FIX FOR POSTGRESQL FREEZING ON NT MACHINES - EVERYONE SHOULD APPLY THIS PATCH
@


1.3.2.4
log
@Update NT readme.
@
text
@d32 1
a32 2
3. Apply the patch pgsql/src/win32/ipc.patch to the CygWin32 sources
   before compiling CygWin32.
@


1.3.2.5
log
@Update README.NT
@
text
@a23 2
   You need at least the crypt library (also available as
   ftp://sourceware.cygnus.com/pub/cygwin/xfree/libcrypt-cygwin-b20.1.tar.bz2)
d32 2
a33 2
3. Apply the patch pgsql/src/win32/ipc.patch to the cygipc sources
   before compiling the library.
d82 166
@


1.3.2.6
log
@Update NT readme with new name.
@
text
@d73 2
a74 1
All test should be run.
a83 3

PS: If you still have problems you can mail to Dan Horak <dan.horak@@email.cz>
    who is the maintainer for the win32 port
@


1.3.2.7
log
@Backpatch Y2K timestamp patch.
@
text
@d1 7
d34 1
a34 1
3. Apply the patch at the end of this file to the cygipc sources
a85 289

---------------------------------------------------------------------------

*** ./ipc-daemon.c.orig	Tue Dec 01 00:04:24 1998
--- ./ipc-daemon.c	Fri Sep 24 13:34:16 1999
***************
*** 270,285 ****
         {
          itoa(100*id+Index, LBuff) ;
          LHandle = OpenSemaphore(SEMAPHORE_ALL_ACCESS, FALSE, LBuff) ;
! 	while (LAdrSem->current_nb[id].current_nb[Index] > 0 )
! 	{
!     	 WaitForSingleObject(LHandle, 0) ;
! 	 LAdrSem->current_nb[id].current_nb[Index]-- ;
! 	}
! 	CloseHandle(LHandle) ;
         }
         LAdrSem->semary[id] = IPC_UNUSED ;
         LAdrSem->state[id]  = 0 ;
        }
        else
        {
         for (Index = 0; Index < sma->sem_nsems; Index++)
--- 270,284 ----
         {
          itoa(100*id+Index, LBuff) ;
          LHandle = OpenSemaphore(SEMAPHORE_ALL_ACCESS, FALSE, LBuff) ;
!         while (WaitForSingleObject(LHandle, 0) == WAIT_OBJECT_0)
!           ;
!         LAdrSem->current_nb[id].current_nb[Index] = 0;
!         CloseHandle(LHandle) ;
         }
         LAdrSem->semary[id] = IPC_UNUSED ;
         LAdrSem->state[id]  = 0 ;
        }
+ /*
        else
        {
         for (Index = 0; Index < sma->sem_nsems; Index++)
***************
*** 288,293 ****
--- 287,293 ----
          LHandle = OpenSemaphore(SEMAPHORE_ALL_ACCESS, FALSE, LBuff) ;
         }
        }
+ */
       }
      }
  
*** ./msg.c.orig	Tue Dec 01 00:16:09 1998
--- ./msg.c	Fri Sep 17 12:50:50 1999
***************
*** 57,62 ****
--- 57,77 ----
  static int		  GFirstMsg	 = 0;		/*PCPC*/
  static int		  GFdMsg	    ;		/*PCPC*/
  
+ /*****************************************/
+ /*	Initialization of static variables   */
+ /*****************************************/
+ static pid_t GProcessId = 0;
+ static void init_globals(void)
+ {
+ 	pid_t pid;
+ 
+ 	if (pid=getpid(), pid != GProcessId)
+ 	{
+ 		GFirstMsg = 0;
+ 		msgbytes = msghdrs = msg_seq = used_queues = max_msqid = 0;
+ 		GProcessId = pid;
+ 	}
+ }
  /************************************************************************/
  /* Demande d'acces a la zone partagee de gestion des semaphores		*/
  /************************************************************************/
***************
*** 79,84 ****
--- 94,100 ----
  {
   int LRet ;
  
+  init_globals();
   if( GFirstMsg == 0 )
   {
    if( IsGSemMsgExist() )
*** ./sem.c.orig	Tue Dec 01 00:16:25 1998
--- ./sem.c	Fri Sep 17 12:47:11 1999
***************
*** 58,63 ****
--- 58,78 ----
  static int		  GFirstSem	 = 0;		/*PCPC*/
  static int		  GFdSem	    ;		/*PCPC*/
  
+ static pid_t	GProcessId = 0;
+ 
+ static void	init_globals(void)
+ {
+ 	pid_t pid;
+ 
+ 	if (pid=getpid(), pid != GProcessId)
+ 	{
+ 		GFirstSem = 0;
+ 		used_sems = used_semids = max_semid = 0;
+ 		sem_seq = 0;
+ 		GProcessId = pid;
+ 	}
+ }
+ 
  /************************************************************************/
  /* Demande d'acces a la zone partagee de gestion des semaphores		*/
  /************************************************************************/
***************
*** 77,82 ****
--- 92,98 ----
  {
      int LRet ;
  
+ 	init_globals();
      if( GFirstSem == 0 )
      {
  	if( IsGSemSemExist() )
***************
*** 187,193 ****
      {
  	CloseHandle ( LHandle ) ;
      }
!     LHandle = CreateSemaphore(NULL, 0, 0x7FFFFFFF, LBuff) ;
      if( LHandle == NULL )
      {
  	printf( "Creation de Semaphore \"Sem\" impossible\n" ) ;
--- 203,209 ----
      {
  	CloseHandle ( LHandle ) ;
      }
!     LHandle = CreateSemaphore(NULL, 0, 1, LBuff) ;
      if( LHandle == NULL )
      {
  	printf( "Creation de Semaphore \"Sem\" impossible\n" ) ;
***************
*** 357,371 ****
  debug_printf("do_semop : return -EACCES\n");
  			CYGWIN32_IPCNT_RETURN (-EACCES) ;
  		    }
! 		    ReleaseSemaphore(LHandle, sop->sem_op, &LVal) ;
! 	    	    shareadrsem->current_nb[id].current_nb[sop->sem_num] +=
! 					sop->sem_op ;
  		    sem_deconnect() ;
  		} else {
  		    if( sop->sem_flg == IPC_NOWAIT )
  		    {
! 			LRet = WaitForSingleObject(LHandle, 0) ;
! 			if( LRet == WAIT_TIMEOUT )
  			{
  debug_printf("do_semop : return -EAGAIN\n");
  			    CYGWIN32_IPCNT_RETURN (-EAGAIN) ;
--- 373,386 ----
  debug_printf("do_semop : return -EACCES\n");
  			CYGWIN32_IPCNT_RETURN (-EACCES) ;
  		    }
!     	    shareadrsem->current_nb[id].current_nb[sop->sem_num] +=
! 				sop->sem_op ;
  		    sem_deconnect() ;
+ 		    ReleaseSemaphore(LHandle, 1 , &LVal) ;
  		} else {
  		    if( sop->sem_flg == IPC_NOWAIT )
  		    {
! 			if( sop->sem_op + shareadrsem->current_nb[id].current_nb[sop->sem_num] <0 )
  			{
  debug_printf("do_semop : return -EAGAIN\n");
  			    CYGWIN32_IPCNT_RETURN (-EAGAIN) ;
***************
*** 375,390 ****
  debug_printf("do_semop : return -EACCES\n");
  			    CYGWIN32_IPCNT_RETURN (-EACCES) ;
  			}
! 	    		shareadrsem->current_nb[id].current_nb[sop->sem_num] -= 1 ;
  			sem_deconnect() ;
  		    } else {
! 			LRet = WaitForSingleObject(LHandle, INFINITE) ;
  			if (sem_connect() == 0)
  			{
  debug_printf("do_semop : return -EACCES\n");
  			    CYGWIN32_IPCNT_RETURN (-EACCES) ;
  			}
! 			    shareadrsem->current_nb[id].current_nb[sop->sem_num] -= 1 ;
  			    sem_deconnect() ;
  		    }
  		}
--- 390,407 ----
  debug_printf("do_semop : return -EACCES\n");
  			    CYGWIN32_IPCNT_RETURN (-EACCES) ;
  			}
! 	    		shareadrsem->current_nb[id].current_nb[sop->sem_num] += sop->sem_op;
  			sem_deconnect() ;
  		    } else {
! 		    while(sop->sem_op + shareadrsem->current_nb[id].current_nb[sop->sem_num] <0)
! 				LRet = WaitForSingleObject(LHandle, INFINITE) ;
! 		    
  			if (sem_connect() == 0)
  			{
  debug_printf("do_semop : return -EACCES\n");
  			    CYGWIN32_IPCNT_RETURN (-EACCES) ;
  			}
! 			    shareadrsem->current_nb[id].current_nb[sop->sem_num] += sop->sem_op ;
  			    sem_deconnect() ;
  		    }
  		}
***************
*** 435,441 ****
  	char LBuff[100] ;
  	HANDLE LHandle ;
  	long LPrevious ;
- 	int LIndex;
  
  debug_printf("semctl : semid=%X semnum=%X cmd=0x%02X arg=%p\n",semid,semnum,cmd,arg);
  	if (semid < 0 || semnum < 0 || cmd < 0)
--- 452,457 ----
***************
*** 568,589 ****
  		if( LHandle != NULL )
  		{
  		    if( arg.val > shareadrsem->current_nb[id].current_nb[semnum] )
! 		    {
! 			ReleaseSemaphore(LHandle,
! 			arg.val-shareadrsem->current_nb[id].current_nb[semnum],
! 			&LPrevious) ;
! 		    }
! 		    else if (arg.val <
! 		             shareadrsem->current_nb[id].current_nb[semnum] )
! 		    {
! 			for( LIndex = arg.val;
! 			LIndex < shareadrsem->current_nb[id].current_nb[semnum];
! 			LIndex++ )
! 			{
! 			    WaitForSingleObject(LHandle, 0) ;
! 			}
! 		    }
!             	    shareadrsem->current_nb[id].current_nb[semnum] = arg.val ;
  		}
  debug_printf("semctl : SETVAL : return 0\n");
  		CYGWIN32_IPCNT_RETURN_DECONNECT (0);
--- 584,591 ----
  		if( LHandle != NULL )
  		{
  		    if( arg.val > shareadrsem->current_nb[id].current_nb[semnum] )
! 				ReleaseSemaphore(LHandle,1,&LPrevious) ;
!             shareadrsem->current_nb[id].current_nb[semnum] = arg.val ;
  		}
  debug_printf("semctl : SETVAL : return 0\n");
  		CYGWIN32_IPCNT_RETURN_DECONNECT (0);
*** ./shm.c.orig	Fri Sep 17 12:46:24 1999
--- ./shm.c	Fri Sep 17 12:47:11 1999
***************
*** 59,64 ****
--- 59,81 ----
  static int		  GFirstShm	 = 0;		/*PCPC*/
  static int		  GFdShm	    ;		/*PCPC*/
  
+ /*****************************************/
+ /*	Initialization of static variables   */
+ /*****************************************/
+ static pid_t GProcessId = 0;
+ static void init_globals(void)
+ {
+ 	pid_t pid;
+ 
+ 	if (pid=getpid(), pid != GProcessId)
+ 	{
+ 		GFirstShm = 0;
+ 		shm_rss = shm_swp = max_shmid = 0;
+ 		shm_seq = 0;
+ 		GProcessId = pid;
+ 	}
+ }
+ 
  /************************************************************************/
  /* Demande d'acces a la zone partagee de gestion des shm		*/
  /************************************************************************/
***************
*** 82,87 ****
--- 99,105 ----
  {
   int LRet ;
  
+  init_globals();
   if( GFirstShm == 0 )
   {
    if( IsGSemShmExist() )

@


1.2
log
@Newer README.NT.
@
text
@d57 1
d59 5
@


1.1
log
@Add NT readme file.
@
text
@d16 1
d18 2
a19 1
1. Install the Andy Piper Tools
d21 2
a22 1
1. Download the Cygwin32 IPC Package by Ludovic LANGE.
d29 1
a29 1
1. Download the current snapshot.tar.gz (24-3-98).
@

