<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Oliver Rau on Medium]]></title>
        <description><![CDATA[Stories by Oliver Rau on Medium]]></description>
        <link>https://medium.com/@olira?source=rss-93d0a6c3459------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vIfSl0ngQFMvMYXkVHWAgA.jpeg</url>
            <title>Stories by Oliver Rau on Medium</title>
            <link>https://medium.com/@olira?source=rss-93d0a6c3459------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 17:48:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@olira/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Agent Skills: Packaging the Context Agents Actually Need]]></title>
            <link>https://medium.com/@olira/agent-skills-packaging-the-context-agents-actually-need-5c2dbf7126d7?source=rss-93d0a6c3459------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c2dbf7126d7</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[skills]]></category>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Oliver Rau]]></dc:creator>
            <pubDate>Fri, 17 Jul 2026 11:22:48 GMT</pubDate>
            <atom:updated>2026-07-17T11:22:48.639Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Disclaimer: The postings on this site are my own and don’t necessarily represent my current or any previous employer’s positions, strategies or opinions.</em></p><p>Most teams do not struggle with AI agents because the model has never heard of OpenAPI, contract review, month-end close, customer escalations, or brand guidelines. They struggle because the agent does not know how <em>their</em> work actually works.</p><p>It does not know which API changes require a full review, which contract clauses legal always flags, which customer issues support should escalate immediately, or which language marketing avoids in launch copy. That gap is not really a reasoning problem; it is a context problem. And that is why Agent Skills are worth paying attention to.</p><p>People can already benefit from skills in simple ways: by making repeated work more consistent, reusable, and easier for an agent to follow. The larger opportunity is that skills give us a way to package local context, decision rules, and repeatable workflows in a form agents can discover and apply.</p><p>Agent Skills are a lightweight, open format for packaging specialized instructions, workflows, scripts, templates, and reference material for AI agents. At the center is a simple idea: put the knowledge an agent needs for a specific kind of work into a folder, make it discoverable, and load it only when the task calls for it. The official overview describes a skill as a folder containing a required SKILL.md file with metadata and instructions, plus optional scripts, references, templates, or other resources.</p><p>A skill might look like this:</p><pre>api-change-review/<br>├── SKILL.md<br>├── references/<br>│   ├── openapi.md<br>│   ├── authorization.md<br>│   └── versioning.md<br>└── scripts/<br>    └── validate-openapi.py</pre><p>The required piece is SKILL.md. It contains metadata such as name and description, followed by instructions. The format does not require every skill to include scripts, references, or templates. In practice, though, these supporting files are often what make a skill useful. SKILL.md gives the agent the core workflow; references provide deeper context; scripts can handle checks or transformations that should be deterministic rather than improvised.</p><p>That sounds almost too simple, but the simplicity is the point. A skill is not the agent itself. It is a package of instructions and resources the agent can use when a task calls for it. And packaging matters.</p><h3>Agents know a lot. They do not know your process.</h3><p>General-purpose agents already know a lot. They can explain REST, draft documentation, summarize a meeting, review a contract, plan a trip, or prepare a report. But in real work, generic knowledge is rarely enough.</p><p>The question is usually not “what is a good process?” It is more often “what does <em>this person, team, or organization</em> consider the right process?” That answer is scattered. Some of it lives in docs. Some of it lives in old comments, review notes, support tickets, templates, or postmortems. Too much of it lives in people’s heads.</p><p>Agent Skills give us a place to put that knowledge in a form agents can use. I will use engineering examples because they are concrete: pull requests, API contracts, validators, and review paths are easy to reason about. But the pattern is not limited to software teams. A finance team could package month-end close procedures. A legal team could encode contract review playbooks. A support team could capture escalation rules and customer communication templates. A marketing team could bundle brand voice, campaign checklists, and launch workflows. An individual user could do the same for recurring personal workflows: planning trips, preparing tax documents, organizing research, or keeping a consistent writing style.</p><p>You can often spot a potential skill by looking for repetition: the same reminder you give an assistant every week, the same checklist you follow before sending a report, the same review steps you apply before approving a document, or the same preferences you explain again and again. When a person has to give the same instruction for the tenth time, that is a skill trying to be born.</p><p>If the process is important enough to repeat, and specific enough that a generic AI agent would not reliably guess it, it may be a good candidate for a skill.</p><h3>Progressive disclosure is the interesting part</h3><p>The Agent Skills specification is built around progressive disclosure. Agents do not load every skill in full. They first see only lightweight metadata: the skill name and description. If a task appears to match, the agent loads the full SKILL.md. If the workflow needs more detail, it can load supporting files or run bundled scripts.</p><p>That design is easy to miss, but it is the most important part. A good skill is not a giant prompt; it is a context-loading strategy.</p><p>The specification recommends keeping the main SKILL.md small and moving detailed material into separate files. The best-practices guide makes this even more specific: keep the core instructions small — under 500 lines — , and tell the agent when to load deeper references.</p><p>For example, an API review skill should not put an entire API handbook into SKILL.md. That would waste context and probably make the agent worse. A better design keeps the core workflow small and points to deeper material only when it matters:</p><pre>Read `references/openapi.md` when an OpenAPI file is added or changed.<br><br>Read `references/authorization.md` when the API handles users, tenants, organizations, roles, permissions, or ownership.<br><br>Run `scripts/validate-openapi.py` when an OpenAPI document is present and Python execution is available.</pre><p>That is the pattern: start small, load intentionally. The best skills feel less like manuals and more like maps.</p><h3>The description is the first design decision</h3><p>Every skill has a description. It is tempting to treat it like documentation, but that is a mistake. The description is routing logic: it is how the agent decides whether to activate the skill.</p><p>The Agent Skills guidance is explicit about this. At startup, agents load only the name and description of each available skill, and the description carries the burden of telling the agent when the skill is useful. If the description is too vague, the skill may not trigger when it should. If it is too broad, it may show up everywhere. (<a href="https://agentskills.io/skill-creation/optimizing-descriptions">agentskills.io</a>)</p><p>This is not useful:</p><pre>description: Helps review APIs.</pre><p>It is true, but it gives the agent almost no signal. This is better:</p><pre>description: Use this skill when reviewing a pull request, design document, or code change that adds, removes, or modifies API endpoints, OpenAPI contracts, request/response schemas, authentication, authorization, error handling, pagination, filtering, or API documentation.</pre><p>That version is longer, but it does real work. It names the situations where the skill should activate, includes words people are likely to use in actual requests, and creates a clearer contract between the user, the agent, and the skill. One thing I like about the format is that it forces you to think about the boundary of the workflow: what is this skill for, and just as importantly, what is it not for?</p><h3>A concrete example: deciding what kind of API review is needed</h3><p>To make this concrete, I will use an engineering example: deciding what kind of API review is needed. The details are technical, but the pattern is not. The same structure applies whenever a skill needs to classify a task first and then apply the right workflow.</p><p>Suppose we want a skill for API changes. The obvious version is a review checklist: check OpenAPI, check documentation, check auth, check compatibility, check tests. That is useful, but it is not quite how real API review works. In real reviews, the first question is often not “did we check everything?” but “what kind of change is this?”</p><p>Sometimes a change touches an API but does not need the full API governance ceremony. Maybe it adds a well-known optional header to an existing endpoint. Maybe it updates documentation without changing behavior. Maybe it corrects an OpenAPI example that was already wrong. The agent should not blindly apply every rule to every change. That creates noise.</p><p>Instead, the skill should help answer three questions:</p><ul><li>What kind of API change is this?</li><li>Which review path and validator rules apply?</li><li>If a rule is overridden, is the override explicit, scoped, and justified?</li></ul><p>That turns the skill from a checklist into a decision workflow. It also shows where skills complement tooling rather than replacing it. A validator can tell you which rules failed. The skill should help determine which rules should apply in the first place, whether an override is legitimate, and what human judgment is still required.</p><p>The skill might start like this:</p><pre>---<br>name: api-change-review<br>description: &gt;<br>  Use this skill when classifying or reviewing an API-related<br>  change, including changes to endpoints, OpenAPI contracts,<br>  schemas, headers, authentication, authorization, validation,<br>  versioning, or API documentation.<br>---<br><br># API Change Review<br><br>Use this skill when preparing or reviewing an API-related change.<br>Authors use it to determine the required review path before submitting.<br>Reviewers use it to verify that the selected path, rules, docs,<br>and overrides are appropriate.<br><br>First classify the change. Do not apply the full review checklist<br>automatically. Decide whether the change is documentation-only,<br>additive and backward-compatible, behavior-changing,<br>security-sensitive, or breaking.<br><br>Then apply the smallest review path sufficient for the risk.</pre><p>That last sentence is the point: apply the smallest review path that is sufficient for the risk of the change. This is the difference between a useful skill and a generic checklist.</p><p>The rest of the skill could define a few review paths. For example, a lightweight path might apply when the change does not alter the public contract or only clarifies existing behavior. A standard path might apply when the change adds or modifies request fields, response fields, headers, status codes, validation behavior, pagination, filtering, or documented error responses in a backward-compatible way. A security-sensitive path would apply when authentication, authorization, permissions, tenant boundaries, ownership checks, tokens, sessions, roles, or sensitive data exposure are involved. A breaking-change path would apply when existing clients may be affected and versioning, migration, deprecation, rollout, or communication plans need to be checked.</p><p>This avoids the common failure mode where the agent dumps every possible API concern onto every small change. The review becomes situational rather than noisy.</p><h3>Skills should come from real work</h3><p>The best skills do not come from asking an LLM to “write a best-practice skill.” They come from real work.</p><p>One practical technique is to do the task once with an agent while deliberately explaining your decisions. Do not just ask for the final output. Tell the agent why you are choosing one path over another, which checks matter, which exceptions are acceptable, and what you would reject. At the end, ask the agent to turn that interaction into a first draft of a skill. The result will not be finished, but it gives you a useful starting point grounded in a real workflow instead of a generic template.</p><p>Look at the comments reviewers keep leaving, the postmortems where someone wrote “we should make sure this never happens again,” the internal docs new people never find, the scripts people copy between projects, and the checklists that live in someone’s notes app. That material is gold.</p><p>The Agent Skills best-practices guide makes a similar point: skills should be grounded in real expertise and real artifacts such as internal docs, runbooks, schemas, issue trackers, version-control history, and failure cases. (<a href="https://agentskills.io/skill-creation/best-practices">agentskills.io</a>)</p><p>For the API review skill, I would start with three sources: repeated review feedback, incidents caused by API compatibility or authorization failures, and existing standards such as API style guides. If your team already has a good standard, do not rewrite it into a giant prompt. Reference it from the skill and tell the agent when to load it.</p><p>That is the work: not writing Markdown, but extracting the workflow, boundaries, exceptions, and lessons that actually matter.</p><h3>Validate the package, then test the behavior</h3><p>There is a reference implementation for working with skills, including validation via skills-ref:</p><pre>skills-ref validate ./api-change-review</pre><p>The specification points to this tooling for validating skill structure and frontmatter. (<a href="https://agentskills.io/specification">agentskills.io</a>) <br>Validation is necessary, but it is not sufficient. A valid skill can still be vague, trigger too often, or encode bad advice.</p><p>So I would add a lightweight behavioral test: collect a handful of prompts where the skill should trigger and a handful where it should not. For the API review skill, “Review this PR that adds a new /payments/refunds endpoint” should trigger. “Check whether this API change needs an OpenAPI update” should trigger. “Refactor this React component” should not. “Explain what REST means” should not.</p><p>That is not a full evaluation framework, but it changes the conversation. You are no longer asking “does the skill exist?” You are asking “does the agent reach for it at the right time?”</p><p>There is also a useful meta-pattern here: skills can help create skills. A skill-creator skill can guide authors through structure, metadata, progressive disclosure, references, and validation. That is powerful, but I would treat it as scaffolding rather than a substitute for judgment. The hard part is not producing a valid SKILL.md; the hard part is extracting the workflow, boundaries, exceptions, and failure cases from real practice.</p><p>For teams, I would treat shared skills like any other important work artifact: put them in version control, review changes, validate them automatically, and revisit them when the workflow changes.</p><h3>Skill registries and trust</h3><p>A registry is a place to find and share skills, similar to how an app store helps people find apps or a package directory helps developers find reusable libraries. For skills, a registry helps answer questions that a local folder cannot: Which skills exist? Who maintains them? Which version should I use? Can I trust this source?</p><p>That is why registries such as <a href="https://skills.sh/">skills.sh</a> matter.</p><p>This does not mean every useful skill has to be generic. A public skill can still be specific: using a particular product, creating a Word document, validating an OpenAPI file, preparing a slide deck, or writing another skill. These workflows are narrow enough to be useful, but common enough to be reused across people and teams. Once skills become discoverable and installable, they start to look less like snippets of guidance and more like reusable packages.</p><p>That makes skills more powerful, but also more complicated. Once people start installing skills from outside their own workspace, they need to know where a skill came from, who maintains it, whether it changed, and whether it is safe to use. If people can publish, discover, review, pin, validate, and reuse skills across tools, skills become a practical distribution mechanism for agent capabilities. But that only works if we take the lifecycle seriously.</p><p>This is also where trust becomes central. A skill can contain natural-language instructions, scripts, templates, references, and assumptions that an agent may follow while it has access to local files, source code, tools, credentials, or deployment environments. That makes skills much closer to software packages than casual notes.</p><p>Dimitrij Pankratz goes deeper on this in “Agent Skills: A Productivity Boost With a Trust Problem.” His article is the security companion to this one: where I am focused on designing useful skills, Dimitrij focuses on what can go wrong when skills are installed, trusted, and executed too casually. (<a href="https://medium.com/%40dimitrij-pankratz/agent-skills-a-productivity-boost-with-a-trust-problem-46940856eafe">medium.com</a>)</p><p>My short version is simple: treat skills like code. Review them. Version them. Avoid secrets. Be skeptical of third-party skills. Look closely at bundled scripts. Prefer pinned versions. Run validation in CI. Make destructive actions explicit. Use sandboxing where possible.</p><p>That is not the whole security model, but it is the right default posture.</p><h3>What makes a good skill?</h3><p>The best skills I have seen, or would want to see, have three properties: they are narrow enough to know when they apply, grounded in real work rather than generic advice, and structured so the core workflow is separate from supporting material.</p><p>That last point matters. If everything is in SKILL.md, the agent has to carry everything at once. If the skill is structured well, the agent can start with a small workflow and pull in deeper references only when needed. For an API review skill, the core workflow might fit in a page. The details can live elsewhere: OpenAPI standards, authorization rules, versioning policy, error model, pagination conventions, and validation scripts.</p><p>That is what turns a skill from static instructions into workflow infrastructure.</p><h3>Closing thought</h3><p>Agent Skills are easy to underestimate because the format is simple: a folder, a SKILL.md file, and some optional scripts and references. But simple packaging formats can become powerful primitives. README, Dockerfile, package.json, Makefile, and OpenAPI all work because they give people and tools a shared place to put conventions.</p><p>Agent Skills feel like they could play a similar role for agents. They give us a way to package local context so it can be reused, reviewed, tested, and loaded when needed.</p><p>The next step is not to create huge libraries of generic skills. It is to capture the workflows that already matter: the review habits, operational checks, domain rules, personal preferences, and hard-earned lessons people apply every day.</p><p>There is also a practical follow-up question: how do you actually build and test one of these skills without turning the process into another documentation project? That deserves its own deep dive, especially around skill-authoring helpers, validation, trigger evals, and keeping a skill useful without making it noisy.</p><p>That is where skills become more than productivity hacks. That is where they become workflow infrastructure for agents.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c2dbf7126d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PostgreSQL Multi-Active Replication - Part 2: Native Replication in PostgreSQL 15 and 16]]></title>
            <link>https://medium.com/@olira/postgresql-multi-active-replication-part-2-native-replication-in-postgresql-15-and-16-42cc3496c46b?source=rss-93d0a6c3459------2</link>
            <guid isPermaLink="false">https://medium.com/p/42cc3496c46b</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[replication]]></category>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[postgres]]></category>
            <dc:creator><![CDATA[Oliver Rau]]></dc:creator>
            <pubDate>Wed, 20 Mar 2024 12:24:51 GMT</pubDate>
            <atom:updated>2024-03-20T12:24:51.932Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ODoFAEJn0CJ2IpGSIv8XkA.jpeg" /><figcaption>(Credit: DALL·E)</figcaption></figure><p><em>Disclaimer: The postings on this site are my own and don’t necessarily represent my current or any previous employer’s positions, strategies or opinions.</em></p><p>This article, the second installment in our series on replication techniques with PostgreSQL, zeroes in on the built-in replication features provided by PostgreSQL, highlighting their limitations and assessing how these native capabilities align with the goal of achieving a global-scale multi-active deployment.</p><p>It’s important to note that, despite the advancements, the current PostgreSQL features do not yet fully support a multi-active replication setup.</p><p>This discussion aims to provide a realistic overview of what is currently achievable with PostgreSQL’s replication capabilities and to set the stage for exploring potential workarounds and enhancements in future articles.</p><h3>Logical-Replication</h3><p>PostgreSQL supports two main replication methods: Physical Replication and Logical Replication. Physical Replication, also known as Log Shipping, is designed to replicate the Write Ahead Log (WAL) either by copying the complete WAL files or streaming them. This method essentially replicates the entire database state from a primary server to a secondary server, mirroring every change as it happens. It’s comparable to continuous archiving from the primary server paired with continuous recovery on a secondary server.</p><p>While effective for scenarios with a single source of data changes, it struggles with environments that have multiple writers due to the risk of data overwrites or collisions, a challenge that PostgreSQL’s native capabilities do not address without the aid of external tools.</p><p>Logical Replication, in contrast, focuses on the replication of specific data objects and their changes, offering more granular control over what gets replicated and how.</p><p>This method is based on a publisher/subscriber model, where a source server (the publisher) defines publications for particular data objects, and a target server (the subscriber) can subscribe to these publications. One of PostgreSQL’s strengths in this area is its flexibility: publications and subscriptions are not mutually exclusive, allowing for complex configurations where a server can publish data objects while also subscribing to publications from other servers, facilitating sophisticated replication schemes beyond simple one-to-one replication scenarios.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*BqbklJF5IoriouZYGnJUlQ.png" /><figcaption>Figure 1: Multi-Layer Publication / Subscriptions</figcaption></figure><p>Given these replication capabilities in PostgreSQL, setting up a global architecture with a single primary (writer) and multiple standby (reader) layers is relatively straightforward.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*KErTQnxjY4b7BXxGHVrvSg.png" /><figcaption>Figure 2: Multi-Layer, Multi-Geo Setup</figcaption></figure><p>This architectural model excels in spreading the read demand across various geographic regions while keeping write operations centralized, enhancing both performance and scalability for applications that experience a significantly higher volume of read transactions than writes. Positioning data geographically closer to the end-users significantly reduces latency for read operations, making the system more efficient and responsive.</p><p>Moreover, having standby servers in different regions not only aids in balancing the read load but also greatly simplifies the failover process. Should the primary server become unavailable, any of the regional standby servers — each potentially located in strategic locations like Germany (de) or France (fr) — is prepared to assume the role of the primary server. This flexibility (with the help of some on-top tooling like <a href="https://github.com/zalando/patroni">Patroni</a>) could ensure high availability and resilience of the system, as there is always a prepared server ready to take over the primary’s duties, minimizing downtime and maintaining continuous service to users.</p><p>For this example, let’s consider a table that stores user information.</p><p>This table, which will call userinfo, might include various fields to capture essential user details. Here’s a simplified schema for the userinfo table:</p><pre>CREATE TABLE userinfo<br>(<br>  id          bigint NOT NULL,<br>  name        varchar(40),<br>  email       varchar(100),<br>  dateOfBirth varchar(10),<br>  citizenship varchar(2)<br>  CONSTRAINT  userinfo_pkey PRIMARY KEY (id)<br>);</pre><p>To facilitate replication of the userinfo table in PostgreSQL using logical replication, you would establish a publication on the publisher database and a subscription on the subscriber database.</p><p>On the publisher side, where the original data resides, you can create a publication for the userinfo. This is done with the CREATE PUBLICATION command. If the publication is intended to include all future tables automatically, you can specify FOR ALL TABLES; otherwise, specify the table explicitly as follows:</p><pre>CREATE PUBLICATION userinfo_pub FOR TABLE userinfo</pre><p>This command creates a publication named userinfo_pub that includes the userinfo table, making its changes available for replication.</p><p>You establish a subscription using the CREATE SUBSCRIPTION command on the subscriber side, which will receive the replicated data. This process requires specifying the connection string to the publisher database, including credentials, as the subscriber needs to authenticate with the publisher to initiate the replication process. Here’s an example command to create a subscription:</p><pre>CREATE SUBSCRIPTION userinfo_sub CONNECTION &#39;host=&lt;hostname&gt; port=5432 user=postgres password=&lt;pass&gt; dbname=rep_test&#39; PUBLICATION userinfo_pub</pre><p>Replace &lt;hostname&gt;, &lt;username&gt;, &lt;password&gt;, and &lt;dbname&gt; with the actual values for your publisher database. This command creates a subscription named userinfo_sub that connects to the specified publisher and subscribes to the userinfo_pub publication.</p><p>By executing these commands on the respective publisher and subscriber databases, you set up logical replication for the userinfo table, allowing for real-time data synchronization between the databases.</p><h3>Extensions to Logical Replication with PG15</h3><p>With PostgreSQL 15, the introduction of row filters to logical replication marks a significant advancement in the customization of data replication. Row filters enhance the ability to control which data gets replicated by allowing publishers to apply a filter (similar to a WHERE clause in SQL) to data changes before publication. This means publishers can now decide more fine-grained what portion of the data should be included in the publication, enabling selective replication based on specific data criteria.</p><p>Such a filter allows selective replication based on the data involved, e.g., region-specific or similar. Columns referenced in a row filter must be part of a replica identity.</p><p>With figure 2 in mind, consider a scenario where the citizenship column of our userinfo table is crucial for ensuring GDPR compliance in data replication. The goal is to replicate only the data related to EU citizens to servers located within the EU. In contrast, data concerning non-EU citizens can be replicated across both EU and US servers.</p><p>Assuming the primary server is located in the EU and replicates data to servers in France, Germany, North Carolina, and Texas, you would want to ensure that only EU citizen data is replicated within the EU boundaries. This can be achieved by applying a row filter on the publication created on the primary server.</p><p>This setup requires that the citizenship column is part of a replica identity, which could be the primary key or a unique index that PostgreSQL can use for row identification during replication.</p><p>To include the citizenship column in the replica identity, you might need to adjust your table’s primary index. In practice, this might involve creating a unique index that includes the citizenship column if you do not wish to alter the existing primary key structure. For simplicity, let’s assume we adjust the primary index to include citizenship.</p><p>The adjusted structure of the userinfo table looks like this:</p><pre>CREATE TABLE userinfo<br>(<br>  id          bigint NOT NULL,<br>  name        varchar(40),<br>  email       varchar(100),<br>  dateOfBirth varchar(10),<br>  citizenship varchar(2)<br>  CONSTRAINT  userinfo_pkey PRIMARY KEY (id, citizenship)<br>);</pre><p>Here’s an illustrative command to create a publication with a row filter applied to the userinfo table, ensuring only rows where the citizenship column indicates non EU country are published:</p><pre>CREATE PUBLICATION userinfo_non_eu_pub FOR TABLE userinfo WHERE citizenship &lt;&gt; &#39;EU&#39;;</pre><p>This command sets up a publication named userinfo_non_eu_pub that only includes changes to rows in the userinfo table where the citizenship value does not equal EU. The WHERE clause applies the selective replication logic based on the citizenship column.</p><p>The strategy outlined above leads to establishing a thorough replication setup consisting of two distinct publications. The first publication, userinfo_pub, includes all data and is designed for replication to EU-based servers to ensure compliance with local data protection laws. The second publication, userinfo_non_eu_pub, filters out records with a citizenship value of EU, making them suitable for replication to non-EU servers.</p><p>To implement this strategy effectively, each subscriber’s configuration must be adjusted to subscribe to the appropriate publication based on the geographical and legal requirements of the data it will store.</p><p>This means modifying the subscriptions on each server so that EU servers subscribe to userinfo_pub, which replicates all user data, and non-EU servers subscribe to userinfo_non_eu_pub, which excludes EU citizen data.</p><p>This replication pattern offers a scalable solution for handling more complex data distribution needs. Organizations can significantly increase read transaction rates by distributing data across multiple servers based on content and geographical considerations and integrating with a load balancer. This setup can efficiently balance the load among servers, improving applications’ overall performance and responsiveness, especially in scenarios with high read demand.</p><h3>Extensions to Logical Replication in PG16</h3><p>Let’s make slight adjustments to the overall architecture example to enhance the resilience and expedite failover procedures within our setup. It’s important to note that this is merely a sample and may not directly translate to real-world configurations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*tRdixQV0kYYxwYwlyeBcjg.png" /><figcaption>Figure 3: Multi-Layer, Redundant replication setup</figcaption></figure><p>In the depicted scenario, the PostgreSQL (PG) instance located in France serves as the primary node and is configured for replication to all standby servers. Additionally, to facilitate rapid failover, the standby servers are configured to replicate data among themselves, enabling them to receive updates from other standby servers.</p><p>However, this setup introduces challenges in tracking the origin of data and managing potential issues like loop-back or duplicate Primary Key conflicts.</p><p>Although PostgreSQL logs would highlight such problems, there are currently no built-in mechanisms to address them automatically.</p><p>PostgreSQL 16 introduces a subscription extension that simplifies handling these challenges: the origin subscription parameter.</p><p>The origin subscription parameter allows us to specify the origin of data we wish to receive. In PostgreSQL 16, the parameter offers two values: none and any, with any being the default. Specifying none indicates that changes must originate directly from the publisher rather than being received from another source. Alternatively, specifying any allows for data replication regardless of its origin.</p><p>For us to get the caveats mentioned earlier out of the way, let’s adjust the subscriptions of the standby servers as follows:</p><pre>CREATE SUBSCRIPTION userinfo_sub <br>  CONNECTION &#39;host=&lt;hostname&gt; port=5432 user=postgres password=&lt;pass&gt; dbname=rep_test&#39; <br>  PUBLICATION userinfo_pub <br>  WITH (origin = none, copy_data = false)</pre><p>In conjunction with specifying the <em>origin</em> parameter, we configure the copy_data parameter to false. This adjustment ensures that the data synchronization process exclusively involves data originating from the source server. In real-world deployments, this setup hinges on the configuration of the standby servers.</p><p>Establishing subscriptions this way lays the groundwork for an advanced initial setup. This approach allows for a streamlined transition in case of a failover, where the process to elevate a standby server to the primary role is simplified to only the essential steps. This strategy enhances efficiency and reliability during critical operational shifts.</p><h3>Conclusion</h3><p>Logical replication in PostgreSQL versions 15 and 16 has introduced significant improvements, making the concept of a multi-geographical, multi-active database setup more feasible with the default PostgreSQL configuration. Despite these advancements, certain limitations remain that hinder achieving a fully functioning setup.</p><p>A primary challenge in implementing such a system is managing conflict resolution across multiple primary servers that can all handle write operations simultaneously. For instance, the process for handling INSERT or UPDATE statements varies depending on where the data was initially recorded. A particular scenario that illustrates this challenge occurs when data is inserted on one server, then updated on another, and subsequently replicated back to the original server. This can lead to primary key conflicts because the system does not recognize the replicated data as a “replica.”</p><p>To mitigate replication loops and directional issues, PostgreSQL introduced the origin filter. However, this feature’s current implementation, which only allows for the specification of ‘none’ or any specific origin (excluding comprehensive or customized lists), restricts its applicability for diverse use cases.</p><p>In upcoming articles, we will explore these new features and other critical aspects relevant to advancing towards a fully functional multi-active setup. We aim to explore strategies and solutions that leverage these enhancements and alternatives to address the current limitations.</p><h3>Upcoming Series Parts</h3><p>The upcoming article by <a href="https://medium.com/u/ad43bef602cf">Dimitrij Pankratz</a> will focus on the open-source PostgreSQL plugins, BDR (Bi-Directional Replication), and pglogical and their roles in our quest to establish a fully functioning global-scale multi-active deployment. These tools are instrumental in overcoming some of the inherent limitations of PostgreSQL’s native replication capabilities, offering enhanced features for more complex replication scenarios.</p><ul><li><a href="https://dimitrij-pankratz.medium.com/postgresql-multi-active-replication-part-1-an-introduction-ff7052eb9fd0">Part 1: Introduction</a></li><li>Part 2: Native replication in PostgreSQL 15 and 16 (this article)</li><li>Part 3: BDR and PGLogical</li><li>Part 4: Change Data Capture Approach</li><li>Part 5: Local-First Approach</li><li>Part 6: Overall Conclusion</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42cc3496c46b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>