debug_print_plan

A GUC controlling whether the plan of a query is logged

debug_print_plan is a GUC controlling whether the plan of a query is logged.

debug_print_plan was added in PostgreSQL 7.1 (commit 6a68f426).

Default

Default value for debug_print_plan is: off

Notes

As far as it's possible to ascertain, debug_print_plan was added in feature commit (commit 6a68f426), in which PostgreSQL's Grand Unified Configuration system was introduced.

Examples

Sample output with an arbitrary query (here an INSERT into a partitioned table):

[2020-08-16 15:10:11 UTC] psql postgres postgres LOG:  00000: statement: INSERT INTO part_parent values(1,'foo')  returning *;
[2020-08-16 15:10:11 UTC] psql postgres postgres LOCATION:  exec_simple_query, postgres.c:1044
[2020-08-16 15:10:11 UTC] psql postgres postgres LOG:  00000: plan:
[2020-08-16 15:10:11 UTC] psql postgres postgres DETAIL:     {PLANNEDSTMT 
	   :commandType 3 
	   :queryId 0 
	   :hasReturning true 
	   :hasModifyingCTE false 
	   :canSetTag true 
	   :transientPlan false 
	   :dependsOnRole false 
	   :parallelModeNeeded false 
	   :jitFlags 0 
	   :planTree 
	      {MODIFYTABLE 
	      :startup_cost 0.00 
	      :total_cost 0.01 
	      :plan_rows 1 
	      :plan_width 86 
	      :parallel_aware false 
	      :parallel_safe false 
	      :plan_node_id 0 
	      :targetlist (
	         {TARGETENTRY 
	         :expr 
	            {VAR 
	            :varno 1 
	            :varattno 1 
	            :vartype 23 
	            :vartypmod -1 
	            :varcollid 0 
	            :varlevelsup 0 
	            :varnosyn 1 
	            :varattnosyn 1 
	            :location 51
	            }
	         :resno 1 
	         :resname id 
	         :ressortgroupref 0 
	         :resorigtbl 16490 
	         :resorigcol 1 
	         :resjunk false
	         }
	         {TARGETENTRY 
	         :expr 
	            {VAR 
	            :varno 1 
	            :varattno 2 
	            :vartype 1043 
	            :vartypmod 36 
	            :varcollid 100 
	            :varlevelsup 0 
	            :varnosyn 1 
	            :varattnosyn 2 
	            :location 51
	            }
	         :resno 2 
	         :resname val 
	         :ressortgroupref 0 
	         :resorigtbl 16490 
	         :resorigcol 2 
	         :resjunk false
	         }
	      )
	      :qual <> 
	      :lefttree <> 
	      :righttree <> 
	      :initPlan <> 
	      :extParam (b)
	      :allParam (b)
	      :operation 3 
	      :canSetTag true 
	      :nominalRelation 1 
	      :rootRelation 1 
	      :partColsUpdated false 
	      :resultRelations (i 1)
	      :resultRelIndex 0 
	      :rootResultRelIndex 0 
	      :plans (
	         {RESULT 
	         :startup_cost 0.00 
	         :total_cost 0.01 
	         :plan_rows 1 
	         :plan_width 86 
	         :parallel_aware false 
	         :parallel_safe false 
	         :plan_node_id 1 
	         :targetlist (
	            {TARGETENTRY 
	            :expr 
	               {CONST 
	               :consttype 23 
	               :consttypmod -1 
	               :constcollid 0 
	               :constlen 4 
	               :constbyval true 
	               :constisnull false 
	               :location 31 
	               :constvalue 4 [ 1 0 0 0 0 0 0 0 ]
	               }
	            :resno 1 
	            :resname id 
	            :ressortgroupref 0 
	            :resorigtbl 0 
	            :resorigcol 0 
	            :resjunk false
	            }
	            {TARGETENTRY 
	            :expr 
	               {CONST 
	               :consttype 1043 
	               :consttypmod 36 
	               :constcollid 100 
	               :constlen -1 
	               :constbyval false 
	               :constisnull false 
	               :location -1 
	               :constvalue 7 [ 28 0 0 0 102 111 111 ]
	               }
	            :resno 2 
	            :resname val 
	            :ressortgroupref 0 
	            :resorigtbl 0 
	            :resorigcol 0 
	            :resjunk false
	            }
	         )
	         :qual <> 
	         :lefttree <> 
	         :righttree <> 
	         :initPlan <> 
	         :extParam (b)
	         :allParam (b)
	         :resconstantqual <>
	         }
	      )
	      :withCheckOptionLists <> 
	      :returningLists ((
	         {TARGETENTRY 
	         :expr 
	            {VAR 
	            :varno 1 
	            :varattno 1 
	            :vartype 23 
	            :vartypmod -1 
	            :varcollid 0 
	            :varlevelsup 0 
	            :varnosyn 1 
	            :varattnosyn 1 
	            :location 51
	            }
	         :resno 1 
	         :resname id 
	         :ressortgroupref 0 
	         :resorigtbl 16490 
	         :resorigcol 1 
	         :resjunk false
	         }
	         {TARGETENTRY 
	         :expr 
	            {VAR 
	            :varno 1 
	            :varattno 2 
	            :vartype 1043 
	            :vartypmod 36 
	            :varcollid 100 
	            :varlevelsup 0 
	            :varnosyn 1 
	            :varattnosyn 2 
	            :location 51
	            }
	         :resno 2 
	         :resname val 
	         :ressortgroupref 0 
	         :resorigtbl 16490 
	         :resorigcol 2 
	         :resjunk false
	         }
	      ))
	      :fdwPrivLists (<>)
	      :fdwDirectModifyPlans (b)
	      :rowMarks <> 
	      :epqParam 0 
	      :onConflictAction 0 
	      :arbiterIndexes <> 
	      :onConflictSet <> 
	      :onConflictWhere <> 
	      :exclRelRTI 0 
	      :exclRelTlist <>
	      }
	   :rtable (
	      {RTE 
	      :alias <> 
	      :eref 
	         {ALIAS 
	         :aliasname part_parent 
	         :colnames ("id" "val")
	         }
	      :rtekind 0 
	      :relid 16490 
	      :relkind p 
	      :rellockmode 3 
	      :tablesample <> 
	      :lateral false 
	      :inh false 
	      :inFromCl false 
	      :requiredPerms 3 
	      :checkAsUser 0 
	      :selectedCols (b 8 9)
	      :insertedCols (b 8 9)
	      :updatedCols (b)
	      :extraUpdatedCols (b)
	      :securityQuals <>
	      }
	      {RTE 
	      :alias <> 
	      :eref 
	         {ALIAS 
	         :aliasname *RESULT* 
	         :colnames <>
	         }
	      :rtekind 8 
	      :lateral false 
	      :inh false 
	      :inFromCl false 
	      :requiredPerms 0 
	      :checkAsUser 0 
	      :selectedCols (b)
	      :insertedCols (b)
	      :updatedCols (b)
	      :extraUpdatedCols (b)
	      :securityQuals <>
	      }
	   )
	   :resultRelations (i 1)
	   :rootResultRelations (i 1)
	   :appendRelations <> 
	   :subplans <> 
	   :rewindPlanIDs (b)
	   :rowMarks <> 
	   :relationOids (o 16490)
	   :invalItems <> 
	   :paramExecTypes (o 0)
	   :utilityStmt <> 
	   :stmt_location 0 
	   :stmt_len 52
	   }
	
[2020-08-16 15:10:11 UTC] psql postgres postgres LOCATION:  elog_node_display, print.c:85

Categories

GUC configuration item, Logging, Planner