Thread: postmaster -d option (was Re: [GENERAL] Relation 0 does not exist)

postmaster -d option (was Re: [GENERAL] Relation 0 does not exist)

From
Tom Lane
Date:
Patrick Welche <prlw1@newn.cam.ac.uk> writes:
> ... I was running postmaster -d4, yet the only
> query I saw was the last LOG one. I pretty sure that I would see all queries
> with -d3 before..

It looked to me like you were just running with the recently-added
frill to log only queries that cause errors; which is on by default.

(Looks at code...)  Ah.  It looks like -d to the postmaster no longer
means anywhere near what it used to.  Bruce --- compare the handling
of -d in the backend (postgres.c lines 1251ff) with its handling in
the postmaster (postmaster.c lines 444ff).  Big difference.  Are we
going to make these more alike?  If so, which one do we like?
        regards, tom lane


Re: postmaster -d option (was Re: [GENERAL] Relation 0 does not exist)

From
Bruce Momjian
Date:
Tom Lane wrote:
> Patrick Welche <prlw1@newn.cam.ac.uk> writes:
> > ... I was running postmaster -d4, yet the only
> > query I saw was the last LOG one. I pretty sure that I would see all queries
> > with -d3 before..
>
> It looked to me like you were just running with the recently-added
> frill to log only queries that cause errors; which is on by default.
>
> (Looks at code...)  Ah.  It looks like -d to the postmaster no longer
> means anywhere near what it used to.  Bruce --- compare the handling
> of -d in the backend (postgres.c lines 1251ff) with its handling in
> the postmaster (postmaster.c lines 444ff).  Big difference.  Are we
> going to make these more alike?  If so, which one do we like?

I am sorry but I don't understand.  They look like they both set
server_min_messages.  There was a comment in one that said
client_min_messages but I just fixed that.

--
  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
Index: src/backend/tcop/postgres.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/tcop/postgres.c,v
retrieving revision 1.294
diff -c -c -r1.294 postgres.c
*** src/backend/tcop/postgres.c    25 Sep 2002 20:31:40 -0000    1.294
--- src/backend/tcop/postgres.c    26 Sep 2002 01:57:48 -0000
***************
*** 1258,1267 ****
                          sprintf(debugstr, "debug%s", optarg);
                          SetConfigOption("server_min_messages", debugstr, ctx, gucsource);
                          pfree(debugstr);
-
                          /*
                           * -d is not the same as setting
!                          * client_min_messages because it enables other
                           * output options.
                           */
                          if (atoi(optarg) >= 1)
--- 1258,1266 ----
                          sprintf(debugstr, "debug%s", optarg);
                          SetConfigOption("server_min_messages", debugstr, ctx, gucsource);
                          pfree(debugstr);
                          /*
                           * -d is not the same as setting
!                          * server_min_messages because it enables other
                           * output options.
                           */
                          if (atoi(optarg) >= 1)
***************
*** 1275,1288 ****
                          if (atoi(optarg) >= 5)
                              SetConfigOption("debug_print_rewritten", "true", ctx, gucsource);
                      }
-                     else
-
-                         /*
-                          * -d 0 allows user to prevent postmaster debug
-                          * from propagating to backend.
-                          */
-                         SetConfigOption("server_min_messages", "notice",
-                                         ctx, gucsource);
                  }
                  break;

--- 1274,1279 ----

Re: postmaster -d option (was Re: [GENERAL] Relation 0 does not exist)

From
Tom Lane
Date:
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> Tom Lane wrote:
>> (Looks at code...)  Ah.  It looks like -d to the postmaster no longer
>> means anywhere near what it used to.  Bruce --- compare the handling
>> of -d in the backend (postgres.c lines 1251ff) with its handling in
>> the postmaster (postmaster.c lines 444ff).  Big difference.  Are we
>> going to make these more alike?  If so, which one do we like?

> I am sorry but I don't understand.  They look like they both set
> server_min_messages.

Yeah, but postgres.c *also* sets log_connections, log_statement,
debug_print_parse, debug_print_plan, debug_print_rewritten depending
on the -d level.  This behavior is not random; it's an attempt to
reproduce the effects of the historical -d switch.  The postmaster.c
code is blowing off all those considerations.

