DEV Community

Sugumar R
Sugumar R

Posted on

PSQL Day: 2

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.

AWS Q Developer image

Your AI Code Assistant

Implement features, document your code, or refactor your projects.
Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay