SkillsMar 29, 2026·1 min read

Gemini CLI Extension: Postgres — Database Management

Gemini CLI extension for PostgreSQL. Query optimization, schema design, migration scripts, and database administration.

TL;DR
Gemini CLI extension for PostgreSQL query optimization, schema design, migration scripts, and database administration.
§01

What it is

The Gemini CLI Postgres extension adds PostgreSQL database management capabilities to Google's Gemini CLI. It provides tools for query optimization, schema design, migration script generation, and database administration tasks. The extension connects to your PostgreSQL instance and lets the AI agent interact with your database directly from the terminal.

The extension targets developers and DBAs who use Gemini CLI and want AI-assisted database work. It handles the PostgreSQL-specific patterns that a general-purpose AI might get wrong: index suggestions, migration ordering, and query plan analysis.

§02

How it saves time or tokens

The extension gives Gemini CLI direct access to your database schema and query plans. Instead of copying CREATE TABLE statements and EXPLAIN output into prompts, the agent queries the database metadata directly. This means more accurate schema-aware suggestions with fewer tokens spent on context setup. Migration scripts are generated with proper dependency ordering based on actual foreign key relationships.

§03

How to use

  1. Install the extension:
gemini extensions install postgres
  1. Configure your PostgreSQL connection.
  1. Ask Gemini CLI to perform database tasks with full schema awareness.
§04

Example

Using the Postgres extension for query optimization:

-- Ask Gemini: 'Optimize this slow query'
SELECT u.name, COUNT(o.id) as order_count
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE o.created_at > '2026-01-01'
GROUP BY u.name
ORDER BY order_count DESC;

-- The extension:
-- 1. Runs EXPLAIN ANALYZE on the query
-- 2. Inspects existing indexes
-- 3. Suggests: CREATE INDEX idx_orders_user_created ON orders(user_id, created_at)
-- 4. Generates a migration script with the index

The agent reads the actual query plan and index state to make targeted optimization recommendations.

§05

Related on TokRepo

§06

Common pitfalls

  • The extension needs read access to pg_catalog and information_schema. Restricted database users may not provide enough metadata for accurate suggestions.
  • Migration scripts should always be reviewed before execution. AI-generated DDL can drop columns or change types in ways that lose data.
  • Connection strings with passwords in plain text should be stored in environment variables, not in shell history or config files.
  • Always check the official documentation for the latest version-specific changes and migration guides before upgrading in production environments.
  • For team deployments, establish clear guidelines on configuration and usage patterns to ensure consistency across developers.

Frequently Asked Questions

What database operations does this extension support?+

The extension supports query optimization via EXPLAIN analysis, schema design suggestions, migration script generation, index recommendations, and general database administration queries. It reads your actual schema to provide context-aware assistance.

Does it work with other databases besides PostgreSQL?+

No. This extension is specifically designed for PostgreSQL. It uses PostgreSQL-specific catalog queries, index types, and query plan formats. Other database dialects would need their own extensions.

Can the extension modify my database?+

The extension primarily provides read access for analysis and generates scripts for you to review and execute. Whether it can execute modifications depends on the permissions of the configured database user. Use a read-only user for safety.

How does query optimization work?+

The extension runs EXPLAIN ANALYZE on your query, inspects existing indexes, analyzes table statistics, and suggests index additions or query rewrites. Recommendations are based on actual query plan data, not just SQL syntax analysis.

Is my database data sent to Google?+

Schema metadata and query plans are sent to Google's Gemini API for analysis. Actual row data is not sent unless you explicitly ask the agent to query and process specific records. Review your data sensitivity requirements before connecting.

Citations (3)
🙏

Source & Thanks

Created by Google. Licensed under Apache 2.0. gemini-cli-extensions/postgres Part of Gemini CLI — ⭐ 99,400+

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets