Thread: Allow psql to work against non-tablespace servers (e.g. 7.4)

Allow psql to work against non-tablespace servers (e.g. 7.4)

From
"Greg Sabino Mullane"
Date:
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);



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

From
Bruce Momjian
Date:
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
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

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

From
"Greg Sabino Mullane"
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


> 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.

Tablespace are the only main difference between 8.0 and 7.4 as far as
psql is concerned, so the patch will allow psql to work against 7.4
servers seamlessly.

If I get time, I will begin making psql backward-compatible to 7.3 and
further, but the changes to do so will not be as small as this patch
and I would rather they get evaluated separately.

- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200408172006

-----BEGIN PGP SIGNATURE-----

iD8DBQFBIp3IvJuQZxSWSsgRAuABAJ0Yzhl7neFUsufTSBRPCw4FtgFHmwCfRF7C
3y+2SRPeIbt5ZAhmSQgHogc=
=t52z
-----END PGP SIGNATURE-----



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

From
Bruce Momjian
Date:
Greg Sabino Mullane wrote:
[ There is text before PGP section. ]
>
[ PGP not available, raw data follows ]
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
> > 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.
>
> Tablespace are the only main difference between 8.0 and 7.4 as far as
> psql is concerned, so the patch will allow psql to work against 7.4
> servers seamlessly.
>
> If I get time, I will begin making psql backward-compatible to 7.3 and
> further, but the changes to do so will not be as small as this patch
> and I would rather they get evaluated separately.

But do we want to do this?  Is it worth doing, and maintaining?

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

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

From
"Greg Sabino Mullane"
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


>> If I get time, I will begin making psql backward-compatible to 7.3 and
>> further, but the changes to do so will not be as small as this patch
>> and I would rather they get evaluated separately.
>
> But do we want to do this?  Is it worth doing, and maintaining?

I think so, within reason. Certainly going back to 7.4 is worthy, and
probably 7.3 as well. Going back to 7.2 is probably not: in addition
to major changes due to schemas appearing, it is a pretty old version
at this point. People have certainly expressed interest in the past
as far making psql backwards-compatible, and I think the code can be
kept fairly clean.

At least we are guaranteed to compile against current libraries - apps
outside the source tree never get that luxury and have worse
compatibility problems. :)

- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200408172031
-----BEGIN PGP SIGNATURE-----

iD8DBQFBIqOnvJuQZxSWSsgRAvdSAJwP1OHX/OAUycm3wqQNApgY06MmXACfbFBH
DxSB1/r6ucXtJgV1GBad+T0=
=QpD8
-----END PGP SIGNATURE-----



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

From
Bruce Momjian
Date:
Greg Sabino Mullane wrote:
[ There is text before PGP section. ]
>
[ PGP not available, raw data follows ]
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
> >> If I get time, I will begin making psql backward-compatible to 7.3 and
> >> further, but the changes to do so will not be as small as this patch
> >> and I would rather they get evaluated separately.
> >
> > But do we want to do this?  Is it worth doing, and maintaining?
>
> I think so, within reason. Certainly going back to 7.4 is worthy, and
> probably 7.3 as well. Going back to 7.2 is probably not: in addition
> to major changes due to schemas appearing, it is a pretty old version
> at this point. People have certainly expressed interest in the past
> as far making psql backwards-compatible, and I think the code can be
> kept fairly clean.
>
> At least we are guaranteed to compile against current libraries - apps
> outside the source tree never get that luxury and have worse
> compatibility problems. :)

The issue is that no one has been asking for this functionality, and I
can imagine it becoming quite a mess after a few releases.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

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

From
Christopher Kings-Lynne
Date:
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
>>
>
>

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

From
Christopher Kings-Lynne
Date:
>>If I get time, I will begin making psql backward-compatible to 7.3 and
>>further, but the changes to do so will not be as small as this patch
>>and I would rather they get evaluated separately.
>
> But do we want to do this?  Is it worth doing, and maintaining?

Yes please, I'll maintain it as well :)

Chris


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

From
Christopher Kings-Lynne
Date:
>>At least we are guaranteed to compile against current libraries - apps
>>outside the source tree never get that luxury and have worse
>>compatibility problems. :)
>
> The issue is that no one has been asking for this functionality, and I
> can imagine it becoming quite a mess after a few releases.

No messier than pg_dump (which yes, is quite messy :) )

Chris


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

From
Bruce Momjian
Date:
Christopher Kings-Lynne wrote:
> >>If I get time, I will begin making psql backward-compatible to 7.3 and
> >>further, but the changes to do so will not be as small as this patch
> >>and I would rather they get evaluated separately.
> >
> > But do we want to do this?  Is it worth doing, and maintaining?
>
> Yes please, I'll maintain it as well :)

OK, I just needed to see it was something that we were going to go into
with a full effort.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

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

From
Andrew Dunstan
Date:

Christopher Kings-Lynne wrote:

>>> At least we are guaranteed to compile against current libraries - apps
>>> outside the source tree never get that luxury and have worse
>>> compatibility problems. :)
>>
>>
>> The issue is that no one has been asking for this functionality, and I
>> can imagine it becoming quite a mess after a few releases.
>
>
> No messier than pg_dump (which yes, is quite messy :) )
>
>

It seems to me it will be a lot messier - pg_dump's functionality is
quite limited.

e.g. what will you do with dollar quoting or \copy's csv mode for
pre-8.0 backends?

cheers

andrew