Re: [PATCHES] [HACKERS] pg_dump --comment?

2004-06-04 Thread Bruce Momjian
Tom Lane wrote:
> Bruce Momjian <[EMAIL PROTECTED]> writes:
> > Tom Lane wrote:
> >> What happens in a pg_dump -Fc / pg_restore scenario?
> 
> > So, in non-ascii format, I need to dump a comment record and read it
> > back on restore?  Yuck.  Anyone want to tackle that?
> 
> Yes.  Hacking the output routines alone is almost never the right way
> to do things in pg_dump.
> 
> My feeling is that if anyone cares to tackle this, it would be
> appropriate to add a record type that carries a user-supplied
> comment, and then people could do something like
>   pg_dump --comment "generated on `date`"
> if they want to have a timestamp.  I don't want a timestamp put
> into the file by default, because that creates problems for
> comparing dump files.

OK, new patch.  This puts start/stop times into dumps if you use -v
during dumping.  It creates a new node type:

--
-- PostgreSQL database dump
--

SET client_encoding = 'SQL_ASCII';
SET check_function_bodies = false;

--
-- Name: DUMP TIMESTAMP; Type: DUMP TIMESTAMP; Schema: -; Owner:
--

-- Started on 2004-06-05 00:41:25 EDT

...

--
-- Name: DUMP TIMESTAMP; Type: DUMP TIMESTAMP; Schema: -; Owner:
--

-- Completed on 2004-06-05 00:44:28 EDT


--
-- PostgreSQL database dump complete
--

One issue is that the system dumps certain settings into the output file
in ascii dumps, but pg_restore sets them on its own during the restore. 
Because the timestamp can't be done during pg_restore, it has to be a
special node.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073
Index: doc/src/sgml/ref/pg_dump.sgml
===
RCS file: /cvsroot/pgsql-server/doc/src/sgml/ref/pg_dump.sgml,v
retrieving revision 1.70
diff -c -c -r1.70 pg_dump.sgml
*** doc/src/sgml/ref/pg_dump.sgml   31 May 2004 13:37:52 -  1.70
--- doc/src/sgml/ref/pg_dump.sgml   5 Jun 2004 04:22:15 -
***
*** 403,409 
 
Specifies verbose mode.  This will cause
pg_dump to output detailed object
! comments in the dump file, and progress messages to standard error.
 

   
--- 403,410 
 
Specifies verbose mode.  This will cause
pg_dump to output detailed object
! comments in the dump file, start and stop times, and progress 
! messages to standard error.
 

   
Index: doc/src/sgml/ref/pg_dumpall.sgml
===
RCS file: /cvsroot/pgsql-server/doc/src/sgml/ref/pg_dumpall.sgml,v
retrieving revision 1.43
diff -c -c -r1.43 pg_dumpall.sgml
*** doc/src/sgml/ref/pg_dumpall.sgml29 Nov 2003 19:51:39 -  1.43
--- doc/src/sgml/ref/pg_dumpall.sgml5 Jun 2004 04:22:15 -
***
*** 192,199 

 
Specifies verbose mode.  This will cause
!   pg_dumpall to print progress
!   messages to standard error.
 

   
--- 192,200 

 
Specifies verbose mode.  This will cause
!   pg_dumpall to output start and stop
! times in the dump file, and progress messages to standard error.
! It will also enable verbose output in pg_dump.
 

   
Index: src/bin/pg_dump/pg_dump.c
===
RCS file: /cvsroot/pgsql-server/src/bin/pg_dump/pg_dump.c,v
retrieving revision 1.373
diff -c -c -r1.373 pg_dump.c
*** src/bin/pg_dump/pg_dump.c   3 Jun 2004 00:07:36 -   1.373
--- src/bin/pg_dump/pg_dump.c   5 Jun 2004 04:22:21 -
***
*** 32,37 
--- 32,38 
  #ifdef HAVE_TERMIOS_H
  #include 
  #endif
+ #include 
  
  #ifndef HAVE_STRDUP
  #include "strdup.h"
***
*** 163,168 
--- 164,170 
  static const char *fmtQualifiedId(const char *schema, const char *id);
  static intdumpBlobs(Archive *AH, void *arg);
  static void dumpDatabase(Archive *AH);
+ static void dumpTimestamp(Archive *AH, char *msg);
  static void dumpEncoding(Archive *AH);
  static const char *getAttrName(int attrnum, TableInfo *tblInfo);
  static const char *fmtCopyColumnList(const TableInfo *ti);
