Re: Allow psql to work against non-tablespace servers (e.g. - Mailing list pgsql-patches

From Christopher Kings-Lynne
Subject Re: Allow psql to work against non-tablespace servers (e.g.
Date
Msg-id 4122B0D7.2000606@familyhealth.com.au
Whole thread Raw
In response to Re: Allow psql to work against non-tablespace servers (e.g.  (Bruce Momjian <pgman@candle.pha.pa.us>)
List 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@postgresql.org
>>
>
>

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Allow psql to work against non-tablespace servers (e.g.
Next
From: Christopher Kings-Lynne
Date:
Subject: Re: Allow psql to work against non-tablespace servers (e.g.