Re: Allow psql to work against non-tablespace servers (e.g.

From: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Greg Sabino Mullane <greg(at)turnstep(dot)com>, pgsql-patches(at)postgresql(dot)org
Subject: Re: Allow psql to work against non-tablespace servers (e.g.
Date: 2004-08-18 01:28:55
Message-ID: 4122B0D7.2000606@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

One of the things I still intend to do is make psql work against all
previous backends, so this patch is a good first step :)

For example, we have web servers on database servers on different
machines. Recompiling psql on the web servers is a PITA since it means
recompiling PHP then recompiling all the updated stuff that PHP depends
on - it's a nightmare.

Ideally we could just update the server and then update web servers much
later or never... If I can't use \db to see tablespaces, then I'll live :)

Chris

Bruce Momjian wrote:
> I don't see any other code in psql that allows it to run with older
> server versions so it doesn't make sense to me to fix things just for
> tablespaces, and doing it for everything seems like it would uglify the
> code too much.
>
> ---------------------------------------------------------------------------
>
> Greg Sabino Mullane wrote:
>
>>Index: describe.c
>>===================================================================
>>RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/describe.c,v
>>retrieving revision 1.103
>>diff -c -r1.103 describe.c
>>*** describe.c 15 Jul 2004 03:56:06 -0000 1.103
>>--- describe.c 11 Aug 2004 21:15:34 -0000
>>***************
>>*** 112,117 ****
>>--- 112,123 ----
>> PGresult *res;
>> printQueryOpt myopt = pset.popt;
>>
>>+ if (pset.sversion < 70500) {
>>+ fprintf(stderr, _("This server version (%d) does not support tablespaces.\n"),
>>+ pset.sversion);
>>+ return true;
>>+ }
>>+
>> initPQExpBuffer(&buf);
>>
>> printfPQExpBuffer(&buf,
>>***************
>>*** 706,713 ****
>> /* Get general table info */
>> printfPQExpBuffer(&buf,
>> "SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules, \n"
>>! "relhasoids, reltablespace \n"
>> "FROM pg_catalog.pg_class WHERE oid = `%s`",
>> oid);
>> res = PSQLexec(buf.data, false);
>> if (!res)
>>--- 712,720 ----
>> /* Get general table info */
>> printfPQExpBuffer(&buf,
>> "SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules, \n"
>>! "relhasoids %s \n"
>> "FROM pg_catalog.pg_class WHERE oid = `%s`",
>>+ pset.sversion >= 70500 ? ", reltablespace" : "",
>> oid);
>> res = PSQLexec(buf.data, false);
>> if (!res)
>>***************
>>*** 729,735 ****
>> tableinfo.hasindex = strcmp(PQgetvalue(res, 0, 0), "t") == 0;
>> tableinfo.hasrules = strcmp(PQgetvalue(res, 0, 4), "t") == 0;
>> tableinfo.hasoids = strcmp(PQgetvalue(res, 0, 5), "t") == 0;
>>! tableinfo.tablespace = atooid(PQgetvalue(res, 0, 6));
>> PQclear(res);
>>
>> headers[0] = _("Column");
>>--- 736,743 ----
>> tableinfo.hasindex = strcmp(PQgetvalue(res, 0, 0), "t") == 0;
>> tableinfo.hasrules = strcmp(PQgetvalue(res, 0, 4), "t") == 0;
>> tableinfo.hasoids = strcmp(PQgetvalue(res, 0, 5), "t") == 0;
>>! tableinfo.tablespace = (pset.sversion >= 70500) ?
>>! atooid(PQgetvalue(res, 0, 6)) : 0;
>> PQclear(res);
>>
>> headers[0] = _("Column");
>>***************
>>*** 932,939 ****
>>
>> footers = pg_malloc_zero(4 * sizeof(*footers));
>> footers[count_footers++] = pg_strdup(tmpbuf.data);
>>! add_tablespace_footer(tableinfo.relkind, tableinfo.tablespace,
>>! footers, &count_footers, tmpbuf);
>> footers[count_footers] = NULL;
>>
>> }
>>--- 940,947 ----
>>
>> footers = pg_malloc_zero(4 * sizeof(*footers));
>> footers[count_footers++] = pg_strdup(tmpbuf.data);
>>! add_tablespace_footer(tableinfo.relkind, tableinfo.tablespace,
>>! footers, &count_footers, tmpbuf);
>> footers[count_footers] = NULL;
>>
>> }
>>Index: settings.h
>>===================================================================
>>RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/settings.h,v
>>retrieving revision 1.18
>>diff -c -r1.18 settings.h
>>*** settings.h 12 May 2004 13:38:45 -0000 1.18
>>--- settings.h 11 Aug 2004 21:15:34 -0000
>>***************
>>*** 41,47 ****
>> FILE *cur_cmd_source; /* describe the status of the current main
>> * loop */
>> bool cur_cmd_interactive;
>>!
>> const char *progname; /* in case you renamed psql */
>> char *inputfile; /* for error reporting */
>> unsigned lineno; /* also for error reporting */
>>--- 41,47 ----
>> FILE *cur_cmd_source; /* describe the status of the current main
>> * loop */
>> bool cur_cmd_interactive;
>>! int sversion; /* backend server version */
>> const char *progname; /* in case you renamed psql */
>> char *inputfile; /* for error reporting */
>> unsigned lineno; /* also for error reporting */
>>Index: startup.c
>>===================================================================
>>RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/startup.c,v
>>retrieving revision 1.95
>>diff -c -r1.95 startup.c
>>*** startup.c 3 Jun 2004 00:07:37 -0000 1.95
>>--- startup.c 11 Aug 2004 21:15:34 -0000
>>***************
>>*** 217,222 ****
>>--- 217,225 ----
>>
>> SyncVariables();
>>
>>+ /* Grab the backend server version */
>>+ pset.sversion = PQserverVersion(pset.db);
>>+
>> if (options.action == ACT_LIST_DB)
>> {
>> int success = listAllDbs(false);
>>
>>
>>
>>---------------------------(end of broadcast)---------------------------
>>TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>>
>
>

In response to

Browse pgsql-patches by date

  From Date Subject
Next Message Christopher Kings-Lynne 2004-08-18 01:31:33 Re: Allow psql to work against non-tablespace servers (e.g.
Previous Message Bruce Momjian 2004-08-18 00:36:28 Re: Allow psql to work against non-tablespace servers (e.g.