Posts

Showing posts from March, 2026

Creating a dns hosted zone in route 53 in aws

 Creating a dns hosted zone in route 53 in aws In this task, we create a dns hosted zone using Amazon Web Services. this helps us manage domain names and connect them to resources like servers or websites. First, go to the aws console and open the route 53 service. route 53 is used for domain name system (dns) management. Next, click on hosted zones and then click create hosted zone. enter your domain name (example: mywebsite.com). choose type as public hosted zone so it can be accessed from the internet. then click create. After creating the hosted zone, aws will automatically generate name servers (ns records). these name servers must be added to your domain registrar (like godaddy) so that your domain points to aws. Now, you can create records inside the hosted zone. for example, you can create an  record to connect your domain to an ec2 public ip address. Once everything is set, it may take some time for dns to update. after that, your domain will start working and point t...

Creating a simple ec2 instance and running a web server

  Creating a simple ec2 instance and running a web server In this task, we create a virtual server using Amazon Web Services and run a simple web server. Then we access it from the internet using its public IP address. First, go to the AWS console and open the EC2 service. Click launch instance and choose an operating system like amazon linux. Select the instance type t2.micro. Create or select a key pair and configure the security group to allow ssh (port 22) and http (port 80). After that, launch the instance. Next, connect to the instance using SSH from the terminal with the .pem key file. After logging in, update the system and install the apache web server. Apache is used to host web pages on the server. Once installed, start the apache service so the server begins running. Finally, copy the public IP address of the EC2 instance and open it in a web browser. When the IP address is entered, the default apache web page will appear. This confirms that the web server is runn...

Select Queries from DVD Rental database

  Select Queries from DVD Rental database 1. Retrieve film titles and rental rates with aliases select title as "Movie Title" , rental_rate as "Rate" from film; 2. List customer names and email with aliases select first_name as "First Name" , last_name as "Last Name" , email from customer; 3. Films sorted by rental rate (desc), then title (asc) select title, rental_rate from film order by rental_rate desc , title asc ; 4. Actor names sorted by last name, then first name select first_name, last_name from actor order by last_name, first_name; 5. Unique replacement costs select distinct replacement_cost from film; 6. Film title and length with alias select title, length as "Duration (min)" from film; 7. Customer names with active status select first_name, last_name, active as "Is Active" from customer; 8. Film categories sorted alphabetically select name from category order by name; 9....

Basic Select SQL Queries

Image
  Basic Select SQL Queries The select statement is used to get data from a table. We can either select all columns using * or choose only the columns we need. The where clause is used to filter rows based on conditions such as id, country, or population. This helps in getting only the required data. Sometimes the result may contain repeated values, so distinct is used to remove duplicates. For searching text based on patterns, like can be used. Aggregate functions such as count help perform calculations on the data.

Filter Assignments

  Filter Assignments: 1. Get movies with rental rate greater than 3 SELECT title, rental_rate FROM film WHERE rental_rate > 3; 2. Rental rate > 3 and replacement cost < 20 SELECT title, rental_rate, replacement_cost FROM film WHERE rental_rate > 3 AND replacement_cost < 20; 3. Rated PG or rental rate 0.99 SELECT title, rating, rental_rate FROM film WHERE rating = 'PG' OR rental_rate = 0.99; 4. Top 10 movies by rental rate SELECT title, rental_rate FROM film ORDER BY rental_rate DESC LIMIT 10; 5. Skip 5 and get next 3 SELECT title, rental_rate FROM film ORDER BY rental_rate ASC OFFSET 5 LIMIT 3; 6. Skip 5 and get next 3 SELECT title, rental_rate FROM film ORDER BY rental_rate ASC OFFSET 5 FETCH NEXT 3 ROWS ONLY; 7. Rental duration between 3 and 7 SELECT title, rental_duration FROM film WHERE rental_duration BETWEEN 3 AND 7; 8. Title starts with A and ends with e SELECT title FROM film WHERE title LIKE 'A%e'; 9. Customers without email SELECT first_name, la...

