DEV Community

Sugumar R
Sugumar R

Posted on

PSQL Day:

What is PostgreSQL?

PostgreSQL is a free, object-relational database management system whose development began in the 1980s and was first used in a public CVS server in July 1996. PostgreSQL was initiated by Michael Stonebraker, who researched and developed databases at the University of California. From his time at Berkeley, the database management system known today as PostgreSQL emerged.

PostgreSQL has been known by this name since the mid-1990s and has been available to all developers as open-source technology and has been continuously developed ever since. PostgreSQL is one of the most popular database management systems, which of course has to do with the fact that it has existed for so long, and the many competent developers have made the open-source project quite practical for a long time.

According to the StackOverflow “2021 Developers Survey” linked above, PostgreSQL is the second most-used database technology behind MySQL – and it’s rising steadily. Because while only about 26% of developers used it in 2017, it was already 34% in 2019 and by 2021 it was even more than 40%.

**** PostgreSQL vs MySQL: Features and Functions ***

Image description

SQL Commands in PostgreSQL:-

Example 1: Connecting to a Database

Open the CMD and execute the below-provided psql command to establish a connection to a particular database:

Image description

Example 2: Checking Postgres Version

Executing the “SELECT VERSION();” command will retrieve the currently installed Postgres version:

Image description

****Example 3: Listing All Databases

Listing available databases is a very common task in Postgres that can be accomplished via the “\l” command:

\l

Image description
The “\l” successfully retrieves the list of available databases.

****Example 4: Accessing/Switching a Database

Performing any operation on a database object requires accessing that database. To accomplish this task, execute the “\c” command from the “SQL Shell”:

\c sample_db;

Image description

The connection with the “sample_db” database has been established successfully.

***Example 5: Listing All Available Tables

In Postgres, the tables are used to represent the data elements in a well-organized format. Run the “\dt” command from SQL Shell to fetch the list of available tables/relations:
https://www.commandprompt.com/media/images/image_gMmra3M.width-1200.png

The stated command returns all the tables available in the selected database.

**Example 6: Describing All Tables

Postgres users can use the “\d” command to get the list of relations, including sequences, views, etc.

\d

Image description

The “\d” command successfully retrieves the “schema name”, “table name”, “relation type”, and owner.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay