Hi all, Sorry for my late reply. There is no other update for this patch since the 13th of August, at least until today. The new patch is attached By the way I worked on the comments that Dan and Gabriel pointed out. I added a check on system such as to prevent an error from this side. By the way, I noticed that the way return values are managed in doCustom and in process_commands is different. Such as to make an homogeneous code, return values are managed the same way in both functions in the patch, explaining why I did not return a specific value when file commands are treated in doCustom.
Here is also as wanted a simple transaction that permits to use this function: \set nbranches :scale \set naccounts 100000 * :scale \setrandom aid 1 :naccounts \setrandom bid 1 :nbranches \setrandom delta -5000 5000 \setrandom txidrand 0 10000 START TRANSACTION; UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid; SELECT abalance FROM pgbench_accounts WHERE aid = :aid; UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid; PREPARE TRANSACTION ':txidrand'; \shell ls -ll $PGDATA/pg_twophase COMMIT PREPARED ':txidrand'; The shell command I use here permits to scan the 2PC state files written in pg_twophase. You will notice that in this case files have a size of 540B. Also please do not forget to set PGDATA. The new functionnality proposed here is just for analysis purposes. Even if it decreased the performance of pgbench, it is interesting to have a simple benchmark that permits to analyse precisely the system while transaction are being run. Regards,
--- postgresql-8.4.0.orig/contrib/pgbench/pgbench.c 2009-09-17 09:07:24.000000000 +0900 +++ postgresql-8.4.0/contrib/pgbench/pgbench.c 2009-09-17 09:03:35.000000000 +0900 @@ -120,6 +120,7 @@ typedef struct } Variable; #define MAX_FILES 128 /* max number of SQL script files allowed */ +#define SHELL_COMMAND_SIZE 256 /* maximum size allowed for shell command */ /* * structures used in custom query mode @@ -984,7 +985,44 @@ top: st->listen = 1; } + else if (pg_strcasecmp(argv[0], "shell") == 0) + { + int j, + retval, + retvalglob; + char commandLoc[SHELL_COMMAND_SIZE]; + + retval = snprintf(commandLoc,SHELL_COMMAND_SIZE-1,"%s",argv[1]); + if (retval < 0 + || retval > SHELL_COMMAND_SIZE-1) + { + fprintf(stderr, "Error launching shell command: too many characters\n"); + return; + } + retvalglob = retval; + for (j = 2; j < argc; j++) + { + char *commandLoc2 = strdup(commandLoc); + retval = snprintf(commandLoc,SHELL_COMMAND_SIZE-1,"%s %s", commandLoc2, argv[j]); + retvalglob += retval; + if (retval < 0 + || retvalglob > SHELL_COMMAND_SIZE-1) + { + fprintf(stderr, "Error launching shell command: too many characters\n"); + free(commandLoc2); + return; + } + free(commandLoc2); + } + retval = system(commandLoc); + if (retval < 0) + { + fprintf(stderr, "Error launching shell command: command not launched"); + return; + } + st->listen = 1; + } goto top; } } @@ -1280,6 +1318,14 @@ process_commands(char *buf) fprintf(stderr, "%s: extra argument \"%s\" ignored\n", my_commands->argv[0], my_commands->argv[j]); } + else if (pg_strcasecmp(my_commands->argv[0], "shell") == 0) + { + if (my_commands->argc < 1) + { + fprintf(stderr, "%s: missing command\n", my_commands->argv[0]); + return NULL; + } + } else { fprintf(stderr, "Invalid command %s\n", my_commands->argv[0]);
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers