[PROPOSAL] comments in repl_scanner - Mailing list pgsql-hackers

From Matěj Klonfar
Subject [PROPOSAL] comments in repl_scanner
Date
Msg-id CA+HFpemwTaRpf8dgEY8OEnG_VrxeVnwaYyc-ZEBtNjzqXopmrQ@mail.gmail.com
Whole thread Raw
List pgsql-hackers
Hi hackers, 

certain instrumentation tools do prefix each statement with an informational comment, typically to provide some tracing information to logs (datadog for example). While this works for SQL statements, it's not possible with logical replication statements because their grammar doesn't support comments and it is causing unnecessary syntax errors.

I can imagine this limitation is likely a holdover from the system's evolution from physical replication where comments make no sense. However, in logical replication walsender mode both SQL and replication statements can be issued [1], so the current state brings the necessity to distinguish when to inject the comment and when not to. What do you feel, are there any unexpected impacts of extending the replication grammar with comments?

I attached a simple patch extending the `replication/repl_scanner.l` with following test:
```

psql  "dbname=postgres replication=database" 


Border style is 2.

Line style is unicode.

psql (14.19 (Homebrew), server 19devel)

WARNING: psql major version 14, server major version 19.

         Some psql features might not work.

Type "help" for help.


postgres=# -- foo

/* bar

/* blah

*/ 

*/

IDENTIFY_SYSTEM;

┌─────────────────────┬──────────┬────────────┬──────────┐

│      systemid       │ timeline │  xlogpos   │  dbname  │

├─────────────────────┼──────────┼────────────┼──────────┤

│ 7561021876571120357 │        1 │ 0/0176B5A8 │ postgres │

└─────────────────────┴──────────┴────────────┴──────────┘

(1 row)

```


What do you feel, is that a good idea and/or are there any downsides I am missing? Thank you all for the feedback.

Regards, 

Matej Klonfar
Attachment

pgsql-hackers by date:

Previous
From: Tatsuo Ishii
Date:
Subject: Re: Add RESPECT/IGNORE NULLS and FROM FIRST/LAST options
Next
From: David Rowley
Date:
Subject: Re: A tidyup of pathkeys.c