Brian Achaye
Brian Achaye

Data Scientist

Data Analyst

ODK/Kobo Toolbox Expert

BI Engineer

Data Solutions Consultant

Brian Achaye

Data Scientist

Data Analyst

ODK/Kobo Toolbox Expert

BI Engineer

Data Solutions Consultant

Articles

How to Set Up PostgreSQL, Use It in VS Code, and Publish to GitHub

How to Set Up PostgreSQL, Use It in VS Code, and Publish to GitHub

PostgreSQL is a powerful open-source relational database, and VS Code is a lightweight yet powerful code editor. In this guide, you’ll learn:
✔ How to install PostgreSQL on your machine.
✔ How to connect and query PostgreSQL in VS Code.
✔ How to save your SQL scripts to GitHub.

Step 1: Install PostgreSQL

1. Download & Install

  • Windows/macOS/Linux: Download from PostgreSQL Official Site.
  • Follow the installer (remember your password—you’ll need it later).

2. Verify Installation

  • Open Command Prompt (Windows) or Terminal (macOS/Linux) and run:shCopypsql –versionIf installed correctly, you’ll see the version number.

Step 2: Set Up a Database

1. Launch PostgreSQL Shell

  • Open pgAdmin (GUI tool) or psql (command line).
  • For psql, run:shCopypsql -U postgres(Default username: postgres)

2. Create a Database

CREATE DATABASE test_db;
\c test_db  -- Connect to the database

3. Create a Table (Example)

CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100),
    email VARCHAR(100) UNIQUE
);

Step 3: Connect PostgreSQL in VS Code

1. Install Extensions

  • Open VS Code → Extensions (Ctrl+Shift+X) → Install:
    • SQLTools (Database client)
    • SQLTools PostgreSQL Driver

2. Connect to PostgreSQL

  • Press Ctrl+Shift+PSQLTools: Add New Connection → Choose PostgreSQL.
  • Fill in details:CopyHost: localhost Port: 5432 User: postgres Password: (your password) Database: test_db
  • Click Save & Connect.

3. Run SQL Queries

  • Open a new file (Ctrl+N) → Save as query.sql.
  • Type a query:sqlCopyINSERT INTO users (name, email) VALUES (‘John Doe', ‘john@example.com'); SELECT * FROM users;
  • Right-click → Execute Query.

Step 4: Publish to GitHub

1. Initialize Git

  • Open Terminal in VS Code (Ctrl+ `).
  • Run:shCopygit init git add . git commit -m “Initial PostgreSQL project”

2. Create a GitHub Repository

  • Go to GitHub → Create a new repo (e.g., postgresql-vscode-demo).

3. Push to GitHub

  • Link your local project to GitHub:shCopygit remote add origin https://github.com/yourusername/postgresql-vscode-demo.git git branch -M main git push -u origin main

Final Checks

PostgreSQL is running.
VS Code connects to the database.
GitHub has your SQL scripts.

Need help? Drop a comment below! 👇

Related Posts
Write a comment