[PATCHES] [subxacts] Some docs
Hackers, Here is a doc patch that includes pages for savepoint commands. It would be cool if they can be applied as starting points for savepoint documentation. Poeple who can do better, please feel free to improve in any way. -- Alvaro Herrera (alvherre[a]dcc.uchile.cl) Cómo ponemos nuestros dedos en la arcilla del otro. Eso es la amistad; jugar al alfarero y ver qué formas se pueden sacar del otro (C. Halloway en La Feria de las Tinieblas, R. Bradbury) diff -Ncr --exclude-from=diff-ignore 00orig/doc/src/sgml/advanced.sgml 03pgproc/doc/src/sgml/advanced.sgml *** 00orig/doc/src/sgml/advanced.sgml 2004-04-14 16:45:53.0 -0400 --- 03pgproc/doc/src/sgml/advanced.sgml 2004-07-26 22:39:01.689881464 -0400 *** *** 257,262 --- 257,310 you are using. /para /note + +para + It's possible to control the statements in a transaction in a more + granular fashion through the use of firsttermsavepoints/. Savepoints + allow you to selectively discard parts of the transaction, while + committing the rest. This is done be defining a savepoint with + commandSAVEPOINT/, to which you can later roll back using + commandROLLBACK TO/. All statements between defining the savepoint + and rolling back to it will have no effect on the final transaction. +/para + +para + After rolling back to a savepoint, it continues to be defined, so you can + roll back to it several times. Conversely, if you are sure you won't need + to roll back to a particular savepoint again, it can be released, so the + system can free some resources. Keep in mind that releasing a savepoint + will automatically release all savepoints that were defined after it. +/para + +para + Remembering the bank database, suppose we debit $100.00 from Alice's + account, and credit Bob's account, only to find later that we wanted to + credit Wally's account. We could do it using savepoints like + + programlisting + BEGIN; + UPDATE accounts SET balance = balance - 100.00 + WHERE name = 'Alice'; + SAVEPOINT my_savepoint; + UPDATE accounts SET balance = balance + 100.00 + WHERE name = 'Bob'; + -- oops ... forget that and use Wally's account + ROLLBACK TO my_savepoint; + UPDATE accounts SET balance = balance + 100.00 + WHERE name = 'Wally'; + COMMIT; + /programlisting +/para + +para + This example is, of course, oversimplified, but there's a lot of control + to be had over a transaction block through the use of savepoints. + Moreover, commandROLLBACK TO/ is the only way to regain control of a + transaction block that was automatically put on aborted state by the + system for some reason, short of rolling it back completely and starting + again. +/para + /sect1 diff -Ncr --exclude-from=diff-ignore 00orig/doc/src/sgml/ref/allfiles.sgml 03pgproc/doc/src/sgml/ref/allfiles.sgml *** 00orig/doc/src/sgml/ref/allfiles.sgml 2004-06-26 00:28:45.0 -0400 --- 03pgproc/doc/src/sgml/ref/allfiles.sgml 2004-07-26 18:27:47.0 -0400 *** *** 88,96 --- 88,99 !entity notify system notify.sgml !entity preparesystem prepare.sgml !entity reindexsystem reindex.sgml + !entity releaseSavepoint system release.sgml !entity reset system reset.sgml !entity revoke system revoke.sgml !entity rollback system rollback.sgml + !entity rollbackTo system rollback_to.sgml + !entity savepoint system savepoint.sgml !entity select system select.sgml !entity selectInto system select_into.sgml !entity setsystem set.sgml diff -Ncr --exclude-from=diff-ignore 00orig/doc/src/sgml/ref/begin.sgml 03pgproc/doc/src/sgml/ref/begin.sgml *** 00orig/doc/src/sgml/ref/begin.sgml 2004-01-11 06:24:17.0 -0300 --- 03pgproc/doc/src/sgml/ref/begin.sgml2004-07-26 18:49:53.0 -0400 *** *** 145,150 --- 145,151 memberxref linkend=sql-commit endterm=sql-commit-title/member memberxref linkend=sql-rollback endterm=sql-rollback-title/member memberxref linkend=sql-start-transaction endterm=sql-start-transaction-title/member +memberxref linkend=sql-savepoint endterm=sql-savepoint-title/member /simplelist /refsect1 /refentry diff -Ncr --exclude-from=diff-ignore 00orig/doc/src/sgml/ref/release.sgml 03pgproc/doc/src/sgml/ref/release.sgml *** 00orig/doc/src/sgml/ref/release.sgml1969-12-31 21:00:00.0 -0300 --- 03pgproc/doc/src/sgml/ref/release.sgml 2004-07-26 19:07:17.0 -0400 *** *** 0 --- 1,138 + !-- + $PostgreSQL$ + PostgreSQL documentation + -- + + refentry id=SQL-RELEASE + refmeta + refentrytitle id=SQL-RELEASE-TITLERELEASE/refentrytitle + refmiscinfoSQL - Language Statements/refmiscinfo + /refmeta + + refnamediv +
[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 +1455,31 @@
[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 sys/file.h #include unistd.h #include dirent.h #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(DataDir); filename = palloc(len+1); memcpy(filename, VARDATA(arg), len); filename[len] = 0; if (strstr(filename, ..) != NULL) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errmsg(No .. allowed in filenames; if (is_absolute_path(filename)) { if (logAllowed !strncmp(filename,
Re: [PATCHES] win32 version info
Claudio Natoli wrote: Seems inconsistent to me. There is no inconsistency, as the two requirements are aimed at very different issues. It was just the case that one (win32 versioning) was inadvertently a potential (and rejected) solution to the other (auto version check). The question now is simply whether or not this versioning cruft justifies its existence, presumably for facilitating packaging and installation of binaries (particularly those that cannot report their version readily, such as DLLs). I personally certainly have no use for it, and I don't see us getting the Designed for Microsoft Windows tick any time soon, but I have no doubt that Magnus, in working on the win32 installer, is perhaps seeing the need in an entirely different light. Designed for Microsoft Windows :-) -- Bruce Momjian| http://candle.pha.pa.us [EMAIL PROTECTED] | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup.| Newtown Square, Pennsylvania 19073 ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]
Re: [PATCHES] [subxacts] Fixing TODO items
Alvaro Herrera [EMAIL PROTECTED] writes: Nesting level report via a ParameterStatus message sent just before ReadyForQuery (Z message). Hasn't this really been obsoleted by events? In the SAVEPOINT world I doubt that it's needed. regards, tom lane ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html
Re: [PATCHES] [subxacts] Fixing TODO items
Alvaro Herrera [EMAIL PROTECTED] writes: Here is a patch that fixes some of the TODO items in the nested xacts list: handle large objects On the large-objects stuff: it seems like a really bad idea to be fooling with CurrentResourceOwner like that. What that means is that if a subtransaction opens a LO and then fails, the associated low-level resources will remain allocated until the top transaction ends ... even though the LargeObjectDesc went away in subtransaction abort. In the worst case with repeated retries, it seems like this could run you out of free buffers, for example. It occurs to me that the only resource held for any long period in this code is the open relations (heap_r and index_r), and that it's pretty silly to have every open LO have its own reference to pg_largeobject. (I believe the code in inv_api.c is a holdover from a time when LOs could live in different tables; but that's been dead for a long time and seems quite unlikely to get resurrected.) Also, there's no urgent need to maintain a distinction between read and write access in terms of the kind of lock we take on pg_largeobject. There aren't any operations that anyone should be performing on pg_largeobject that would care about the difference between AccessShareLock and RowExclusiveLock. This means that upon first use of any LO within a main transaction, we can open pg_largeobject *once* and use it for all LOs for the rest of the transaction. This reference would be okay to assign to the top ResourceOwner. The resources acquired and released during inv_read, inv_write, etc, can be left with the normal CurrentResourceOwner so that they'll be dropped immediately in case of error. Any comments on this plan? regards, tom lane ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org
Re: [PATCHES] [subxacts] Fixing TODO items
Alvaro Herrera [EMAIL PROTECTED] writes: There are some likely controversial changes; the Xid caches, in the first place. No kidding ;-) Do you have any theoretical or practical evidence for the usefulness of the negxids cache? Seems to me the shared memory space would be better spent on allowing deeper nesting of the running-subxids list. Also, what happened to marking whether the running-subxids list has overflowed? If none of them have then there's no need to wonder whether we have a still-running subxact. The apparent lack of any locking on these data structures seems wrong too. regards, tom lane ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster
[PATCHES] USING INDEX TABLESPACE
The attached patch allows the specification of the tablespace the index is to be created in for unique and pk constraints. It also fixes the dumping of such constraints so that they are restored into the correct tablespace, after they have been moved with SET TABLESPACE. This is currently an outstanding pg_dump bug. The syntax is exactly what Oracle uses as far as i can tell, and I think that we need 'using index' in there, because it's the index that's in a tablespace, NOT the constraint itself. Includes docs. eg: create table test (a integer primary key index tablespace loc); create table test (a integer unique index tablespace loc); create table test (a integer); alter table test add primary key(a) index tablespace loc; create table test (a integer); alter table test add unique(a) index tablespace loc; Chris conspc.txt.gz Description: GNU Zip compressed data ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]