Skillpedia
برمجة عامة48k · #5471

postgresql-cli

ما الذي تفعله

psql أداة تتيح لك التفاعل مع قواعد بيانات PostgreSQL مباشرة من الطرفية. يمكنك استخدامها لكتابة الأوامر وتشغيلها، وفحص المعلومات عن الجداول وغيرها من عناصر قاعدة البيانات.

متى تستخدمها

  • ✓عندما تحتاج إلى تنفيذ أوامر SQL على قاعدة بيانات PostgreSQL.
  • ✓للتحقق من بنية الجداول أو العروض أو غيرها من معلومات قاعدة البيانات.
  • ✓عند استيراد البيانات من قاعدة بيانات أو تصديرها.

رابط المهارة

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/postgresql-cli/SKILL.md

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/postgresql-cli/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“اتصل بقاعدة البيانات «my_database» بصفتك المستخدم «my_user» على المضيف «my_host»، ونفّذ الاستعلام «SELECT * FROM customers;».”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

تكتب أوامر في الطرفية للاتصال بقاعدة البيانات، ثم تكتب أوامر SQL الخاصة بك. يُنفذ psql هذه الأوامر ويعرض لك النتائج.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

psql — PostgreSQL Interactive Terminal

psql is PostgreSQL's feature-rich interactive terminal. It lets you write and execute queries, inspect database objects, import/export data, script batch operations, and customize output formatting — all from the command line.

Prerequisites

Before using psql, verify it is installed and available:

# Check if psql is installed
psql --version

# If not found, install PostgreSQL client tools:

# macOS (Homebrew)
brew install libpq
brew link --force libpq

# Ubuntu / Debian
sudo apt install postgresql-client

# CentOS / RHEL
sudo yum install postgresql

# Alpine
apk add postgresql-client

# Windows — install PostgreSQL via the official installer or use WSL

psql ships as part of the postgresql-client package. The server (postgresql) is not required — you only need the client to connect to a remote PostgreSQL instance.

Quick Reference

Connecting

# 1. CLI flags
psql -h host -p port -U user -d dbname

# 2. Connection URI
# WARNING: Password in URI is visible in shell history and process listings.
#          Prefer ~/.pgpass for production use (see method 4 below).
psql "postgresql://user:YOUR_PASSWORD@host:port/dbname"

# 3. Environment variables (no flags needed)
export PGHOST=localhost
export PGPORT=5432
export PGDATABASE=mydb
export PGUSER=postgres
# WARNING: PGPASSWORD is visible in process listings (e.g. `ps aux`).
#          Use ~/.pgpass in production instead.
export PGPASSWORD=YOUR_PASSWORD
psql                       # picks up all params from env

# 4. ~/.pgpass file (RECOMMENDED for passwords)
#    Format: hostname:port:database:username:password
touch ~/.pgpass && chmod 600 ~/.pgpass
# Then manually edit ~/.pgpass and add entries (avoids password in shell history):
# hostname:port:database:username:password
# Example: localhost:5432:mydb:postgres:YOUR_PASSWORD
psql -h localhost -U postgres -d mydb   # no password prompt

# 5. Execute and exit
psql -f script.sql dbname                        # execute file then exit
psql -c "SELECT 1" dbname                        # run single command then exit
psql -1 -f migration.sql dbname                  # run in single transaction

# 6. Service connection (reads from pg_service.conf)
psql service=mydb_prod

# 7. Reconnect within a session
\c dbname                                       # reconnect to different db
\c -reuse-previous=on sslmode=require           # change only sslmode
\c "host=newhost port=5432 dbname=mydb"         # conninfo string

On connection failure: interactive mode keeps the previous connection; script mode closes it and all subsequent database commands fail until the next successful \c.

Key flags: -h host, -p port, -U user, -d database, -w no password prompt, -W force password prompt, -1 single transaction, -f execute file, -c execute command, -t tuples only, -x expanded, -A unaligned, -E echo hidden queries (\d internals), -L log file, -X skip ~/.psqlrc.

Connection precedence: CLI flags > environment variables > pg_service.conf > defaults. Password precedence: connection string/password flag > PGPASSWORD env > ~/.pgpass. Use ~/.pgpass instead of PGPASSWORD in production — PGPASSWORD is visible in process listings (ps aux).

Object Inspection (\d family)

Command Shows
\d All tables, views, materialized views, sequences, foreign tables (equiv.\dtvmsE)
\dP Partitioned tables
\dt Tables only
\dv Views only
\di Indexes only
\ds Sequences only
\dm Materialized views only

…

الأسئلة الشائعة

هل أحتاج إلى تثبيت PostgreSQL كاملاً لاستخدام psql؟

لا، تحتاج فقط إلى تثبيت postgresql-client الذي يحتوي على أداة psql. ويمكنها الاتصال بقواعد بيانات PostgreSQL على حواسيب أخرى.

كيف أتصل بقاعدة بيانات؟

يمكنك الاتصال بأمر مثل `psql -h host -p port -U user -d dbname`. وهناك طرق أخرى، مثل استخدام متغيرات البيئة أو ملف الإعداد.

كيف أرى الجداول في قاعدة بيانات؟

بعد الاتصال، اكتب `\dt` في الطرفية لعرض كل الجداول.

التفاصيل

الوصف الأصلي من المؤلف

PostgreSQL interactive terminal (psql) reference and usage guide.

repo: sickn33/agentic-awesome-skills

الشعبية

نجوم GitHub
48k
الترتيب
#5471
الترخيص
MIT
آخر تحديث
15‏/10‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة