Re: [PATCHES] latest plperl
Andrew Dunstan wrote: The attached patch (and 2 new files incorporating previous eloglvl.[ch] as before) has the following changes over previously sent patch (fixes all by me): Some comments below: In plperl_trigger_build_args(), this looks bogus: + char *tmp; + + tmp = (char *) malloc(sizeof(int)); ... + sprintf(tmp, %d, tdata-tg_trigger-tgnargs); + sv_catpvf(rv, , argc = %s, tmp); ... + free(tmp); I changed it to: + sv_catpvf(rv, , argc = %d, tdata-tg_trigger-tgnargs); In this section, it appears that empty strings in the tuple will be coerced into NULL values: + plval = plperl_get_elem(hvNew, platt); + if (plval) + { + src = plval; + if (strlen(plval)) + { + modvalues[j] = FunctionCall3(finfo, + CStringGetDatum(src), + ObjectIdGetDatum(typelem), + Int32GetDatum(tupdesc-attrs[atti]-atttypmod)); + modnulls[j] = ' '; + } + else + { + modvalues[i] = (Datum) 0; + modnulls[j] = 'n'; + } + } + plval = NULL; Shouldn't that look more like this? + plval = plperl_get_elem(hvNew, platt); + if (plval) + { + modvalues[j] = FunctionCall3(finfo, + CStringGetDatum(plval), + ObjectIdGetDatum(typelem), + Int32GetDatum(tupdesc-attrs[atti]-atttypmod)); + modnulls[j] = ' '; + } + else + { + modvalues[i] = (Datum) 0; + modnulls[j] = 'n'; + } Joe ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org
Re: [PATCHES] latest plperl
Andrew Dunstan wrote: I will do some checking on these changes, but with those caveats they look good to me. Attached is an all inclusive revised patch. Please review and comment. If there are no objections, I'll commit in a few hours. As a side note, I think it would be *really* helpful if there were a more comprehensive test script, and an expected results file available. Not sure though if it could be included in the standard regression tests on a configure-conditional basis -- anyone know? Joe Index: src/pl/plperl/GNUmakefile === RCS file: /cvsroot/pgsql-server/src/pl/plperl/GNUmakefile,v retrieving revision 1.12 diff -c -r1.12 GNUmakefile *** src/pl/plperl/GNUmakefile 21 Jan 2004 19:04:11 - 1.12 --- src/pl/plperl/GNUmakefile 1 Jul 2004 16:24:53 - *** *** 25,32 SO_MAJOR_VERSION = 0 SO_MINOR_VERSION = 0 ! OBJS = plperl.o eloglvl.o SPI.o SHLIB_LINK = $(perl_embed_ldflags) $(BE_DLLLIBS) include $(top_srcdir)/src/Makefile.shlib --- 25,37 SO_MAJOR_VERSION = 0 SO_MINOR_VERSION = 0 ! OBJS = plperl.o spi_internal.o SPI.o ! ! ifeq ($(enable_rpath), yes) SHLIB_LINK = $(perl_embed_ldflags) $(BE_DLLLIBS) + else + SHLIB_LINK = $(perl_embed_ldflags) $(BE_DLLLIBS) -Wl,-rpath,$(perl_archlibexp)/CORE + endif include $(top_srcdir)/src/Makefile.shlib Index: src/pl/plperl/SPI.xs === RCS file: /cvsroot/pgsql-server/src/pl/plperl/SPI.xs,v retrieving revision 1.5 diff -c -r1.5 SPI.xs *** src/pl/plperl/SPI.xs 4 Sep 2002 22:49:37 - 1.5 --- src/pl/plperl/SPI.xs 1 Jul 2004 16:24:53 - *** *** 6,22 #include perl.h #include XSUB.h ! #include eloglvl.h ! MODULE = SPI PREFIX = elog_ PROTOTYPES: ENABLE VERSIONCHECK: DISABLE void ! elog_elog(level, message) int level char* message CODE: --- 6,22 #include perl.h #include XSUB.h ! #include spi_internal.h ! MODULE = SPI PREFIX = spi_ PROTOTYPES: ENABLE VERSIONCHECK: DISABLE void ! spi_elog(level, message) int level char* message CODE: *** *** 24,44 int ! elog_DEBUG() int ! elog_LOG() int ! elog_INFO() int ! elog_NOTICE() int ! elog_WARNING() int ! elog_ERROR() ! --- 24,56 int ! spi_DEBUG() int ! spi_LOG() int ! spi_INFO() int ! spi_NOTICE() int ! spi_WARNING() int ! spi_ERROR() + SV* + spi_spi_exec_query(query, ...) + char* query; + PREINIT: + HV *ret_hash; + int limit=0; + CODE: + if (items2) Perl_croak(aTHX_ Usage: spi_exec_query(query, limit) or spi_exec_query(query)); + if (items == 2) limit = SvIV(ST(1)); + ret_hash=plperl_spi_exec(query, limit); + RETVAL = newRV_noinc((SV*)ret_hash); + OUTPUT: + RETVAL Index: src/pl/plperl/eloglvl.c === RCS file: src/pl/plperl/eloglvl.c diff -N src/pl/plperl/eloglvl.c *** src/pl/plperl/eloglvl.c 25 Jul 2003 23:37:28 - 1.9 --- /dev/null 1 Jan 1970 00:00:00 - *** *** 1,45 - #include postgres.h - - /* - * This kludge is necessary because of the conflicting - * definitions of 'DEBUG' between postgres and perl. - * we'll live. - */ - - #include eloglvl.h - - int - elog_DEBUG(void) - { - return DEBUG2; - } - - int - elog_LOG(void) - { - return LOG; - } - - int - elog_INFO(void) - { - return INFO; - } - - int - elog_NOTICE(void) - { - return NOTICE; - } - - int - elog_WARNING(void) - { - return WARNING; - } - - int - elog_ERROR(void) - { - return ERROR; - } --- 0 Index: src/pl/plperl/eloglvl.h === RCS file: src/pl/plperl/eloglvl.h diff -N src/pl/plperl/eloglvl.h *** src/pl/plperl/eloglvl.h 4 Sep 2002 20:31:47 - 1.5 --- /dev/null 1 Jan 1970 00:00:00 - *** *** 1,12 - - int elog_DEBUG(void); - - int elog_LOG(void); - - int elog_INFO(void); - - int elog_NOTICE(void); - - int elog_WARNING(void); - - int elog_ERROR(void); --- 0 Index: src/pl/plperl/plperl.c === RCS file: /cvsroot/pgsql-server/src/pl/plperl/plperl.c,v retrieving revision 1.44 diff -c -r1.44 plperl.c *** src/pl/plperl/plperl.c 6 Jun 2004 00:41:28 - 1.44 --- src/pl/plperl/plperl.c 1 Jul 2004 16:24:53 - *** *** 49,54 --- 49,55 #include catalog/pg_language.h #include catalog/pg_proc.h #include catalog/pg_type.h + #include funcapi.h /* need for SRF support */ #include commands/trigger.h #include executor/spi.h #include fmgr.h *** *** 78,83 --- 79,86 TransactionId fn_xmin; CommandId fn_cmin; bool lanpltrusted; + bool fn_retistuple; /* true, if function returns tuple */ + Oid ret_oid; /* Oid of returning type */ FmgrInfo
Re: [PATCHES] latest plperl
Andrew Dunstan wrote: Doh! Very bogus! sizeof(int)and a malloc to boot ??? I didn't check the trigger code much because it has supposedly been working for quite a while. I will examine more closely. Well, essentially 4 bytes (sizeof(int)) were being allocated to print a two byte interger that can never be greater than two characters (32), so I don't expect it would have ever failed, but only by serendipity. Shouldn't that look more like this? + plval = plperl_get_elem(hvNew, platt); + if (plval) + { + modvalues[j] = FunctionCall3(finfo, + CStringGetDatum(plval), + ObjectIdGetDatum(typelem), + Int32GetDatum(tupdesc-attrs[atti]-atttypmod)); + modnulls[j] = ' '; + } + else + { + modvalues[i] = (Datum) 0; + modnulls[j] = 'n'; + } Yes, except that that [i] looks wrong too. Surely it should be [j]. And with this change decl of src appears redundant. Hmmm, I missed that -- looks wrong to me too. I'll check it out. I will do some checking on these changes, but with those caveats they look good to me. Do you need a revised patch? Nah, I'll make the changes and post a revised patch for you to comment on prior to committing. Joe ---(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] latest plperl
Joe Conway [EMAIL PROTECTED] writes: As a side note, I think it would be *really* helpful if there were a more comprehensive test script, and an expected results file available. Not sure though if it could be included in the standard regression tests on a configure-conditional basis -- anyone know? pltcl has a separate regression test, which seems to serve the purpose well enough. I'd suggest focusing more on getting the tests into existence than on whether they have to be integrated ;-) regards, tom lane ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster
Re: [PATCHES] latest plperl
Alvaro Herrera said: On Thu, Jul 01, 2004 at 09:33:57AM -0700, Joe Conway wrote: As a side note, I think it would be *really* helpful if there were a more comprehensive test script, and an expected results file available. Not sure though if it could be included in the standard regression tests on a configure-conditional basis -- anyone know? Can't this stuff be tested somehow using Test::Simple, Test::Harness or something like that? I know this is not standard perl stuff but ... Not really. These subroutines have no names nor even references from Perl's POV. I really don't want to build a test harness into the dynamic lib. And in any case, the test really needs to come from postgres, not from perl. The test is 'does this trigger/function do the right thing in the sense of the value returned to postgres or effect on the database?' The place where things are likely to break is not in the perl interpreter, but in the glue code. cheers andrew ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]
Re: [PATCHES] latest plperl
On Thu, Jul 01, 2004 at 09:33:57AM -0700, Joe Conway wrote: As a side note, I think it would be *really* helpful if there were a more comprehensive test script, and an expected results file available. Not sure though if it could be included in the standard regression tests on a configure-conditional basis -- anyone know? Can't this stuff be tested somehow using Test::Simple, Test::Harness or something like that? I know this is not standard perl stuff but ... -- Alvaro Herrera (alvherre[a]dcc.uchile.cl) I call it GNU/Linux. Except the GNU/ is silent. (Ben Reiter) ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]
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. If there are no objections, I'll review and apply this tonight (west coast USA time). Andreas, please provide a corresponding documentation patch. Thanks, Joe ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster
Re: [PATCHES] latest plperl
Andrew Dunstan wrote: Joe Conway said: As a side note, I think it would be *really* helpful if there were a more comprehensive test script, and an expected results file available. Not sure though if it could be included in the standard regression tests on a configure-conditional basis -- anyone know? To the best of my knowledge you cannot. We will provide an analogue for pltcl's test directory shortly, if that is desired - it will probably take a few days, though. I assume that will be acceptable after feature freeze? Yup, I think that falls into Tom's loose ends category. At a quick glance, modulo the makefile change, the patch looks good. Great! I'll commit shortly. Thanks, Joe ---(end of broadcast)--- TIP 7: don't forget to increase your free space map settings
Re: [PATCHES] [PATCH] s_lock support for win32
Tom Lane writes: Claudio Natoli [EMAIL PROTECTED] writes: The win32 port doesn't have a native user space spinlock implementation yet. It does when compiled with MingW. Are we intending to support any other compilers/build environments than that one? Not currently; at least not for the backend, as psql/libpq etc continue to also be supported under VC++. Cheers, Claudio --- Certain disclaimers and policies apply to all email sent from Memetrics. For the full text of these disclaimers and policies see a href=http://www.memetrics.com/emailpolicy.html;http://www.memetrics.com/em ailpolicy.html/a ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html
Re: [PATCHES] contrib/dbmirror
[EMAIL PROTECTED] wrote: Attached is a 1 line bug fix for dbmirror that was submitted. It fixes a bug where some transactions could be dropped when writing mirrored SQL statements to files. Patch applied. Joe ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]
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. 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: + row + entryliteralfunctionpg_tablespace_databases/function(parameternamespace_oid/parameter)/literal/entry + entrytypesetof oid/type/entry + entryget set of database oids that have objects in the namespace/entry + /row 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); I take it that is (path len + '/' + strlen(pg_tablespaces) + '/' + oid string length + terminator). I did this instead: + #define PG_TABLESPACE_DIR pg_tblspc + /* assumes unsigned, 10 digits */ + #define OID_AS_STR10 + /* +* size = path length + tablespace dirname length +*+ 2 dir sep chars + oid + terminator +*/ + fctx-location = (char*) palloc(strlen(DataDir) + + strlen(PG_TABLESPACE_DIR) + + 2 + OID_AS_STR + 1); Usage looks like this: regression=# select d.datname from pg_tablespace_databases(1663) as t(oid) join pg_database d on t.oid = d.oid order by 1; datname regression template0 template1 (3 rows) initdb forced. Any objections? Joe Index: doc/src/sgml/func.sgml === RCS file: /cvsroot/pgsql-server/doc/src/sgml/func.sgml,v retrieving revision 1.211 diff -c -r1.211 func.sgml *** doc/src/sgml/func.sgml 25 Jun 2004 17:20:21 - 1.211 --- doc/src/sgml/func.sgml 2 Jul 2004 05:12:56 - *** *** 7232,7237 --- 7232,7241 primarypg_get_serial_sequence/primary /indexterm +indexterm zone=functions-misc + primarypg_tablespace_databases/primary +/indexterm + para xref linkend=functions-misc-catalog-table lists functions that extract information from the system catalogs. *** *** 7325,7330 --- 7329,7339 entryget name of the sequence that a serial or bigserial column uses/entry /row + row +entryliteralfunctionpg_tablespace_databases/function(parametertablespace_oid/parameter)/literal/entry +entrytypesetof oid/type/entry +entryget set of database oids that have objects in the tablespace/entry + /row /tbody /tgroup /table *** *** 7360,7365 --- 7369,7384 for passing to the sequence functions (see xref linkend=functions-sequence). NULL is returned if the column does not have a sequence attached. + /para + + para + functionpg_tablespace_databases/function 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 + functionpg_tablespace_databases/function to query pg_class. /para indexterm zone=functions-misc Index: src/backend/utils/adt/misc.c === RCS file: /cvsroot/pgsql-server/src/backend/utils/adt/misc.c,v retrieving revision 1.34 diff -c -r1.34 misc.c *** src/backend/utils/adt/misc.c 2 Jun 2004 21:29:29 - 1.34 --- src/backend/utils/adt/misc.c 2 Jul 2004 05:12:56 - *** *** 16,26 --- 16,31 #include sys/file.h #include signal.h + #include dirent.h #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,105 --- 107,210 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; + #define PG_TABLESPACE_DIR pg_tblspc + /* assumes unsigned, 10 digits */ + #define OID_AS_STR 10 + + 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); + +