postgresql
Skill0 starsChanged 7 months agoMITView on GitHub
PostgreSQL database patterns. TRIGGER when: SQL query, migration, psql, PostgreSQL, pg, database schema, CREATE TABLE, SELECT JOIN, INDEX, backup, pg_dump, БД запрос, DB query, миграция базы данных, database migration, таблица пользователей, users table, транзакция, transaction, база данных, database. Stack: Node.js pg/postgres driver on Beget VPS.
- Reads credentials
12 other projects use a version of this.
Adopted by
Most recently taken up by
- lawless-m/claude-skillstheir own version, first seen Oct 4, 2026
- iliaal/ai-skillstheir own version, first seen Oct 3, 2026
- speakeasy-api/gramtheir own version, first seen Oct 1, 2026
- stonegiantstudio/skillstheir own version, first seen Sep 29, 2026
- TheHiddenDeveloper/jarvis-skillstheir own version, first seen Aug 19, 2026
- anurag-azure/skillstheir own version, first seen Jun 27, 2026
Other versions12 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 12
- speakeasy-api/gram★ 271same name
- iliaal/ai-skills★ 43same name
- kumaran-is/claude-code-onboarding★ 36same name
- xfstudio/skills★ 9same name
- lawless-m/claude-skills★ 6same name
- ai4brands-design/claude-skills★ 2same name
- ffsshhttiikk/opencode-agents-skills★ 2same name
- Sorcha-Platform/Sorcha★ 2same name
- stonegiantstudio/skills★ 2same name
- jornalistainclusivo/jinc-skills★ 1same name
2 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository15 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- api-scaffoldSkill
- content-agentSkill
- db-healthSkill
- debug-serverSkill
- deploySkill
- git-workflowSkill
- log-monitorSkill
- max-apiSkill
- new-featureSkill
- notebooklmSkill
- qa-agentSkill
- security-checkSkill
- ui-ux-pro-maxSkill
- web-proSkill
The file
Files
PostgreSQL — Patterns and Commands
Connection (Node.js)
const { Pool } = require('pg');
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
// or
host: process.env.DB_HOST,
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASS,
port: 5432,
});
// Query
const { rows } = await pool.query('SELECT * FROM users WHERE id = $1', [id]);Common Patterns
Upsert (INSERT or UPDATE)
INSERT INTO settings (key, value)
VALUES ('token', 'xxx')
ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value;Pagination
SELECT * FROM orders
ORDER BY created_at DESC
LIMIT $1 OFFSET $2;
-- OFFSET = (page - 1) * limitJSON Field
-- Save
UPDATE users SET meta = $1::jsonb WHERE id = $2;
-- Read a field
SELECT meta->>'name' FROM users WHERE id = $1;Transaction
const client = await pool.connect();
try {
await client.query('BEGIN');
await client.query('UPDATE ...', [...]);
await client.query('INSERT INTO ...', [...]);
await client.query('COMMIT');
} catch (e) {
await client.query('ROLLBACK');
throw e;
} finally {
client.release();
}Migrations (without ORM)
// migrations/001_add_column.sql
ALTER TABLE users ADD COLUMN IF NOT EXISTS phone VARCHAR(20);
CREATE INDEX IF NOT EXISTS idx_users_phone ON users(phone);psql -U user -d dbname -f migrations/001_add_column.sqlpsql Commands
psql -U fuji -d fujidb # connect
\dt # list tables
\d tablename # table structure
\q # exit
# Quick query without entering psql
psql -U fuji -d fujidb -c "SELECT COUNT(*) FROM users;"Backup and Restore
# Backup
pg_dump -U fuji fujidb > backup_$(date +%Y%m%d).sql
# Restore
psql -U fuji_user fuji_routes < backup.sqlIndexes — When to Add
-- On fields used in WHERE and JOIN conditions
CREATE INDEX idx_orders_user_id ON orders(user_id);
CREATE INDEX idx_orders_status ON orders(status) WHERE status != 'done';
-- Check slow queries
EXPLAIN ANALYZE SELECT * FROM orders WHERE user_id = 123;Errors and Solutions
| Error | Cause | Solution |
ECONNREFUSED | DB not running | systemctl start postgresql |
password auth failed | Wrong password in .env | Check DB_PASS |
relation does not exist | Table not created | Apply migration |
duplicate key value | Uniqueness violation | Use ON CONFLICT |
too many connections | Connection leak | pool.release() in finally |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

