postgres-patterns

Standardize PostgreSQL data access in multi-tenant Go microservices.

1|Updated Apr 17, 2026
One-click install
npx skills add https://github.com/PremModhaOfficial/motadata-ai-pipeline --skill postgres-patterns-premmodhaofficial
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgres-patterns
Source: https://github.com/PremModhaOfficial/motadata-ai-pipeline/tree/main/.claude/skills/postgres-patterns
Command: npx skills add https://github.com/PremModhaOfficial/motadata-ai-pipeline --skill postgres-patterns-premmodhaofficial

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

PostgreSQL data access in multi-tenant Go microservices requires consistent patterns for repository interfaces, transaction handling, and tenant isolation. This Skill provides a standardized approach to building per-tenant aware services using a single app-database pool and schema-per-tenant routing.

Core Features & Use Cases

  • Repository interfaces and structs that route to tenant-scoped pools
  • Transaction management with begin/commit/rollback
  • Cursor-based pagination and per-tenant migrations
  • Migration templates and pool configuration for scalable Go microservices

Quick Start

Create a Go repository that uses a shared pgxpool.Pool and a TenantRouter to route operations to the correct tenant schema.

Frequently Asked Questions about postgres-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce tenant isolation in PostgreSQL for Go microservices?

Enforce tenant isolation in PostgreSQL by routing queries through a TenantRouter that sets the search_path to the correct schema. This approach uses a shared pgxpool.Pool to execute operations securely within tenant-scoped boundaries.

What is the best way to manage SQL transactions across a shared pgxpool in a multi-tenant Go service?

Manage SQL transactions by routing begin, commit, and rollback operations through repository structs connected to a shared pgxpool.Pool. This pattern standardizes transaction handling while maintaining per-tenant schema isolation via search_path.

How do I implement cursor-based pagination in a Go repository pattern?

Implement cursor-based pagination by applying standardized repository interface templates provided for Go microservices. These templates integrate with the pgxpool connection to fetch tenant-scoped data efficiently without offset overhead.

Can I run per-tenant database migrations using a single app-database pool?

Yes, you can run per-tenant migrations using a single app-database pool. The pattern provides migration templates that execute schema changes against individual tenant schemas routed dynamically by the TenantRouter.

Does this PostgreSQL repository pattern work for schema-per-tenant database architectures?

Yes, this repository pattern is specifically designed for schema-per-tenant database architectures. It routes data access to the correct tenant schema using PostgreSQL search_path while relying on a single shared pgxpool.Pool connection.