Connecting to PostgreSQL and Managing Databases

Intermediate

🔗 Connecting to and Managing PostgreSQL Databases

PostgreSQL offers both command-line tools and GUI clients for managing databases.


🖥️ Connection Methods

  • 🛠️ Command-line: psql
  • 📊 GUI: pgAdmin

🆕 Create a New Database

CREATE DATABASE mydatabase;

🔌 Connect to the Database

psql -d mydatabase -U postgres

💾 Backup and Restore

📤 Export with pg_dump:

pg_dump mydatabase > mydatabase_backup.sql

📥 Restore with psql:

psql mydatabase < mydatabase_backup.sql

🧰 These tools facilitate efficient database management for both development and production environments.