Re: [PATCHES] ruleutils with pretty-print option
The patch has been updated, the attached files will replace my previous post completely against ruleutils.c 1.143. pg_get_indexdef is extended to take 3 arguments: pg_get_indexdef(index_oid, columnNr_int, prettyOpt_int) Still, pg_get_indexdef(oid) will deliver the same result as it used to be. The second parameter selects the nth expression of an index (1..indnatts). If zero, a complete CREATE INDEX statement is generated to obtain the previous behaviour. The third is the pretty-print option as mentioned before. example: pg_get_indexdef(12345, 0, 7) -> CREATE INDEX foo ON bar (numcol, length(txtcol), intcol2, length(txtcol2)) pg_get_indexdef(12345, 1, 7) -> numcol pg_get_indexdef(12345, 1, 7) -> length(txtcol) Regards, Andreas The attached patches will add pg_get_ruledef(oid, int) pg_get_viewdef(text, int) pg_get_viewdef(oid, int) pg_get_indexdef(oid, int) pg_get_constraintdef(oid, int) pg_get_expr(text, oid, int) If the last parameter "pretty-print" is 0, these function will return the same result as their original counterparts without that parameter. The source is based on ruleutils.c 1.143, and should return exactly the same result as before if no pretty-print is selected. My tests didn't show any differences for pg_dump output with old or new version. The pretty-print parameter is evaluated bit-wise. PRETTY_PAREN 1 - Parentheses are checked; only necessary parentheses will be emitted. PRETTY_INDENT 2 - pretty indentation and line formatting is performed PRETTY_OPPAREN4 - For T_BoolExpr operators, AND/OR/NOT precedence is checked, for T_OpExpr +-*/% precedence is checked. If precedence is identified, parentheses are omitted. This option is only active if PRETTY_PAREN is also used. Index: ruleutils.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/ruleutils.c,v retrieving revision 1.143 diff -c -r1.143 ruleutils.c *** ruleutils.c 29 Jun 2003 00:33:44 - 1.143 --- ruleutils.c 2 Jul 2003 16:27:32 - *** *** 71,76 --- 71,97 #include "utils/lsyscache.h" + /** + * Pretty formatting constants + **/ + + /* Indent counts */ + #define PRETTYINDENT_STD8 + #define PRETTYINDENT_JOIN 13 + #define PRETTYINDENT_JOIN_ON(PRETTYINDENT_JOIN-PRETTYINDENT_STD) + #define PRETTYINDENT_VAR4 + + /* Pretty flags */ + #define PRETTYFLAG_PAREN1 + #define PRETTYFLAG_INDENT 2 + #define PRETTYFLAG_OPPAREN 4 + + /* macro to test if pretty action needed */ + #define PRETTY_PAREN(context) (context->prettyFlags & PRETTYFLAG_PAREN) + #define PRETTY_INDENT(context) (context->prettyFlags & PRETTYFLAG_INDENT) + #define PRETTY_OPPAREN(context) (context->prettyFlags & PRETTYFLAG_OPPAREN) + + /* -- * Local data types * -- *** *** 81,86 --- 102,109 { StringInfo buf;/* output buffer to append to */ List *namespaces; /* List of deparse_namespace nodes */ + int prettyFlags;/* if non-zero, parentheses are minimized. */ + int indentLevel;/* for prettyPrint, we perform indentation and line splitting */ boolvarprefix; /* TRUE to print prefixes on Vars */ } deparse_context; *** *** 123,135 * as a parameter, and append their text output to its contents. * -- */ ! static text *pg_do_getviewdef(Oid viewoid); static void decompile_column_index_array(Datum column_index_array, Oid relId, StringInfo buf); ! static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc); ! static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc); static void get_query_def(Query *query, StringInfo buf, List *parentnamespace, ! TupleDesc resultDesc); static void get_select_query_def(Query *query, deparse_context *context, TupleDesc resultDesc); static void get_insert_query_def(Query *query, deparse_context *context); --- 146,164 * as a parameter, and append their text output to its contents. * -- */ ! static char *get_simple_binary_op_name(OpExpr *expr); ! static void appendStringInfoSpace(StringInfo buf, int count); ! static void appendContextKeyword(deparse_context *context, char *str, int indentBefore, int indentAfter, int indentPlus); ! static char *deparse_expression_pretty(Node *expr, List *dpcontext, ! bool forceprefix, bool showimplicit, int prettyFlags, int startIndent); ! static bool isSimpleNode(Node *node, Node *parentNode, int prettyFlags); ! static text *pg_do_getviewdef(Oid viewoid, int pretty
[PATCHES] ruleutils with pretty-print option
Is there a problem about the archive? I posted this addition to the patch on July 2, and received it over the patches mailing list. Still, it doesn't appear in cvs, in "unapplied patches" or in the mailing list archive! So although that message made its way through the list server, it didn't end up in the archive, but was lost. In the meantime, some changes occurred to cvs, which merged smoothly. For convenience, the attached diffs against the latest cvs versions. Regards, Andreas Previous message (2003-07-02): The patch has been updated, the attached files will replace my previous post completely against ruleutils.c 1.143. pg_get_indexdef is extended to take 3 arguments: pg_get_indexdef(index_oid, columnNr_int, prettyOpt_int) Still, pg_get_indexdef(oid) will deliver the same result as it used to be. The second parameter selects the nth expression of an index (1..indnatts). If zero, a complete CREATE INDEX statement is generated to obtain the previous behaviour. The third is the pretty-print option as mentioned before. example: pg_get_indexdef(12345, 0, 7) -> CREATE INDEX foo ON bar (numcol, length(txtcol), intcol2, length(txtcol2)) pg_get_indexdef(12345, 1, 7) -> numcol pg_get_indexdef(12345, 2, 7) -> length(txtcol) Regards, Andreas The attached patches will add pg_get_ruledef(oid, int) pg_get_viewdef(text, int) pg_get_viewdef(oid, int) pg_get_indexdef(oid, int) pg_get_constraintdef(oid, int) pg_get_expr(text, oid, int) If the last parameter "pretty-print" is 0, these function will return the same result as their original counterparts without that parameter. The source is based on ruleutils.c 1.143, and should return exactly the same result as before if no pretty-print is selected. My tests didn't show any differences for pg_dump output with old or new version. The pretty-print parameter is evaluated bit-wise. PRETTY_PAREN 1 - Parentheses are checked; only necessary parentheses will be emitted. PRETTY_INDENT 2 - pretty indentation and line formatting is performed PRETTY_OPPAREN4 - For T_BoolExpr operators, AND/OR/NOT precedence is checked, for T_OpExpr +-*/% precedence is checked. If precedence is identified, parentheses are omitted. This option is only active if PRETTY_PAREN is also used. Index: pg_proc.h === RCS file: /projects/cvsroot/pgsql-server/src/include/catalog/pg_proc.h,v retrieving revision 1.309 diff -c -r1.309 pg_proc.h *** pg_proc.h 1 Jul 2003 00:04:38 - 1.309 --- pg_proc.h 6 Jul 2003 10:08:23 - *** *** 3405,3410 --- 3405,3424 DATA(insert OID = 2503 ( anyarray_send PGNSP PGUID 12 f f t f s 1 17 "2277" anyarray_send - _null_ )); DESCR("I/O"); + /* System-view support functions with pretty-print option */ + DATA(insert OID = 2504 ( pg_get_ruledef PGNSP PGUID 12 f f t f s 2 25 "26 23" pg_get_ruledef - _null_ )); + DESCR("source text of a rule with pretty-print option"); + DATA(insert OID = 2505 ( pg_get_viewdef PGNSP PGUID 12 f f t f s 2 25 "25 23" pg_get_viewdef_name - _null_ )); + DESCR("select statement of a view with pretty-print option"); + DATA(insert OID = 2506 ( pg_get_viewdef PGNSP PGUID 12 f f t f s 2 25 "26 23" pg_get_viewdef - _null_ )); + DESCR("select statement of a view with pretty-print option"); + DATA(insert OID = 2507 ( pg_get_indexdefPGNSP PGUID 12 f f t f s 3 25 "26 23 23" pg_get_indexdef - _null_ )); + DESCR("index description (full create statement or single expression) with pretty-print option"); + DATA(insert OID = 2508 ( pg_get_constraintdef PGNSP PGUID 12 f f t f s 2 25 "26 23" pg_get_constraintdef - _null_ )); + DESCR("constraint description with pretty-print option"); + DATA(insert OID = 2509 ( pg_get_exprPGNSP PGUID 12 f f t f s 3 25 "25 26 23" pg_get_expr - _null_ )); + DESCR("deparse an encoded expression with pretty-print option"); + /* * Symbolic values for provolatile column: these indicate whether the result Index: ruleutils.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/ruleutils.c,v retrieving revision 1.145 diff -c -r1.145 ruleutils.c *** ruleutils.c 4 Jul 2003 02:51:34 - 1.145 --- ruleutils.c 6 Jul 2003 10:09:51 - *** *** 71,76 --- 71,97 #include "utils/lsyscache.h" + /** + * Pretty formatting constants + **/ + + /* Indent counts */ + #define PRETTYINDENT_STD8 + #define PRETTYINDENT_JOIN 13 + #define PRETTYINDENT_JOIN_ON(PRETTYINDENT_JOIN-PRETTYINDENT_STD) + #define PRETTYINDENT_VAR4 + + /* Pretty flags */ + #define PRETTYFLAG_PAREN1 + #define PRETTYFLAG_INDENT 2 + #define PRETTYFLAG_OPPAREN 4 + + /* macro to test i
Re: [PATCHES] ruleutils with pretty-print option
Hi Bruce, so here's the complete patch against the current cvs. Description: The attached patches will add pg_get_ruledef(oid, bool) pg_get_viewdef(text, bool) pg_get_viewdef(oid, bool) pg_get_indexdef(oid, int4, bool) pg_get_constraintdef(oid, bool) pg_get_expr(text, oid, bool) If the last parameter "pretty-print" is false, these function will return the same result as their original counterparts without that parameter. The source is based on ruleutils.c 1.145 and pg_proc 1.309, and should return exactly the same result as before if no pretty-print is selected. My tests didn't show any differences for pg_dump output with old or new version. If the last parameter "pretty-print" is true, parentheses are checked; only necessary parentheses will be emitted. Additionally, line and indentation formatting is performed. pg_get_indexdef has one additional parameter. The second parameter (int4) selects the nth expression of an index (1..indnatts). If zero, a complete CREATE INDEX statement is generated to obtain the previous behaviour. The third is the pretty-print option as described. example: pg_get_indexdef(12345, 0, true) -> CREATE INDEX foo ON bar (numcol, length(txtcol), intcol2, (8+length(txtcol2))) pg_get_indexdef(12345, 1, true) -> numcol pg_get_indexdef(12345, 2, true) -> length(txtcol) pg_get_indexdef(12345, 3, true) -> intcol2 pg_get_indexdef(12345, 4, true) -> (8+length(txtcol2)) Regards, Andreas Index: pg_proc.h === RCS file: /projects/cvsroot/pgsql-server/src/include/catalog/pg_proc.h,v retrieving revision 1.309 diff -r1.309 pg_proc.h 3407a3408,3421 > /* System-view support functions with pretty-print option */ > DATA(insert OID = 2504 ( pg_get_ruledef PGNSP PGUID 12 f f t f s 2 25 "26 > 16" pg_get_ruledef - _null_ )); > DESCR("source text of a rule with pretty-print option"); > DATA(insert OID = 2505 ( pg_get_viewdef PGNSP PGUID 12 f f t f s 2 25 "25 > 16" pg_get_viewdef_name - _null_ )); > DESCR("select statement of a view with pretty-print option"); > DATA(insert OID = 2506 ( pg_get_viewdef PGNSP PGUID 12 f f t f s 2 25 "26 > 16" pg_get_viewdef - _null_ )); > DESCR("select statement of a view with pretty-print option"); > DATA(insert OID = 2507 ( pg_get_indexdefPGNSP PGUID 12 f f t f s 3 25 "26 > 23 16" pg_get_indexdef - _null_ )); > DESCR("index description (full create statement or single expression) with > pretty-print option"); > DATA(insert OID = 2508 ( pg_get_constraintdef PGNSP PGUID 12 f f t f s 2 25 "26 16" > pg_get_constraintdef - _null_ )); > DESCR("constraint description with pretty-print option"); > DATA(insert OID = 2509 ( pg_get_exprPGNSP PGUID 12 f f t f s 3 25 "25 > 26 16" pg_get_expr - _null_ )); > DESCR("deparse an encoded expression with pretty-print option"); > Index: ruleutils.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/ruleutils.c,v retrieving revision 1.145 diff -r1.145 ruleutils.c 73a74,92 > /** > * Pretty formatting constants > **/ > > /* Indent counts */ > #define PRETTYINDENT_STD8 > #define PRETTYINDENT_JOIN 13 > #define PRETTYINDENT_JOIN_ON(PRETTYINDENT_JOIN-PRETTYINDENT_STD) > #define PRETTYINDENT_VAR4 > > /* Pretty flags */ > #define PRETTYFLAG_PAREN1 > #define PRETTYFLAG_INDENT 2 > > /* macro to test if pretty action needed */ > #define PRETTY_PAREN(context) (context->prettyFlags & PRETTYFLAG_PAREN) > #define PRETTY_INDENT(context) (context->prettyFlags & PRETTYFLAG_INDENT) > > 83a103,104 > int prettyFlags;/* enabling/disabling of > pretty-print functions */ > int indentLevel;/* for prettyPrint, current space > indents are counted */ 126c147,153 < static text *pg_do_getviewdef(Oid viewoid); --- > static char *get_simple_binary_op_name(OpExpr *expr); > static void appendStringInfoSpace(StringInfo buf, int count); > static void appendContextKeyword(deparse_context *context, char *str, int > indentBefore, int indentAfter, int indentPlus); > static char *deparse_expression_pretty(Node *expr, List *dpcontext, > bool forceprefix, bool showimplicit, int prettyFlags, int > startIndent); > static bool isSimpleNode(Node *node, Node *parentNode, int prettyFlags); > static text *pg_do_getviewdef(Oid viewoid, int prettyFlags); 129,130c156,157 < static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc); < static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc); --- > static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc, int > prettyFlags); > static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc, int > prettyFlags); 132c159 <
Re: [PATCHES] ruleutils with pretty-print option
Bruce Momjian wrote: Andreas, looks good, but I need a diff -c, context diff. Hi Bruce, I intentionally only attached only non-context diffs because the patch is about 50 % size of the original file. Now, here's the same as context diff. Regards, Andreas Index: pg_proc.h === RCS file: /projects/cvsroot/pgsql-server/src/include/catalog/pg_proc.h,v retrieving revision 1.309 diff -c -r1.309 pg_proc.h *** pg_proc.h 1 Jul 2003 00:04:38 - 1.309 --- pg_proc.h 22 Jul 2003 12:52:07 - *** *** 3405,3410 --- 3405,3424 DATA(insert OID = 2503 ( anyarray_send PGNSP PGUID 12 f f t f s 1 17 "2277" anyarray_send - _null_ )); DESCR("I/O"); + /* System-view support functions with pretty-print option */ + DATA(insert OID = 2504 ( pg_get_ruledef PGNSP PGUID 12 f f t f s 2 25 "26 16" pg_get_ruledef - _null_ )); + DESCR("source text of a rule with pretty-print option"); + DATA(insert OID = 2505 ( pg_get_viewdef PGNSP PGUID 12 f f t f s 2 25 "25 16" pg_get_viewdef_name - _null_ )); + DESCR("select statement of a view with pretty-print option"); + DATA(insert OID = 2506 ( pg_get_viewdef PGNSP PGUID 12 f f t f s 2 25 "26 16" pg_get_viewdef - _null_ )); + DESCR("select statement of a view with pretty-print option"); + DATA(insert OID = 2507 ( pg_get_indexdefPGNSP PGUID 12 f f t f s 3 25 "26 23 16" pg_get_indexdef - _null_ )); + DESCR("index description (full create statement or single expression) with pretty-print option"); + DATA(insert OID = 2508 ( pg_get_constraintdef PGNSP PGUID 12 f f t f s 2 25 "26 16" pg_get_constraintdef - _null_ )); + DESCR("constraint description with pretty-print option"); + DATA(insert OID = 2509 ( pg_get_exprPGNSP PGUID 12 f f t f s 3 25 "25 26 16" pg_get_expr - _null_ )); + DESCR("deparse an encoded expression with pretty-print option"); + /* * Symbolic values for provolatile column: these indicate whether the result Index: ruleutils.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/ruleutils.c,v retrieving revision 1.145 diff -c -r1.145 ruleutils.c *** ruleutils.c 4 Jul 2003 02:51:34 - 1.145 --- ruleutils.c 22 Jul 2003 12:54:10 - *** *** 71,76 --- 71,95 #include "utils/lsyscache.h" + /** + * Pretty formatting constants + **/ + + /* Indent counts */ + #define PRETTYINDENT_STD8 + #define PRETTYINDENT_JOIN 13 + #define PRETTYINDENT_JOIN_ON(PRETTYINDENT_JOIN-PRETTYINDENT_STD) + #define PRETTYINDENT_VAR4 + + /* Pretty flags */ + #define PRETTYFLAG_PAREN1 + #define PRETTYFLAG_INDENT 2 + + /* macro to test if pretty action needed */ + #define PRETTY_PAREN(context) (context->prettyFlags & PRETTYFLAG_PAREN) + #define PRETTY_INDENT(context) (context->prettyFlags & PRETTYFLAG_INDENT) + + /* -- * Local data types * -- *** *** 81,86 --- 100,107 { StringInfo buf;/* output buffer to append to */ List *namespaces; /* List of deparse_namespace nodes */ + int prettyFlags;/* enabling/disabling of pretty-print functions */ + int indentLevel;/* for prettyPrint, current space indents are counted */ boolvarprefix; /* TRUE to print prefixes on Vars */ } deparse_context; *** *** 123,135 * as a parameter, and append their text output to its contents. * -- */ ! static text *pg_do_getviewdef(Oid viewoid); static void decompile_column_index_array(Datum column_index_array, Oid relId, StringInfo buf); ! static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc); ! static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc); static void get_query_def(Query *query, StringInfo buf, List *parentnamespace, ! TupleDesc resultDesc); static void get_select_query_def(Query *query, deparse_context *context, TupleDesc resultDesc); static void get_insert_query_def(Query *query, deparse_context *context); --- 144,162 * as a parameter, and append their text output to its contents. * -- */ ! static char *get_simple_binary_op_name(OpExpr *expr); ! static void appendStringInfoSpace(StringInfo buf, int count); ! static void appendContextKeyword(deparse_context *context, char *str, int indentBefore, int indentAfter, int indentPlus); ! static char *deparse_expression_pretty(Node *expr, List *dpcontext, ! bool forceprefix, bool showimplicit, int prettyFlags, int star
Re: [PATCHES] ruleutils with pretty-print option
Bruce Momjian wrote: Tom Lane wrote: Bruce Momjian <[EMAIL PROTECTED]> writes: Tom, how do I pass PG_FUNCTION_ARGS to another function, while adding a new parameter? I wouldn't. Do the PG_GETARGS in the wrapper, and have the called function take a normal C parameter list. So I need to wrappers for each function, one that pulls the pretty print option, and another that doesn't, and they both call a normal C function? Hi Bruce, sorry for my late reply, I was out for a day. I wasn't aware of that regression test checking the arg count of the functions. I wanted to keep the impact on the source tree as small as possible, so I implemented that kind of overloaded functions. I clearly understand that Tom doesn't like to weaken the check, because in most cases a regression failure really is a coding problem. I recoded the stuff as Tom recommended, leaving the non-pretty version function names as they used to be, inventing new pg_get__ext functions for the extended stuff, and pushing the code down into pg_get__worker functions when needed. We now need the additional prototype include patch from builtins.h. All-new stuff attached, diff'ed against the current cvs. Regards, Andreas Index: include/catalog/pg_proc.h === RCS file: /projects/cvsroot/pgsql-server/src/include/catalog/pg_proc.h,v retrieving revision 1.309 diff -c -r1.309 pg_proc.h *** include/catalog/pg_proc.h 1 Jul 2003 00:04:38 - 1.309 --- include/catalog/pg_proc.h 27 Jul 2003 23:40:49 - *** *** 3405,3410 --- 3405,3424 DATA(insert OID = 2503 ( anyarray_send PGNSP PGUID 12 f f t f s 1 17 "2277" anyarray_send - _null_ )); DESCR("I/O"); + /* System-view support functions with pretty-print option */ + DATA(insert OID = 2504 ( pg_get_ruledef PGNSP PGUID 12 f f t f s 2 25 "26 16" pg_get_ruledef_ext - _null_ )); + DESCR("source text of a rule with pretty-print option"); + DATA(insert OID = 2505 ( pg_get_viewdef PGNSP PGUID 12 f f t f s 2 25 "25 16" pg_get_viewdef_name_ext - _null_ )); + DESCR("select statement of a view with pretty-print option"); + DATA(insert OID = 2506 ( pg_get_viewdef PGNSP PGUID 12 f f t f s 2 25 "26 16" pg_get_viewdef_ext - _null_ )); + DESCR("select statement of a view with pretty-print option"); + DATA(insert OID = 2507 ( pg_get_indexdefPGNSP PGUID 12 f f t f s 3 25 "26 23 16" pg_get_indexdef_ext - _null_ )); + DESCR("index description (full create statement or single expression) with pretty-print option"); + DATA(insert OID = 2508 ( pg_get_constraintdef PGNSP PGUID 12 f f t f s 2 25 "26 16" pg_get_constraintdef_ext - _null_ )); + DESCR("constraint description with pretty-print option"); + DATA(insert OID = 2509 ( pg_get_exprPGNSP PGUID 12 f f t f s 3 25 "25 26 16" pg_get_expr_ext - _null_ )); + DESCR("deparse an encoded expression with pretty-print option"); + /* * Symbolic values for provolatile column: these indicate whether the result Index: include/utils/builtins.h === RCS file: /projects/cvsroot/pgsql-server/src/include/utils/builtins.h,v retrieving revision 1.223 diff -c -r1.223 builtins.h *** include/utils/builtins.h27 Jun 2003 00:33:26 - 1.223 --- include/utils/builtins.h27 Jul 2003 23:41:58 - *** *** 441,453 --- 441,459 /* ruleutils.c */ extern Datum pg_get_ruledef(PG_FUNCTION_ARGS); + extern Datum pg_get_ruledef_ext(PG_FUNCTION_ARGS); extern Datum pg_get_viewdef(PG_FUNCTION_ARGS); + extern Datum pg_get_viewdef_ext(PG_FUNCTION_ARGS); extern Datum pg_get_viewdef_name(PG_FUNCTION_ARGS); + extern Datum pg_get_viewdef_name_ext(PG_FUNCTION_ARGS); extern Datum pg_get_indexdef(PG_FUNCTION_ARGS); + extern Datum pg_get_indexdef_ext(PG_FUNCTION_ARGS); extern Datum pg_get_triggerdef(PG_FUNCTION_ARGS); extern Datum pg_get_constraintdef(PG_FUNCTION_ARGS); + extern Datum pg_get_constraintdef_ext(PG_FUNCTION_ARGS); extern Datum pg_get_userbyid(PG_FUNCTION_ARGS); extern Datum pg_get_expr(PG_FUNCTION_ARGS); + extern Datum pg_get_expr_ext(PG_FUNCTION_ARGS); extern char *deparse_expression(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit); extern List *deparse_context_for(const char *aliasname, Oid relid); Index: backend/utils/adt/ruleutils.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/ruleutils.c,v retrieving revision 1.146 diff -c -r1.146 ruleutils.c *** backend/utils/adt/ruleutils.c 27 Jul 2003 04:53:09 - 1.146 --- backend/utils/adt/ruleutils.c 27 Jul 2003 23:42:40 - *** *** 71,76 --- 71,95 #include "utils/lsyscache.h" + /** + * Pretty formatting c
Re: [PATCHES] ruleutils with pretty-print option
Tom Lane wrote: Andreas Pflug <[EMAIL PROTECTED]> writes: + int prettyFlags = !PG_ARGISNULL(1) && PG_GETARG_BOOL(1) ? PRETTYFLAG_PAREN|PRETTYFLAG_INDENT : 0; Since the pg_proc entries are all marked strict, it's unnecessary for you to write any ARGISNULL checks. Yeah you're right, it's a remainder of the previous solution. it was late at night... But it won't do any harm either. Regards, Andreas ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org
Re: [PATCHES] ruleutils with pretty-print option
Tom Lane wrote: Applied with some editorializing. In particular, I don't believe the original did the right thing with (a - (b - c)). Oops, missed that case... But now, we have (a + ( b + c)) again. A patch that removes parentheses for + and * is appended. Regards, Andfdsa ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])
[Fwd: Re: [PATCHES] ruleutils with pretty-print option]
Now the patch is *really* appended :-) Tom Lane wrote: Applied with some editorializing. In particular, I don't believe the original did the right thing with (a - (b - c)). Oops, missed that case... But now, we have (a + ( b + c)) again. A patch that removes parentheses for + and * is appended. Regards, Andfdsa Index: backend/utils/adt/ruleutils.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/ruleutils.c,v retrieving revision 1.147 diff -c -r1.147 ruleutils.c *** backend/utils/adt/ruleutils.c 30 Jul 2003 22:56:23 - 1.147 --- backend/utils/adt/ruleutils.c 31 Jul 2003 09:32:15 - *** *** 2547,2552 --- 2547,2559 if (node == (Node *) lfirst(((OpExpr *) parentNode)->args)) return true; + /* + * Exception: for * and +, ordering doesn't matter + */ + if ((*op == '+' && *parentOp == '+') || + (*op == '*' && *parentOp == '*')) + return true; + return false; } /* else do the same stuff as for T_SubLink et al. */ ---(end of broadcast)--- TIP 7: don't forget to increase your free space map settings
Re: [Fwd: Re: [PATCHES] ruleutils with pretty-print option]
Tom Lane wrote: Now the patch is *really* appended :-) And rejected. Ok, the ckeck for node being the first child already does the trick for standard l-t-r evaluation. You cannot assume that an operator is commutative or associative just because it has a name you think ought to be. (For a counter-example, it's well known that floating-point addition is not associative.) Well, to me it's not well-known that floating-point addition is not associative, do I need to re-learn my math? More: if the tree structure for ops of equal precedence looks like a + (b + c), then it's a near certainty that the user wrote those parentheses. Why would you think that removing them is pretty-printing? In this case the user really wrote the parentheses, so they should be shown. This stuff is all about guessing what the original definition looked like, if we just had the source ... I had a conversation with Bruce about embedded comments, and we found that the idea of (mis-)using nodes for this seems to be not viable. Still seeking for a way to preserve more-or-less the original user's definition. Regards, Andreas ---(end of broadcast)--- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [Fwd: Re: [PATCHES] ruleutils with pretty-print option]
Tom Lane wrote: Andreas Pflug <[EMAIL PROTECTED]> writes: Well, to me it's not well-known that floating-point addition is not associative, do I need to re-learn my math? regression=# select (1.0::float8 + (-1.0::float8)) + 1.0e-20::float8; ?column? -- 1e-20 (1 row) regression=# select 1.0::float8 + ((-1.0::float8) + 1.0e-20::float8); ?column? -- 0 (1 row) Hi Tom, I already suspected an example like this. Obviously in a pure math world, the second example is wrong, caused by implicite rounding. Fortunately, if omitting the float8 casts numeric is used, delivering ultimate precision. Just for curiousity: on MSSQL2000, the first will deliver 9.95E-21, and if the type decimal(30,25) is used both give 0.000. Even better, CAST( CAST(1E-20 AS DECIMAL(30,25) AS FLOAT) is 0.0 :-> Oracle 9.2 will calculate correctly with float down to 1.0e-40. Regards, Andreas ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org
[PATCHES] win32 libpq
The attached patch allows libpq to be compiled under native win32. It adds the missing thread.c. Additionally, it corrects the option to compile for debugging. Regards, Andreas RCS file: /projects/cvsroot/pgsql-server/src/include/pg_config.h.win32,v retrieving revision 1.11 diff -u -r1.11 pg_config.h.win32 --- pg_config.h.win32 12 Jun 2003 08:15:29 - 1.11 +++ pg_config.h.win32 24 Aug 2003 18:26:16 - @@ -60,4 +60,9 @@ #include #endif +#include + +/* getpwuid doesn't exist under win32 */ +#define getpwuid(uid) NULL + #endif /* pg_config_h_win32__ */ RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/win32.mak,v retrieving revision 1.18 diff -u -r1.18 win32.mak --- win32.mak 12 Jun 2003 08:15:29 - 1.18 +++ win32.mak 24 Aug 2003 18:03:43 - @@ -8,7 +8,7 @@ !MESSAGE !IFDEF DEBUG -OPT=/Od +OPT=/Od /Zi LOPT=/debug DEBUGDEF=/D _DEBUG !ELSE @@ -26,12 +26,16 @@ CPP=cl.exe RSC=rc.exe +!IFDEF DEBUG +OUTDIR=.\Debug +INTDIR=.\Debug +CPP_OBJS=.\Debug/ +!ELSE OUTDIR=.\Release INTDIR=.\Release +CPP_OBJS=.\Release/ +!ENDIF -# Begin Custom Macros -OutDir=.\Release -# End Custom Macros ALL : "$(OUTDIR)\libpq.lib" "$(OUTDIR)\libpq.dll" @@ -72,16 +76,15 @@ "WIN32" /D "_WINDOWS" /Fp"$(INTDIR)\libpq.pch" /YX\ /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c /D "HAVE_VSNPRINTF" /D "HAVE_STRDUP" -CPP_OBJS=.\Release/ CPP_SBRS=. LIB32=link.exe -lib LIB32_FLAGS=$(LOPT) /nologo /out:"$(OUTDIR)\libpq.lib" LIB32_OBJS= \ - "$(OUTDIR)\win32.obj" \ + "$(INTDIR)\win32.obj" \ "$(INTDIR)\getaddrinfo.obj" \ "$(INTDIR)\inet_aton.obj" \ - "$(INTDIR)\crypt.obj" \ +"$(INTDIR)\crypt.obj" \ "$(INTDIR)\path.obj" \ "$(INTDIR)\dllist.obj" \ "$(INTDIR)\md5.obj" \ @@ -94,6 +97,7 @@ "$(INTDIR)\fe-lobj.obj" \ "$(INTDIR)\fe-misc.obj" \ "$(INTDIR)\fe-print.obj" \ + "$(INTDIR)\thread.obj" \ "$(INTDIR)\fe-secure.obj" \ "$(INTDIR)\pqexpbuffer.obj" \ "$(INTDIR)\wchar.obj" \ @@ -126,38 +130,43 @@ $(LINK32_FLAGS) $(LINK32_OBJS) << -"$(OUTDIR)\getaddrinfo.obj" : ..\..\port\getaddrinfo.c +"$(INTDIR)\getaddrinfo.obj" : ..\..\port\getaddrinfo.c $(CPP) @<< $(CPP_PROJ) ..\..\port\getaddrinfo.c << -"$(OUTDIR)\inet_aton.obj" : ..\..\port\inet_aton.c +"$(INTDIR)\thread.obj" : ..\..\port\thread.c +$(CPP) @<< +$(CPP_PROJ) ..\..\port\thread.c +<< + +"$(INTDIR)\inet_aton.obj" : ..\..\port\inet_aton.c $(CPP) @<< $(CPP_PROJ) ..\..\port\inet_aton.c << -"$(OUTDIR)\crypt.obj" : ..\..\port\crypt.c +"$(INTDIR)\crypt.obj" : ..\..\port\crypt.c $(CPP) @<< $(CPP_PROJ) ..\..\port\crypt.c << -"$(OUTDIR)\path.obj" : ..\..\port\path.c +"$(INTDIR)\path.obj" : ..\..\port\path.c $(CPP) @<< $(CPP_PROJ) ..\..\port\path.c << -"$(OUTDIR)\dllist.obj" : ..\..\backend\lib\dllist.c +"$(INTDIR)\dllist.obj" : ..\..\backend\lib\dllist.c $(CPP) @<< $(CPP_PROJ) ..\..\backend\lib\dllist.c << -"$(OUTDIR)\md5.obj" : ..\..\backend\libpq\md5.c +"$(INTDIR)\md5.obj" : ..\..\backend\libpq\md5.c $(CPP) @<< $(CPP_PROJ) ..\..\backend\libpq\md5.c << -"$(OUTDIR)\ip.obj" : ..\..\backend\libpq\ip.c +"$(INTDIR)\ip.obj" : ..\..\backend\libpq\ip.c $(CPP) @<< $(CPP_PROJ) ..\..\backend\libpq\ip.c << ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster
[PATCHES] non-blocking libpq under win32
The attached patch reenables non-blocking operation under win32. The global variable was left uninitialized, so the compiler would silently make it 0. This resulted in connectMakeNonblocking() setting nonblocking to zero, i.e. blocking. Regards, Andreas RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-connect.c,v retrieving revision 1.259 diff -u -r1.259 fe-connect.c --- fe-connect.c4 Aug 2003 02:40:16 - 1.259 +++ fe-connect.c24 Aug 2003 21:10:38 - @@ -48,7 +48,7 @@ /* For FNCTL_NONBLOCK */ #if defined(WIN32) || defined(__BEOS__) -long ioctlsocket_ret; +long ioctlsocket_ret=1; #endif ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org
[PATCHES] libpq with ssl under win32
The attached patch enables libpq to be linked with ssl support (openssl 0.9.7.b tested). Client certificates are commented out because the implementation is *nix specific, regarding the location resolution of the .pem files. It needs to be discussed where these files should be located. For NT/W2K and up, the natural way would be using GetUserProfileDirectory, but this would exclude Win9x. Regards, Andreas RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-secure.c,v retrieving revision 1.29 diff -u -r1.29 fe-secure.c --- fe-secure.c 4 Aug 2003 17:25:14 - 1.29 +++ fe-secure.c 24 Aug 2003 23:24:49 - @@ -312,7 +312,7 @@ printfPQExpBuffer(&conn->errorMessage, libpq_gettext("SSL SYSCALL error: EOF detected\n")); - SOCK_ERRNO = ECONNRESET; + SOCK_ERRNO_SET(ECONNRESET); n = -1; } break; @@ -322,7 +322,7 @@ libpq_gettext("SSL error: %s\n"), SSLerrmessage()); /* fall through */ case SSL_ERROR_ZERO_RETURN: - SOCK_ERRNO = ECONNRESET; + SOCK_ERRNO_SET(ECONNRESET); n = -1; break; default: @@ -383,7 +383,7 @@ { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("SSL SYSCALL error: EOF detected\n")); - SOCK_ERRNO = ECONNRESET; + SOCK_ERRNO_SET(ECONNRESET); n = -1; } break; @@ -393,7 +393,7 @@ libpq_gettext("SSL error: %s\n"), SSLerrmessage()); /* fall through */ case SSL_ERROR_ZERO_RETURN: - SOCK_ERRNO = ECONNRESET; + SOCK_ERRNO_SET(ECONNRESET); n = -1; break; default: @@ -544,6 +544,9 @@ static DH * load_dh_file(int keylength) { +#ifdef WIN32 +return NULL; +#else charpwdbuf[BUFSIZ]; struct passwd pwdstr; struct passwd *pwd = NULL; @@ -558,6 +561,7 @@ /* attempt to open file. It's not an error if it doesn't exist. */ snprintf(fnbuf, sizeof fnbuf, "%s/.postgresql/dh%d.pem", pwd->pw_dir, keylength); + if ((fp = fopen(fnbuf, "r")) == NULL) return NULL; @@ -583,6 +587,7 @@ } return dh; +#endif } /* @@ -686,6 +691,9 @@ static int client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey) { +#ifdef WIN32 + return 0; +#else charpwdbuf[BUFSIZ]; struct passwd pwdstr; struct passwd *pwd = NULL; @@ -785,6 +793,7 @@ } return 1; +#endif } /* @@ -793,11 +802,13 @@ static int initialize_SSL(PGconn *conn) { +#ifndef WIN32 struct stat buf; charpwdbuf[BUFSIZ]; struct passwd pwdstr; struct passwd *pwd = NULL; charfnbuf[2048]; +#endif if (!SSL_context) { @@ -813,6 +824,7 @@ } } +#ifndef WIN32 if (pqGetpwuid(getuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pwd) == 0) { snprintf(fnbuf, sizeof fnbuf, "%s/.postgresql/root.crt", @@ -849,6 +861,7 @@ /* set up mechanism to provide client certificate, if available */ SSL_CTX_set_client_cert_cb(SSL_context, client_cert_cb); +#endif return 0; } RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/libpq-int.h,v retrieving revision 1.81 diff -u -r1.81 libpq-int.h --- libpq-int.h 13 Aug 2003 18:56:21 - 1.81 +++ libpq-int.h 24 Aug 2003 23:25:46 - @@ -465,9 +465,11 @@ #ifdef WIN32 #define SOCK_ERRNO (WSAGetLastError()) #define SOCK_STRERROR winsock_strerror +#define SOCK_ERRNO_SET(e) WSASetLastError(e) #else #define SOCK_ERRNO errno #define SOCK_STRERROR pqStrerror +#define SOCK_ERRNO_SET(e) errno=e #endif #endif /* LIBPQ_INT_H */RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/win32.mak,v retrieving revision 1.18 diff -u -r1.18 win32.mak --- win32.mak 12 Jun 2003 08:15:29 - 1.18 +++ win32.mak 24 Aug 2003 23:32:42 - @@ -8,7 +8,7 @@ !MESS
[PATCHES] non-blocking libpq under win32
The attached patch reenables non-blocking operation under win32. The global variable was left uninitialized, so the compiler would silently make it 0. This resulted in connectMakeNonblocking() setting nonblocking to zero, i.e. blocking. Regards, Andreas RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-connect.c,v retrieving revision 1.259 diff -u -r1.259 fe-connect.c --- fe-connect.c4 Aug 2003 02:40:16 - 1.259 +++ fe-connect.c24 Aug 2003 21:10:38 - @@ -48,7 +48,7 @@ /* For FNCTL_NONBLOCK */ #if defined(WIN32) || defined(__BEOS__) -long ioctlsocket_ret; +long ioctlsocket_ret=1; #endif ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org
[PATCHES] libpq-win32 patches
Hm, I don't see any reaction on my posts from last sunday, neither in this list nor in unapplied patches, did they get lost? If so, attached is a combined patch for all three problems with libpq compiling under win32. Regards, Andreas cvs diff -u interfaces\libpq\fe-connect.c interfaces\libpq\fe-exec.c interfaces\libpq\fe-secure.c interfaces\libpq\libpq-int.h include\pg_config.h.win32 interfaces\libpq\win32.c interfaces\libpq\win32.mak (in directory C:\postgresql\src\) Index: interfaces/libpq/fe-connect.c === RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-connect.c,v retrieving revision 1.259 diff -u -r1.259 fe-connect.c --- interfaces/libpq/fe-connect.c 4 Aug 2003 02:40:16 - 1.259 +++ interfaces/libpq/fe-connect.c 31 Aug 2003 23:22:25 - @@ -48,7 +48,7 @@ /* For FNCTL_NONBLOCK */ #if defined(WIN32) || defined(__BEOS__) -long ioctlsocket_ret; +long ioctlsocket_ret=1; #endif #define PGPASSFILE ".pgpass" Index: interfaces/libpq/fe-exec.c === RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-exec.c,v retrieving revision 1.146 diff -u -r1.146 fe-exec.c --- interfaces/libpq/fe-exec.c 27 Aug 2003 00:33:34 - 1.146 +++ interfaces/libpq/fe-exec.c 31 Aug 2003 23:22:28 - @@ -2304,7 +2304,7 @@ if (buffer == NULL) return NULL; - for (i = j = buflen = 0; i < strtextlen;) + for (i = j = buflen = 0; i < (int)strtextlen;) { switch (strtext[i]) { Index: interfaces/libpq/fe-secure.c === RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-secure.c,v retrieving revision 1.29 diff -u -r1.29 fe-secure.c --- interfaces/libpq/fe-secure.c4 Aug 2003 17:25:14 - 1.29 +++ interfaces/libpq/fe-secure.c31 Aug 2003 23:22:29 - @@ -312,7 +312,7 @@ printfPQExpBuffer(&conn->errorMessage, libpq_gettext("SSL SYSCALL error: EOF detected\n")); - SOCK_ERRNO = ECONNRESET; + SOCK_ERRNO_SET(ECONNRESET); n = -1; } break; @@ -322,7 +322,7 @@ libpq_gettext("SSL error: %s\n"), SSLerrmessage()); /* fall through */ case SSL_ERROR_ZERO_RETURN: - SOCK_ERRNO = ECONNRESET; + SOCK_ERRNO_SET(ECONNRESET); n = -1; break; default: @@ -383,7 +383,7 @@ { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("SSL SYSCALL error: EOF detected\n")); - SOCK_ERRNO = ECONNRESET; + SOCK_ERRNO_SET(ECONNRESET); n = -1; } break; @@ -393,7 +393,7 @@ libpq_gettext("SSL error: %s\n"), SSLerrmessage()); /* fall through */ case SSL_ERROR_ZERO_RETURN: - SOCK_ERRNO = ECONNRESET; + SOCK_ERRNO_SET(ECONNRESET); n = -1; break; default: @@ -544,6 +544,9 @@ static DH * load_dh_file(int keylength) { +#ifdef WIN32 +return NULL; +#else charpwdbuf[BUFSIZ]; struct passwd pwdstr; struct passwd *pwd = NULL; @@ -558,6 +561,7 @@ /* attempt to open file. It's not an error if it doesn't exist. */ snprintf(fnbuf, sizeof fnbuf, "%s/.postgresql/dh%d.pem", pwd->pw_dir, keylength); + if ((fp = fopen(fnbuf, "r")) == NULL) return NULL; @@ -583,6 +587,7 @@ } return dh; +#endif } /* @@ -686,6 +691,9 @@ static int client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey) { +#ifdef WIN32 + return 0; +#else charpwdbuf[BUFSIZ]; struct passwd pwdstr; struct passwd *pwd = NULL; @@ -785,6 +793,7 @@ } return 1; +#endif } /* @@ -793,11 +802,13 @@ static int initialize_SSL(PGconn *conn) { +#ifndef WIN
[PATCHES] IPV4 addresses on IPV6 machines in pg_hba.conf
This was discussed in [HACKERS] TCP/IP with 7.4 beta2 broken? I created a patch to hba.c which uses IPV4 entries as IPV6 entries if running on a IPV6 system (which is detected from a port coming in as AF_INET6). 192.168.0.0/24 -> :::102.168.0/120 192.168.0.0 255.255.255.0 -> :::102.168.0 ::::::255.255.255.0 This helps people that think they're using IPV4 while actually their system silently is using IPV6 (such as SuSE 8.1, 8.2). Regards, Andreas ? hba.conf.diff Index: hba.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/libpq/hba.c,v retrieving revision 1.111 diff -c -r1.111 hba.c *** hba.c 4 Aug 2003 02:39:59 - 1.111 --- hba.c 2 Sep 2003 11:07:10 - *** *** 673,708 if (cidr_slash) *cidr_slash = '/'; ! if (file_ip_addr->ai_family != port->raddr.addr.ss_family) { ! /* Wrong address family. */ freeaddrinfo_all(hints.ai_family, file_ip_addr); - return; - } ! /* Get the netmask */ ! if (cidr_slash) { ! if (SockAddr_cidr_mask(&mask, cidr_slash + 1, ! file_ip_addr->ai_family) < 0) ! goto hba_syntax; } else { ! /* Read the mask field. */ ! line = lnext(line); ! if (!line) ! goto hba_syntax; ! token = lfirst(line); ! ! ret = getaddrinfo_all(token, NULL, &hints, &file_ip_mask); ! if (ret || !file_ip_mask) ! goto hba_syntax; ! ! mask = (struct sockaddr_storage *) file_ip_mask->ai_addr; ! ! if (file_ip_addr->ai_family != mask->ss_family) ! goto hba_syntax; } /* Read the rest of the line. */ --- 673,761 if (cidr_slash) *cidr_slash = '/'; ! if (file_ip_addr->ai_family == AF_INET && port->raddr.addr.ss_family == AF_INET6) { ! /* port got a IPV6 address, but the current line is IPV4. ! * We'll make a IPV6 entry from this line, to check if by chance the connecting port ! * is a converted IPV4 address. */ ! ! char *v6addr=palloc(strlen(token)+8); ! char *v6mask; ! freeaddrinfo_all(hints.ai_family, file_ip_addr); ! if (cidr_slash) ! *cidr_slash = 0; ! sprintf(v6addr, ":::%s", token); ! if (cidr_slash) ! *cidr_slash = '/'; ! ! ret = getaddrinfo_all(v6addr, NULL, &hints, &file_ip_addr); ! if (ret || !file_ip_addr) ! { ! ereport(LOG, ! (errcode(ERRCODE_CONFIG_FILE_ERROR), !errmsg("could not interpret converted IP address \"%s\" in config file: %s", ! token, gai_strerror(ret; ! } ! if (cidr_slash) ! { ! v6mask = palloc(20); ! sprintf(v6mask, "%d", atoi(cidr_slash+1)+96); ! if (SockAddr_cidr_mask(&mask, v6mask, file_ip_addr->ai_family) < 0) ! goto hba_syntax; ! } ! else ! { ! line = lnext(line); ! if (!line) ! goto hba_syntax; ! token = lfirst(line); ! v6mask = palloc(strlen(token)+32); ! sprintf(v6mask, "::::::%s", token); ! ! ret = getaddrinfo_all(v6mask, NULL, &hints, &file_ip_mask); ! if (ret || !file_ip_mask) ! goto hba_syntax; ! ! mask = (struct sockaddr_storage *) file_ip_mask->ai_addr; ! ! if (file_ip_addr->ai_family != mask->ss_family) ! goto hba_syntax; ! } ! } !
Re: [PATCHES] IPV4 addresses on IPV6 machines in pg_hba.conf
Kurt Roeckx wrote: You're assuming all systems have an AF_INET6 constant, which is not the case. Please make use of HAVE_IPV6. Can't directly see anything else wrong with it. Here's the patch with HAVE_IPV6 conditional compiling. Regards, Andreas Index: hba.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/libpq/hba.c,v retrieving revision 1.111 diff -c -r1.111 hba.c *** hba.c 4 Aug 2003 02:39:59 - 1.111 --- hba.c 5 Sep 2003 00:24:47 - *** *** 673,708 if (cidr_slash) *cidr_slash = '/'; ! if (file_ip_addr->ai_family != port->raddr.addr.ss_family) { ! /* Wrong address family. */ freeaddrinfo_all(hints.ai_family, file_ip_addr); ! return; } ! /* Get the netmask */ ! if (cidr_slash) { ! if (SockAddr_cidr_mask(&mask, cidr_slash + 1, ! file_ip_addr->ai_family) < 0) ! goto hba_syntax; } else { ! /* Read the mask field. */ ! line = lnext(line); ! if (!line) ! goto hba_syntax; ! token = lfirst(line); ! ! ret = getaddrinfo_all(token, NULL, &hints, &file_ip_mask); ! if (ret || !file_ip_mask) ! goto hba_syntax; ! ! mask = (struct sockaddr_storage *) file_ip_mask->ai_addr; ! ! if (file_ip_addr->ai_family != mask->ss_family) ! goto hba_syntax; } /* Read the rest of the line. */ --- 673,767 if (cidr_slash) *cidr_slash = '/'; ! #ifdef HAVE_IPV6 ! ! if (file_ip_addr->ai_family == AF_INET && port->raddr.addr.ss_family == AF_INET6) { ! /* port got a IPV6 address, but the current line is IPV4. ! * We'll make a IPV6 entry from this line, to check if by chance the connecting port ! * is a converted IPV4 address. */ ! ! char *v6addr=palloc(strlen(token)+8); ! char *v6mask; ! freeaddrinfo_all(hints.ai_family, file_ip_addr); ! ! if (cidr_slash) ! *cidr_slash = 0; ! sprintf(v6addr, ":::%s", token); ! if (cidr_slash) ! *cidr_slash = '/'; ! ! ret = getaddrinfo_all(v6addr, NULL, &hints, &file_ip_addr); ! if (ret || !file_ip_addr) ! { ! ereport(LOG, ! (errcode(ERRCODE_CONFIG_FILE_ERROR), !errmsg("could not interpret converted IP address \"%s\" in config file: %s", ! token, gai_strerror(ret; ! } ! if (cidr_slash) ! { ! v6mask = palloc(20); ! sprintf(v6mask, "%d", atoi(cidr_slash+1)+96); ! if (SockAddr_cidr_mask(&mask, v6mask, file_ip_addr->ai_family) < 0) ! goto hba_syntax; ! } ! else ! { ! line = lnext(line); ! if (!line) ! goto hba_syntax; ! token = lfirst(line); ! v6mask = palloc(strlen(token)+32); ! sprintf(v6mask, "::::::%s", token); ! ! ret = getaddrinfo_all(v6mask, NULL, &hints, &file_ip_mask); ! if (ret || !file_ip_mask) ! goto hba_syntax; ! ! mask = (struct sockaddr_storage *) file_ip_mask->ai_addr; ! ! if (file_ip_addr->ai_family != mask->ss_family) ! goto hba_syntax; ! } } + else + + #endif // HAVE_IPV6 ! if (file_ip_addr->ai_family != port->raddr.addr.ss_family) { ! /* Wrong address family. */ ! freeaddrinfo_all(hints.ai_family, file_ip_add
Re: [PATCHES] libpq-win32 patches
Hi Bruce, + +/* getpwuid doesn't exist under win32 */ +#define getpwuid(uid) NULL + #endif /* pg_config_h_win32__ */ Why was this needed? I realize we don't have getpwuid() on Win32, but we do have GetUserName() for cases where we need the name but not the directory. Because all the getpwuid() calls seem ifdef'ed out under Win32 anyway, I don't understand why you needed it. I believe it was the first thing I did to have libpq compile at all. Later, I went into the ssl code and made it work, effectively commenting out all calls to getpwuid() making that line unnecessary. Can't we check the OS version via the compiler? Maybe not portabily between the various compilers supported. If you're talking about the WIN32 macro, this should be supported by every compiler running for win32, because windows headers rely on this. Regards, Andreas ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])
Re: [PATCHES] IPV4 addresses on IPV6 machines in pg_hba.conf
Andrew Dunstan wrote: Andreas, You should check that the CIDR mask is a valid integer. You would need to use strtol() rather than atoi() to do that. Perhaps this should be hoisted out of ip.c:SockAddr_cidr_mask() and put in hba.c. Right, I added this. Regards, Andreas Index: hba.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/libpq/hba.c,v retrieving revision 1.112 diff -c -r1.112 hba.c *** hba.c 5 Sep 2003 03:57:13 - 1.112 --- hba.c 5 Sep 2003 09:04:33 - *** *** 673,708 if (cidr_slash) *cidr_slash = '/'; ! if (file_ip_addr->ai_family != port->raddr.addr.ss_family) { ! /* Wrong address family. */ freeaddrinfo_all(hints.ai_family, file_ip_addr); ! return; } ! /* Get the netmask */ ! if (cidr_slash) { ! if (SockAddr_cidr_mask(&mask, cidr_slash + 1, ! file_ip_addr->ai_family) < 0) ! goto hba_syntax; } else { ! /* Read the mask field. */ ! line = lnext(line); ! if (!line) ! goto hba_syntax; ! token = lfirst(line); ! ! ret = getaddrinfo_all(token, NULL, &hints, &file_ip_mask); ! if (ret || !file_ip_mask) ! goto hba_syntax; ! ! mask = (struct sockaddr_storage *) file_ip_mask->ai_addr; ! ! if (file_ip_addr->ai_family != mask->ss_family) ! goto hba_syntax; } /* Read the rest of the line. */ --- 673,774 if (cidr_slash) *cidr_slash = '/'; ! #ifdef HAVE_IPV6 ! ! if (file_ip_addr->ai_family == AF_INET && port->raddr.addr.ss_family == AF_INET6) { ! /* port got a IPV6 address, but the current line is IPV4. ! * We'll make a IPV6 entry from this line, to check if by chance the connecting port ! * is a converted IPV4 address. */ ! ! char *v6addr=palloc(strlen(token)+8); ! char *v6mask; ! freeaddrinfo_all(hints.ai_family, file_ip_addr); ! ! if (cidr_slash) ! *cidr_slash = 0; ! sprintf(v6addr, ":::%s", token); ! if (cidr_slash) ! *cidr_slash = '/'; ! ! ret = getaddrinfo_all(v6addr, NULL, &hints, &file_ip_addr); ! if (ret || !file_ip_addr) ! { ! ereport(LOG, ! (errcode(ERRCODE_CONFIG_FILE_ERROR), !errmsg("could not interpret converted IP address \"%s\" in config file: %s", ! token, gai_strerror(ret; ! } ! if (cidr_slash) ! { ! int v4bits; ! char *endptr; ! ! v4bits=strtol(cidr_slash+1, &endptr, 10); ! if (cidr_slash[1]==0 || *endptr!=0 || v4bits<0 || v4bits>32) ! goto hba_syntax; ! ! v6mask = palloc(20); ! sprintf(v6mask, "%d", v4bits+96); ! if (SockAddr_cidr_mask(&mask, v6mask, file_ip_addr->ai_family) < 0) ! goto hba_syntax; ! } ! else ! { ! line = lnext(line); ! if (!line) ! goto hba_syntax; ! token = lfirst(line); ! v6mask = palloc(strlen(token)+32); ! sprintf(v6mask, "::::::%s", token); ! ! ret = getaddrinfo_all(v6mask, NULL, &hints, &file_ip_mask); ! if (ret || !file_ip_mask) ! goto hba_syntax; ! ! mask = (struct sockaddr_storage *) file_ip_mask->ai_addr; ! ! if (file_ip_addr->ai_family != mask->ss_family) !
Re: [PATCHES] IPV4 addresses on IPV6 machines in pg_hba.conf
Tom Lane wrote: I thought this was still really messy, so I modified it to use a separate "promote v4 address to v6" subroutine. I've applied the attached patch (plus docs). It's not very well tested since I don't have an IPv6 setup here; please check that it does what you want. It SEGVs. Reason is that the memcpy of the promote_v4_to_v6_XXX functions assumes that the sockaddr_storage is large enough to hold an IPV6 address, which appears to be not true. Since the struct isn't created by a plain malloc() and returned by free(), but assembled by getaddrinfo() according to the family's requirement, I don't see a way how to fix this. IMHO the struct needs to be created officially by getaddrinfo(), which will lead more or less the the same solution I posted previously. Regards, Andreas ---(end of broadcast)--- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [PATCHES] IPV4 addresses on IPV6 machines in pg_hba.conf
Tom Lane wrote: IMHO the struct needs to be created officially by getaddrinfo(), which will lead more or less the the same solution I posted previously. No, we just need to use datastructures that are under our control for the values that will get passed to rangeSockAddr. A few more lines... Hm, are you sure it's not just for beauty's sake? While talking about beauty: that setting of *cidr_slash to '/' and 0 doesn't look too esthetic... Regards, Andreas ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]
Re: [PATCHES] Unixware 713 probs
Larry Rosenman wrote: Here's a quickie patch I did to fix it. Patching this or not, if the function's called the backend will SEGV either (at least on my 2.4.20 it does) because a IPV6 address is copied in the memory space of a IPV4 address. Regards, Andreas ---(end of broadcast)--- TIP 7: don't forget to increase your free space map settings
Re: [PATCHES] Unixware 713 probs
Tom Lane wrote: Andreas Pflug <[EMAIL PROTECTED]> writes: Larry Rosenman wrote: Here's a quickie patch I did to fix it. Patching this or not, if the function's called the backend will SEGV either (at least on my 2.4.20 it does) because a IPV6 address is copied in the memory space of a IPV4 address. I fixed that yesterday. Ah, didn't notice, I thought you would announce this to have it tested. I just did and it works as expected. Regards, Andreas ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org
Re: [PATCHES] preliminary: logical column order
I wonder if it wouldn't be easier to reorder the TupDesc->attrs[] array according to an attphysid when filling the TupDesc structure, right after a column was dropped/recreated (before any indexes/constraints are recreated), so attnum remains, while storage changes. Example: before: attnum attphysid attname attisdropped 1 1 foo f 2 2 bar f after drop/recreate col: 1 3 foo f 2 2 bar f 3 1 foo_del t resulting in an attrs array attrs[0] describing physical col 3 attrs[1] describing physical col 2 attrs[2] describing physical col 1 Regards, Andreas ---(end of broadcast)--- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
[PATCHES] libpq endless loop if client_min_messages=debug1
My Deja wrote: I am trying to get some query trees to appear in the PostgreSQL log and in order to that I have set client_min_messages = DEBUG1 in order to use the following settings debug_print_parse, debug_print_rewritten, or debug_print_plan which are required for the query tree to show up in the log. pgAdmin crashes whenever I set that option. I tried a few times and I am sure of it. I am using PostgreSQL 7.4 under Cygwin on a Windows 2000 machine, but I don't think that has any relevance. I reproduced this problem with 7.5 head backend and libpq under win32 and Linux, and found that the problem is pqParseInput3 expecting a message length >= 3 only for message types 'T', 'D' and 'd', but not 'N'. In the case tested above, the message will be 49336 bytes long, causing an endless loop in PQexecFinish because PQgetResult will deliver the same broken message forever. The attached patch fixes this. I wonder if there are additional message types that might be longer? Regards, Andreas Index: fe-protocol3.c === RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-protocol3.c,v retrieving revision 1.10 diff -u -r1.10 fe-protocol3.c --- fe-protocol3.c 29 Nov 2003 19:52:12 - 1.10 +++ fe-protocol3.c 28 Dec 2003 11:26:09 - @@ -84,7 +84,7 @@ return; } if (msgLength > 3 && - !(id == 'T' || id == 'D' || id == 'd')) + !(id == 'N' || id == 'T' || id == 'D' || id == 'd')) { handleSyncLoss(conn, id, msgLength); return; ---(end of broadcast)--- TIP 8: explain analyze is your friend
[PATCHES] thread safety testing fix
When checking for thread safety with src/tools/thread/thread_test.c, the mktemp function wants an argument that contains 6 X, while the current version only supplies 5 X which will fail on my SuSE 8.1. Patch attached. Regards, Andreas Index: thread_test.c === RCS file: /projects/cvsroot/pgsql-server/src/tools/thread/thread_test.c,v retrieving revision 1.29 diff -u -r1.29 thread_test.c --- thread_test.c 27 Apr 2004 19:51:12 - 1.29 +++ thread_test.c 28 May 2004 11:39:00 - @@ -64,8 +64,8 @@ void func_call_1(void); void func_call_2(void); -#defineTEMP_FILENAME_1 "/tmp/thread_test.1.X" -#defineTEMP_FILENAME_2 "/tmp/thread_test.2.X" +#defineTEMP_FILENAME_1 "/tmp/thread_test.1.XX" +#defineTEMP_FILENAME_2 "/tmp/thread_test.2.XX" char *temp_filename_1; char *temp_filename_2; ---(end of broadcast)--- TIP 7: don't forget to increase your free space map settings
[PATCHES] Compiling libpq with VisualC
Some modifications are needed to compile libpq with vc6: 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 win32.mak: - pg_config.h must be generated - port/pgstrcasecmp.c is needed - port/path.c is not needed - the current cvs version includes some bogus cr characters, when checking out with wincvs the file will contain several cr cr lf lines which will confuse nmake. Because the last problem might be difficult to handle as diff, I attached win32.mak as complete file, with all cr stripped so it may be committed safely with any cvs client. Regards, Andreas Index: fe-connect.c === RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-connect.c,v retrieving revision 1.271 diff -u -r1.271 fe-connect.c --- fe-connect.c26 May 2004 18:35:51 - 1.271 +++ fe-connect.c28 May 2004 11:48:56 - @@ -29,7 +29,10 @@ #include "libpq-fe.h" #include "libpq-int.h" #include "fe-auth.h" + +#ifndef SYSCONFDIR #include "pg_config_paths.h" +#endif #ifdef WIN32 #include "win32.h" # Makefile for Microsoft Visual C++ 5.0 (or compat) # Will build a Win32 static library libpq(d).lib #and a Win32 dynamic library libpq(d).dll with import library libpq(d)dll.lib # USE_SSL=1 will compile with OpenSSL # DEBUG=1 compiles with debugging symbols !MESSAGE Building the Win32 static library... !MESSAGE !IFDEF DEBUG OPT=/Od /Zi /MDd LOPT=/DEBUG DEBUGDEF=/D _DEBUG OUTFILENAME=libpqd !ELSE OPT=/O2 /MD LOPT= DEBUGDEF=/D NDEBUG OUTFILENAME=libpq !ENDIF !IF "$(OS)" == "Windows_NT" NULL= !ELSE NULL=nul !ENDIF CPP=cl.exe RSC=rc.exe !IFDEF DEBUG OUTDIR=.\Debug INTDIR=.\Debug CPP_OBJS=.\Debug/ !ELSE OUTDIR=.\Release INTDIR=.\Release CPP_OBJS=.\Release/ !ENDIF ALL : config "$(OUTDIR)\$(OUTFILENAME).lib" "$(OUTDIR)\$(OUTFILENAME).dll" CLEAN : [EMAIL PROTECTED] "$(INTDIR)\getaddrinfo.obj" [EMAIL PROTECTED] "$(INTDIR)\pgstrcasecmp.obj" [EMAIL PROTECTED] "$(INTDIR)\thread.obj" [EMAIL PROTECTED] "$(INTDIR)\inet_aton.obj" [EMAIL PROTECTED] "$(INTDIR)\crypt.obj" [EMAIL PROTECTED] "$(INTDIR)\noblock.obj" [EMAIL PROTECTED] "$(INTDIR)\dllist.obj" [EMAIL PROTECTED] "$(INTDIR)\md5.obj" [EMAIL PROTECTED] "$(INTDIR)\ip.obj" [EMAIL PROTECTED] "$(INTDIR)\fe-auth.obj" [EMAIL PROTECTED] "$(INTDIR)\fe-protocol2.obj" [EMAIL PROTECTED] "$(INTDIR)\fe-protocol3.obj" [EMAIL PROTECTED] "$(INTDIR)\fe-connect.obj" [EMAIL PROTECTED] "$(INTDIR)\fe-exec.obj" [EMAIL PROTECTED] "$(INTDIR)\fe-lobj.obj" [EMAIL PROTECTED] "$(INTDIR)\fe-misc.obj" [EMAIL PROTECTED] "$(INTDIR)\fe-print.obj" [EMAIL PROTECTED] "$(INTDIR)\fe-secure.obj" [EMAIL PROTECTED] "$(INTDIR)\pqexpbuffer.obj" [EMAIL PROTECTED] "$(OUTDIR)\libpqdll.obj" [EMAIL PROTECTED] "$(OUTDIR)\win32.obj" [EMAIL PROTECTED] "$(OUTDIR)\$(OUTFILENAME).lib" [EMAIL PROTECTED] "$(OUTDIR)\$(OUTFILENAME).dll" [EMAIL PROTECTED] "$(OUTDIR)\libpq.res" [EMAIL PROTECTED] "*.pch" [EMAIL PROTECTED] "$(OUTDIR)\libpq.pch" [EMAIL PROTECTED] "$(OUTDIR)\$(OUTFILENAME)dll.exp" [EMAIL PROTECTED] "$(OUTDIR)\$(OUTFILENAME)dll.lib" [EMAIL PROTECTED] "$(INTDIR)\wchar.obj" [EMAIL PROTECTED] "$(INTDIR)\encnames.obj" config: ..\..\include\pg_config.h ..\..\include\pg_config.h: ..\..\include\pg_config.h.win32 copy ..\..\include\pg_config.h.win32 ..\..\include\pg_config.h "$(OUTDIR)" : if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)" CPP_PROJ=/nologo /W3 /GX $(OPT) /I "..\..\include" /D "FRONTEND" $(DEBUGDEF) /D\ "WIN32" /D "_WINDOWS" /Fp"$(INTDIR)\libpq.pch" /YX\ /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c /D "HAVE_VSNPRINTF" /D "HAVE_STRDUP" !IFDEF USE_SSL CPP_PROJ=$(CPP_PROJ) /D USE_SSL SSL_LIBS=ssleay32.lib libeay32.lib gdi32.lib !ENDIF CPP_SBRS=. LIB32=link.exe -lib LIB32_FLAGS=$(LOPT) /nologo /out:"$(OUTDIR)\$(OUTFILENAME).lib" LIB32_OBJS= \ "$(INTDIR)\win32.obj" \ "$(INTDIR)\getaddrinfo.obj" \ "$(INTDIR)\pgstrcasecmp.obj" \ "$(INTDIR)\thread.obj" \ "$(INTDIR)\inet_aton.obj" \ "$(INTDIR)\crypt.obj" \ "$(INTDIR)\noblock.obj" \ "$(INTDIR)\dllist.obj" \ "$(INTDIR)\md5.obj" \ "$(INTDIR)\ip.obj" \ "$(INTDIR)\fe-auth.obj" \ "$(INTDIR)\fe-protocol2.obj" \ "$(INTDIR)\fe-protocol3.obj" \ "$(INTDIR)\fe-connect.obj" \ "$(INTDIR)\fe-exec.obj" \ "$(INTDIR)\fe-lobj.obj" \ "$(INTDIR)\fe-misc.obj" \ "$(INTDIR)\fe-print.obj" \ "$(INTDIR)\fe-secure.obj" \ "$(INTDIR)\pqexpbuffer.obj" \ "$(INTDIR)\wchar.obj" \ "$(INTDIR)\encnames.obj" RSC_PROJ=/l 0x409 /fo"$(INTDIR)\libpq.res" LINK32=link.exe LINK32_FLAGS=kernel32.lib u
[PATCHES] Libpq ssl fix
init_ssl_system will return 0 on success and -1 on failure, which will be interpreted just the other way round in initialize_SSL. Patch appended. Regards, Andreas Index: fe-secure.c === RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-secure.c,v retrieving revision 1.40 diff -u -r1.40 fe-secure.c --- fe-secure.c 7 May 2004 00:24:59 - 1.40 +++ fe-secure.c 28 May 2004 14:00:40 - @@ -922,7 +922,7 @@ charfnbuf[2048]; #endif - if(!init_ssl_system(conn)) + if(init_ssl_system(conn)) return -1; #ifndef WIN32 ---(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] Libpq ssl fix
Manfred Spraul wrote: Btw, --enable-thread-safety on Linux (RedHat Fedora Core 1) fails in configure with configure: error: *** Thread test program failed. Your platform is not thread-safe. *** Check the file 'config.log'for the exact reason. I had this too, for two reasons: - configure checks for libpthreads, while the libs are called libpthread on my system. - patch for thread_test.c needed posted some hours ago. Regards, Andreas ---(end of broadcast)--- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [PATCHES] thread safety testing fix
Tom Lane wrote: Andreas Pflug <[EMAIL PROTECTED]> writes: When checking for thread safety with src/tools/thread/thread_test.c, the mktemp function wants an argument that contains 6 X, while the current version only supplies 5 X which will fail on my SuSE 8.1. Patch attached. Isn't this going to break platforms that only want 5 X's ? Probably not., any additional X will just be ignored. AFAICS all platforms want at least 6 X anyway. Regards, Andreas ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])
Re: [PATCHES] Libpq ssl fix
Tom Lane wrote: Andreas Pflug <[EMAIL PROTECTED]> writes: init_ssl_system will return 0 on success and -1 on failure, which will be interpreted just the other way round in initialize_SSL. Patch appended. Hmm, that looks backwards to me too, but this would seem to imply that Manfred Spraul failed to test his last patch at all. Manfred, care to explain why we shouldn't revert that patch in toto? FYI: I tried to compile libpq with ENABLE_THREAD_SAFETY under win32, and quickly stopped it because the implementation has pthread stuff buried deep inside the sources. No pthread under win32... This needs quite some portability work. Regards, Andreas ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html
Re: [PATCHES] Compiling libpq with VisualC
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. Regards, Andreas ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html
Re: [PATCHES] Compiling libpq with VisualC
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
Re: [PATCHES] Compiling libpq with VisualC
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
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
[PATCHES] Int2 vector to array equality
While trying to pg_constraint JOIN pg_index ON indrelid=conrelid AND conkey=indkey I noticed (once again) that these columns have different types (although describing the same thing), and there's no equality operator for them. The attached patch adds an equality operator bool int2array_int2vector_eq(int2[], int2vector) to enable this join. Regards, Andreas Index: backend/utils/adt/arrayfuncs.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/arrayfuncs.c,v retrieving revision 1.103 diff -u -r1.103 arrayfuncs.c --- backend/utils/adt/arrayfuncs.c 6 Jun 2004 00:41:27 - 1.103 +++ backend/utils/adt/arrayfuncs.c 6 Jun 2004 23:14:44 - @@ -2447,6 +2447,77 @@ } + +/*- + * int2array_int2vector_eq : + * compares an int2[] and an int2vector for equality + * result : + * returns true if array and vector are equal, false otherwise. + * + * Note: we do not use array_cmp here, since equality may be meaningful in + * datatypes that don't have a total ordering (and hence no btree support). + *- + */ +Datum +int2array_int2vector_eq(PG_FUNCTION_ARGS) +{ + ArrayType *array = PG_GETARG_ARRAYTYPE_P(0); + int16 *vec = (int16 *) PG_GETARG_POINTER(1); + char *p = (char *) ARR_DATA_PTR(array); + int ndims = ARR_NDIM(array); + int*dims = ARR_DIMS(array); + int nitems = ArrayGetNItems(ndims, dims); + Oid element_type = ARR_ELEMTYPE(array); + boolresult = true; + TypeCacheEntry *typentry; + int typlen; + booltypbyval; + chartypalign; + int i; + + typentry = (TypeCacheEntry *) fcinfo->flinfo->fn_extra; + if (typentry == NULL || + typentry->type_id != element_type) + { + typentry = lookup_type_cache(element_type, + TYPECACHE_EQ_OPR_FINFO); + if (!OidIsValid(typentry->eq_opr_finfo.fn_oid)) + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_FUNCTION), +errmsg("could not identify an equality operator for type %s", + format_type_be(element_type; + fcinfo->flinfo->fn_extra = (void *) typentry; + } + typlen = typentry->typlen; + typbyval = typentry->typbyval; + typalign = typentry->typalign; + + /* Loop over source data */ + for (i = 0; i < nitems ; i++, vec++) + { + Datum elt; + booloprresult; + + elt = fetch_att(p, typbyval, typlen); + + p = att_addlength(p, typlen, PointerGetDatum(p)); + p = (char*) att_align(p, typalign); + + oprresult = (DatumGetInt16(elt) == *vec); + if (!oprresult) + { + result = false; + break; + } + } + + /* Avoid leaking memory when handed toasted input. */ + PG_FREE_IF_COPY(array, 0); + + PG_RETURN_BOOL(result); +} + + /*- * array-array bool operators: * Given two arrays, iterate comparison operators Index: include/catalog/pg_proc.h === RCS file: /projects/cvsroot/pgsql-server/src/include/catalog/pg_proc.h,v retrieving revision 1.334 diff -u -r1.334 pg_proc.h --- include/catalog/pg_proc.h 2 Jun 2004 21:29:29 - 1.334 +++ include/catalog/pg_proc.h 6 Jun 2004 23:15:00 - @@ -3588,6 +3588,9 @@ DATA(insert OID = 2243 ( bit_or PGNSP PGUID 12 t f f f i 1 1560 "1560" _null_ aggregate_dummy - _null_)); DESCR("bitwise-or bit aggregate"); +DATA(insert OID = 2546( int2array_int2vector_eq PGNSP PGUID 12 f f t f i 2 16 "1005 22" _null_ int2array_int2vector_eq - _null_ )); +DESCR("int2array int2vector equal"); + /* * Symbolic values for provolatile column: these indicate whether the result * of a function is dependent *only* on the values of its explicit arguments, ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster
Re: [PATCHES] Int2 vector to array equality
Tom Lane wrote: Andreas Pflug <[EMAIL PROTECTED]> writes: The attached patch adds an equality operator bool int2array_int2vector_eq(int2[], int2vector) This seems like a remarkably specialized kluge ... gotta be a better way ... How? This could be coded to support any element type, but we only have int2vector anyway. 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
Re: [PATCHES] [HACKERS] serverlog function (log_destination file)
Magnus Hagander wrote: Specifically about the logs, I still think there is a lot of value to being able to read the logs remotely even if you can't restart postmaster. Since I believe that retrieving the logs easily without server file access is a feature that's welcomed by many users, here's my proposal. The attached diff will - add a guc-variable log_filename - extend log_destination to accept the keyword 'file' - elog to that file if configured - provide two functions pg_logfile_length() and pg_logfile to obtain the contents. int4 pg_logfile_length() cstring pg_logfile(int4 size, int4 position) size (may be null meaning max) is the chunk size (max: currently 5) position (may be null meaning -size) is the start position; positive counting from log file start, negative from end. Regards, Andreas Index: backend/postmaster/postmaster.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/postmaster.c,v retrieving revision 1.402 diff -u -r1.402 postmaster.c --- backend/postmaster/postmaster.c 3 Jun 2004 02:08:03 - 1.402 +++ backend/postmaster/postmaster.c 8 Jun 2004 18:07:30 - @@ -532,6 +532,9 @@ /* If timezone is not set, determine what the OS uses */ pg_timezone_initialize(); +/* open alternate logfile, if any */ + LogFileOpen(); + #ifdef EXEC_BACKEND write_nondefault_variables(PGC_POSTMASTER); #endif Index: backend/storage/ipc/ipc.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/storage/ipc/ipc.c,v retrieving revision 1.87 diff -u -r1.87 ipc.c --- backend/storage/ipc/ipc.c 12 Dec 2003 18:45:09 - 1.87 +++ backend/storage/ipc/ipc.c 8 Jun 2004 18:07:31 - @@ -111,6 +111,8 @@ on_proc_exit_list[on_proc_exit_index].arg); elog(DEBUG3, "exit(%d)", code); + + LogFileClose(); exit(code); } Index: backend/utils/adt/misc.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/misc.c,v retrieving revision 1.34 diff -u -r1.34 misc.c --- backend/utils/adt/misc.c2 Jun 2004 21:29:29 - 1.34 +++ backend/utils/adt/misc.c8 Jun 2004 18:07:36 - @@ -103,3 +103,64 @@ { PG_RETURN_INT32(pg_signal_backend(PG_GETARG_INT32(0),SIGINT)); } + +Datum pg_logfile_length(PG_FUNCTION_ARGS) +{ + extern FILE *logfile; // in elog.c + + if (logfile) + PG_RETURN_INT32(ftell(logfile)); + PG_RETURN_INT32(0); +} + + +#define MAXLOGFILECHUNK 5 +Datum pg_logfile(PG_FUNCTION_ARGS) +{ + size_t size=MAXLOGFILECHUNK; + char *buf=0; + size_t nbytes; + + char *filename = LogFileName(); + if (filename) + { + if (!PG_ARGISNULL(0)) + size = PG_GETARG_INT32(0); + if (size > MAXLOGFILECHUNK) + { + size = MAXLOGFILECHUNK; + ereport(WARNING, + (errcode(ERRCODE_OUT_OF_MEMORY), +errmsg("Maximum size is %d.", MAXLOGFILECHUNK))); + } + + FILE *f=fopen(filename, "r"); + if (f) + { + if (PG_ARGISNULL(1)) + fseek(f, -size, SEEK_END); + else + { + long pos = PG_GETARG_INT32(1); + if (pos >= 0) + fseek(f, pos, SEEK_SET); + else + fseek(f, pos, SEEK_END); + } + buf = palloc(size+1); + nbytes = fread(buf, 1, size, f); + buf[nbytes] = 0; + + fclose(f); + } + else + { + ereport(WARNING, + (errcode(ERRCODE_NO_DATA), +errmsg("Could not open log file %s.", filename))); + } + free(filename); + } + + PG_RETURN_CSTRING(buf); +} Index: backend/utils/error/elog.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/error/elog.c,v retrieving revision 1.140 diff -u -r1.140 elog.c --- backend/utils/error/elog.c 3 Jun 2004 02:08:04 - 1.140 +++ backend/utils/error/elog.c 8 Jun 2004 18:07:39 - @@ -71,8 +71,10 @@ PGErrorVerbosity Log_error_verbosity = PGERROR_VERBOSE; char *Log_line_prefix = NULL; /* format for extra log line info */ unsigned int Log_destination = LOG_DESTINATION_STDERR; +char *Log_filename = NULL; bo
Re: [PATCHES] [HACKERS] serverlog function (log_destination file)
Tom Lane wrote: Bruce Momjian <[EMAIL PROTECTED]> writes: Looks good to me. The only issue I saw was that the default file name mentioned in postgresql.conf doesn't match the actual default. I'm really not happy with the concept that the postmaster overrides its stderr direction. I agree, that's why I implemented it as *additional* log_destination. Regards, Andreas ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])
Re: [PATCHES] [HACKERS] serverlog function (log_destination file)
Sorry I didn't get back on this earlier, yesterday morning my internet access was literally struck by lightning, I'm running temporary hardware now. Bruce Momjian wrote: Looks good to me. The only issue I saw was that the default file name mentioned in postgresql.conf doesn't match the actual default. I'll fix the default filename difference, postgresql.log seems best. I'll add doc too. One idea would be to send a message to stderr when this option is used stating that everything is going to 'filename'. I can ereport LogFileOpen and LogFileClose, do we need this? Currently, only open problems will be reported. Also can we close/reopen the file on SIGHUP. My guess is we can't because of all the backends accessing the output file. I'd also like it flushed in pg_logfile and pg_logfile_length, same problem; any hints welcome. Regards, Andreas ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html
Re: [PATCHES] Compiling libpq with VisualC
Bruce Momjian wrote: I have looked over this patch. I noticed this: -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); +} While this might work using your pthread compatibility implementation using CreateMutex(), it will not work on a native pthread implementation because you can only call pthread_mutex_init() once. Your code allows two threads to both call it. I don't really think so. That mutex_initialized is a globally static variable, not a thread local one. Thread interruption between testing mutex_initialized and setting it is very unlikely and still wouldn't do much harm if it actually does happen. Also, do you not have the problem with SIGPIPE from send(), so you don't need set/get_thread_specific()? There's no SIGPIPE under win32, thus no problem. Regards, Andreas ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])
Re: [PATCHES] Compiling libpq with VisualC
Bruce Momjian wrote: Agreed. My pthread book says pthread_mutex_init() should be called only once, and we have to guarantee that. If the Windows implentation allows it to be called multiple times, just create a function to be called only by Win32 that does that and leave the Unix safe. Ok, so here's the win32 workaround with the unix stuff left untouched. There's no memory interlocking api in win32 that wouldn't need some initializing api call itself, so we'd have to go for assembly level test-and-set code or introduce a mandatory global libpq initializing api. Considering the probably quite low usage of kerberos/ssl together with threads under win32, and the very low probability of two threads/processors (!) trying to initiate a connection at the same time, it doesn't seem to be worth the compiler hassle with assembly inline. Regards, Andreas Index: interfaces/libpq/fe-connect.c === RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-connect.c,v retrieving revision 1.274 diff -u -r1.274 fe-connect.c --- interfaces/libpq/fe-connect.c 10 Jun 2004 22:26:24 - 1.274 +++ interfaces/libpq/fe-connect.c 11 Jun 2004 17:33:34 - @@ -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; @@ -3183,11 +3185,22 @@ } static pgthreadlock_t default_threadlock; + static void default_threadlock(int acquire) { #ifdef ENABLE_THREAD_SAFETY +#ifndef WIN32 static pthread_mutex_t singlethread_lock = PTHREAD_MUTEX_INITIALIZER; +#else + static pthread_mutex_t singlethread_lock; +static int mutex_initialized = 0; +if (!mutex_initialized) +{ +mutex_initialized = 1; +pthread_mutex_init(&singlethread_lock, NULL); +} +#endif if (acquire) pthread_mutex_lock(&singlethread_lock); else Index: interfaces/libpq/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 --- interfaces/libpq/fe-secure.c3 Jun 2004 00:13:19 - 1.41 +++ interfaces/libpq/fe-secure.c11 Jun 2004 17:33:36 - @@ -864,8 +864,17 @@ init_ssl_system(PGconn *conn) { #ifdef ENABLE_THREAD_SAFETY -static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER; - +#ifndef WIN32 +static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER; +#else +static pthread_mutex_t init_mutex; +static int mutex_initialized = 0; +if (!mutex_initialized) +{ +mutex_initialized = 1; +pthread_mutex_init(&init_mutex, NULL); +} +#endif pthread_mutex_lock(&init_mutex); if (pq_initssllib && pq_lockarray == NULL) { @@ -1171,6 +1180,7 @@ #ifdef ENABLE_THREAD_SAFETY +#ifndef WIN32 /* * Check SIGPIPE handler and perhaps install our own. */ @@ -1210,6 +1220,7 @@ if (!PQinSend()) exit(128 + SIGPIPE);/* typical return value for SIG_DFL */ } +#endif #endif /* Index: interfaces/libpq/win32.mak === RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/win32.mak,v retrieving revision 1.24 diff -u -r1.24 win32.mak --- interfaces/libpq/win32.mak 4 Jun 2004 13:30:04 - 1.24 +++ interfaces/libpq/win32.mak 11 Jun 2004 17:33:37 - @@ -74,21 +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 pg_config_paths.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" @@ -127,7 +131,8 @@ "$(INTDIR)\fe-secure.obj" \ "$(INTDIR)\pqexpbuffer.obj" \ "$(INTDIR)\w
Re: [PATCHES] [HACKERS] serverlog function (log_destination file)
Bruce Momjian wrote: I was thinking of close/reopen so log files could be rotated. Log file rotation is fine, if we find a consensus quite soon how to implement it... Seems as if I might find some time to implement it until feature freeze. The attached patch has the default filename issue fixed, and documentation. Since I don't have a doc build system functional, there might be tag mismatches or other typos; please check. IMHO this should be committed without waiting for log rotation stuff. Regards, Andreas Index: doc/src/sgml/func.sgml === RCS file: /projects/cvsroot/pgsql-server/doc/src/sgml/func.sgml,v retrieving revision 1.206 diff -u -r1.206 func.sgml --- doc/src/sgml/func.sgml 2 Jun 2004 21:34:49 - 1.206 +++ doc/src/sgml/func.sgml 11 Jun 2004 17:58:35 - @@ -7308,6 +7308,53 @@ columns do not have OIDs of their own. + + pg_logfile + + + pg_logfile_length + + +The functions shown in + deal with the server log file if configured with log_destination + file. +previously stored with the COMMENT command. A +null value is returned if no comment could be found matching the +specified parameters. + + + +Server Logfile Functions + + + Name Return Type Description + + + + + pg_logfile(size_int4, offset_int4) + cstring + get a part of the server log file + + + pg_logfile_length() + int4 + return the current length of the server log file + + + + + +The pg_logfile function will return the + contents of the server log file, limited by the size + parameter. If size is NULL, a server internal limit (currently + 5) is applied. The position parameter determines the + starting position of the server log chunk to be returned. A + positive number or 0 will be counted from the start of the file, + a negative number from the end; if NULL, -size is assumed + (i.e. the tail of the log file). + + Index: doc/src/sgml/runtime.sgml === RCS file: /projects/cvsroot/pgsql-server/doc/src/sgml/runtime.sgml,v retrieving revision 1.266 diff -u -r1.266 runtime.sgml --- doc/src/sgml/runtime.sgml 10 Jun 2004 22:26:17 - 1.266 +++ doc/src/sgml/runtime.sgml 11 Jun 2004 17:58:46 - @@ -1721,14 +1721,25 @@ PostgreSQL supports several methods -for loggning, including stderr and -syslog. On Windows, -eventlog is also supported. Set this +for logging, including stderr, +file and syslog. + On Windows, eventlog is also supported. Set this option to a list of desired log destinations separated by a comma. The default is to log to stderr only. This option must be set at server start. + + + + log_filename (string) + + + This option sets the target filename for the log destination + file option. It may be specified as absolute + path or relative to the cluster directory. + + Index: src/backend/postmaster/postmaster.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/postmaster.c,v retrieving revision 1.403 diff -u -r1.403 postmaster.c --- src/backend/postmaster/postmaster.c 11 Jun 2004 03:54:43 - 1.403 +++ src/backend/postmaster/postmaster.c 11 Jun 2004 17:58:52 - @@ -532,6 +532,9 @@ /* If timezone is not set, determine what the OS uses */ pg_timezone_initialize(); +/* open alternate logfile, if any */ + LogFileOpen(); + #ifdef EXEC_BACKEND write_nondefault_variables(PGC_POSTMASTER); #endif Index: src/backend/storage/ipc/ipc.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/storage/ipc/ipc.c,v retrieving revision 1.87 diff -u -r1.87 ipc.c --- src/backend/storage/ipc/ipc.c 12 Dec 2003 18:45:09 - 1.87 +++ src/backend/storage/ipc/ipc.c 11 Jun 2004 17:58:52 - @@ -111,6 +111,8 @@ on_proc_exit_list[on_proc_exit_index].arg); elog(DEBUG3, "exit(%d)", code); + + LogFileClose(); exit(code); } Index: src/backend/utils/adt/misc.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/misc.c,v retrieving revision 1.34 diff -u -r1.34 misc.c --- src/backend/utils/adt/misc.c2 Jun 2004 21:29:29 - 1.34 +++ src/backend/utils/adt/misc.c11 Jun 2004 17:58:58 - @@ -103,3 +103,70 @@ { PG_RETURN_INT32(pg_signal_backend(PG_GETARG_INT
Re: [PATCHES] [HACKERS] serverlog function (log_destination file)
Tom Lane wrote: This has got portability issues (fopen("ab")) My doc says b is ignored on ansi systems, and recommends using it. Do you have other experiences? and I don't care for its use of malloc in preference to palloc either. Do we already have an applicable memory context in the postmaster at that early stage of initialization? Also, pg_logfile() will dump core if LogFileName returns null. How that? char *filename=LogFileName(); if (filename) { ... free(filename); } The bigger issue though is whether this is useful at all, if you cannot solve the file rotation issue (and I don't think you can). As implemented, the secondary log file cannot be truncated without restarting the postmaster. I think that reduces it from a possibly useful feature to a useless toy. This patch isn't trying to be better on logfile handling than the default stderr redirection behavior, besides being able to access it through the postmaster. Seems you insist to name this a toy, many users don't. (The fact that pg_logfile_length returns int and not something wider is pretty silly in this connection.) 2GB logfile seems pretty big... Regards, Andreas ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html
Re: [PATCHES] Compiling libpq with VisualC
Manfred Spraul wrote: Wrong. There are portable test-and-set functions in the Win32 SDK: for example InterlockedCompareExchange. They operate on ints and do not need initialization. 'k, missed that one. Lets use it. There is a third option: Add one C++ file and use the constructor to initialize the mutex. VisualC is always a C++ compiler, thus C++ support shouldn't be an issue. Our code is potentially not only VC. Regards, Andreas ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org
[PATCHES] win32 libpq ENABLE_THREAD_SAFETY
So here's the updated ENABLE_THREAD_SAFETY patch for win32, to be compiled under VC5/6/7 (tested with VC6). nmake -f win32.mak [DEBUG=1] [USE_SSL=1] [ENABLE_THREAD_SAFETY=1] are supported. Regards, Andreas /*- * * pthread-win32.c *partial pthread implementation for win32 * * Copyright (c) 2004, PostgreSQL Global Development Group * IDENTIFICATION * $PostgreSQL: $ * *- */ #include "windows.h" #include "pthread.h" HANDLE pthread_self() { return GetCurrentThread(); } void pthread_setspecific(pthread_key_t key, void *val) { } void *pthread_getspecific(pthread_key_t key) { return NULL; } void pthread_mutex_init(pthread_mutex_t *mp, void *attr) { *mp = CreateMutex(0, 0, 0); } void pthread_mutex_lock(pthread_mutex_t *mp) { WaitForSingleObject(*mp, INFINITE); } void pthread_mutex_unlock(pthread_mutex_t *mp) { ReleaseMutex(*mp); } #ifndef __PTHREAD_H #define __PTHREAD_H typedef ULONG pthread_key_t; typedef HANDLE pthread_mutex_t; typedef int pthread_once_t; HANDLE pthread_self(); void pthread_setspecific(pthread_key_t, void*); void* pthread_getspecific(pthread_key_t); void pthread_mutex_init(pthread_mutex_t *, void *attr); void pthread_mutex_lock(pthread_mutex_t*); // blocking void pthread_mutex_unlock(pthread_mutex_t*); #endif Index: interfaces/libpq/fe-connect.c === RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-connect.c,v retrieving revision 1.274 diff -u -r1.274 fe-connect.c --- interfaces/libpq/fe-connect.c 10 Jun 2004 22:26:24 - 1.274 +++ interfaces/libpq/fe-connect.c 13 Jun 2004 19:13:58 - @@ -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; @@ -3183,11 +3185,19 @@ } static pgthreadlock_t default_threadlock; + static void default_threadlock(int acquire) { #ifdef ENABLE_THREAD_SAFETY +#ifndef WIN32 static pthread_mutex_t singlethread_lock = PTHREAD_MUTEX_INITIALIZER; +#else + static pthread_mutex_t singlethread_lock; +static long mutex_initialized = 0; +if (!InterlockedExchange(&mutex_initialized, 1L)) +pthread_mutex_init(&singlethread_lock, NULL); +#endif if (acquire) pthread_mutex_lock(&singlethread_lock); else Index: interfaces/libpq/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 --- interfaces/libpq/fe-secure.c3 Jun 2004 00:13:19 - 1.41 +++ interfaces/libpq/fe-secure.c13 Jun 2004 19:14:00 - @@ -864,8 +864,14 @@ init_ssl_system(PGconn *conn) { #ifdef ENABLE_THREAD_SAFETY -static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER; - +#ifndef WIN32 +static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER; +#else +static pthread_mutex_t init_mutex; +static long mutex_initialized = 0L; +if (!InterlockedExchange(&mutex_initialized, 1L)) +pthread_mutex_init(&init_mutex, NULL); +#endif pthread_mutex_lock(&init_mutex); if (pq_initssllib && pq_lockarray == NULL) { @@ -1171,6 +1177,7 @@ #ifdef ENABLE_THREAD_SAFETY +#ifndef WIN32 /* * Check SIGPIPE handler and perhaps install our own. */ @@ -1210,6 +1217,7 @@ if (!PQinSend()) exit(128 + SIGPIPE);/* typical return value for SIG_DFL */ } +#endif #endif /* Index: interfaces/libpq/win32.mak === RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/win32.mak,v retrieving revision 1.24 diff -u -r1.24 win32.mak --- interfaces/libpq/win32.mak 4 Jun 2004 13:30:04 - 1.24 +++ interfaces/libpq/win32.mak 13 Jun 2004 19:14:01 - @@ -74,21 +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 pg_config_paths.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)" :
Re: [PATCHES] stderr & win32 admin check
Dave Page wrote: It could still be run on NT4 under the following conditions: 1) Running as a service 2) Running if the user logged in is not an administrator. Well, isn't "running as a service" sufficient? I thought that was the only interesting case for non-hackers anyway. As long as you get an error message that's reasonably clear about what you can do instead, this hardly seems like a showstopper... Well, that's kinda the point. If you are a hacker who has local admin privs (not exactly unusual on Windows networks - in some cases Power User group membership is required to run legacy software), Not only legacy software... you *cannot* run PostgreSQL except as a service, thus potentially making it a show stopper for those users. Actually I wouldn't expect a server to run as anything else but a service. Running a server from a command line is for debugging purposes only (in the win32 world). Thus I'd consider the non-admin check as acceptable, while quite irritating for most win32 users. Many win32 servers create an own account on installation or suggest to do so (instead of using the "Local System" account), this could make things more convenient for the average win32 user. Regards, Andreas Regards, Andreas ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html
Re: [PATCHES] stderr & win32 admin check
Dave Page wrote: you can only run one instance as a service on a single machine. If you mean only run one instance of postmaster as service, that's not true. If you like two pgsql servers (i.e. db clusters), you can install two services, both using the same binary with different cmd line arguments. Regards, Andreas ---(end of broadcast)--- TIP 8: explain analyze is your friend
Re: [PATCHES] Tablespace patch review
Gavin Sherry wrote: On Fri, 18 Jun 2004, Bruce Momjian wrote: [snip] TODO. You sound like a man who's expecting a several-generations-polished facility when we only just committed the first version today. I do not feel a need to have any of these features in 7.5 ... I just need to know what to add to the TODO list, and so we can answer people who are going to ask for this functionality. Added to TODO: * Allow reporting of which objects are in which tablespaces Do we need an information_schema.tablespaces view as well as an update to information_schema.{tables|indexes|...} ? I checked this to implement it, and found it being less then trivial when *all* objects of a tablespace should be displayed, not just the ones in the current database. There seem to be several ways to implement: (1) dblink like access iterating all databases. This seems extraordinarily expensive (2) low level scanning tablespace location, then try to translate found oids to names withoug SPI. Probably not desirable. (3) extending parser/executor to allow a table specification of the form database.namespace.tablename. This has been requested several times before, but was rejected, with the advise to use dblink. (4) Copy the contents of the desired cross-db table to a temporary table (generate new oid in local db, copy cross-db table file to new oid file, insert pg_class). A typically weird Andreas' approach :-) Regards, Andreas ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org
Re: [PATCHES] Tablespace patch review
Gavin Sherry wrote: On Fri, 18 Jun 2004, Andreas Pflug wrote: Gavin Sherry wrote: On Fri, 18 Jun 2004, Bruce Momjian wrote: [snip] TODO. You sound like a man who's expecting a several-generations-polished facility when we only just committed the first version today. I do not feel a need to have any of these features in 7.5 ... I just need to know what to add to the TODO list, and so we can answer people who are going to ask for this functionality. Added to TODO: * Allow reporting of which objects are in which tablespaces Do we need an information_schema.tablespaces view as well as an update to information_schema.{tables|indexes|...} ? I checked this to implement it, and found it being less then trivial when *all* objects of a tablespace should be displayed, not just the ones in the current database. I don't think we should try and show all objects for a tablespace in information_schema. Agreed, information_schema is database specific. I was thinking about a pg_tablespace_contents(..) function anyway. Being able to list all objects in a tablespace, including which databases they are in, is clearly useful, however (eg: hunting down use of a give tablespace that you want dropped). Sounds like a script in contrib (or the main source tree?) to me. You're suggesting the dblink way using a shell script. Imagine 20, 200, ... databases. This would be a costly thing (and has to be implemented differently in win32). I'd like to see an implementation that enables gui interfaces to show objects that depend on a tablespace, so you'd need to be aware of a user clicking on "show what's in that tablespace" and he probably wouldn't expect to wait an extended period of time for all databases to be scanned, or impose a 200-connection load on the server. IMHO checking objects in a tablespace is a routine administrative task, so it should be supported natively by the server without need of contribs. And for win user acceptance, a command line tool won't be sufficient either. Regards, Andreas ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]
Re: [PATCHES] Tablespace patch review
Gavin Sherry wrote: I would debate that. Firstly, tablespaces aren't supported on windows yet. Just a matter of time. And I'm talking of win32 workstations connecting to *ix servers too. Secondly, I'd think that Unix users would be fine with a command line tool, especially one that can connect to a remote host. For those not used to command line tools, I can imagine extensions to pgadmin or phppgadmin. :-) :-) :-) Unfortunately, us admin tool programmers can't practice witchcraft, so we need a pgsql function for that... Certainly, we could iterate all known databases making a one-time connection (if allowed to connect, what about template0?), retrieving tablespace dependencies, and close again. As debated above, that's quite costly, especially if more sophisticated authentication mechanisms are used. Regards, Andreas ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]
Re: [PATCHES] Tablespace patch review
Tom Lane wrote: Andreas Pflug <[EMAIL PROTECTED]> writes: IMHO checking objects in a tablespace is a routine administrative task, so it should be supported natively by the server without need of contribs. I strongly disagree. Dropping a tablespace is not a routine activity, Dropping certainly not. But inspecting? If implemented in a gui, it's just a click away. As for the authentication-is-expensive issue, what of it? You *should* have to authenticate yourself in order to look inside another person's database. The sort of cross-database inspection being proposed here would be a big security hole in many people's view. Accessing pg_class et al using the current sysuseid with acl checking should be ok and satisfy security demands, no? Since it's the same cluster, we can be sure that it 's the same user in that cross db too. If the user has no access, the result won't have a meaning either. The auth-is-expensive issue is about creating the db connection itself again and again, when we only want to change a database. And for win user acceptance, a command line tool won't be sufficient either. This does not deserve a response. Well, that's not quite appropriate. A 'command line is enough for server maintenance' attitude won't attract win people; they're blind without a mouse. Regards, Andreas ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]
Re: [PATCHES] Tablespace patch review
Tom Lane wrote: Andreas Pflug <[EMAIL PROTECTED]> writes: Tom Lane wrote: As for the authentication-is-expensive issue, what of it? You *should* have to authenticate yourself in order to look inside another person's database. The sort of cross-database inspection being proposed here would be a big security hole in many people's view. Accessing pg_class et al using the current sysuseid with acl checking should be ok and satisfy security demands, no? No. If the other user has you locked out from connecting to his database at all, he's probably not going to feel that he should have to disable your access to individual objects inside it. Well he's using my tablespace, so I'd like to know at least the object name. This has some connections to the discussions we periodically have about preventing Joe User from looking at the system catalogs. If we make any changes in this area at all, I would expect them to be in the direction of narrowing access, not widening it to include being able to see other databases' catalogs. Superuser/tablespace owner isn't quite Joe User, I believe. Actually, there seem quite some other cross database/shared table issues (schema default tablespace, dropping user who owns objects) which make it desirable to have superuser readonly access to pg_catalog tables. Maybe a todo for 7.6... Regards, Andreas ---(end of broadcast)--- TIP 7: don't forget to increase your free space map settings
Re: [PATCHES] Tablespace patch review
Dave Page wrote: -Original Message- From: [EMAIL PROTECTED] on behalf of Bruce Momjian Sent: Sat 6/19/2004 1:05 AM To: Andreas Pflug Cc: Tom Lane; Gavin Sherry; PostgreSQL-patches Subject: Re: [PATCHES] Tablespace patch review We can build a gui on top of the command-line tool, no? No, we can't. Don't forget, everything we do in pgAdmin is via libpq. Yeah, gui on top of cmd line is nasty and a pain in regarding portability. It's not exactly challenging to implement it directly either, that's what I'll do in absence of a serverside solution. I'll redirect all pgadmin user speed complaints about this to Toms personal mailbox ;-) Regards, Andreas ---(end of broadcast)--- TIP 7: don't forget to increase your free space map settings
Re: [PATCHES] Tablespace patch review
Bruce Momjian wrote: I don't see why an admin tool can't connect to each database and get a listing of what is in each tablespace. I don't think connecting to 100 databases to get that information will be slow. Well, whatever you call slow or not slow. I checked it; connecting 10 databases, retrieving tablespace dependencies (pg_class union pg_schema) and closing takes about one second over an ssl connection, 0.2 seconds with non-ssl. This was a trusted connection, can't check what will happen with md5, krb or so. Regards, Andreas ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html
Re: [PATCHES] Tablespace patch review
Dave Page wrote: -Original Message- From: Andreas Pflug [mailto:[EMAIL PROTECTED] Sent: Sat 6/19/2004 6:40 PM To: Bruce Momjian Cc: Dave Page; Tom Lane; PostgreSQL-patches Subject: Re: [PATCHES] Tablespace patch review Well, whatever you call slow or not slow. I checked it; connecting 10 databases, retrieving tablespace dependencies (pg_class union pg_schema) and closing takes about one second over an ssl connection, 0.2 seconds with non-ssl. This was a trusted connection, can't check what will happen with md5, krb or so. Don't suppose you happened to try it on Win32 did you? This was from a win32 workstation (pgadmin3) to a Linux server. Regards, Andreas ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])
Re: [PATCHES] Compiling libpq with VisualC
Two minor tweaks: in libpq-be.h isn't present on win32 vc6. Apparently, it isn't used in Linux either; libpq will compile without it. All usages of gettimeofday throughout the backend don't seem connection related, so libpq-be.h seems an odd place to include it. ERROR in elog.h has conflicts with a win32 defined macro; #undef WIN32 solves the conflict (or not including elog.h for libpq purposes would do too) Regards, Andreas Index: include/libpq/libpq-be.h === RCS file: /projects/cvsroot/pgsql-server/src/include/libpq/libpq-be.h,v retrieving revision 1.45 diff -u -r1.45 libpq-be.h --- include/libpq/libpq-be.h21 May 2004 05:08:04 - 1.45 +++ include/libpq/libpq-be.h19 Jun 2004 19:46:52 - @@ -18,7 +18,10 @@ #ifndef LIBPQ_BE_H #define LIBPQ_BE_H +#ifndef WIN32 #include +#endif + #ifdef USE_SSL #include Index: include/utils/elog.h === RCS file: /projects/cvsroot/pgsql-server/src/include/utils/elog.h,v retrieving revision 1.68 diff -u -r1.68 elog.h --- include/utils/elog.h5 Apr 2004 03:02:10 - 1.68 +++ include/utils/elog.h19 Jun 2004 19:46:53 - @@ -14,6 +14,10 @@ #ifndef ELOG_H #define ELOG_H +#ifdef ERROR +#undef ERROR/* possible conflict in win32 */ +#endif + /* Error level codes */ #define DEBUG5 10 /* Debugging messages, in categories of * decreasing detail. */ ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster
Re: [PATCHES] Compiling libpq with VisualC
Tom wrote: It's there to declare struct timeval, and I'm fairly certain that diking it out of the header would break things on some platforms. Where does Windows define struct timeval? struct timeval is defined in winsock.h under vc6. I'm checking for _MSC_VER now. Agreed. We define FRONTEND when compiling libpq. Please test for that and send another patch. elog.h is included in postgres.h, which is included in many src/port/*.c. Many of them are pretty straight, not requiring any backend specific stuff, so the attached patch will change postgres.h to c.h for most of them. Regards, Andreas Index: include/libpq/libpq-be.h === RCS file: /projects/cvsroot/pgsql-server/src/include/libpq/libpq-be.h,v retrieving revision 1.45 diff -u -r1.45 libpq-be.h --- include/libpq/libpq-be.h21 May 2004 05:08:04 - 1.45 +++ include/libpq/libpq-be.h20 Jun 2004 09:19:54 - @@ -18,7 +18,12 @@ #ifndef LIBPQ_BE_H #define LIBPQ_BE_H +#if _MSC_VER > 0 +/* struct timeval is declared in winsock.h */ +#else #include +#endif + #ifdef USE_SSL #include Index: port/getopt.c === RCS file: /projects/cvsroot/pgsql-server/src/port/getopt.c,v retrieving revision 1.5 diff -u -r1.5 getopt.c --- port/getopt.c 4 Aug 2003 00:43:33 - 1.5 +++ port/getopt.c 20 Jun 2004 09:19:55 - @@ -32,7 +32,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF */ -#include "postgres.h" +#include "c.h" #if defined(LIBC_SCCS) && !defined(lint) Index: port/getrusage.c === RCS file: /projects/cvsroot/pgsql-server/src/port/getrusage.c,v retrieving revision 1.4 diff -u -r1.4 getrusage.c --- port/getrusage.c29 Nov 2003 19:52:13 - 1.4 +++ port/getrusage.c20 Jun 2004 09:19:55 - @@ -16,7 +16,7 @@ #include #include -#include "postgres.h" +#include "c.h" #include "rusagestub.h" /* This code works on: Index: port/gettimeofday.c === RCS file: /projects/cvsroot/pgsql-server/src/port/gettimeofday.c,v retrieving revision 1.4 diff -u -r1.4 gettimeofday.c --- port/gettimeofday.c 21 May 2004 05:08:05 - 1.4 +++ port/gettimeofday.c 20 Jun 2004 09:19:55 - @@ -23,7 +23,7 @@ * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. */ -#include "postgres.h" +#include "c.h" #include Index: port/kill.c === RCS file: /projects/cvsroot/pgsql-server/src/port/kill.c,v retrieving revision 1.1 diff -u -r1.1 kill.c --- port/kill.c 27 May 2004 13:08:57 - 1.1 +++ port/kill.c 20 Jun 2004 09:19:55 - @@ -14,7 +14,7 @@ *- */ -#include "postgres.h" +#include "c.h" #ifdef WIN32 /* signal sending */ Index: port/noblock.c === RCS file: /projects/cvsroot/pgsql-server/src/port/noblock.c,v retrieving revision 1.1 diff -u -r1.1 noblock.c --- port/noblock.c 10 Mar 2004 21:12:49 - 1.1 +++ port/noblock.c 20 Jun 2004 09:19:55 - @@ -12,7 +12,7 @@ *- */ -#include "postgres.h" +#include "c.h" #include #include Index: port/pgsleep.c === RCS file: /projects/cvsroot/pgsql-server/src/port/pgsleep.c,v retrieving revision 1.3 diff -u -r1.3 pgsleep.c --- port/pgsleep.c 12 Apr 2004 16:19:18 - 1.3 +++ port/pgsleep.c 20 Jun 2004 09:19:56 - @@ -10,7 +10,7 @@ * *- */ -#include "postgres.h" +#include "c.h" #include #include Index: port/pgstrcasecmp.c === RCS file: /projects/cvsroot/pgsql-server/src/port/pgstrcasecmp.c,v retrieving revision 1.1 diff -u -r1.1 pgstrcasecmp.c --- port/pgstrcasecmp.c 7 May 2004 00:24:59 - 1.1 +++ port/pgstrcasecmp.c 20 Jun 2004 09:19:56 - @@ -20,7 +20,7 @@ * *- */ -#include "postgres.h" +#include "c.h" #include Index: port/pipe.c === RCS file: /projects/cvsroot/pgsql-server/src/port/pipe.c,v retrieving revision 1.5 diff -u -r1.5 pipe.c --- port/pipe.c 11 Jun 2004 03:48:35 - 1.5 +++ port/pipe.c 20 Jun 2004 09:19:56 - @@ -15,7 +15,7 @@ *- */ -#include "postgres.h" +#include "c.h" #ifdef WIN32 int Index: port/sprompt.c === RCS file: /
[PATCHES] serverlog rotation/functions
The attached patch includes serverlog rotation with minimal shared memory usage as discussed and functions to access it. Regards, Andreas Index: doc/src/sgml/func.sgml === RCS file: /projects/cvsroot/pgsql-server/doc/src/sgml/func.sgml,v retrieving revision 1.211 diff -u -r1.211 func.sgml --- doc/src/sgml/func.sgml 25 Jun 2004 17:20:21 - 1.211 +++ doc/src/sgml/func.sgml 28 Jun 2004 10:35:09 - @@ -7430,6 +7430,80 @@ + pg_logfile_get + + + pg_logfile_length + + + pg_logfile_name + + + pg_logfile_rotate + + +The functions shown in + deal with the server log file if configured with log_destination + file. + + + +Server Logfile Functions + + + Name Return Type Description + + + + + pg_logfile_get(size_int4, + offset_int4,filename_text) + cstring + get a part of the current server log file + + + pg_logfile_length(filename_text) + int4 + return the current length of the server log file + + + pg_logfile_rotate() + cstring + rotates the server log file and returns the new log file + name + + + pg_logfile_name() + cstring + returns the current server log file name + + + pg_logfile_rotate() + cstring + rotates the server log file and returns the previous log file + name + + + + + +The pg_logfile_get function will return the + contents of the current server log file, limited by the size + parameter. If size is NULL, a server internal limit (currently + 5) is applied. The position parameter specifies the + starting position of the server log chunk to be returned. A + positive number or 0 will be counted from the start of the file, + a negative number from the end; if NULL, -size is assumed + (i.e. the tail of the log file). + + +Both pg_logfile_get and + pg_logfile_length have a filename + parameter which may specify the logfile to examine or the + current logfile if NULL. + + + pg_cancel_backend Index: doc/src/sgml/runtime.sgml === RCS file: /projects/cvsroot/pgsql-server/doc/src/sgml/runtime.sgml,v retrieving revision 1.268 diff -u -r1.268 runtime.sgml --- doc/src/sgml/runtime.sgml 27 Jun 2004 22:58:19 - 1.268 +++ doc/src/sgml/runtime.sgml 28 Jun 2004 10:35:19 - @@ -1721,14 +1721,25 @@ PostgreSQL supports several methods -for loggning, including stderr and -syslog. On Windows, -eventlog is also supported. Set this +for logging, including stderr, +file> and syslog. + On Windows, eventlog is also supported. Set this option to a list of desired log destinations separated by a comma. The default is to log to stderr only. This option must be set at server start. + + + + log_filename (string) + + + This option sets the target filename for the log destination + file option. It may be specified as absolute + path or relative to the cluster directory. + + Index: src/backend/postmaster/postmaster.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/postmaster.c,v retrieving revision 1.405 diff -u -r1.405 postmaster.c --- src/backend/postmaster/postmaster.c 24 Jun 2004 21:02:55 - 1.405 +++ src/backend/postmaster/postmaster.c 28 Jun 2004 10:35:26 - @@ -729,6 +729,11 @@ reset_shared(PostPortNumber); /* +* Opens alternate log file +*/ + LogFileInit(); + + /* * Estimate number of openable files. This must happen after setting * up semaphores, because on some platforms semaphores count as open * files. Index: src/backend/utils/adt/misc.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/misc.c,v retrieving revision 1.34 diff -u -r1.34 misc.c --- src/backend/utils/adt/misc.c2 Jun 2004 21:29:29 - 1.34 +++ src/backend/utils/adt/misc.c28 Jun 2004 10:35:33 - @@ -103,3 +103,138 @@ { PG_RETURN_INT32(pg_signal_backend(PG_GETARG_INT32(0),SIGINT)); } + + + + +extern FILE *logfile; // in elog.c +#define MAXLOGFILECHUNK 5 + +static char *absClusterPath(text *arg) +{ + char *filename; + + if (is_absolute_path(VARDATA(arg))) + filename=VARDATA(arg); + else + { + filename = palloc(strlen(DataDir)+VARSIZE(arg)+2); + sprintf(filename, "%s/%s", DataDir, VARDATA(
[PATCHES] pg_tablespace_databases
From an idea of Bruce, the attached patch implements the function pg_tablespace_databases(oid) RETURNS SETOF oid which delivers as set of database oids having objects in the selected tablespace, enabling an admin to examine only the databases affecting the tablespace for objects instead of scanning all of them. 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
Re: [PATCHES] pg_tablespace_databases
Andreas Pflug wrote: From an idea of Bruce, the attached patch implements the function pg_tablespace_databases(oid) RETURNS SETOF oid which delivers as set of database oids having objects in the selected tablespace, enabling an admin to examine only the databases affecting the tablespace for objects instead of scanning all of them. It might be easier to review if I attach the file... Regards, Andreas Index: src/backend/utils/adt/misc.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/misc.c,v retrieving revision 1.34 diff -u -r1.34 misc.c --- src/backend/utils/adt/misc.c2 Jun 2004 21:29:29 - 1.34 +++ src/backend/utils/adt/misc.c28 Jun 2004 11:16:05 - @@ -16,11 +16,16 @@ #include #include +#include #include "commands/dbcommands.h" #include "miscadmin.h" #include "storage/sinval.h" +#include "storage/fd.h" #include "utils/builtins.h" +#include "funcapi.h" +#include "catalog/pg_type.h" +#include "catalog/pg_tablespace.h" /* @@ -102,4 +107,92 @@ pg_cancel_backend(PG_FUNCTION_ARGS) { PG_RETURN_INT32(pg_signal_backend(PG_GETARG_INT32(0),SIGINT)); +} + + +typedef struct +{ + char *location; + DIR *dirdesc; +} ts_db_fctx; + +Datum pg_tablespace_databases(PG_FUNCTION_ARGS) +{ + FuncCallContext *funcctx; + struct dirent *de; + ts_db_fctx *fctx; + + if (SRF_IS_FIRSTCALL()) + { + MemoryContext oldcontext; + Oid tablespaceOid=PG_GETARG_OID(0); + + funcctx=SRF_FIRSTCALL_INIT(); + oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); + + fctx = palloc(sizeof(ts_db_fctx)); + + fctx->location = (char*)palloc(strlen(DataDir)+16+10+1); + if (tablespaceOid == GLOBALTABLESPACE_OID) + { + fctx->dirdesc = NULL; + ereport(NOTICE, + (errcode(ERRCODE_WARNING), +errmsg("global tablespace never has databases."))); + } + else + { + if (tablespaceOid == DEFAULTTABLESPACE_OID) + sprintf(fctx->location, "%s/base", DataDir); + else + sprintf(fctx->location, "%s/pg_tblspc/%u", DataDir, tablespaceOid); + + fctx->dirdesc = AllocateDir(fctx->location); + + if (!fctx->dirdesc) /* not a tablespace */ + ereport(NOTICE, + (errcode(ERRCODE_WARNING), +errmsg("%d is no tablespace oid.", tablespaceOid))); + } + funcctx->user_fctx = fctx; + MemoryContextSwitchTo(oldcontext); + } + + funcctx=SRF_PERCALL_SETUP(); + fctx = (ts_db_fctx*)funcctx->user_fctx; + + if (!fctx->dirdesc) /* not a tablespace */ + SRF_RETURN_DONE(funcctx); + + while ((de = readdir(fctx->dirdesc)) != NULL) + { + char *subdir; + DIR *dirdesc; + + Oid datOid = atol(de->d_name); + if (!datOid) + continue; + + subdir = palloc(strlen(fctx->location) + 1 + strlen(de->d_name) +1 ); + sprintf(subdir, "%s/%s", fctx->location, de->d_name); + dirdesc = AllocateDir(subdir); + if (dirdesc) + { + while ((de = readdir(dirdesc)) != 0) + { + if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) + break; + } + pfree(subdir); + FreeDir(dirdesc); + + if (!de) /* database subdir is empty; don't report tablespace as used */ + continue; + } + + SRF_RETURN_NEXT(funcctx, ObjectIdGetDatum(datOid)); + } + + FreeDir(fctx->dirdesc); + SRF_RETURN_DONE(funcctx); } Index: src/include/catalog/pg_proc.h === RCS file: /projects/cvsroot/pgsql-server/src/include/catalog/pg_proc.h,v retrieving revision 1.339 diff -u -r1.339 pg_proc.h --- src/include/catalog/pg_proc.h 25 Jun 2004 17:20:28 - 1.339 +++ src/include/catalog/pg_proc.h 28 Jun 2004 11:16:32 - @@ -3595,6 +3595,9 @@ DATA(insert OID = 2243 ( bit_or
Re: [PATCHES] patch queue reminder
Fabien COELHO wrote: Dear patchers, I have two minor patches that are being submitted but which do not appear yet in the "official" patch queue on the web site: http://momjian.postgresql.org/cgi-bin/pgpatches That site is maintained by Bruce, who is out to Armenia until next week, with virtually no internet access. In the meanwhile, Tom is trying to take Bruce's part as far as his spare time allowes, but he probably won't maintain the pending-patches site, so please be patient. I'd expect that patches stuck in pgsql-patches are still supposed to be in-time for feature freeze. Regards, Andreas ---(end of broadcast)--- TIP 7: don't forget to increase your free space map settings
Re: [PATCHES] pg_tablespace_databases
Joe Conway wrote: If there are no objections, I'll review and apply this tonight (west coast USA time). Andreas, please provide a corresponding documentation patch. Here we are. Since I don't have a SGML build environment, syntax is not checked. Regards, Andreas Index: func.sgml === RCS file: /projects/cvsroot/pgsql-server/doc/src/sgml/func.sgml,v retrieving revision 1.211 diff -u -r1.211 func.sgml --- func.sgml 25 Jun 2004 17:20:21 - 1.211 +++ func.sgml 1 Jul 2004 18:38:34 - @@ -7232,6 +7232,10 @@ pg_get_serial_sequence + +pg_tablespace_databases + + lists functions that extract information from the system catalogs. @@ -7325,6 +7329,11 @@ get name of the sequence that a serial or bigserial column uses + + pg_tablespace_databases(namespace_oid) + setof oid + get set of database oids that have objects in the namespace + @@ -7360,6 +7369,16 @@ for passing to the sequence functions (see ). NULL is returned if the column does not have a sequence attached. + + + + pg_tablespace_databases allows usage examination of a + tablespace. It will return a set of database oids, that have objects + stored in the tablespace. If this function returns any row, the + tablespace is assumed not to be empty and cannot be dropped. To + display the actual objects populating the tablespace, you will need + to connect to the databases returned by + pg_tablespace_databases to query pg_class. ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]
Re: [PATCHES] pg_tablespace_databases
Joe Conway wrote: Attached is the patch I plan to apply. There are a couple of changes from what was posted. 1) You must have meant tablespace instead of namespace here: + + pg_tablespace_databases(namespace_oid) + setof oid Of course. I just call everything namespace :-) 2) This allocation size was a bit ambigous and I think based on a once longer tablespace directory name: +fctx->location = (char*)palloc(strlen(DataDir)+16+10+1); This size calculation originated (copy/paste) from commands/tablespace.c, should be clarified there too (and "pg_tblspc" is hardcoded in strings, could be extracted to a macro definition). Regards, Andreas ---(end of broadcast)--- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [PATCHES] serverlog rotation/functions
Tom Lane wrote: Andreas Pflug <[EMAIL PROTECTED]> writes: The attached patch includes serverlog rotation with minimal shared memory usage as discussed and functions to access it. This patch is still unsafe and unworkable. Why would you make the mechanism dependent on shared memory *and* an intermediate data file *and* an inherited file handle to access that data file? The inherited handle is subject to race conditions (because you've got different processes fseeking the same file descriptor with no interlocking) and I don't really see that it's buying anything anyway. If you stored the value of time(NULL) to use in shared memory, you'd not need the data file because every process could compute the correct logfile name for itself. 'k, the timestamp may be used as a flag to reopen too, probably better than that filehandle stuff. I can rewrite that. An issue that doesn't matter a whole lot on Unix, but I think would matter on Windows, is that with the patch as given a process will not reopen the log file until it's got something to write there. Non-chatty processes could easily hold open the old log file indefinitely. It might be a good idea to force the log file to be reopened at SIGHUP, and for the "rotate" command to do such a SIGHUP. Why do you expect problems on win32 here? I intentionally did *not* tie this to a SIGHUP, which I consider to be quite an expensive signal for this case, to reopen a file that is (hopefully) rarely used. Imagine 100 backends, SIGHUPping every minute or so. But certainly a backend could check for the logfile to be current when SIGHUP is received. Overall though, I still quite fail to see the point of doing it this way compared to piping the postmaster's stderr into something that can rotate log files. The fundamental objection to this whole feature is that it can only capture elog output, which is not everything of interest. (For example, dynamic linker failures will usually be reported to stderr, a behavior that we cannot override.) If this "something" is tightly coupled to the postmaster, and can be retrieved over a database connection, fine. The restriction about messages going to stderr are valid for log_destination syslog too, so the new log_destination=file is no regression. What would you use on win32? Piping stderr isn't really popular there, and eventlog is shared between all apps (that's probably the reason why M$ uses an own log infrastructure for MSSQL). Regards, Andreas ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])
Re: [PATCHES] serverlog rotation/functions
Updated version. Only timestamp of fresh logfile in shared mem, with sanity checks. On SIGHUP, timestamp is checked if rotation was issued, as well as changed log_filename setting from postgresql.conf. Regards, Andreas Index: src/backend/postmaster/postmaster.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/postmaster.c,v retrieving revision 1.405 diff -u -r1.405 postmaster.c --- src/backend/postmaster/postmaster.c 24 Jun 2004 21:02:55 - 1.405 +++ src/backend/postmaster/postmaster.c 6 Jul 2004 22:12:22 - @@ -729,6 +729,11 @@ reset_shared(PostPortNumber); /* +* Opens alternate log file +*/ + LogFileInit(); + + /* * Estimate number of openable files. This must happen after setting * up semaphores, because on some platforms semaphores count as open * files. Index: src/backend/utils/adt/misc.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/misc.c,v retrieving revision 1.35 diff -u -r1.35 misc.c --- src/backend/utils/adt/misc.c2 Jul 2004 18:59:22 - 1.35 +++ src/backend/utils/adt/misc.c6 Jul 2004 22:12:34 - @@ -202,3 +202,137 @@ FreeDir(fctx->dirdesc); SRF_RETURN_DONE(funcctx); } + + +extern FILE *logfile; // in elog.c +#define MAXLOGFILECHUNK 5 + +static char *absClusterPath(text *arg) +{ + char *filename; + + if (is_absolute_path(VARDATA(arg))) + filename=VARDATA(arg); + else + { + filename = palloc(strlen(DataDir)+VARSIZE(arg)+2); + sprintf(filename, "%s/%s", DataDir, VARDATA(arg)); + } + return filename; +} + + +Datum pg_logfile_get(PG_FUNCTION_ARGS) +{ + size_t size=MAXLOGFILECHUNK; + char *buf=0; + size_t nbytes; + FILE *f; + + if (!PG_ARGISNULL(0)) + size = PG_GETARG_INT32(0); + if (size > MAXLOGFILECHUNK) + { + size = MAXLOGFILECHUNK; + ereport(WARNING, + (errcode(ERRCODE_OUT_OF_MEMORY), +errmsg("Maximum size is %d.", size))); + } + + if (PG_ARGISNULL(2)) + f = logfile; + else + { +/* explicitely named logfile */ + char *filename = absClusterPath(PG_GETARG_TEXT_P(2)); + f = fopen(filename, "r"); + if (!f) + { + ereport(WARNING, + (errcode_for_file_access(), +errmsg("file not found %s", filename))); + PG_RETURN_NULL(); + } + } + + if (f) + { + + if (PG_ARGISNULL(1)) + fseek(f, -size, SEEK_END); + else + { + long pos = PG_GETARG_INT32(1); + if (pos >= 0) + fseek(f, pos, SEEK_SET); + else + fseek(f, pos, SEEK_END); + } + buf = palloc(size+1); + nbytes = fread(buf, 1, size, f); + buf[nbytes] = 0; + + fseek(f, 0, SEEK_END); + + if (!PG_ARGISNULL(2)) + fclose(f); + } + + if (buf) + PG_RETURN_CSTRING(buf); + else + PG_RETURN_NULL(); +} + + +Datum pg_logfile_length(PG_FUNCTION_ARGS) +{ + if (PG_ARGISNULL(0)) + { + if (logfile) + { + fflush(logfile); + PG_RETURN_INT32(ftell(logfile)); + } + } + else + { + struct stat fst; + fst.st_size=0; + stat(absClusterPath(PG_GETARG_TEXT_P(0)), &fst); + + PG_RETURN_INT32(fst.st_size); + } + PG_RETURN_INT32(0); +} + + +Datum pg_logfile_name(PG_FUNCTION_ARGS) +{ + char *filename=LogFileName(); + if (filename) + { + if (strncmp(filename, DataDir, strlen(DataDir))) + PG_RETURN_CSTRING(filename); + else + PG_RETURN_CSTRING(filename+strlen(DataDir)+1); + } + PG_RETURN_NULL(); +} + + +Datum pg_logfile_rotate(PG_FUNCTION_ARGS) +{ + char *renamedFile = LogFileRotate(); + + if (renamedFile) + { + if (strncmp(renamedFile, DataDir, strlen(DataDir))) + PG_RETURN_CSTRING(renamedFile); + else + PG_RETURN_CSTRING(renamedFile+strlen(DataDir)+1); + } + else + PG_RETURN_NULL(); +} + Index: src/backend/utils/error/elog.c === RCS
Re: [PATCHES] pg_autovacuum integration attempt #2
Peter Eisentraut wrote: Bruce Momjian wrote: I have added this patch plus your later comments to the patch queue. The autovacuum process still uses libpq to send its queries, which is not the idea behind backend integration. Can we consider this a non-fatal bug that has to be solved soon after the patch is applied? 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
Re: [PATCHES] serverlog rotation/functions
Bruce Momjian wrote: How is this patch supposed to work? Do people need to modify postgresql.conf and then sighup the postmaster? It seems more logical for the super-user to call a server-side function. I assume calling pg_logfile_rotate() to be the standard way. calling pg_logfile_rotate will increment the internal logfile timestamp, so each backend's next write to the logfile will lead to a reopen. On the other hand, if nothing is to be logged, nothing happens in the backends. You have pg_logfile_rotate(), but that doesn't send a sighup to the postmaster so all the backends will reread the global log file name. As long as there's no SIGHUP, the logfile name template will not change, so each backend can calculate the logfile's name from the timestamp. In case a SIGHUP *is* issued, the template might have changed, so despite an unchanged timestamp the filename to create might be different. Additionally, SIGHUP will force all backends to check for current logfile name, and close/reopen if their internal timestamp isn't up-to-date with the common timestamp. Also, what mechanism is there to prevent backends from reading the log filename _while_ it is being modified? I don't understand your concern. There's no place where the name is stored, only the GUC log_filename which is actually the template, and the timestamp (probably accessed atomically by the processor). Also there are no documenttion changes. Hm, seems I missed this in this posting; the previous had it. I'll repost it. However, looking at the issue of backends all reloading their postgresql.conf files at different times and sending output to different files, We might have a fraction of a second in practice, when a SIGHUP was issued to reread postgresql.conf, with a log_filename change, and a backend still writing its log to the "old" log because GUC reread is deferred for queries that started before SIGHUP. I don't really see a problem with that. I wonder if it would be best to create a log process and have each backend connect to that. That way, all the logging happens in one process. All I wanted was displaying the serverlog While this might be ultimately the best solution (we even might find a way to catch stderr without interrupting further stderr piping), currently this doesn't seem to be the right moment. We'd have several inter process issues (and more with win32), which probably need some discussion. OTOH, if the current implementation is replaced by a log process later, the api interface probably would stay the same. Regards, Andreas ---(end of broadcast)--- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [PATCHES] serverlog rotation/functions
Tom Lane wrote: That was something that bothered me too. I think in the patch as given, the GUC parameter determining the logfile name would have to be PGC_POSTMASTER, ie, you could not change it on the fly because the backends wouldn't all switch together. In my original posting it was PGC_POSTMASTER, I changed it recently after I added rotation handling in ProcessConfigFile. If you think this is critical, we can revert it. Regards, Andreas ---(end of broadcast)--- TIP 8: explain analyze is your friend
Re: [PATCHES] serverlog rotation/functions
Tom Lane wrote: That struck me as not only useless but the deliberately hard way to do it. To use that in the real world, you'd have to set up a cron job to trigger the rotation, Still on my radar... which means a lot of infrastructure and privilege; whereas ISTM the point of this feature was to avoid both. ... I was thinking about putting this into the pg_autovacuum process. The log capture process should just do its own rotation on a pre-configured time-interval basis, and/or maximum-file-size basis. Yup. I see zero value added in having it respond to external signals. I see >0 value. I like to truncate my logfile before doing some complicated stuff, to have a handy file for debugging purposes. Regards, Andreas ---(end of broadcast)--- TIP 7: don't forget to increase your free space map settings
Re: [PATCHES] serverlog rotation/functions
Bruce Momjian wrote: Also there are no documenttion changes. Here are the missing docs, freshly created against cvs. Regards, Andreas Index: func.sgml === RCS file: /projects/cvsroot/pgsql-server/doc/src/sgml/func.sgml,v retrieving revision 1.214 diff -u -r1.214 func.sgml --- func.sgml 12 Jul 2004 20:23:47 - 1.214 +++ func.sgml 14 Jul 2004 19:08:16 - @@ -7455,6 +7455,80 @@ + pg_logfile_get + + + pg_logfile_length + + + pg_logfile_name + + + pg_logfile_rotate + + +The functions shown in + deal with the server log file if configured with log_destination + file. + + + +Server Logfile Functions + + + Name Return Type Description + + + + + pg_logfile_get(size_int4, + offset_int4,filename_text) + cstring + get a part of the current server log file + + + pg_logfile_length(filename_text) + int4 + return the current length of the server log file + + + pg_logfile_rotate() + cstring + rotates the server log file and returns the new log file + name + + + pg_logfile_name() + cstring + returns the current server log file name + + + pg_logfile_rotate() + cstring + rotates the server log file and returns the previous log file + name + + + + + +The pg_logfile_get function will return the + contents of the current server log file, limited by the size + parameter. If size is NULL, a server internal limit (currently + 5) is applied. The position parameter specifies the + starting position of the server log chunk to be returned. A + positive number or 0 will be counted from the start of the file, + a negative number from the end; if NULL, -size is assumed + (i.e. the tail of the log file). + + +Both pg_logfile_get and + pg_logfile_length have a filename + parameter which may specify the logfile to examine or the + current logfile if NULL. + + + pg_cancel_backend Index: runtime.sgml === RCS file: /projects/cvsroot/pgsql-server/doc/src/sgml/runtime.sgml,v retrieving revision 1.269 diff -u -r1.269 runtime.sgml --- runtime.sgml 11 Jul 2004 00:18:40 - 1.269 +++ runtime.sgml 14 Jul 2004 19:08:26 - @@ -1769,9 +1769,9 @@ PostgreSQL supports several methods - for loggning, including stderr and - syslog. On Windows, - eventlog is also supported. Set this + for logging, including stderr, + file> and syslog. + On Windows, eventlog is also supported. Set this option to a list of desired log destinations separated by a comma. The default is to log to stderr only. This option must be set at server start. @@ -1779,6 +1779,17 @@ + + log_filename (string) + + + This option sets the target filename for the log destination + file option. It may be specified as absolute + path or relative to the cluster directory. + + + + syslog_facility (string) ---(end of broadcast)--- TIP 7: don't forget to increase your free space map settings
[PATCHES] logfile subprocess and Fancy File Functions
The attached patch and additional src/backend/postmaster/syslogger.c implements the logfile subprocess as discussed. TODO: - documentation - win32 code (forkexec) is included, but not tested (no build env) Functions (all are superuser only): int4 pg_reload_conf() Sends SIGHUP to postmaster bool pg_logfile_rotate() initiates logfile rotation, same does SIGUSR1 to the syslogger subprocess; returns true if logging is enabled setof record pg_logfiles_ls() lists all available logfiles, should we have a view as well? CREATE VIEW pg_logfiles AS SELECT ts, pid, fn FROM pg_logfiles_ls() AS pgls(ts timestamp, pid int4, fn text) int8 pg_file_length(filename_text) returns length of file, or -1 if non existent (no ERROR) text pg_file_read(filename_text, startpos_int6, length_int8) reads file int8 pg_file_write(filename_text, data_text, append_bool) writes file. creates or appends to create, file must not exist, to append, file may exist. bool pg_file_rename(filename_old_text, filenamenew_text) rename file bool pg_file_unlink(filename_text) unlinks file. returns true/false if done (no ERROR) bool pg_file_rename(filename_old_text, filename_new_text, filename_archive_text) chain rename: new->archive, old->archive, example: It should be quite safe to do pg_file_write('postgresql.conf.tmp', '.some stuff...', false); pg_file_unlink('postgresql.conf.bak'); pg_file_rename('postgresql.conf.tmp', 'postgresql.conf', 'postgresql.conf.bak'); pg_reload_conf(); Regards, Andreas /*- * * syslogger.c * * The system logger (syslogger) is new in Postgres 7.5. It catches all * stderr output from backends, the postmaster and subprocesses by * redirecting to a pipe, and writes it to a logfile and stderr if * configured. * It's possible to have size and age limits for the logfile configured * in postgresql.conf. If these limits are reached or passed, the * current logfile is closed and a new one is created (rotated). * The logfiles are stored in a subdirectory (configurable in * postgresql.conf), using an internal naming scheme that mangles * creation time and current postmaster pid. * * Author: Andreas Pflug <[EMAIL PROTECTED]> * * Copyright (c) 2004, PostgreSQL Global Development Group * * * IDENTIFICATION * $PostgreSQL: $ * *- */ #include "postgres.h" #include #include #include #include "libpq/pqsignal.h" #include "miscadmin.h" #include "postmaster/postmaster.h" #include "storage/pmsignal.h" #include "storage/pg_shmem.h" #include "storage/ipc.h" #include "postmaster/syslogger.h" #include "utils/ps_status.h" #include "utils/guc.h" /* * GUC parameters */ int Log_RotationAge = 24*60; int Log_RotationSize = 10*1024; char * Log_directory = "pg_log"; /* * Flags set by interrupt handlers for later service in the main loop. */ static volatile sig_atomic_t got_SIGHUP = false; static volatile sig_atomic_t rotation_requested = false; static pg_time_t last_rotation_time = 0; static void sigHupHandler(SIGNAL_ARGS); static void rotationHandler(SIGNAL_ARGS); #ifdef EXEC_BACKEND static pid_t syslogger_forkexec(); #endif static char* logfile_getname(pg_time_t timestamp); static bool logfile_rotate(void); FILE *realStdErr = NULL; FILE *syslogFile = NULL; int syslogPipe[2] = {0, 0}; /* * Main entry point for syslogger process * argc/argv parameters are valid only in EXEC_BACKEND case. */ void SysLoggerMain(int argc, char *argv[]) { IsUnderPostmaster = true; MyProcPid = getpid(); init_ps_display("system logger process", "", ""); set_ps_display(""); #ifdef EXEC_BACKEND Assert(argc == 6); argv += 3; StrNCpy(postgres_exec_path, argv++, MAXPGPATH); syslogPipe[0] = atoi(argv++); syslogPipe[1] = atoi(argv); #endif /* * Properly accept or ignore signals the postmaster might send us * * Note: we ignore all termination signals, and wait for the postmaster * to die to catch as much pipe output as possible. */ pqsignal(SIGHUP, sigHupHandler); /* set flag to read config file */ pqsignal(SIGINT, SIG_IGN); pqsignal(SIGTERM, SIG_IGN); pqsignal(SIGQUIT, SIG_IGN); pqsignal(SIGALRM, SIG_IGN); pqsignal(SIGPIPE, SIG_IGN); pqsignal(SIGUSR1, rotationHandler); /* request log rotation */ pqsignal(SIGUSR2, SIG_IGN); /* * Reset some signals that are accepted by postmaster but not here */ pqsignal(SIGCHLD, SIG_DFL); pqsignal(SIGTTIN, SIG_DFL); pqsignal(SIGTTOU, SIG_DFL); pqsignal(SIGCONT, SIG_DFL); pqsignal(SIGWINCH, SIG_DFL); PG_SETMASK(&UnBlockSig); /* * if we restarted, our stderr is redirected. * Direct it back to system stderr. */ if (realStd
Re: [PATCHES] logfile subprocess and Fancy File Functions
es is reached. 0 to disable. +#log_rotation_size = 10240 # Automatic rotation of logfiles will happen if +# specified size in kb is reached. 0 to disable. + #syslog_facility = 'LOCAL0' #syslog_ident = 'postgres' Index: src/include/catalog/pg_proc.h === RCS file: /projects/cvsroot/pgsql-server/src/include/catalog/pg_proc.h,v retrieving revision 1.342 diff -u -r1.342 pg_proc.h --- src/include/catalog/pg_proc.h 12 Jul 2004 20:23:53 - 1.342 +++ src/include/catalog/pg_proc.h 18 Jul 2004 22:14:32 - @@ -2819,6 +2819,8 @@ DESCR("Terminate a backend process"); DATA(insert OID = 2172 ( pg_cancel_backend PGNSP PGUID 12 f f t f s 1 23 "23" _null_ pg_cancel_backend - _null_ )); DESCR("Cancel running query on a backend process"); +DATA(insert OID = 2173 ( pg_reload_confPGNSP PGUID 12 f f t f s 1 23 "" _null_ pg_reload_conf - _null_ )); +DESCR("Reload postgresql.conf"); DATA(insert OID = 1946 ( encode PGNSP PGUID 12 f f t f i 2 25 "17 25" _null_ binary_encode - _null_ )); DESCR("Convert bytea value into some ascii-only text string"); @@ -3607,6 +3609,25 @@ DATA(insert OID = 2556 ( pg_tablespace_databases PGNSP PGUID 12 f f t t s 1 26 "26" _null_ pg_tablespace_databases - _null_)); DESCR("returns database oids in a tablespace"); +DATA(insert OID = 2557( pg_file_length PGNSP PGUID 12 f f t f v 1 20 "25" _null_ pg_file_length - _null_ )); +DESCR("length of generic file"); +DATA(insert OID = 2558( pg_file_read PGNSP PGUID 12 f f t f v 3 25 "25 20 20" _null_ pg_file_read - _null_ )); +DESCR("read contents of generic file"); +DATA(insert OID = 2559( pg_file_write PGNSP PGUID 12 f f t f v 3 20 "25 25 16" _null_ pg_file_write - _null_ )); +DESCR("write generic file"); +DATA(insert OID = 2560( pg_file_renamePGNSP PGUID 12 f f t f v 2 16 "25 25" _null_ pg_file_rename - _null_ )); +DESCR("rename generic file"); +DATA(insert OID = 2561( pg_file_renamePGNSP PGUID 12 f f t f v 33 16 "25 25 25" _null_ pg_file_rename - _null_ )); +DESCR("rename generic file"); +DATA(insert OID = 2562( pg_file_unlink PGNSP PGUID 12 f f t f v 1 16 "25" _null_ pg_file_unlink - _null_ )); +DESCR("remove generic file"); +DATA(insert OID = 2563( pg_dir_ls PGNSP PGUID 12 f f t t v 2 25 "25 16" _null_ pg_dir_ls - _null_ )); +DESCR("list generic directory"); + +DATA(insert OID = 2564( pg_logfile_rotate PGNSP PGUID 12 f f t f v 0 16 "" _null_ pg_logfile_rotate - _null_ )); +DESCR("rotate log file"); +DATA(insert OID = 2565( pg_logfiles_ls PGNSP PGUID 12 f f t t v 0 2249 "" _null_ pg_logfiles_ls - _null_ )); +DESCR("list all available log files"); /* * Symbolic values for provolatile column: these indicate whether the result Index: src/include/storage/pmsignal.h === RCS file: /projects/cvsroot/pgsql-server/src/include/storage/pmsignal.h,v retrieving revision 1.8 diff -u -r1.8 pmsignal.h --- src/include/storage/pmsignal.h 29 May 2004 22:48:23 - 1.8 +++ src/include/storage/pmsignal.h 18 Jul 2004 22:14:33 - @@ -24,6 +24,7 @@ { PMSIGNAL_PASSWORD_CHANGE, /* pg_pwd file has changed */ PMSIGNAL_WAKEN_CHILDREN, /* send a SIGUSR1 signal to all backends */ + PMSIGNAL_ROTATE_LOGFILE, /* send SIGUSR1 to syslogger to rotate logfile */ NUM_PMSIGNALS/* Must be last value of enum! */ } PMSignalReason; Index: src/include/utils/builtins.h === RCS file: /projects/cvsroot/pgsql-server/src/include/utils/builtins.h,v retrieving revision 1.246 diff -u -r1.246 builtins.h --- src/include/utils/builtins.h 12 Jul 2004 20:23:59 - 1.246 +++ src/include/utils/builtins.h 18 Jul 2004 22:14:35 - @@ -362,8 +362,20 @@ extern Datum current_database(PG_FUNCTION_ARGS); extern Datum pg_terminate_backend(PG_FUNCTION_ARGS); extern Datum pg_cancel_backend(PG_FUNCTION_ARGS); +extern Datum pg_reload_conf(PG_FUNCTION_ARGS); extern Datum pg_tablespace_databases(PG_FUNCTION_ARGS); +extern Datum pg_logfile_rotate(PG_FUNCTION_ARGS); +extern Datum pg_logfiles_ls(PG_FUNCTION_ARGS); + +extern Datum pg_file_length(PG_FUNCTION_ARGS); +extern Datum pg_file_read(PG_FUNCTION_ARGS); +extern Datum pg_file_write(PG_FUNCTION_ARGS); +extern Datum pg_file_rename(PG_FUNCTION_ARGS); +extern Datum pg_file_unlink(PG_FUNCTION_ARGS); + +extern Datum pg_dir_ls(PG_FUNCTION_ARGS); + /* not_in.c */ extern Datum int4notin(PG_FUNCTION_ARGS); extern Datum oidnotin(PG_FUNCTION_ARGS); Index: src/include/utils/elog.h ==
Re: [PATCHES] logfile subprocess and Fancy File Functions
Magnus Hagander wrote: > Super-minor nitpicking from just eyeing over the patch, not actually > checking how it works. Reviewing the own code the most obvious things are overlooked. > > This patch changes the error message for pg_signal_backend() to "only > superuser may access generic file functions". > > I'm sure that was not intended.. You probably need to pass a parameter > to requireSuperuser() about what should go in the err msg. Yes, seems I was a bit overenthusiastic... > > Also, I think you forgot to attach syslogger.h. Indeed, attached is include/postmaster/syslogger.h Regards, Andreas /*- * * syslogger.h * Exports from postmaster/syslogger.c. * * Portions Copyright (c) 2004, PostgreSQL Global Development Group * * $PostgreSQL: $ * *- */ #ifndef _SYSLOGGER_H #define _SYSLOGGER_H #include "pgtime.h" /* GUC options */ extern int Log_RotationAge; extern int Log_RotationSize; extern char * Log_directory; int SysLogger_Start(void); void SysLoggerMain(int argc, char *argv[]); extern bool LogFileRotate(void); #endif /* _SYSLOGGER_H */ ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org
Re: [PATCHES] logfile subprocess and Fancy File Functions
Bruce Momjian wrote: Andreas Pflug wrote: Very nice. You did a nice trick of reading the log filenames into a timestamp field: count = sscanf(de->d_name, "%04d-%02d-%02d_%02d%02d%02d_%05d.log", &yea$ You only process files that match that pattern for pg_logfiles_ls() (perhaps this should be pg_logdir_ls for consistency). Yup. And you can then process the timestamp field in queries. Good idea. What happens if a filename matches the above pattern but isn't a valid timestamp? Does the function fail? Right now, BuildTupleFromCString will fail for invalid timestamps. I'm going to change that to pgsql's internal function (strptime seems a bad idea though). My only question is whether we need to allow a custom prefix for the log filenames so they can be distinguished from other file names in a user-supplied log directory, like /var/log, or would they always go into a separate directory under there. I think a prefix would be nice. How should the prefix be named? pgsql_ ? Of course this needs docs but I assume you are waiting to see it applied first. Not necessarily, but I'd like names etc. fixed before. Regards, Andreas ---(end of broadcast)--- TIP 7: don't forget to increase your free space map settings
Re: [PATCHES] logfile subprocess and Fancy File Functions
Bruce Momjian wrote: Peter Eisentraut wrote: Bruce Momjian wrote: Peter Eisentraut wrote: Andreas Pflug wrote: How should the prefix be named? pgsql_ ? Make the file names configurable. He has code to interpret the file names as timestamps that can be used in queries. If we allowed full user control over the file name, he couldn't do that. I can't see this working. As you know, there are constantly people who want to install and configure PostgreSQL in the weirdest ways. If we tell everybody, you log files must be named like this, it will start all over again. Maybe it would be better if the time stamps of the files are used as time stamps in queries. Imagine an older logfile was edited with lets say emacs, which will rename the old and create a new file. Or after log_directory was changed, the files from the old location are copied to the new location. This would garble the log_dir_ls output badly. The logfilename currently also includes the postmaster's pid, there's no file metadata that could take this information safely. Apparently it's best to invent a log_file_prefix = 'pgsql_' guc variable. In fact one idea would be to add new stat() columns for creation/mod/access file times to the directory listing command. Actually, a preliminary version of pg_dir_ls did also return some stat data. I removed this, in favor of functions like pg_file_length. SELECT fn, pg_file_length(fn) FROM pg_dir_ls('/etc', true) AS fn WHERE fn like '/etc/p%' I certainly could supply a record-returning pg_dir_ls (fn text, fullfn text, len int8, ctime timestamp, atime timestamp, mtime timestamp) 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
Re: [PATCHES] logfile subprocess and Fancy File Functions
Peter Eisentraut wrote: Bruce Momjian wrote: For logs I think pgsql_ is best because that filename is already going to be long, and I don't usually like dashes in file names. They look too much like arguments, but tarballs use them and it looks OK there, I guess. I wasn't talking about what looks best, I was talking about current practice for log files. From that you might be able to extrapolate what other people have previously found to look best. In any case, we're not using DOS and 12 inch monitors any more. File names can be as long as we want. Before the thread concentrates too much on a decent default value, I'm posting a fresh version of the patch, for some more discussion. Current default for pg_logfile_prefix is 'postgresql-', may the committers decide which name is The Perfect One. All previous suggestions have been included, (nb: abstimein is not usable, because it ereports(ERROR) on failure; we want to skip wrong files gracefully, so I'm using ParseDateTime and DecodeDateTime instead). I'd still need feedback on pg_dir_ls: should it merely return a setof text, or should I enrich it to a record returning all stat data? After spending another thought on it, I believe the more sql-like approach is to deliver a full-featured record which is selected for the desired data, not adding columns with functions. Regards, Andreas /*- * * syslogger.c * * The system logger (syslogger) is new in Postgres 7.5. It catches all * stderr output from backends, the postmaster and subprocesses by * redirecting to a pipe, and writes it to a logfile and stderr if * configured. * It's possible to have size and age limits for the logfile configured * in postgresql.conf. If these limits are reached or passed, the * current logfile is closed and a new one is created (rotated). * The logfiles are stored in a subdirectory (configurable in * postgresql.conf), using an internal naming scheme that mangles * creation time and current postmaster pid. * * Author: Andreas Pflug <[EMAIL PROTECTED]> * * Copyright (c) 2004, PostgreSQL Global Development Group * * * IDENTIFICATION * $PostgreSQL: $ * *- */ #include "postgres.h" #include #include #include #include "libpq/pqsignal.h" #include "miscadmin.h" #include "postmaster/postmaster.h" #include "storage/pmsignal.h" #include "storage/pg_shmem.h" #include "storage/ipc.h" #include "postmaster/syslogger.h" #include "utils/ps_status.h" #include "utils/guc.h" /* * GUC parameters */ int Log_RotationAge = 24*60; int Log_RotationSize = 10*1024; char * Log_directory = "pg_log"; char * Log_filename_prefix = "postgresql_"; /* * Flags set by interrupt handlers for later service in the main loop. */ static volatile sig_atomic_t got_SIGHUP = false; static volatile sig_atomic_t rotation_requested = false; static pg_time_t last_rotation_time = 0; static void sigHupHandler(SIGNAL_ARGS); static void rotationHandler(SIGNAL_ARGS); #ifdef EXEC_BACKEND static pid_t syslogger_forkexec(); #endif static char* logfile_getname(pg_time_t timestamp); static bool logfile_rotate(void); FILE *realStdErr = NULL; FILE *syslogFile = NULL; int syslogPipe[2] = {0, 0}; /* * Main entry point for syslogger process * argc/argv parameters are valid only in EXEC_BACKEND case. */ void SysLoggerMain(int argc, char *argv[]) { IsUnderPostmaster = true; MyProcPid = getpid(); init_ps_display("system logger process", "", ""); set_ps_display(""); #ifdef EXEC_BACKEND Assert(argc == 6); argv += 3; StrNCpy(postgres_exec_path, argv++, MAXPGPATH); syslogPipe[0] = atoi(argv++); syslogPipe[1] = atoi(argv); #endif /* * Properly accept or ignore signals the postmaster might send us * * Note: we ignore all termination signals, and wait for the postmaster * to die to catch as much pipe output as possible. */ pqsignal(SIGHUP, sigHupHandler); /* set flag to read config file */ pqsignal(SIGINT, SIG_IGN); pqsignal(SIGTERM, SIG_IGN); pqsignal(SIGQUIT, SIG_IGN); pqsignal(SIGALRM, SIG_IGN); pqsignal(SIGPIPE, SIG_IGN); pqsignal(SIGUSR1, rotationHandler); /* request log rotation */ pqsignal(SIGUSR2, SIG_IGN); /* * Reset some signals that are accepted by postmaster but not here */ pqsignal(SIGCHLD, SIG_DFL); pqsignal(SIGTTIN, SIG_DFL); pqsignal(SIGTTOU, SIG_DFL); pqsignal(SIGCONT, SIG_DFL); pqsignal(SIGWINCH, SIG_DFL); PG_SETMASK(&UnBlockSig); /* * if we restarted, our stderr is redirected. * Direct it back to system stderr. */ if (realStdErr != NULL) { if (dup2(fileno(realStdErr), fileno(stderr)) < 0) { char *errstr = strerror(errno
Re: [PATCHES] logfile subprocess and Fancy File Functions
Bruce Momjian wrote: Andreas Pflug wrote: OK, new idea. Forget about modifying pg_dir_ls(). Instead add pg_file_stat the returns the file size, times. You can then easily use that for file size and times. Also, if you want, add an is_dir boolean so people can write functions that walk the directory tree. I now replaced pg_logfile_length, instead pg_logfile_stat(text) will return a record (len int8, ctime timestamp, atime timestamp, mtime timestamp, isdir bool). For convenience, I'd like to have the function CREATE FUNCTION pg_file_length(text) RETURNS int8 AS $BODY$ SELECT len FROM pg_file_stat($1) AS stat (len int8, ctime timestamp, atime timestamp, mtime timestamp, isdir bool) $BODY$ LANGUAGE SQL STRICT; Where is the right place to put it? Also, I wonder how to join pg_file_stat and pg_dir_ls to get a ls -l like listing. Apparently I can't do that, unless I don't code pg_dir_ls as returning records too, right? I noticed we had a big logging discussion during 7.4 beta about logging and log rotation. This patch is clearly superior to the ideas we had at that time. Currently, the discussion circles around file functions, not logging. If you think that part is clean, how about committing it separately so it can be tested/used (no problem if pg_logfile_rotate() isn't available right from the start). I'll supply docs RSN. Regards, Andreas Index: src/backend/catalog/system_views.sql === RCS file: /projects/cvsroot/pgsql-server/src/backend/catalog/system_views.sql,v retrieving revision 1.6 diff -u -r1.6 system_views.sql --- src/backend/catalog/system_views.sql 26 Apr 2004 15:24:41 - 1.6 +++ src/backend/catalog/system_views.sql 21 Jul 2004 09:49:22 - @@ -273,3 +273,8 @@ DO INSTEAD NOTHING; GRANT SELECT, UPDATE ON pg_settings TO PUBLIC; + +CREATE VIEW pg_logdir_ls AS + SELECT * + FROM pg_logdir_ls() AS A + (filetime timestamp, pid int4, filename text); Index: src/backend/postmaster/Makefile === RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/Makefile,v retrieving revision 1.16 diff -u -r1.16 Makefile --- src/backend/postmaster/Makefile 19 Jul 2004 02:47:08 - 1.16 +++ src/backend/postmaster/Makefile 21 Jul 2004 09:49:23 - @@ -12,7 +12,7 @@ top_builddir = ../../.. include $(top_builddir)/src/Makefile.global -OBJS = postmaster.o bgwriter.o pgstat.o pgarch.o +OBJS = postmaster.o bgwriter.o pgstat.o pgarch.o syslogger.o all: SUBSYS.o Index: src/backend/postmaster/postmaster.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/postmaster.c,v retrieving revision 1.412 diff -u -r1.412 postmaster.c --- src/backend/postmaster/postmaster.c 19 Jul 2004 02:47:08 - 1.412 +++ src/backend/postmaster/postmaster.c 21 Jul 2004 09:49:29 - @@ -118,7 +118,7 @@ #include "utils/ps_status.h" #include "bootstrap/bootstrap.h" #include "pgstat.h" - +#include "postmaster/syslogger.h" /* * List of active backends (or child processes anyway; we don't actually @@ -201,6 +201,7 @@ BgWriterPID = 0, PgArchPID = 0, PgStatPID = 0; +pid_t SysLoggerPID = 0; /* Startup/shutdown state */ #define NoShutdown 0 @@ -852,6 +853,12 @@ #endif /* + * start logging to file + */ + +SysLoggerPID = SysLogger_Start(); + + /* * Reset whereToSendOutput from Debug (its starting state) to None. * This prevents ereport from sending log messages to stderr unless * the syslog/stderr switch permits. We don't do this until the @@ -1230,6 +1237,11 @@ StartupPID == 0 && !FatalError && Shutdown == NoShutdown) PgStatPID = pgstat_start(); + /* If we have lost the system logger, try to start a new one */ + if (SysLoggerPID == 0 && + StartupPID == 0 && !FatalError && Shutdown == NoShutdown) + SysLoggerPID = SysLogger_Start(); + /* * Touch the socket and lock file at least every ten minutes, to ensure * that they are not removed by overzealous /tmp-cleaning tasks. @@ -1770,6 +1782,9 @@ kill(BgWriterPID, SIGHUP); if (PgArchPID != 0) kill(PgArchPID, SIGHUP); + if (SysLoggerPID != 0) + kill(SysLoggerPID, SIGHUP); + /* PgStatPID does not currently need SIGHUP */ load_hba(); load_ident(); @@ -1835,7 +1850,6 @@ if (PgStatPID != 0) kill(PgStatPID, SIGQUIT); break; - case SIGINT: /* * Fast Shutdown: @@ -1902,6 +1916,7 @@ kill(PgStatPID, SIGQUIT); if (DLGetHead(BackendList)) SignalChildren(SIGQUIT); + ExitPostmaster(0); break; } @@ -2059,6 +2074,15 @@ continue; } + /* was it the system logger, try to start a new one */ + if (SysLoggerPID != 0 && pid == SysLoggerPID) + { + if (exitstatus != 0) +LogChi
Re: [PATCHES] logfile subprocess and Fancy File Functions
t f i 2 25 "17 25" _null_ binary_encode - _null_ )); DESCR("Convert bytea value into some ascii-only text string"); @@ -3607,6 +3609,30 @@ DATA(insert OID = 2556 ( pg_tablespace_databases PGNSP PGUID 12 f f t t s 1 26 "26" _null_ pg_tablespace_databases - _null_)); DESCR("returns database oids in a tablespace"); +/* logfile functions */ +DATA(insert OID = 2244( pg_logfile_rotate PGNSP PGUID 12 f f t f v 0 16 "" _null_ pg_logfile_rotate - _null_ )); +DESCR("rotate log file"); +DATA(insert OID = 2245( pg_logdir_ls PGNSP PGUID 12 f f t t v 0 2249 "" _null_ pg_logdir_ls - _null_ )); +DESCR("list all available log files"); + +/* generic file functions */ +DATA(insert OID = 2557( pg_file_stat PGNSP PGUID 12 f f t f v 1 2249 "25" _null_ pg_file_stat - _null_ )); +DESCR("stat properties of generic file"); +DATA(insert OID = 2558 ( pg_file_length PGNSP PGUID 14 f f t f v 1 20 "25" _null_ "SELECT len FROM pg_file_stat($1) AS s(len int8, c timestamp, a timestamp, m timestamp, d bool)" - _null_ )); +DESCR("length of a generic file"); +DATA(insert OID = 2559( pg_file_read PGNSP PGUID 12 f f t f v 3 25 "25 20 20" _null_ pg_file_read - _null_ )); +DESCR("read contents of generic file"); +DATA(insert OID = 2560( pg_file_write PGNSP PGUID 12 f f t f v 3 20 "25 25 16" _null_ pg_file_write - _null_ )); +DESCR("write generic file"); +DATA(insert OID = 2561( pg_file_renamePGNSP PGUID 12 f f t f v 2 16 "25 25 25" _null_ pg_file_rename - _null_ )); +DESCR("rename generic file"); +DATA(insert OID = 2562( pg_file_renamePGNSP PGUID 14 f f t f v 2 16 "25 25" _null_ "SELECT pg_file_rename($1,$2,NULL)" - _null_ )); +DESCR("rename generic file"); +DATA(insert OID = 2563( pg_file_unlink PGNSP PGUID 12 f f t f v 1 16 "25" _null_ pg_file_unlink - _null_ )); +DESCR("remove generic file"); + +DATA(insert OID = 2564( pg_dir_ls PGNSP PGUID 12 f f t t v 2 25 "25 16" _null_ pg_dir_ls - _null_ )); +DESCR("list generic directory"); /* * Symbolic values for provolatile column: these indicate whether the result Index: src/include/storage/pmsignal.h === RCS file: /projects/cvsroot/pgsql-server/src/include/storage/pmsignal.h,v retrieving revision 1.9 diff -u -r1.9 pmsignal.h --- src/include/storage/pmsignal.h 19 Jul 2004 02:47:15 - 1.9 +++ src/include/storage/pmsignal.h 21 Jul 2004 17:26:42 - @@ -25,7 +25,7 @@ PMSIGNAL_PASSWORD_CHANGE, /* pg_pwd file has changed */ PMSIGNAL_WAKEN_CHILDREN, /* send a SIGUSR1 signal to all backends */ PMSIGNAL_WAKEN_ARCHIVER, /* send a NOTIFY signal to xlog archiver */ - + PMSIGNAL_ROTATE_LOGFILE, /* send SIGUSR1 to syslogger to rotate logfile */ NUM_PMSIGNALS/* Must be last value of enum! */ } PMSignalReason; Index: src/include/utils/builtins.h === RCS file: /projects/cvsroot/pgsql-server/src/include/utils/builtins.h,v retrieving revision 1.246 diff -u -r1.246 builtins.h --- src/include/utils/builtins.h 12 Jul 2004 20:23:59 - 1.246 +++ src/include/utils/builtins.h 21 Jul 2004 17:26:44 - @@ -362,8 +362,20 @@ extern Datum current_database(PG_FUNCTION_ARGS); extern Datum pg_terminate_backend(PG_FUNCTION_ARGS); extern Datum pg_cancel_backend(PG_FUNCTION_ARGS); +extern Datum pg_reload_conf(PG_FUNCTION_ARGS); extern Datum pg_tablespace_databases(PG_FUNCTION_ARGS); +extern Datum pg_logfile_rotate(PG_FUNCTION_ARGS); +extern Datum pg_logdir_ls(PG_FUNCTION_ARGS); + +extern Datum pg_file_stat(PG_FUNCTION_ARGS); +extern Datum pg_file_read(PG_FUNCTION_ARGS); +extern Datum pg_file_write(PG_FUNCTION_ARGS); +extern Datum pg_file_rename(PG_FUNCTION_ARGS); +extern Datum pg_file_unlink(PG_FUNCTION_ARGS); + +extern Datum pg_dir_ls(PG_FUNCTION_ARGS); + /* not_in.c */ extern Datum int4notin(PG_FUNCTION_ARGS); extern Datum oidnotin(PG_FUNCTION_ARGS); Index: src/include/utils/elog.h === RCS file: /projects/cvsroot/pgsql-server/src/include/utils/elog.h,v retrieving revision 1.70 diff -u -r1.70 elog.h --- src/include/utils/elog.h 6 Jul 2004 19:51:59 - 1.70 +++ src/include/utils/elog.h 21 Jul 2004 17:26:44 - @@ -185,10 +185,10 @@ #define LOG_DESTINATION_STDERR 1 #define LOG_DESTINATION_SYSLOG 2 #define LOG_DESTINATION_EVENTLOG 4 +#define LOG_DESTINATION_FILE 8 /* Other exported functions */ extern void DebugFileOpen(void); - /* * Write errors to stderr (or by equal means when stderr is * not available). Used before ereport/elog can be used /*---
Re: [PATCHES] logfile subprocess and Fancy File Functions
Bruce Momjian wrote: Here is what you can do: SELECT filename, (SELECT file_len FROM pg_file_stat(filename)), (SELECT file_ctime FROM pg_file_stat(filename)), (SELECT file_mtime FROM pg_file_stat(filename)), (SELECT file_atime FROM pg_file_stat(filename)) FROM pg_dir_ls('/etc') AS d (filename text...) WHERE filename like 's%' Not really satisfying (pg_file_stat is volatile) but subselects give the desired result. Are we done? Seems pg_file_stat() works fine. Do we need other adjustments? The only single spot where performance could be improved is in pg_file_stat, where attinmeta is created again and again; this may be cached in a static memory context instead. ---(end of broadcast)--- TIP 8: explain analyze is your friend
Re: [PATCHES] logfile subprocess and Fancy File Functions
Bruce Momjian wrote: Are we done? Seems pg_file_stat() works fine. Do we need other adjustments? Here are the documentation changes. Regards, Andreas Index: catalogs.sgml === RCS file: /projects/cvsroot/pgsql-server/doc/src/sgml/catalogs.sgml,v retrieving revision 2.89 diff -u -r2.89 catalogs.sgml --- catalogs.sgml 4 Jul 2004 23:34:23 - 2.89 +++ catalogs.sgml 23 Jul 2004 12:16:47 - @@ -3855,6 +3855,11 @@ + pg_logdir_ls + log files in log directory + + + pg_rules rules @@ -3943,6 +3948,50 @@ + + pg_logdir_ls + + + pg_logdir_ls + + + + The view pg_logdir_ls provides access to +log files stored in the log directory. + + + + pg_logdir_ls Columns + + + + + Name + Type + Description + + + + + filetime + timestamp + timestamp of log file creation + + + pid + int4 + process id of postmaster that created the logfile + + + filename + text + full pathname of log file + + + + + + pg_locks Index: func.sgml === RCS file: /projects/cvsroot/pgsql-server/doc/src/sgml/func.sgml,v retrieving revision 1.214 diff -u -r1.214 func.sgml --- func.sgml 12 Jul 2004 20:23:47 - 1.214 +++ func.sgml 23 Jul 2004 12:17:06 - @@ -2658,8 +2658,10 @@ function fails and returns null. To indicate the part of the pattern that should be returned on success, the pattern must contain two occurrences of the escape character followed by a double quote - ("). The text matching the portion of the pattern + ("). The text matching the portion of the pattern between these markers is returned. + @@ -7455,6 +7457,41 @@ + pg_logdir_ls + + + pg_logfile_rotate + + +The functions shown in + deal with the server log file if configured with log_destination + file. + + + +Server Logfile Functions + + + Name Return Type Description + + + + + pg_logfile_rotate() + bool + rotates the server log file + + + + + + pg_logfile_rotate will force the logger + process to rotate log files. If logging to file was not enabled + ('file' in log_destination configuration + parameter), false will be returned. + + + pg_cancel_backend @@ -7463,6 +7500,10 @@ +pg_reload_config + + + signal backend processes @@ -7497,6 +7538,13 @@ int Terminate a backend process + + + pg_reload_config() + + int + Reload configuration from postgresql.conf + @@ -7508,6 +7556,196 @@ pg_stat_activity view, or by listing the postgres processes on the server. + + pg_reload_config will send +a SIGHUP signal to all backends, forcing them to +reload their configuration from postgresql.conf. + + + +pg_file_stat + + +pg_file_length + + +pg_file_read + + +pg_file_write + + +pg_file_rename + + +pg_file_unlink + + +pg_dir_ls + + + +generic file + + + +The functions shown in implement generic file access +and directory listing functions. Use of these functions is +restricted to superusers. + + + +Generic File and Directory Access Functions + + + Name Return Type Description + + + + + + + pg_file_stat(filename_text) + + record + Retrieves file stat information + + + + pg_file_length(filename_text) + + int8 + Retrieves length of file + + + + pg_file_read(filename_text, offset_int8, length_int8) + + text + Retrieves contents of text file + + + + pg_file_write(filename_text, contents_text, append_bool) + + int8 + Writes data to text file + + + + pg_file_ren(oldname_text, newname_text) + + bool + Renames file + + + + pg_file_ren(oldname_text, newname_text) + + bool + Renames file + + + + pg_file_ren(oldname_text, newname_text, archivename_text) + + bool + Renames file and previous file + + + + + pg_file_unlink(filename_text) + + bool + unlinks/deletes file + + + + pg_dir_ls(filename_text, fullpath_bool) + + setof text + Retrieves list of filenames in a directory + + + + + + +All file functions take a filename_text argument, +which may specify an absolute path or is evaluated relative to the +cluster directory $PG_DATA. Wh
Re: [PATCHES] logfile subprocess and Fancy File Functions
Tom Lane wrote: Bruce Momjian wrote: Are we done? Nope, the syslogger part of this is still a mess. I don't want any pg_logfile_rotate() function in there at all: its presence is a hangover from a different design philosophy. No. As I mentioned earlier, there might be cases when a superuser wants to issue the rotation to keep some stuff in a single log file. Nor pg_reload_conf(); where did that come from? (Hint: if you can edit postgresql.conf you do not need a helper function to signal the postmaster.) Wrong. The generic file functions allow editing postgresql.conf without having file access, and consequently you'd like to make that active without consoling to the server. Nor the pg_logdir_ls view, as that will malfunction completely if we aren't actually using the syslogger facility, yet there's no graceful way to make it go away. ? It will show nothing if there are no files, so what's the problem? I also find the Log_destination setup to be less than carefully thought out: what in the world does it mean to specify stderr and file as distinct log destinations? stderr is simply untouched. Actually it works parallel. This design cannot support that, and doesn't need to AFAICS. I didn't want to wipe out the default logging method right away. Of course, even log_destination=syslog might be redirected. What we probably want instead is a separate redirect_stderr_to_files boolean (I'm sure a better name could be thought of). Also, while I'm aware that a superuser can persuade the backend to write on anything, it doesn't follow that we should invent pg_file_write(), pg_file_rename(), or pg_file_unlink(). Those are not needed for the originally intended purpose of this patch I proposed to separate them, they're indeed non-related. What I'd like is SELECT pg_file_unlink('postgresql.conf.bak'); SELECT pg_file_write('postgresql.conf.tmp', 'listen_addresses=...'); SELECT pg_file_rename('postgresql.conf.tmp', 'postgresql.conf', 'postgresql.conf.bak'); SELECT pg_reload_conf(); and I think that they are just invitations to trouble. If you are aware that there are burglars out there who know how to pick your door lock, do you then post directions and tools to help on your door? These are superuser only, and executed in the postgres user context. We're offering a superuser to shoot himself into the foot wherever he likes regarding system catalog etc. I wouldn't have a problem if paths may only be relative to PG_DATA and .. is disallowed. Finally, I can tell without even trying it that the present syslogger code will fail miserably in EXEC_BACKEND case. I don't have an EXEC_BACKEND environment, I already pointed out that this has to be tested. It's expecting realStdErr to be inherited which it will not be. Yes, this is probably one source of problems for EXEC_BACKEND. I don't think the notion of respawning the logger will work; we're just going to have to assume it is as reliable as the postmaster is, and we only need launch it once. It works. (BTW, did Magnus ever verify for us that redirecting stderr into a pipe will work at all on Windows? Actually, dup2 etc is documented perfectly for win32. This certainly doesn't mean anything... win32 system error messages are retrieved using GetLastError, not from stderr, so problems are a bit different anyway. 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
Re: [PATCHES] [HACKERS] Function to kill backend
Would you use a kill operation in the way you describe above if you knew that it had, say, a 1% chance of causing a database-wide PANIC each time you used it? Seems there's the need for some connection killing functionality. If it's not present, the whole cluster needs to be shut down, which makes it unavailable with 100 % chance. If there's a .1 % chance it *corrupts* the cluster, the function is not acceptable. But iff it's a good chance to keep the cluster running, it's worth having it (and should be used sensibly). 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
Re: [PATCHES] [HACKERS] Function to kill backend
Tom Lane wrote: If you don't mind plastering a "use at your own risk" sign on it, then go for it. killing a backend is obviously much more "at your own risk" than a descent function. Taken from your mail, I understand that a killed backend might leave some loose ends, eg. open locks, which would degrade the cluster's performance. Still, it should not corrupt the shared mem, just leave it as if the backend's still alive and sleeping, right? You'd kill a backend only if your complete cluster is suffering from it, and you hope to keep it running by just shooting that process. If the cluster still has that uncleaned locks or so, you're unlucky and need to shutdown the cluster. Maybe we should supply a restricted version of pg_terminate_backend that's callable from admin interfaces only so we can make sure that the user was warned what he's doing before the termination is executed, something like that: ticket := select pg_admin_ticket(); /* calculate well-known stuff on ticket and issue before it times out */ select pg_terminate_backend(ticket_hash); Regards, Andreas ---(end of broadcast)--- TIP 8: explain analyze is your friend
[PATCHES] logger subprocess
This is the known patch, with following changes: - realStdErr handed over for EXEC_BACKEND, but still not tested - Sometimes EMFILE is received in the logger's process queue, when a backend ended after a SSL connection was interrupted. This is ignored now (previously it forced an exit(1) and restart of the subprocess) - log_destination needs to be PGC_POSTMASTER, because the logger process creation depends on that. - no functions included Regards, Andreas Index: src/backend/postmaster/Makefile === RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/Makefile,v retrieving revision 1.18 diff -u -r1.18 Makefile --- src/backend/postmaster/Makefile 21 Jul 2004 20:34:46 - 1.18 +++ src/backend/postmaster/Makefile 27 Jul 2004 10:33:30 - @@ -12,7 +12,7 @@ top_builddir = ../../.. include $(top_builddir)/src/Makefile.global -OBJS = postmaster.o bgwriter.o pgstat.o pgarch.o +OBJS = postmaster.o bgwriter.o pgstat.o pgarch.o syslogger.o all: SUBSYS.o Index: src/backend/postmaster/postmaster.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/postmaster.c,v retrieving revision 1.416 diff -u -r1.416 postmaster.c --- src/backend/postmaster/postmaster.c 27 Jul 2004 01:46:03 - 1.416 +++ src/backend/postmaster/postmaster.c 27 Jul 2004 10:33:36 - @@ -118,7 +118,7 @@ #include "utils/ps_status.h" #include "bootstrap/bootstrap.h" #include "pgstat.h" - +#include "postmaster/syslogger.h" /* * List of active backends (or child processes anyway; we don't actually @@ -201,6 +201,7 @@ BgWriterPID = 0, PgArchPID = 0, PgStatPID = 0; +pid_t SysLoggerPID = 0; /* Startup/shutdown state */ #define NoShutdown 0 @@ -852,6 +853,12 @@ #endif /* + * start logging to file + */ + +SysLoggerPID = SysLogger_Start(); + + /* * Reset whereToSendOutput from Debug (its starting state) to None. * This stops ereport from sending log messages to stderr unless * Log_destination permits. We don't do this until the postmaster @@ -1231,6 +1238,11 @@ StartupPID == 0 && !FatalError && Shutdown == NoShutdown) PgStatPID = pgstat_start(); + /* If we have lost the system logger, try to start a new one */ + if (SysLoggerPID == 0 && + StartupPID == 0 && !FatalError && Shutdown == NoShutdown) + SysLoggerPID = SysLogger_Start(); + /* * Touch the socket and lock file at least every ten minutes, to ensure * that they are not removed by overzealous /tmp-cleaning tasks. @@ -1771,6 +1783,9 @@ kill(BgWriterPID, SIGHUP); if (PgArchPID != 0) kill(PgArchPID, SIGHUP); + if (SysLoggerPID != 0) + kill(SysLoggerPID, SIGHUP); + /* PgStatPID does not currently need SIGHUP */ load_hba(); load_ident(); @@ -1836,7 +1851,6 @@ if (PgStatPID != 0) kill(PgStatPID, SIGQUIT); break; - case SIGINT: /* * Fast Shutdown: @@ -1903,6 +1917,7 @@ kill(PgStatPID, SIGQUIT); if (DLGetHead(BackendList)) SignalChildren(SIGQUIT); + ExitPostmaster(0); break; } @@ -2065,6 +2080,15 @@ continue; } + /* was it the system logger, try to start a new one */ + if (SysLoggerPID != 0 && pid == SysLoggerPID) + { + if (exitstatus != 0) +LogChildExit(LOG, gettext("system logger process"), + pid, exitstatus); + SysLoggerPID = SysLogger_Start(); + continue; + } /* * Else do standard backend child cleanup. */ @@ -2968,6 +2992,16 @@ PgstatCollectorMain(argc, argv); proc_exit(0); } + if (strcmp(argv[1], "-forklog") == 0) + { + /* Close the postmaster's sockets */ + ClosePostmasterPorts(); + + /* Do not want to attach to shared memory */ + + SysLoggerMain(argc, argv); + proc_exit(0); + } return 1; /* shouldn't get here */ } @@ -3024,7 +3058,6 @@ if (Shutdown <= SmartShutdown) SignalChildren(SIGUSR1); } - if (PgArchPID != 0 && Shutdown == NoShutdown) { if (CheckPostmasterSignal(PMSIGNAL_WAKEN_ARCHIVER)) @@ -3036,6 +3069,10 @@ kill(PgArchPID, SIGUSR1); } } + if (CheckPostmasterSignal(PMSIGNAL_ROTATE_LOGFILE) && SysLoggerPID != 0) + { + kill(SysLoggerPID, SIGUSR1); + } PG_SETMASK(&UnBlockSig); Index: src/backend/utils/error/elog.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/error/elog.c,v retrieving revision 1.142 diff -u -r1.142 elog.c --- src/backend/utils/error/elog.c 24 Jun 2004 21:03:13 - 1.142 +++ src/backend/utils/error/elog.c 27 Jul 2004 10:33:39 - @@ -84,6 +84,10 @@ static void write_eventlog(int level, const char *line); #endif +/* in syslogger.c */ +extern FILE *syslogFile; +extern FILE *realStdErr; +extern pid_t SysLoggerPID; /* * ErrorData holds the data accumulated during any one ereport() cycle. * Any non-NULL pointers must point to palloc'd data in ErrorContext. @@ -1451,10 +
[PATCHES] Admin functions contrib
These files add administrative functions to pgsql 7.5. All are used by pgAdmin3 or will be used in the near future if available. This is meant as contrib module, whilst IMHO all these functions should be integrated into the backend. Included are functions to log file access These where previously posted together with the logger subprocess patch and might get committed to the backend code. misc. send SIGHUP to postmaster generic file access functions These are more restrictive than the previously posted: Write access is necessary for files to rename and unlink, and paths are restricted to PGDATA and the logdir. size functions These are 7.5 replacements for dbsize. Regards, Andreas subdir = contrib/admin top_builddir = ../.. include $(top_builddir)/src/Makefile.global MODULE_big = admin DATA_built = admin.sql DOCS = README.admin OBJS = size.o genfile.o misc.o include $(top_srcdir)/contrib/contrib-global.mk /* ** * Administrative functions * * */ /* database object size functions (admin.c) */ CREATE FUNCTION pg_tablespace_size(oid) RETURNS bigint AS 'MODULE_PATHNAME', 'pg_tablespace_size' LANGUAGE C STABLE STRICT; CREATE FUNCTION pg_database_size(oid) RETURNS bigint AS 'MODULE_PATHNAME', 'pg_database_size' LANGUAGE C STABLE STRICT; CREATE FUNCTION pg_relation_size(oid) RETURNS bigint AS 'MODULE_PATHNAME', 'pg_relation_size' LANGUAGE C STABLE STRICT; CREATE FUNCTION pg_size_pretty(bigint) RETURNS text AS 'MODULE_PATHNAME', 'pg_size_pretty' LANGUAGE C STABLE STRICT; /* generic file access functions (genfile.c) */ CREATE FUNCTION pg_file_stat(text) RETURNS record AS 'MODULE_PATHNAME', 'pg_file_stat' LANGUAGE C VOLATILE STRICT; CREATE FUNCTION pg_file_length(text) RETURNS bigint AS 'SELECT len FROM pg_file_stat($1) AS s(len int8, c timestamp, a timestamp, m timestamp, i bool)' LANGUAGE SQL VOLATILE STRICT; CREATE FUNCTION pg_file_read(text, bigint, bigint) RETURNS text AS 'MODULE_PATHNAME', 'pg_file_read' LANGUAGE C VOLATILE STRICT; CREATE FUNCTION pg_file_write(text, text, bool) RETURNS bigint AS 'MODULE_PATHNAME', 'pg_file_write' LANGUAGE C VOLATILE STRICT; CREATE FUNCTION pg_file_rename(text, text, text) RETURNS bool AS 'MODULE_PATHNAME', 'pg_file_rename' LANGUAGE C VOLATILE STRICT; CREATE FUNCTION pg_file_unlink(text) RETURNS bool AS 'MODULE_PATHNAME', 'pg_file_unlink' LANGUAGE C VOLATILE STRICT; CREATE FUNCTION pg_file_rename(text, text) RETURNS bool AS 'SELECT pg_file_rename($1, $2, NULL); ' LANGUAGE SQL VOLATILE STRICT; CREATE FUNCTION pg_dir_ls(text, bool) RETURNS setof text AS 'MODULE_PATHNAME', 'pg_dir_ls' LANGUAGE C VOLATILE STRICT; /* Miscellaneous functions (misc.c) */ CREATE FUNCTION pg_reload_conf() RETURNS int4 AS 'MODULE_PATHNAME', 'pg_reload_conf' LANGUAGE C STABLE STRICT; CREATE FUNCTION pg_logfile_rotate() RETURNS bool AS 'MODULE_PATHNAME', 'pg_logfile_rotate' LANGUAGE C STABLE STRICT; CREATE FUNCTION pg_logdir_ls() RETURNS setof record AS 'MODULE_PATHNAME', 'pg_logdir_ls' LANGUAGE C VOLATILE STRICT; CREATE VIEW pg_logdir_ls AS SELECT * FROM pg_logdir_ls() AS A (filetime timestamp, pid int4, filename text); /*- * * genfile.c * * * Copyright (c) 2004, PostgreSQL Global Development Group * * Author: Andreas Pflug <[EMAIL PROTECTED]> * * IDENTIFICATION * $PostgreSQL: $ * *- */ #include "postgres.h" #include #include #include #include "miscadmin.h" #include "storage/fd.h" #include "catalog/pg_type.h" #include "funcapi.h" Datum pg_file_stat(PG_FUNCTION_ARGS); Datum pg_file_read(PG_FUNCTION_ARGS); Datum pg_file_write(PG_FUNCTION_ARGS); Datum pg_file_rename(PG_FUNCTION_ARGS); Datum pg_file_unlink(PG_FUNCTION_ARGS); Datum pg_dir_ls(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(pg_file_stat); PG_FUNCTION_INFO_V1(pg_file_read); PG_FUNCTION_INFO_V1(pg_file_write); PG_FUNCTION_INFO_V1(pg_file_rename); PG_FUNCTION_INFO_V1(pg_file_unlink); PG_FUNCTION_INFO_V1(pg_dir_ls); extern char *Log_directory; typedef struct { char *location; DIR *dirdesc; } directory_fctx; /*--- * some helper functions */ /* * Return an absolute path. Argument may be absolute or * relative to the DataDir. */ static char *absClusterPath(text *arg, bool logAllowed) { char *filename; int len=VARSIZE(arg) - VARHDRSZ; int dlen = strlen(Data
[PATCHES] ruleutils with pretty-print option
The attached patches will add pg_get_ruledef(oid, int) pg_get_viewdef(text, int) pg_get_viewdef(oid, int) pg_get_indexdef(oid, int) pg_get_constraintdef(oid, int) pg_get_expr(text, oid, int) If the last parameter "pretty-print" is 0, these function will return the same result as their original counterparts without that parameter. The source is based on ruleutils.c 1.143, and should return exactly the same result as before if no pretty-print is selected. My tests didn't show any differences for pg_dump output with old or new version. The pretty-print parameter is evaluated bit-wise. PRETTY_PAREN 1 - Parentheses are checked; only necessary parentheses will be emitted. PRETTY_INDENT 2 - pretty indentation and line formatting is performed PRETTY_OPPAREN4 - For T_BoolExpr operators, AND/OR/NOT precedence is checked, for T_OpExpr +-*/% precedence is checked. If precedence is identified, parentheses are omitted. This option is only active if PRETTY_PAREN is also used. Regards, Andreas Index: ruleutils.c === RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/ruleutils.c,v retrieving revision 1.143 diff -c -r1.143 ruleutils.c *** ruleutils.c 29 Jun 2003 00:33:44 - 1.143 --- ruleutils.c 29 Jun 2003 16:54:48 - *** *** 71,76 --- 71,97 #include "utils/lsyscache.h" + /** + * Pretty formatting constants + **/ + + /* Indent counts */ + #define PRETTYINDENT_STD8 + #define PRETTYINDENT_JOIN 13 + #define PRETTYINDENT_JOIN_ON(PRETTYINDENT_JOIN-PRETTYINDENT_STD) + #define PRETTYINDENT_VAR4 + + /* Pretty flags */ + #define PRETTYFLAG_PAREN1 + #define PRETTYFLAG_INDENT 2 + #define PRETTYFLAG_OPPAREN 4 + + /* macro to test if pretty action needed */ + #define PRETTY_PAREN(context) (context->prettyFlags & PRETTYFLAG_PAREN) + #define PRETTY_INDENT(context) (context->prettyFlags & PRETTYFLAG_INDENT) + #define PRETTY_OPPAREN(context) (context->prettyFlags & PRETTYFLAG_OPPAREN) + + /* -- * Local data types * -- *** *** 81,86 --- 102,109 { StringInfo buf;/* output buffer to append to */ List *namespaces; /* List of deparse_namespace nodes */ + int prettyFlags;/* if non-zero, parentheses are minimized. */ + int indentLevel;/* for prettyPrint, we perform indentation and line splitting */ boolvarprefix; /* TRUE to print prefixes on Vars */ } deparse_context; *** *** 123,135 * as a parameter, and append their text output to its contents. * -- */ ! static text *pg_do_getviewdef(Oid viewoid); static void decompile_column_index_array(Datum column_index_array, Oid relId, StringInfo buf); ! static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc); ! static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc); static void get_query_def(Query *query, StringInfo buf, List *parentnamespace, ! TupleDesc resultDesc); static void get_select_query_def(Query *query, deparse_context *context, TupleDesc resultDesc); static void get_insert_query_def(Query *query, deparse_context *context); --- 146,164 * as a parameter, and append their text output to its contents. * -- */ ! static char *get_simple_binary_op_name(OpExpr *expr); ! static void appendStringInfoSpace(StringInfo buf, int count); ! static void appendContextKeyword(deparse_context *context, char *str, int indentBefore, int indentAfter, int indentPlus); ! static char *deparse_expression_pretty(Node *expr, List *dpcontext, ! bool forceprefix, bool showimplicit, int prettyFlags, int startIndent); ! static bool isSimpleNode(Node *node, Node *parentNode, int prettyFlags); ! static text *pg_do_getviewdef(Oid viewoid, int prettyFlags); static void decompile_column_index_array(Datum column_index_array, Oid relId, StringInfo buf); ! static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc, int prettyFlags); ! static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc, int prettyFlags); static void get_query_def(Query *query, StringInfo buf, List *parentnamespace, ! TupleDesc resultDesc, int prettyFlags, int startIndent); static void get_select_query_def(Query *query, deparse_context *context, TupleDesc resultDesc); static void get_insert_query_def(Query *query, deparse_context *co
Re: [PATCHES] Patch for UUID datatype (beta)
Gevik Babakhani wrote: > - new_guid() function is supported. This function is based on V4 random > uuid value. It generated 16 random bytes with uuid 'variant' and > 'version'. It is not guaranteed to produce unique values Isn't guaranteed uniqueness the very attribute that's expected? AFAIK there's a commonly accepted algorithm providing this. Regards, Andreas ---(end of broadcast)--- TIP 6: explain analyze is your friend
Re: [PATCHES] [HACKERS] For review: Server instrumentation patch
Dave Page wrote: -Original Message- From: Bruce Momjian [mailto:[EMAIL PROTECTED] Sent: 01 August 2005 03:26 To: Dave Page Cc: PostgreSQL-patches Subject: Re: [HACKERS] For review: Server instrumentation patch Dave Page wrote: [Resent as the list seems to have rejected yesterdays attempt] As per Bruce's request, here's a copy of Andreas' server instrumentation patch for review. I've separated out the dbsize stuff and pg_terminate_backend is also not included. This version was generated against CVS today. As far as I can tell from review of comments made back to pre-8.0, all security and other concerns raised have been addressed. Here is a modified version of your patch that adds functions to do configuration file reload, and log file rotation. OK, thanks. Are there any objections to adding pg_dir_ls() and pg_file_read() which will allow us to look at the log directory, and the logfiles themselves? pg_dir_ls isn't necessary for reading the logfiles; pg_logdir_ls will do this. Regards, Andreas ---(end of broadcast)--- TIP 1: 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] [HACKERS] For review: Server instrumentation patch
Dave Page wrote: pg_dir_ls isn't necessary for reading the logfiles; pg_logdir_ls will do this. Err, yes, sorry - that was a thinko. The list isn't complete. pgadmin uses these three functions for logfile tracking: - pg_logdir_ls to list logfiles - pg_file_length to check for changes of the current logfile - pg_file_read to retrieve a logfile Regards, Andreas ---(end of broadcast)--- TIP 6: explain analyze is your friend
Re: [PATCHES] [HACKERS] For review: Server instrumentation patch
Bruce Momjian wrote: Dave Page wrote: The only part I didn't like about the patch is the stat display: test=> select pg_file_stat('postgresql.conf'); pg_file_stat - (12287,"2005-08-11 00:06:30","2005-08-11 00:06:43","2005-08-11 00:06:30",f) (1 row) Shouldn't this return multiple labeled columns rather than an array? pg_show_all_settings output is equally unreadable, designed not to be used directly. Regards, Andreas ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [PATCHES] [HACKERS] For review: Server instrumentation patch
Bruce Momjian wrote: I did not include pg_logdir_ls because that was basically pg_ls_dir with logic to decode the log file name and convert it to a timestamp. That seemed best done in the client. IMHO omitting pg_logdir_ls is a bad idea, because the function is intended to hide server internal's naming scheme from the user. We want as few server side implementation specific client side code as possible. In addition, pg_logdir_ls filters files that are not log files. You'll probably have trouble writing a query that performes this task. Regards, Andreas ---(end of broadcast)--- TIP 1: 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] [HACKERS] For review: Server instrumentation patch
Bruce Momjian wrote: BTW, it surprised me that one of the functions (don't remember which one) expected the log files to be named in a very specific fashion. So there's no flexibility for changing the log_prefix. Probably it's not so bad, but strange anyway. Is this for "security" reasons? The logger subprocess patch originally didn't allow changing the the logfile name pattern, to make sure it can be interpreted safely at a later time. There's simply no way to mark the file with a timestamp without the risk of it being arbitrarily modified by file commands, thus screwing up the order of logfiles. Later, there was the request to alternatively append a timestamp instead of a date pattern, to use apache logging tools that will probably access the logfiles directly anyway. This ended up in the log_filename GUC variable. Righ, pg_logdir_ls() was the function. My feeling is that the application has access to the log_directory and log_filename values and can better and move flexibly filter pg_ls_dir() on the client end than we can do on the server. It just seemed like something that we better done outside the server. Outside the server means pure SQL, if you don't want to drop psql as client. So how would your query to display all all available _logfiles_ look like? You'd need to check for a valid date, besides interpreting pg_strfime's patterns. Doesn't sound exactly like fun, but I'm keen to see how your equivalent to SELECT *, pg_file_length(filename) AS len FROM pg_logdir_ls looks like. Regards, Andreas ---(end of broadcast)--- TIP 6: explain analyze is your friend
Re: [PATCHES] [HACKERS] For review: Server instrumentation patch
Tom Lane wrote: Andreas Pflug <[EMAIL PROTECTED]> writes: So how would your query to display all all available _logfiles_ look like? I think it's perfectly reasonable to assume that all the files in the log directory are logfiles --- more so than assuming that the admin hasn't exercised his option to change the log filename pattern, anyway. I also don't have a problem with using the file mod times to sort them. ... until you copy the database cluster. See discussion from last year. Regards, Andreas ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [PATCHES] [HACKERS] For review: Server instrumentation patch
Bruce Momjian wrote: I don't assume people using psql will care about the current log files --- Hm. Probably because you think these users will have direct file access? Which in turn means they can edit *.conf directly too and don't need an interface for that either. it would be something done in C or another application language. Aren't the file names already ordered based on their file names, given the default pattern, postgresql-%Y-%m-%d_%H%M%S.log? The issue is _filtering_, not ordering. Since the log directory might be directed to a different location, non-pgsql logfiles might be there too. You'd probably won't expect to retrieve these files over a pgsql connection. Regards, Andreas ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [PATCHES] [HACKERS] For review: Server instrumentation patch
Bruce Momjian wrote: I don't see how listing the log files relates to editing the confuration files. Both are remote administration. While we've seen the discussion that one aspect (config file editing) should be performed in psql, you assume the other aspect (viewing the logfile) to be not interesting. Your argumentation doesn't seem consequent to me. it would be something done in C or another application language. Aren't the file names already ordered based on their file names, given the default pattern, postgresql-%Y-%m-%d_%H%M%S.log? The issue is _filtering_, not ordering. Since the log directory might be directed to a different location, non-pgsql logfiles might be there too. You'd probably won't expect to retrieve these files over a pgsql connection. Well, if they mix log files and non-log files in the same directory, we would have to filter based on the log_filename directive in the application, or use LIKE in a query. .. which is what pg_logdir_ls does. And it's robust against filenames that don't have valid dates too; imagine postgresql-2005-01-01_crash1.log. Regards, Andreas ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org
Re: [PATCHES] [HACKERS] For review: Server instrumentation patch
Bruce Momjian wrote: True, but that is more for the application. I don't imagine a user looking at that from psql would have a problem. However, you asked for a query that looks like pg_ls_logdir() and here it is: SELECT pg_ls_dir FROM( SELECT pg_ls_dir(t1.setting) FROM(SELECT setting FROM pg_settings WHERE NAME = 'log_directory') AS t1 ) AS t2, (SELECT setting FROM pg_settings WHERE NAME = 'log_filename') AS t3 WHERE t2.pg_ls_dir LIKE regexp_replace(t3.setting, '%.*', '') || '%'; The one thing it doesn't do, as you mentioned, is check for valid dates, but it is certainly more flexible than embedding something in the backend. The interesting part of pg_logdir_ls is the filetime, to enable SELECT pg_file_unlink(filename) FROM pg_logdir_ls() WHERE filetime < now() - '30 days'::interval Regards, Andreas ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster
Re: [PATCHES] [HACKERS] For review: Server instrumentation patch
Tom Lane wrote: Andreas Pflug <[EMAIL PROTECTED]> writes: Bruce Momjian wrote: Well, if they mix log files and non-log files in the same directory, we would have to filter based on the log_filename directive in the application, or use LIKE in a query. .. which is what pg_logdir_ls does. And it's robust against filenames that don't have valid dates too; imagine postgresql-2005-01-01_crash1.log. The proposed version of pg_logdir_ls could not be called "robust" in any way at all, considering that it fails as soon as you modify the log_filename pattern. This is caused by the exposure of log_filename, I never proposed to do that for good reasons. Any try to interpret it and read files back will break finally when log_filename is changed at runtime, i.e. it's a 'break me' option by design. Regards, Andreas ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings
Re: [PATCHES] [HACKERS] For review: Server instrumentation patch
Bruce Momjian wrote: Also, do we have a way to return columns from a system-installed function? I really don't like that pg_stat_file() to returns a record rather than named columns. How do I even access the individual record values? As in pg_settings: SELECT length, mtime FROM pg_file_stat('postgresql.conf') AS st(length int4, ctime timestamp, atime timestamp, mtime timestamp, isdir bool) Regards, Andreas ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq
Re: [PATCHES] [HACKERS] For review: Server instrumentation patch
Tom Lane wrote: I removed the separate pg_file_length() function, as it doesn't have any significant notational advantage anymore; you can do Please note that there are pg_file_length functions in use for 8.0 on probably >95 % of win32 installations, so you're breaking backwards compatibility. Regards, Andreas ---(end of broadcast)--- TIP 1: 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