> *** 1275,1288 ****
>                           if (atoi(optarg) >= 5)
>                               SetConfigOption("debug_print_rewritten", "true", ctx, gucsource);
>                       }
> -                     else
> - 
> -                         /*
> -                          * -d 0 allows user to prevent postmaster debug
> -                          * from propagating to backend.
> -                          */
> -                         SetConfigOption("server_min_messages", "notice",
> -                                         ctx, gucsource);
>                   }
>                   break;

I think you are deleting your own code there ... why?
        regards, tom lane


Re: postmaster -d option (was Re: [GENERAL] Relation 0 does not exist)

From
Bruce Momjian
Date:
Uh, yes, it is a little confusing and I am not sure that patch is right
anymore. I haven't applied it.

Another issue is that we used to have a global debug_level variable that was
propogated to the client.  Now, we just have the GUC value which does
propogate like the global one did.  Does the postmaster still pass -dX
down to the child like it used to?  I don't see why you say, "The
postmaster.c code is blowing off all those considerations."

I -d0 think functions properly except that it sets the value to 'notice'
rather than resetting it to the postgresql.conf value.  Is there a way
to do that?

---------------------------------------------------------------------------

Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > Tom Lane wrote:
> >> (Looks at code...)  Ah.  It looks like -d to the postmaster no longer
> >> means anywhere near what it used to.  Bruce --- compare the handling
> >> of -d in the backend (postgres.c lines 1251ff) with its handling in
> >> the postmaster (postmaster.c lines 444ff).  Big difference.  Are we
> >> going to make these more alike?  If so, which one do we like?
> 
> > I am sorry but I don't understand.  They look like they both set
> > server_min_messages.
> 
> Yeah, but postgres.c *also* sets log_connections, log_statement,
> debug_print_parse, debug_print_plan, debug_print_rewritten depending
> on the -d level.  This behavior is not random; it's an attempt to
> reproduce the effects of the historical -d switch.  The postmaster.c
> code is blowing off all those considerations.
> 
> > *** 1275,1288 ****
> >                           if (atoi(optarg) >= 5)
> >                               SetConfigOption("debug_print_rewritten", "true", ctx, gucsource);
> >                       }
> > -                     else
> > - 
> > -                         /*
> > -                          * -d 0 allows user to prevent postmaster debug
> > -                          * from propagating to backend.
> > -                          */
> > -                         SetConfigOption("server_min_messages", "notice",
> > -                                         ctx, gucsource);
> >                   }
> >                   break;
> 
> I think you are deleting your own code there ... why?
> 
>             regards, tom lane
> 

--  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,
Pennsylvania19073
 


Re: postmaster -d option (was Re: [GENERAL] Relation 0 does not exist)

From
Tom Lane
Date:
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> ... Now, we just have the GUC value which does
> propogate like the global one did.  Does the postmaster still pass -dX
> down to the child like it used to?

Evidently not; else Patrick wouldn't be complaining that it doesn't
work like it used to.
        regards, tom lane


Re: postmaster -d option (was Re: [GENERAL] Relation 0 does not exist)

From
Bruce Momjian
Date:
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > ... Now, we just have the GUC value which does
> > propogate like the global one did.  Does the postmaster still pass -dX
> > down to the child like it used to?
>
> Evidently not; else Patrick wouldn't be complaining that it doesn't
> work like it used to.

OK, got it.  I knew server_min_messages would propogate to the client,
but that doesn't trigger the -d special cases in postgres.c.  I re-added
the -d flag propogation to the postmaster.  I also changed the postgres
-d0 behavior to just reset server_min_messages rather than setting it to
'notice.

--
  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
Index: src/backend/postmaster/postmaster.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/postmaster/postmaster.c,v
retrieving revision 1.288
diff -c -c -r1.288 postmaster.c
*** src/backend/postmaster/postmaster.c    4 Sep 2002 20:31:24 -0000    1.288
--- src/backend/postmaster/postmaster.c    26 Sep 2002 05:15:33 -0000
***************
*** 230,235 ****
--- 230,237 ----

  static unsigned int random_seed = 0;