***
*** 598,603 
--- 600,608 
 * in a safe order.
 */
  
+   if (g_fout->verbose)
+   dumpTimestamp(g_fout, "Started on");
+ 
/* First the special encoding entry. */
dumpEncoding(g_fout);
  
***
*** 615,620 
--- 620,628 
dumpDumpableObject(g_fout, dobjs[i]);
}
  
+   if (g_fout->verbose)
+  

Re: [PATCHES] Compiling libpq with VisualC

2004-06-04 Thread Andreas Pflug
The appended patch implements ENABLE_THREAD_SAFETY for win32 compiled 
with Visual C. Two additional files will supply the needed pthread stuff.

There's no SIGPIPE for native win32, so there are some #IFNDEF WIN32 to 
skip installing a signal handler for this. I'm not sure if this is going 
to show conflicts for CYGWIN or other unix-like builds on win32 
platforms, i.e. if WIN32 is defined in such cases or not; please check.

Note: the previously posted win32.mak patch is superseded by this.
Regards,
Andreas
Index: win32.mak
===
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/win32.mak,v
retrieving revision 1.23
diff -u -r1.23 win32.mak
--- win32.mak   3 Jun 2004 00:11:13 -   1.23
+++ win32.mak   4 Jun 2004 13:26:39 -
@@ -74,19 +74,25 @@
[EMAIL PROTECTED] "$(OUTDIR)\$(OUTFILENAME)dll.lib"
[EMAIL PROTECTED] "$(INTDIR)\wchar.obj"
[EMAIL PROTECTED] "$(INTDIR)\encnames.obj"
+   [EMAIL PROTECTED] "$(INTDIR)\pthread-win32.obj"
 
 
 
-config: ..\..\include\pg_config.h
+config: ..\..\include\pg_config.h pthread.h pg_config_paths.h
 
 ..\..\include\pg_config.h: ..\..\include\pg_config.h.win32
copy ..\..\include\pg_config.h.win32 ..\..\include\pg_config.h
 
+pthread.h: pthread.h.win32
+   copy pthread.h.win32 pthread.h
+
+pg_config_paths.h: win32.mak
+   echo #define SYSCONFDIR "" >pg_config_paths.h
 
 "$(OUTDIR)" :
 if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
 
-CPP_PROJ=/nologo /W3 /GX $(OPT) /I "..\..\include" /D "FRONTEND" $(DEBUGDEF) /D\
+CPP_PROJ=/nologo /W3 /GX $(OPT) /I "..\..\include" /I. /D "FRONTEND" $(DEBUGDEF) /D\
  "WIN32" /D "_WINDOWS" /Fp"$(INTDIR)\libpq.pch" /YX\
  /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c  /D "HAVE_VSNPRINTF" /D "HAVE_STRDUP"
 
@@ -95,6 +101,10 @@
 SSL_LIBS=ssleay32.lib libeay32.lib gdi32.lib
 !ENDIF
 
+!IFDEF ENABLE_THREAD_SAFETY
+CPP_PROJ=$(CPP_PROJ) /D ENABLE_THREAD_SAFETY
+!ENDIF
+
 CPP_SBRS=.
 
 LIB32=link.exe -lib
@@ -121,7 +131,8 @@
"$(INTDIR)\fe-secure.obj" \
"$(INTDIR)\pqexpbuffer.obj" \
"$(INTDIR)\wchar.obj" \
-   "$(INTDIR)\encnames.obj"
+   "$(INTDIR)\encnames.obj" \
+   "$(INTDIR)\pthread-win32.obj"
 
 
 RSC_PROJ=/l 0x409 /fo"$(INTDIR)\libpq.res"
Index: fe-connect.c
===
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-connect.c,v
retrieving revision 1.272
diff -u -r1.272 fe-connect.c
--- fe-connect.c3 Jun 2004 00:07:38 -   1.272
+++ fe-connect.c4 Jun 2004 13:26:43 -
@@ -882,11 +882,13 @@
const char *node = NULL;
int ret;
 #ifdef ENABLE_THREAD_SAFETY
+#ifndef WIN32
static pthread_once_t check_sigpipe_once = PTHREAD_ONCE_INIT;
 
/* Check only on first connection request */
pthread_once(&check_sigpipe_once, check_sigpipe_handler);
 #endif
+#endif
 