CREATE TABLES

 CREATE TABLES: 1. Students table with unique id create table students (id serial primary key, name text, age int); Ensuring primary key that each student is uniquely identified. 2. Employees table where name and email cannot be NULL create table employees (id serial primary key, name text not null, email text not null, phone_number text); Here,not null ensures that it cannot be empty(for name and email) 3. Users table where username and email are unique create table users (id serial primary key, username text unique, email text unique); Usernames and emails will be unique and duplicates are avoided. 4. Products table with price > 0 and stock >= 0 create table products (id serial primary key, name text, price numeric check (price > 0), stock int check (stock >= 0)); Chech ensures that valid price and non-negative stock. 5. Orders table with default values create table orders (id serial primary key, status text default 'pending', created_at timestamp default current...

ALTER TABLES

 ALTER TABLES: 1. Make email NOT NULL in customers ALTER TABLE customers ALTER COLUMN email SET NOT NULL; Ensures that all the future records must have an email. 2. Make username unique in users ALTER TABLE users ADD CONSTRAINT unique_username UNIQUE (username); Prevents duplicate usernames and it is unique. 3. Add CHECK on price in products ALTER TABLE products ADD CONSTRAINT check_price CHECK (price > 0); Ensures price is always greater than 0 using alter command. 4. Set default status in orders ALTER TABLE orders ALTER COLUMN status SET DEFAULT 'pending'; Automatically assigns pending if no value is given during insertion. 5. Add salary column with constraints ALTER TABLE employees ADD COLUMN salary INT NOT NULL CHECK (salary > 10000); Ensures salary is mandatory and above 10,000 and it cannot be NULL. 6. Add ON DELETE CASCADE to foreign key ALTER TABLE employees DROP CONSTRAINT employees_department_id_fkey; ALTER TABLE employees ADD CONSTRAINT employees_department_id_...

Users, Roles, Groups

Image
  Users, Roles, Groups In database systems, it is important to control who can see or change the data. In real applications like websites or apps, different users should have different permissions depending on their role. To understand how this works, I tried a few tasks using the DVD Rental database in PostgreSQL. First, I created a role called report_user with login permission. I allowed this user to only read data from the film table. This means the user can see the data but cannot change or delete anything. Next, I tried to access the customer table using report_user. As expected, the database showed a permission denied error because that user did not have access to that table. After seeing this, I gave SELECT permission on the customer table so the user could read it. Then I tried something more specific. Instead of giving access to the whole customer table, I allowed report_user to see only a few columns: customer_id, first_name, and last_name. This shows how column-level per...

Idempotency Situation

Image
  Idempotency Situation In digital wallet apps like PhonePe or GPay, sometimes the same request can be sent more than once. If the system processes the same request many times, it can create wrong account balances. This is why idempotency is important. To understand this, I tried a small simulation using two accounts: Alice and Bob. At the beginning, their balances were: Alice = 600 Bob = 700 First, I performed a transfer of 200 from Alice to Bob. After the transfer, the balances became: Alice = 400 Bob = 900 This is correct because the transfer happened once. Then I repeated the same transfer again to simulate a duplicate request. After running the same operation again, the balances became: Alice = 200 Bob = 1100 This shows that the system processed the same request again. The amount was deducted and added one more time, even though the transfer was supposed to happen only once. From this simple test, we can see that if a system does not control duplicate requests, the data can be...

How DNS resolver is happening?

How DNS resolver is happening? The user makes an request, the DNS query will be initiated. At first, it goes to the local machine that is internally and it will, the system will check the cache, DHCP, etc. If the IP is ready, which is already present, it will return immediately. Or else it will go to the resolver, that is ISP. For example, like Jio, etc.  This resolver checks in its cache. If it has the IP, it will return. If not, it will move to further process. Then the resolver contacts the root name server. The root name server does not know the exact IP, but it knows where it is, like where the TLD servers are there. So it directs, it will give the direction, like there are three name servers like .org, .com, .in.  Then the resolver asks the, will ask the TLD, that is top level domain. Then it will ask the SLT, that is secondary level domain. Then it will ask the subdomain. Then the resolver asks the server, finally it will give the IP address.  Then the IP address i...

How a request originates from client and reaches the server ?

  How a request originates from client and reaches the server ? When we use the internet, a simple action like opening a website involves many steps happening in the background. It usually starts when a user enters a URL in the browser, for example www.example.com . The browser cannot directly communicate using this name because computers identify each other using IP addresses. So the browser first needs to find the IP address of that website. To do this, the browser performs DNS resolution. It first checks if the IP address is already stored in the system cache. If it is not found there, the request goes to a DNS resolver. The resolver then finds the correct IP address for the domain. Once the IP address is found, the client can start communicating with the server. The client creates a connection using a protocol such as TCP. If the website uses HTTPS, it is a secure connection . This step involves a handshake where the client and server agree on how they will communicate. Af...