+ static int    debug_flag = 0;
+
  extern char *optarg;
  extern int    optind,
              opterr;
***************
*** 452,457 ****
--- 454,460 ----
                      SetConfigOption("server_min_messages", debugstr,
                                      PGC_POSTMASTER, PGC_S_ARGV);
                      pfree(debugstr);
+                     debug_flag = atoi(optarg);
                      break;
                  }
              case 'F':
***************
*** 2028,2033 ****
--- 2031,2037 ----
      char       *remote_host;
      char       *av[ARGV_SIZE * 2];
      int            ac = 0;
+     char        debugbuf[ARGV_SIZE];
      char        protobuf[ARGV_SIZE];
      char        dbbuf[ARGV_SIZE];
      char        optbuf[ARGV_SIZE];
***************
*** 2207,2212 ****
--- 2211,2225 ----
       */

      av[ac++] = "postgres";
+
+     /*
+      * Pass the requested debugging level along to the backend.
+      */
+     if (debug_flag > 0)
+     {
+         sprintf(debugbuf, "-d%d", debug_flag);
+         av[ac++] = debugbuf;
+     }

      /*
       * Pass any backend switches specified with -o in the postmaster's own
Index: src/backend/tcop/postgres.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/tcop/postgres.c,v
retrieving revision 1.294
diff -c -c -r1.294 postgres.c
*** src/backend/tcop/postgres.c    25 Sep 2002 20:31:40 -0000    1.294
--- src/backend/tcop/postgres.c    26 Sep 2002 05:15:41 -0000
***************
*** 1281,1288 ****
                           * -d 0 allows user to prevent postmaster debug
                           * from propagating to backend.
                           */
!                         SetConfigOption("server_min_messages", "notice",
!                                         ctx, gucsource);
                  }
                  break;

--- 1281,1287 ----
                           * -d 0 allows user to prevent postmaster debug
                           * from propagating to backend.
                           */
!                         ResetPGVariable("server_min_messages");
                  }
                  break;


Re: postmaster -d option (was Re: [GENERAL] Relation 0 does not exist)

From
Tom Lane
Date:
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> diff -c -c -r1.294 postgres.c
> *** src/backend/tcop/postgres.c    25 Sep 2002 20:31:40 -0000    1.294
> --- src/backend/tcop/postgres.c    26 Sep 2002 05:15:41 -0000
> ***************
> *** 1281,1288 ****
>                            * -d 0 allows user to prevent postmaster debug
>                            * from propagating to backend.
>                            */
> !                         SetConfigOption("server_min_messages", "notice",
> !                                         ctx, gucsource);
>                   }
>                   break; 
> --- 1281,1287 ----
>                            * -d 0 allows user to prevent postmaster debug
>                            * from propagating to backend.
>                            */
> !                         ResetPGVariable("server_min_messages");
>                   }
>                   break; 

If you want "export PGOPTIONS=-d0" to do what the comment says, you'd
also need to Reset all of the other GUC variables that -dN might have
set.  However, I'm not sure that I agree with the goal in the first
place.  If the admin has set debugging on the postmaster command line,
should it really be possible for users to turn it off so easily?
        regards, tom lane


Re: postmaster -d option (was Re: [GENERAL] Relation 0 does

From
Bruce Momjian
Date:
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > diff -c -c -r1.294 postgres.c
> > *** src/backend/tcop/postgres.c    25 Sep 2002 20:31:40 -0000    1.294
> > --- src/backend/tcop/postgres.c    26 Sep 2002 05:15:41 -0000
> > ***************
> > *** 1281,1288 ****
> >                            * -d 0 allows user to prevent postmaster debug
> >                            * from propagating to backend.
> >                            */
> > !                         SetConfigOption("server_min_messages", "notice",
> > !                                         ctx, gucsource);
> >                   }
> >                   break;
>
> > --- 1281,1287 ----
> >                            * -d 0 allows user to prevent postmaster debug
> >                            * from propagating to backend.
> >                            */
> > !                         ResetPGVariable("server_min_messages");
> >                   }
> >                   break;
>

