Querying rows from PostgreSQL from Go lang project

Introduction

In the last post Updating/Deleting rows with Go, we learned to manipulate rows in PostgreSQL database in Go project using database/sql package that ships with Go, along with github.com/lib/pq Postgres driver. In this post, we’ll learn how to query rows i.e. SELECT

Continue reading “Querying rows from PostgreSQL from Go lang project”

Connecting to PostgreSQL from Go lang project

Introduction

The Go programming language, sometimes referred to as Go lang, is making strong gains in popularity. Chances are if you are a Go developer, you will have to interact with SQL at some point in your project. This blog post will show how to connect to a PostgreSQL database from Go using database/sql package.

Continue reading “Connecting to PostgreSQL from Go lang project”

Connect to PostgreSQL in VS Code

To connect to PostgreSQL from Visual Studio Code (VS Code), you can use an extension called “PostgreSQL” which provides a graphical interface to interact with your PostgreSQL database.

Install Link – PostgreSQL extension

Connecting to PostgreSQL from VS Code provides several benefits, including:

    • Connect to PostgreSQL instances
    • Manage connection profiles
    • Connect to a different Postgres instance or database in each tab
    • View object DDL with ‘Go to Definition’ and ‘Peek Definition’
    • Write queries with IntelliSense
    • Run queries and save results as JSON, csv, or Excel

Install VS Code PostgreSQL extension

  1. Install the “PostgreSQL” extension in VS Code. You can do this by opening the Extensions view (Ctrl + Shift + X), searching for “PostgreSQL” in the search bar, and clicking on “Install” next to the “PostgreSQL” extension by Microsoft.

  2. Open the “PostgreSQL” extension by clicking on its icon in the Activity Bar (left sidebar).
    a

QuickStart

  1. Open the Command Palette Ctrl + Shift + P  (On mac use  ⌘ + Shift + P)
  2. Search and select PostgreSQL: New Query
  3. In the command palette, select Create Connection Profile. Follow the prompts to enter your Postgres instance hostname, database, username, and password.

a

You are now connected to your Postgres database. You can confirm this via the Status Bar (the ribbon at the bottom of the VS Code window). It will show your connected hostname, database, and user.

Query the database

  1. Type a query ex. SELECT * FROM pg_stat_activity;
  2. Right-click, select Execute Query / keyboard shortcut [⌘M ⌘R] and the results will show in a new window.
  3. You can also save the query results as JSONCSV or Excel.

So now, you can seamlessly code for PostgreSQL from Microsoft VS Code without switching screens, leverage powerful intellisense and execute queries.

Enjoy Coding!

IMP NOTE: Result windows from queries won´t show up again after being closed. This is bug with current version and is being worked by dev team. Workaround is either to keep the result window Open Or close / re-open the VS code window.

 

Site Reliability Engineering: How Google Runs Production Systems – Book Review

Essential Read for anyone managing highly available distributed systems at scale

First off – It’s worth let you know that Google lets you read this “entire” book online for free on their website. Yes you read it right, you don’t need to buy the book, just click on below link – https://landing.google.com/sre/sre-book/toc/index.html and start reading!

Continue reading “Site Reliability Engineering: How Google Runs Production Systems – Book Review”