DEV Community

Cover image for POSTGRESQL
G Gokul
G Gokul

Posted on

POSTGRESQL

Database:

  • A database is an organized collection of digital data stored in a computer system.
  • It lets people and apps find, change, and save information fast.

use of database:

  • speed
  • safety

types of database:

Relational (SQL):

  • Structured Query Language
  • Stores data in tables with rows and columns, like a spreadsheet.
  • Great for banking or user lists.
  • Examples are MySQL and PostgreSQL and SQLite.

Non-Relational (NoSQL):

  • not only sql
  • Uses flexible formats like documents or key-values instead of rigid tables.
  • Great for messy or fast-changing data.
  • Examples are MongoDB and Firebase.

Cloud:

  • Runs on cloud platforms, making it easy to scale up without local hardware.

Difference between sql and nosql

db

DBMS:

  • A Database Management System (DBMS) is a software tool used to create, store, manage, and retrieve data in a database.
  • It acts as a safe bridge between the user or application and the actual data, keeping everything organized, secure, and easy to access.

Key Functions of a DBMS:

  • Data Storage
  • CRUD Operations
  • Security
  • Multi-User Access
  • Backup and Recovery

RDBMS:

  • RDBMS stands for Relational Database Management System, a software program that stores data in structured, tabular formats of rows and columns using tables linked by keys.

Difference between dbms and rdbms:

db

PostgreSQL :

  • PostgreSQL (often called Postgres) is a free, open-source relational database management system.
  • It stores data in tables with rows and columns, uses the SQL language, and is famous for being very reliable, fast, and safe with data.

why postgresql?

  • PostgreSQL is a top choice for developers because it is a free, open-source relational database that balances strict ACID compliance and data safety with extreme flexibility, powerful JSON support, and a vast ecosystem of extensions.

Key Features:

  • Open Source
  • ACID Compliant
  • Flexible
  • Extensible

ORDBMS :

  • ORDBMS stands for Object-Relational Database Management System.
  • It is a database system that mixes a standard relational database with object-oriented programming features.
  • It lets you store data in normal tables while also supporting complex data types, classes, and inheritance.

Difference between postgresql and mysql:

db

SUDO:

  • The term sudo is a command used in Linux, macOS, and other Unix-like operating systems.
  • It stands for "superuser do" or "substitute user do".
  • It lets an authorized user run a program with the security power of another user, usually the system administrator or root.

APT:

  • APT (short for Advanced Package Tool) is the default command-line software management system used by Debian and its derivative Linux distributions, including Ubuntu, Linux Mint, and Pop!_OS.
  • It acts like an "app store" for your terminal, allowing you to easily find, install, update, and delete software packages.

PostgreSQL Installation:

use this command

sudo apt install postgresql postgresql-contrib
Enter fullscreen mode Exit fullscreen mode

to check the status of postgresql is active or not

sudo systemctl status postgresql
Enter fullscreen mode Exit fullscreen mode

p

sudo -i -u postgres
Enter fullscreen mode Exit fullscreen mode

this command used to run a specific command as the postgres user.

psql
Enter fullscreen mode Exit fullscreen mode

psql is the terminal-based interactive command-line interface for PostgreSQL, allowing you to type, execute, and manage SQL queries and database structures directly.

to create a database

create database cinemas;
Enter fullscreen mode Exit fullscreen mode

db
use this command to connect database with user

\c cinemas;
Enter fullscreen mode Exit fullscreen mode

to know the version of postgreSQL using this command

select version();
Enter fullscreen mode Exit fullscreen mode

postgresql 16.14

to create a table

create table movie
(
movie_name varchar(80),
release_date date,
ticket int
);
Enter fullscreen mode Exit fullscreen mode

db
to insert values to a table

insert into movie values('jananayagan','2026-07-15', 120);
Enter fullscreen mode Exit fullscreen mode

to insert a value based on columns name

insert into movie (release_date, movie_name, ticket) values ('2025-01-10','sirai', 120);
Enter fullscreen mode Exit fullscreen mode

we can also insert values without some values

insert into movie(movie_name, ticket) values ('karuppu',120);
Enter fullscreen mode Exit fullscreen mode

db
to read a table using this command

select * from movie;
Enter fullscreen mode Exit fullscreen mode

db

Top comments (0)