Turns out I had to revert this change.  There isn't a username at this
point in the code so the ResetPGVariable username test fails, and even
then, I don't think there is any way to set a variable to the value
before -d5 set it.

> If you want "export PGOPTIONS=-d0" to do what the comment says, you'd
> also need to Reset all of the other GUC variables that -dN might have
> set.  However, I'm not sure that I agree with the goal in the first
> place.  If the admin has set debugging on the postmaster command line,
> should it really be possible for users to turn it off so easily?

I see what you are saying, that you can pass -d0 from the client and
undo the -d5.  Yes, I was wondering about that because even on the
command line, if you do -d5 -d0, you still get those extra options.

OK, attached patch applied.  The restriction that you can't lower the
debug level with PGOPTIONS is a separate issue.  What I clearly didn't
want to do was to reset those other options for -d0, and I didn't have
to do that for -d0 to work as advertised.

--
  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
Index: src/backend/tcop/postgres.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/tcop/postgres.c,v
retrieving revision 1.296
diff -c -c -r1.296 postgres.c
*** src/backend/tcop/postgres.c    27 Sep 2002 03:34:15 -0000    1.296
--- src/backend/tcop/postgres.c    27 Sep 2002 03:49:34 -0000
***************
*** 1136,1141 ****
--- 1136,1142 ----
      const char *DBName = NULL;
      bool        secure;
      int            errs = 0;
+     int            debug_flag = 0;
      GucContext    ctx;
      GucSource    gucsource;
      char       *tmp;
***************
*** 1250,1255 ****
--- 1251,1257 ----

              case 'd':            /* debug level */
                  {
+                     debug_flag = atoi(optarg);
                      /* Set server debugging level. */
                      if (atoi(optarg) != 0)
                      {
***************
*** 1259,1283 ****
                          SetConfigOption("server_min_messages", debugstr, ctx, gucsource);
                          pfree(debugstr);

-                         /*
-                          * -d is not the same as setting
-                          * client_min_messages because it enables other
-                          * output options.
-                          */
-                         if (atoi(optarg) >= 1)
-                             SetConfigOption("log_connections", "true", ctx, gucsource);
-                         if (atoi(optarg) >= 2)
-                             SetConfigOption("log_statement", "true", ctx, gucsource);
-                         if (atoi(optarg) >= 3)
-                             SetConfigOption("debug_print_parse", "true", ctx, gucsource);
-                         if (atoi(optarg) >= 4)
-                             SetConfigOption("debug_print_plan", "true", ctx, gucsource);
-                         if (atoi(optarg) >= 5)
-                             SetConfigOption("debug_print_rewritten", "true", ctx, gucsource);
                      }
                      else
                          /*
!                          * -d 0 allows user to prevent postmaster debug
                           * from propagating to backend.  It would be nice
                           * to set it to the postgresql.conf value here.
                           */
--- 1261,1270 ----
                          SetConfigOption("server_min_messages", debugstr, ctx, gucsource);
                          pfree(debugstr);

                      }
                      else
                          /*
!                          * -d0 allows user to prevent postmaster debug
                           * from propagating to backend.  It would be nice
                           * to set it to the postgresql.conf value here.
                           */
***************
*** 1519,1524 ****
--- 1506,1527 ----
                  errs++;
                  break;
          }
+
+     /*
+      * -d is not the same as setting
+      * server_min_messages because it enables other
+      * output options.
+      */
+     if (debug_flag >= 1)
+         SetConfigOption("log_connections", "true", ctx, gucsource);
+     if (debug_flag >= 2)
+         SetConfigOption("log_statement", "true", ctx, gucsource);
+     if (debug_flag >= 3)
+         SetConfigOption("debug_print_parse", "true", ctx, gucsource);
+     if (debug_flag >= 4)
+         SetConfigOption("debug_print_plan", "true", ctx, gucsource);
+     if (debug_flag >= 5)
+         SetConfigOption("debug_print_rewritten", "true", ctx, gucsource);

      /*
       * Post-processing for command line options.