if (!conn)
return 0;
@@ -3187,7 +3189,13 @@
 default_threadlock(int acquire)
 {
 #ifdef ENABLE_THREAD_SAFETY
-   static pthread_mutex_t singlethread_lock = PTHREAD_MUTEX_INITIALIZER;
+   static pthread_mutex_t singlethread_lock;
+static int mutex_initialized = 0;
+if (!mutex_initialized)
+{
+mutex_initialized = 1;
+pthread_mutex_init(&singlethread_lock, NULL);
+}
if (acquire)
pthread_mutex_lock(&singlethread_lock);
else
Index: fe-secure.c
===
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-secure.c,v
retrieving revision 1.41
diff -u -r1.41 fe-secure.c
--- fe-secure.c 3 Jun 2004 00:13:19 -   1.41
+++ fe-secure.c 4 Jun 2004 13:26:45 -
@@ -864,8 +864,13 @@
 init_ssl_system(PGconn *conn)
 {
 #ifdef ENABLE_THREAD_SAFETY
-static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER;
-
+static pthread_mutex_t init_mutex;
+static int mutex_initialized = 0;
+if (!mutex_initialized)
+{
+mutex_initialized = 1;
+pthread_mutex_init(&init_mutex, NULL);
+}
pthread_mutex_lock(&init_mutex);

if (pq_initssllib && pq_lockarray == NULL) {
@@ -1171,6 +1176,7 @@
 
 
 #ifdef ENABLE_THREAD_SAFETY
+#ifndef WIN32
 /*
  * Check SIGPIPE handler and perhaps install our own.
  */
@@ -1210,6 +1216,7 @@
if (!PQinSend())
exit(128 + SIGPIPE);/* typical return value for SIG_DFL */
 }
+#endif
 #endif
  
 /*
/*-
*
* pthread-win32.c
*partial pthread implementation for win32
*
* Copyright (c) 2004, PostgreSQL Global Development Group
* IDENTIFICATION
*   $PostgreSQL: $ 
*
*-
*/


#include "windows.h"
#include "pthread.h"

HANDLE pthrea

Re: [PATCHES] [HACKERS] pg_dump --comment?

2004-06-04 Thread Tom Lane
Bruce Momjian <[EMAIL PROTECTED]> writes:
> Tom Lane wrote:
>> What happens in a pg_dump -Fc / pg_restore scenario?

> So, in non-ascii format, I need to dump a comment record and read it
> back on restore?  Yuck.  Anyone want to tackle that?

Yes.  Hacking the output routines alone is almost never the right way
to do things in pg_dump.

My feeling is that if anyone cares to tackle this, it would be
appropriate to add a record type that carries a user-supplied
comment, and then people could do something like
pg_dump --comment "generated on `date`"
if they want to have a timestamp.  I don't want a timestamp put
into the file by default, because that creates problems for
comparing dump files.

regards, tom lane

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [PATCHES] Compiling libpq with VisualC

2004-06-04 Thread Bruce Momjian

Patch applied.  I didn't realize that file was for win32 _client_
compiles, and I didn't realize it had no pg_config_paths.h.

---

Andreas Pflug wrote:
> Bruce Momjian wrote:
> 
> >Andreas Pflug wrote:
> >  
> >
> >>Bruce Momjian wrote:
> >>
> >>
> >>
> >>> 
> >>>
> >>>  
> >>>
> >fe-connect.c:
> >- pg_config_paths.h isn't available. SYSCONFDIR is already defined so 
> >fe-connect.c doesn't need to include that.
> >patch appended
> > 
> >
> >  
> >
> >>>This shouldn't be needed anymore.  Where is SYSCONFDIR coming from?  Is
> >>>it from some Win32 include file?  It should only be coming from
> >>>pg_config_paths.h now.
> >>> 
> >>>
> >>>  
> >>>
> >>It's defined in pg_config.h.win32, which is copied to pg_config.h. 
> >>There's no pg_config_paths.h for win32, and I wonder if the code which 
> >>uses SYSCONFDIR is of any use for win32.
> >>
> >>
> >
> >Thanks.  Removed.  I never saw that because the file has a .win32
> >extension and my search tools didn't look in there.
> >  
> >
> Well, that doesn't work like this. As I already wrote, there's no 
> SYSCONFDIR, and if there was it can't have any sensible value for win32 
> clients. SYSCONFDIR as of pg_config.h.win32 version 1.13 was just a 
> dummy to make the compiler happy. Now there's no SYSCONFDIR around, and 
> no pg_config_paths.h either...
> 
> The attached patch will create a dummy pg_config_paths.h. Additionally, 
> ENABLE_THREAD_SAFETY is supported by the makefile (but not by the 
> sources, which need some rework)
> 
> Regards,
> Andreas
> 
> 
> 
> ---(end of broadcast)---
> TIP 3: if posting/reading through Usenet, please send an appropriate
>   subscribe-nomail command to [EMAIL PROTECTED] so that your
>   message can get through to the mailing list cleanly
> 

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 6: Have you searched our list archives?

   http://archives.postgresql.org


Re: [PATCHES] [HACKERS] pg_dump --comment?

2004-06-04 Thread Bruce Momjian
Tom Lane wrote:
> Bruce Momjian <[EMAIL PROTECTED]> writes:
> > The following patch adds start/stop times for pg_dump and pg_dumpall
> 
> What happens in a pg_dump -Fc / pg_restore scenario?

Uh, do those markers not appear in that dump type?  I thought they did.

I just tried pg_restore -v and while I see the lines, they are changing
every time I run it, meaning it isn't stored in the file but is showing
current time.  I looked in the dump file and I don't see the dates
either.

So, in non-ascii format, I need to dump a comment record and read it
back on restore?  Yuck.  Anyone want to tackle that?

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [PATCHES] Compiling libpq with VisualC

2004-06-04 Thread Andreas Pflug
Andreas Pflug wrote:
The attached patch will create a dummy pg_config_paths.h. 
Additionally, ENABLE_THREAD_SAFETY is supported by the makefile (but 
not by the sources, which need some rework)

Now including the patch...
Regards,
Andreas
Index: win32.mak
===
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/win32.mak,v
retrieving revision 1.23
diff -u -r1.23 win32.mak
--- win32.mak   3 Jun 2004 00:11:13 -   1.23
+++ win32.mak   4 Jun 2004 08:22:50 -
@@ -77,11 +77,13 @@
 
 
 
-config: ..\..\include\pg_config.h
+config: ..\..\include\pg_config.h pg_config_paths.h
 
 ..\..\include\pg_config.h: ..\..\include\pg_config.h.win32
copy ..\..\include\pg_config.h.win32 ..\..\include\pg_config.h
 
+pg_config_paths.h: win32.mak
+   echo #define SYSCONFDIR "" >pg_config_paths.h
 
 "$(OUTDIR)" :
 if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
@@ -93,6 +95,10 @@
 !IFDEF USE_SSL
 CPP_PROJ=$(CPP_PROJ) /D USE_SSL
 SSL_LIBS=ssleay32.lib libeay32.lib gdi32.lib
+!ENDIF
+
+!IFDEF ENABLE_THREAD_SAFETY
+CPP_PROJ=$(CPP_PROJ) /D ENABLE_THREAD_SAFETY
 !ENDIF
 
 CPP_SBRS=.



---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [PATCHES] Compiling libpq with VisualC

2004-06-04 Thread Andreas Pflug
Bruce Momjian wrote:
Andreas Pflug wrote:
 

Bruce Momjian wrote:
   


 

fe-connect.c:
- pg_config_paths.h isn't available. SYSCONFDIR is already defined so 
fe-connect.c doesn't need to include that.
patch appended


 

This shouldn't be needed anymore.  Where is SYSCONFDIR coming from?  Is
it from some Win32 include file?  It should only be coming from
pg_config_paths.h now.
 

It's defined in pg_config.h.win32, which is copied to pg_config.h. 
There's no pg_config_paths.h for win32, and I wonder if the code which 
uses SYSCONFDIR is of any use for win32.
   

Thanks.  Removed.  I never saw that because the file has a .win32
extension and my search tools didn't look in there.
 

Well, that doesn't work like this. As I already wrote, there's no 
SYSCONFDIR, and if there was it can't have any sensible value for win32 
clients. SYSCONFDIR as of pg_config.h.win32 version 1.13 was just a 
dummy to make the compiler happy. Now there's no SYSCONFDIR around, and 
no pg_config_paths.h either...

The attached patch will create a dummy pg_config_paths.h. Additionally, 
ENABLE_THREAD_SAFETY is supported by the makefile (but not by the 
sources, which need some rework)

Regards,
Andreas

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
 subscribe-nomail command to [EMAIL PROTECTED] so that your
 message can get through to the mailing list cleanly