How to Use the New debug_print_raw_parse Parameter in PostgreSQL 19

PostgreSQL 19 introduces a new debugging parameter named debug_print_raw_parse, expanding the existing set of debug print parameters from three to four compared with PostgreSQL version 18. This parameter allows you to log the raw parse tree that PostgreSQL generates immediately after parsing an SQL statement to the postgres log file.

In this blog, we will compare the available debug print parameters in PostgreSQL 18 and PostgreSQL 19, enable debug_print_raw_parse, and check the log output to understand what information it provides when we execute a query in the psql terminal.

Before that, check the current postgres clusters in your system by using the pg_lsclusters command like this.

cybrosys@cybrosys:~$ pg_lscluster

Result:

Ver Cluster Port Status Owner    Data directory               Log file
18  main    5432 online postgres /var/lib/postgresql/18/main  /var/log/postgresql/postgresql-18-main.log
19  main    5433 online postgres /var/lib/postgresql/19/main  /var/log/postgresql/postgresql-19-main.log

Here, postgres version 18 is running on port 5432, and postgresql 19 is running on port 5433.

In PostgreSQL 18, execute the following query to check the parameters related to debug_print like this.

postgres=# select name, setting from pg_settings where name ilike '%debug_print%';

Result:

         name          | setting 
-----------------------+---------
 debug_print_parse     | off
 debug_print_plan      | off
 debug_print_rewritten | off
(3 rows)

In postgres version 18, you can only see 3 parameters. Execute the same query in postgresql 18 and check the result.

postgres=# select name, setting from pg_settings where name ilike '%debug_print%';

Result:

         name          | setting 
-----------------------+---------
 debug_print_parse     | off
 debug_print_plan      | off
 debug_print_raw_parse | off
 debug_print_rewritten | off
(4 rows)

Here, we can see that a new parameter is added named debug_print_raw_parse.

Check the current value of this parameter named debug_print_raw_parse.

postgres=# show debug_print_raw_parse ;

Result:

 debug_print_raw_parse 
-----------------------
 off
(1 row)

The default value for this parameter is off.

Now, check this parameter’s metadata from the pg_settings catalogue like this.

postgres=# select * from pg_settings where name = 'debug_print_raw_parse';

Result:

-[ RECORD 1 ]---+------------------------------------
name            | debug_print_raw_parse
setting         | off
unit            | 
category        | Reporting and Logging / What to Log
short_desc      | Logs each query's raw parse tree.
extra_desc      | 
context         | user
vartype         | bool
source          | default
min_val         | 
max_val         | 
enumvals        | 
boot_val        | off
reset_val       | off
sourcefile      | 
sourceline      | 
pending_restart | f

Check this parameter’s internal definition from the postgres 19 source code file named guc_parameters.dat.

{ name => 'debug_print_raw_parse', type => 'bool', context => 'PGC_USERSET', group => 'LOGGING_WHAT',
  short_desc => 'Logs each query\'s raw parse tree.',
  variable => 'Debug_print_raw_parse',
  boot_val => 'false',
},

Now, enable this parameter by using the alter command.

postgres=# alter system set debug_print_raw_parse = 'on';

Result:

ALTER SYSTEM

Now, using the command below to reload the postgres configuration without restarting the postgres server.

postgres=# select pg_reload_conf();

Result:

-[ RECORD 1 ]--+--
pg_reload_conf | t

Ensure the value of this parameter is changed or not.

postgres=# show debug_print_raw_parse ;

Result:

-[ RECORD 1 ]---------+---
debug_print_raw_parse | on

Here, we can see the value of this parameter is changed.

Now, execute some queries inside the psql terminal like this.

 select * from customers limit 10;

Check the log file of postgres version 19.

sudo tail -f /var/log/postgresql/postgresql-19-main.log

Result:

026-12-01 20:00:24.219 IST [1659687] postgres@postgres LOG:  raw parse tree:
2026-12-01 20:00:24.219 IST [1659687] postgres@postgres DETAIL:  (
   {RAWSTMT 
   :stmt 
      {SELECTSTMT 
      :distinctClause <> 
      :intoClause <> 
      :targetList (
         {RESTARGET 
         :name <> 
         :indirection <> 
         :val 
            {COLUMNREF 
            :fields (
               {A_STAR
               }
            )
            :location 7
            }
         :location 7
         }
      )
      :fromClause (
         {RANGEVAR 
         :catalogname <> 
         :schemaname <> 
         :relname customers 
         :inh true 
         :relpersistence p 
         :alias <> 
         :location 14
         }
      )
      :whereClause <> 
      :groupClause <> 
      :groupDistinct false 
      :havingClause <> 
      :windowClause <> 
      :valuesLists <> 
      :sortClause <> 
      :limitOffset <> 
      :limitCount 
         {A_CONST 
         :val 10 
         :location 30
         }
      :limitOption 0 
      :lockingClause <> 
      :withClause <> 
      :op 0 
      :all false 
      :larg <> 
      :rarg <>
      }
   :stmt_location 0 
   :stmt_len 32
   }
)
2026-12-01 20:00:24.219 IST [1659687] postgres@postgres STATEMENT:  select * from customers limit 10;

The parameter named debug_print_raw_parse in PostgreSQL 19 is a debugging parameter that logs the raw parse tree immediately after the SQL parser processes a query. The output represents the query's internal syntax tree before parse analysis, semantic validation, query rewriting, or planning occurs. It reveals how PostgreSQL initially interprets SQL statements, including their structure, clauses, constants, and identifiers, making it a valuable tool for understanding the parser's behaviour and debugging SQL parsing issues.

The debug_print_raw_parse parameter is a useful addition to PostgreSQL 19 for developers and contributors who want to inspect how SQL statements are represented immediately after parsing.

By enabling this parameter and reviewing the generated log entries, you can better understand PostgreSQL's parsing process before query analysis, rewriting, and planning begin. This can be especially helpful when studying PostgreSQL internals or troubleshooting query parsing behaviour.

WhatsApp