postgres
PostgreSQL database management for day-to-day operations. Use when the user needs to run SQL queries, inspect schemas, manage tables, monitor performance, handle backups, or administer a PostgreSQL database via psql or DATABASE_URL.
What this skill does
# PostgreSQL ๐ PostgreSQL database management โ queries, schema inspection, inserts, updates, and performance monitoring. ## Setup ```bash export DATABASE_URL="postgresql://user:pass@localhost:5432/dbname" ``` Connect using psql: ```bash psql "$DATABASE_URL" # or psql -h localhost -U user -d dbname ``` ## Azure PostgreSQL (Entra ID Authentication) For Azure-hosted PostgreSQL, **prefer Entra ID authentication** over password-based authentication. Connect using the logged-in user's Entra ID: ```bash # Get Entra ID access token az account get-access-token --resource-type oss-rdbms --query accessToken -o tsv | \ psql "host=myserver.postgres.database.azure.com port=5432 dbname=mydb [email protected] sslmode=require" --set=PGPASSWORD=$(cat) ``` Or set the token as an environment variable: ```bash export PGPASSWORD=$(az account get-access-token --resource-type oss-rdbms --query accessToken -o tsv) psql "host=myserver.postgres.database.azure.com port=5432 dbname=mydb [email protected] sslmode=require" ``` **Benefits:** - No password management required - Centralized identity and access management - Automatic token rotation - Enhanced security with MFA support **Note:** The username must match the Entra ID identity (e.g., `[email protected]` or the managed identity name). ## Essential psql Meta-Commands | Command | Description | |---|---| | `\l` | List all databases | | `\c dbname` | Connect to a database | | `\dt [pattern]` | List tables (optionally filtered) | | `\d tablename` | Describe a table (columns, types, constraints) | | `\d+ tablename` | Describe with extra detail (storage, comments) | | `\di` | List indexes | | `\dv` | List views | | `\df` | List functions | | `\dn` | List schemas | | `\du` | List roles/users | | `\conninfo` | Show current connection info | | `\timing` | Toggle query timing | | `\x` | Toggle expanded output mode | | `\e` | Open query in `$EDITOR` | | `\i file.sql` | Execute SQL from a file | | `\o file.txt` | Send output to a file | | `\q` | Quit | ## Common Operations ### Query ```sql SELECT * FROM users LIMIT 10; SELECT column1, column2 FROM table WHERE condition ORDER BY column1 DESC; ``` ### Insert / Update / Delete ```sql INSERT INTO users (name, email) VALUES ('Alice', '[email protected]'); UPDATE users SET email = '[email protected]' WHERE id = 1; DELETE FROM users WHERE id = 1; ``` ### Schema ```sql -- Create table CREATE TABLE orders ( id SERIAL PRIMARY KEY, user_id INT REFERENCES users(id), total NUMERIC(10,2), created_at TIMESTAMPTZ DEFAULT NOW() ); -- Add / drop column ALTER TABLE orders ADD COLUMN status TEXT DEFAULT 'pending'; ALTER TABLE orders DROP COLUMN status; -- Create index CREATE INDEX CONCURRENTLY idx_orders_user_id ON orders(user_id); ``` ### Transactions ```sql BEGIN; UPDATE accounts SET balance = balance - 100 WHERE id = 1; UPDATE accounts SET balance = balance + 100 WHERE id = 2; COMMIT; -- or ROLLBACK; to undo ``` ## Performance & Monitoring ```sql -- Slow queries (requires pg_stat_statements extension) SELECT query, calls, mean_exec_time, total_exec_time FROM pg_stat_statements ORDER BY mean_exec_time DESC LIMIT 10; -- Active connections SELECT pid, usename, application_name, state, query FROM pg_stat_activity WHERE state != 'idle'; -- Table sizes SELECT relname AS table, pg_size_pretty(pg_total_relation_size(relid)) AS total_size FROM pg_catalog.pg_statio_user_tables ORDER BY pg_total_relation_size(relid) DESC; -- Explain query plan EXPLAIN ANALYZE SELECT * FROM orders WHERE user_id = 42; -- Kill a blocking query SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid = <pid>; ``` ## Backup & Restore ```bash # Dump a database pg_dump "$DATABASE_URL" -Fc -f backup.dump # Restore pg_restore -d "$DATABASE_URL" backup.dump # Plain SQL dump pg_dump "$DATABASE_URL" > backup.sql psql "$DATABASE_URL" < backup.sql ``` ## Copy (Bulk Import/Export) ```bash # Export table to CSV psql "$DATABASE_URL" -c "\copy orders TO 'orders.csv' CSV HEADER" # Import CSV into table psql "$DATABASE_URL" -c "\copy orders FROM 'orders.csv' CSV HEADER" ``` ## Safety Rules 1. **Always confirm** before running `DELETE`, `DROP`, or `TRUNCATE` 2. **Always backup** before schema migrations 3. **Use transactions** for multi-step data changes 4. Use `EXPLAIN ANALYZE` to preview query plans before running on large tables 5. Prefer `CREATE INDEX CONCURRENTLY` to avoid locking tables in production ## Reference Full psql documentation: <https://www.postgresql.org/docs/current/app-psql.html> Retrieve and read this page if you need meta-commands, options, or behaviour not covered above.
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only โ no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.