AgentSkillsCN

xano-database-best-practices

Xano 的监控与诊断——查询分析、慢查询调试、性能追踪,以及错误日志记录。当排查性能问题,或搭建监控系统时,可使用此技能。

SKILL.md
--- frontmatter
name: xano-database-best-practices
description: Overview of PostgreSQL best practices adapted for Xano's architecture. Use as an entry point to understand Xano database optimization, then reference specialized skills for specific topics.

Xano Database Best Practices

PostgreSQL best practices adapted for Xano's architecture, XanoScript, and abstraction layer.

Quick Reference: Related Skills

TopicSkillPriority
Query optimization, N+1, indexingxano-query-performanceCRITICAL
Schema design, normalization, constraintsxano-schema-designHIGH
RLS, injection prevention, authxano-securityCRITICAL
Addons, batch operations, cachingxano-data-accessMEDIUM
Query Analytics, debuggingxano-monitoringMEDIUM

Xano Architecture Overview

Data Format Options

Xano supports two PostgreSQL data formats:

Standard SQL Format (Default since late 2025):

sql
CREATE TABLE x_<workspaceID>_<tableID> (
  id SERIAL PRIMARY KEY,
  name VARCHAR(255),
  email VARCHAR(255),
  created_at TIMESTAMP
);
  • Full indexing support (B-tree, partial, composite)
  • Native SQL query optimization
  • Recommended for production applications

JSONB Format (Legacy):

sql
CREATE TABLE mvpw_<workspaceID>_<tableID> (
  id SERIAL PRIMARY KEY,
  data JSONB
);
  • Flexible schema changes
  • Limited indexing (GIN indexes only)
  • Better for prototyping or document-like data

XanoScript Query Syntax

OperationPostgreSQLXanoScript
Select allSELECT * FROM usersdb.query user { return = {type: "list"} }
FilterWHERE age > 25db.query user { filter = "age > ?", 25 }
Single recordSELECT * FROM users WHERE id = 1 LIMIT 1db.get user { field_name = "id", field_value = 1 }
InsertINSERT INTO users (name) VALUES (?)db.add user { name = "John" }
JoinLEFT JOIN posts ON...Use Addons pattern (see xano-data-access)
Raw SQLDirect executiondb.raw "SELECT * FROM users"

Data Format Decision Tree

code
Does the optimization rely on field-level indexing?
├─ YES → Use Standard SQL format (B-tree indexes)
└─ NO → Does it involve complex queries (joins, CTEs)?
        ├─ YES → Use Standard SQL format
        └─ NO → Does schema change frequently?
                ├─ YES → JSONB format acceptable
                └─ NO → Use Standard SQL format (better performance)

Key Best Practice Categories

1. Query Performance (CRITICAL)

See: xano-query-performance skill

Critical patterns:

  • Use Addons instead of N+1 query loops
  • Create indexes on frequently queried columns
  • Always paginate large result sets
  • Chain filters in single blocks

2. Schema Design (HIGH)

See: xano-schema-design skill

Key principles:

  • Normalize data appropriately
  • Choose correct data types
  • Set up proper foreign keys and constraints
  • Consider Standard SQL format for performance-critical tables

3. Security (CRITICAL)

See: xano-security skill

Essential practices:

  • Enable Row Level Security (RLS) for sensitive data
  • Use parameterized queries to prevent SQL injection
  • Implement proper authentication flows
  • Validate all user inputs

4. Data Access Patterns (MEDIUM)

See: xano-data-access skill

Optimization techniques:

  • Use Addons for efficient joins
  • Implement cursor-based pagination for large datasets
  • Batch operations for bulk inserts/updates
  • Leverage Xano's built-in caching

5. Monitoring & Diagnostics (MEDIUM)

See: xano-monitoring skill

Monitoring approach:

  • Use Query Analytics dashboard
  • Analyze slow queries via Direct Database Connector
  • Set up performance baselines
  • Track API response times

JSONB vs Standard SQL Quick Reference

FeatureJSONB FormatStandard SQL Format
B-tree indexesNoYes
Partial indexesNoYes
Composite indexesLimitedYes
Field-level SELECTNo (full record)Yes
Schema flexibilityHighLow
Query optimizationLimitedFull PostgreSQL
Recommended forPrototyping, documentsProduction, complex queries

Performance Measurement

Use Xano Query Analytics (Dashboard → Analytics) to:

  • Identify slow queries
  • Track query frequency
  • Monitor error rates
  • Compare before/after optimizations

For advanced analysis with EXPLAIN:

  • Use Direct Database Connector (Premium tier)
  • Run EXPLAIN ANALYZE on problematic queries
  • Check for sequential scans vs index scans

Resources