question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using text parameters for replication

See original GitHub issue

Hi everybody! I’m playing with the logical decoding feature, but I fail to see how to actually use the data I receive.

I explain a little further.

Messages of type DeleteMessage, FullDeleteMessage, FullUpdateMessage, IndexUpdateMessage, InsertMessage, KeyDeleteMessage, UpdateMessage contain at least one list (actually Memory<>) of TupleData. TupleData contains either:

  • NULL wihth two meaning

    • null when Kind == TupleDataKind.Null
    • unchanged when Kind == TupleDataKind.UnchangedToastedValue
  • the stringified value (when Kind == TupleDataKind.TextValue).

This follows what pgoutput exports. The stringified version is not the .ToString of C#, but the result of the text output function for the type of the related column (as in CREATE TYPE).

Now if I wanted to replay the transaction to a secondary server I would need to:

  • open a connection to the secondary database;
  • generate a proper query;
  • add the parameters with the values I received;
  • execute the command.

This would possibly happen in a transaction. However, I only have the string representation of the parameters, so I can’t find a way to pass the non-string parameters as strings.

If I was using libpq, that would be very trivial as I would just call PQexecParams or similar and specifying the OIDS of my types (taken from the RelationMessage), my string values, and 0-initialized array for the paramFormats parameter. This is also guaranteed to work for user-defined types as textual input-output functions are required.

On the other side, I can’t find anything in the documentation that allows me to do such a thing with npgsql, except encoding the text directly in the query which implies escaping (with all the problems it brings).

As a last note, to my surprise, NpgsqlDbType enum does not use the well-known type OIDs under the hood, so AFAIK there is no way with Npgsql to map a type OID returned by its own API (in the RelationMessage::Column.DataTypeId field) to a usable NpgsqlDbType. While this is (of course) a minor problem it still makes it difficult to actually use the replication feature.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
marco6commented, Oct 27, 2021

Hi @roji ! I read all of your comments but I didn’t have time to answer yet. I hope to have a couple of hours during this weekend 😃 Thank you for your support and thoughts so far!

0reactions
rojicommented, Oct 27, 2021

@marco6 most of the discussion above seems to be covered by the other linked issues, so I’m going to go ahead and close this one. But we can continue having general conversation here for sure.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure the max text repl size (server configuration option)
In Object Explorer, right-click a server and select Properties. Click the Advanced node. Under Miscellaneous, change the Max Text Replication ...
Read more >
Replication configuration parameters
You can view the values of replication configuration parameters by using either an SQL query or the command line, as follows: SELECT FROM...
Read more >
Replication configuration parameters
You can configure parameters in the ReplicationSKLMConfig.properties file that specify various aspects of IBM Security Key Lifecycle Manager automated ...
Read more >
Key Parameters and Configuration for Streaming ...
In this blog, we will be discussing the essential parameters and configuration for streaming replication in Postgres.
Read more >
create function replication definition
Adaptive Server stored procedures and function replication definitions cannot contain parameters with the text, unitext, rawobject, and image datatypes.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found