Thursday, June 11, 2026

Implementing Oracle Database Security: VPD, Data Redaction, Database Vault, and TDE End-to-End

Implementing Oracle Database Security: VPD, Data Redaction, Database Vault, and TDE End-to-End


VPD (Virtual Private Database / Row-Level Security)

What it is: Oracle security feature implemented through the DBMS_RLS package for Fine-Grained Access Control (FGAC).

Description:
VPD is Oracle's Fine-Grained Access Control mechanism that dynamically restricts row visibility by attaching security policies to database objects. Oracle automatically appends policy predicates to SQL statements during parse time, ensuring users only access authorized rows without requiring application code changes.

Technical Key Points
Implemented using DBMS_RLS
Policy metadata stored in DBA_POLICIES
Policy function executes during SQL parse phase
Predicate dynamically appended to SQL statement
Query rewrite occurs transparently to application
Supports SELECT, INSERT, UPDATE, DELETE
Can use Application Context (DBMS_SESSION, SYS_CONTEXT)
Supports Static, Dynamic, Shared Context-Sensitive policies
Predicate becomes part of optimizer execution plan
Index design must consider VPD predicates
Policy evaluation introduces parse-time overhead
UPDATE_CHECK=>TRUE validates DML against policy rules
Users with EXEMPT ACCESS POLICY bypass VPD
Enforcement occurs inside kernel, not application layer
Works across SQL*Plus, JDBC, ODBC, EBS, APEX and custom applications
Commonly used for tenant isolation and data segregation


Data Redaction (Column-Level Masking)

What it is: Oracle Advanced Security feature implemented through the DBMS_REDACT package for runtime column masking.

Description:
Data Redaction is a runtime data protection feature that masks sensitive column values before they are returned to the client. The original data remains unchanged in the database, while different users can receive different representations of the same data based on security policies.

Technical Key Points
Implemented using DBMS_REDACT
Metadata stored in REDACTION_POLICIES
Runtime protection mechanism
Original data remains unchanged in database blocks
Redaction applied after row retrieval and before result delivery
Supports Full, Partial, Random and Regex redaction
Policy expressions evaluated per session
No modification to underlying table data
Transparent to applications
Can protect PII, PCI and PHI data
Introduces CPU overhead proportional to rows returned
Does not protect datafiles, backups, redo or undo
Does not prevent direct object access
Primarily a presentation-layer security feature
Often used for PCI-DSS and privacy compliance


Database Vault

What it is: Oracle Database Security Option that uses Realms, Rule Sets, Factors, and Command Rules to control privileged-user access.

Description:
Database Vault is Oracle's privileged-access security framework that enforces separation of duties and restricts access to sensitive data even for highly privileged users such as DBAs and SYS accounts. It provides protection against insider threats and unauthorized administrative access.

Technical Key Points
Uses Realms, Rule Sets, Factors, Command Rules
Security metadata stored in DVSYS schema
Enforces separation of duties
Restricts SYS and powerful administrative accounts
Realm protection overrides traditional object privileges
Protects application schemas from privileged access
Prevents insider-threat data exposure
Controls DDL and administrative operations
Supports Secure Application Roles
Integrates with Unified Auditing
Supports conditional access decisions
Frequently used for SOX, PCI-DSS, HIPAA compliance
Does not encrypt data
Does not provide row filtering
Operates above privilege management layer

Transparent Data Encryption (TDE)

What it is: Oracle encryption framework managed through Wallet/Keystore and ADMINISTER KEY MANAGEMENT commands.

Description:
Transparent Data Encryption (TDE) protects sensitive information by encrypting data at rest within Oracle datafiles, tablespaces, backups, and storage media. Encryption and decryption occur transparently within the database engine, requiring no application modifications.

Technical Key Points
Encrypts data at rest
Uses Oracle Wallet / Keystore
Managed through ADMINISTER KEY MANAGEMENT
Supports Tablespace TDE and Column TDE
Encryption performed below SQL layer
Applications require no code changes
Encryption keys stored outside database objects
Uses key hierarchy architecture
Master Encryption Key protects Data Encryption Keys
Protects datafiles, backups and exported storage
Integrates with RMAN and Data Guard
Supports online key rotation
Supports HSM integration
Decryption occurs transparently during block access
Does not restrict authorized database access
Does not replace access control mechanisms

VPD is implemented through the DBMS_RLS package, Data Redaction through the DBMS_REDACT package, Database Vault through DVSYS-managed security components such as Realms and Rule Sets, and TDE through Oracle's keystore and key-management framework using ADMINISTER KEY MANAGEMENT commands.

Friday, May 15, 2026

What is a List in Python?

What is a List in Python?

A list is a container that holds multiple items in a single variable, in a specific order.

How to Create a Lists:

# Empty list
my_list = []

# List of numbers
numbers = [1, 2, 3, 4, 5]

# List of strings
names = ["Alice", "Bob", "Charlie"]

# Mixed list (different data types)
mixed = [1, "hello", 3.14, True]

# List inside a list (nested)
nested = [[1, 2], [3, 4], [5, 6]]

Accessing Items — Indexing

fruits = ["apple", "banana", "mango", "orange"]

#index 0 1 2 3

print(fruits[0]) # apple ← first item
print(fruits[2]) # mango ← third item
print(fruits[-1]) # orange ← last item (negative index)
print(fruits[-2]) # mango ← second from last

Slicing a List

fruits = ["apple", "banana", "mango", "orange", "grape"]

print(fruits[1:3]) # ["banana", "mango"] ← index 1 to 2
print(fruits[:3]) # ["apple","banana","mango"] ← start to index 2
print(fruits[2:]) # ["mango","orange","grape"] ← index 2 to end
print(fruits[::2]) # ["apple","mango","grape"] ← every 2nd item

Most Used List Methods

fruits = ["apple", "banana", "mango"]

# ADD items

fruits.append("orange") # adds to END → ["apple","banana","mango","orange"]
fruits.insert(1, "grape") # adds at index 1 → ["apple","grape","banana"...]

# REMOVE items

fruits.remove("banana") # removes by VALUE
fruits.pop() # removes LAST item
fruits.pop(0) # removes item at index 0

# FIND items

print(len(fruits)) # total count of items
print(fruits.index("mango")) # finds index of "mango"
print("apple" in fruits) # True/False — does it exist?

# SORT items

fruits.sort() # sorts A→Z or small→big
fruits.sort(reverse=True) # sorts Z→A or big→small
fruits.reverse() # reverses the order

# COPY & CLEAR

copy = fruits.copy() # makes a copy of the list
fruits.clear() # empties the entire list

Looping Through a List

fruits = ["apple", "banana", "mango"]

# Basic loop
for fruit in fruits:
print(fruit)

# apple
# banana
# mango

# Loop with index

for i, fruit in enumerate(fruits):
print(i, fruit)

# 0 apple
# 1 banana
# 2 mango

# creating a simple list in python

groceries = ["Apple", "Banana", "Pineapple", "Cherry"]
print(groceries)

# Accessing elements

groceries = ["milk", "noodles", "bread"]
print(groceries[2])
print(groceries[-1])

# Modifying a list:

my_list = ["apple", "banana", "cherry", "pineapple"]
print(my_list)

my_list[0] = "strawberry"
print(my_list)

# Adding elements:

my_list = ["apple", "banana", "cherry"]
my_list.append("grapes") # add grapes
print(my_list)

# Insert elements:

my_list = ["apple", "banana", "cherry", "kiwi"]
print(my_list)
my_list.insert(1, "raspberry") # insert raspberry
print(my_list)

# Removing elements (using 3 methods)

1)

my_list = ["apple", "banana", "berry", "cherry"]
print(my_list)
my_list.remove ("apple") # remove apple
print(my_list)

2)

my_list = ["apple", "banana", "berry", "cherry"]
print(my_list)
my_list.pop() # it will remove the last value "cherry"
print(my_list)

3)

my_list = ["apple", "banana", "berry", "cherry"]
print(my_list)
del my_list[1]
print(my_list)

# Length and looping:

my_list = ["apple", "banana", "berry", "cherry"]
print(my_list)
print(len(my_list)
for item in my_list
print(item)

# List slicing:

my_list = ["apple", "banana", "berry", "cherry"]
print(my_list)
print(my_list[1:3])

# Sorting and Reversing:

num = [2,4,6,3,0,11,19,22,35]
num.sort()
print(num)
rum.reverse()
print(num)

What is a Function in Python?

What is a Function in Python?

A function is a reusable block of code that runs only when you call it.

Basic Syntax

# DEFINING a function
def function_name(parameters):
# code block
return result
# CALLING a function
function_name(arguments)

Simplest Example

# Define once

def say_hello():
print("Hello, World!")

# Call anytime, anywhere
say_hello() # Hello, World!
say_hello() # Hello, World!
say_hello() # Hello, World!

Functions with Parameters (Inputs)

# One parameter

def greet(name):
print("Hello", name)

greet("Alice") # Hello Alice
greet("Bob") # Hello Bob

# Two parameters

def add(a, b):
print(a + b)
add(3, 5) # 8
add(10, 20) # 30

4 Types of Functions:

1️ No Input, No Output
2 Input, No Output
3 No Input, With Output
4 Input AND Output

1️ No Input, No Output

def say_hello():
print("Hello!")
say_hello()

2 Input, No Output

def greet(name):
print("Hello", name)
greet("Alice")

3 No Input, With Output

def get_pi():
return 3.14159
pi = get_pi()
print(pi) # 3.14159

4 Input AND Output

def multiply(a, b):
return a * b
result = multiply(4, 5)
print(result) # 20

# Why we use functions?

To avoid repeating the same code again and again.

# Creating and calling a function

def text():
print("Hello Welcome to python Functions")
text()
text()

a = 3
b = 5
multiplication = a*b
print(multiplication)

a = 11
b = 15
multiplication = a*b
print(multiplication)

a = 20
b = 35

multiplication = a*b
print(multiplication)'''

# funtion with parameters

def multiplication(a, b):
print(a * b)
multiplication(6, 7)
multiplication(55, 60)'''

def addition(q, r):
print(q + r)
addition(20, 35)
addition(3500, 3223)
addition(25,45)'

def greet_user(name):
print(f"Hello {name} Glad To Meet You!")
greet_user("Qader")
greet_user("Lubna")
greet_user("Shoaib")
greet_user("Rumaysa")'''

#creating and calling a function (without parameters)

def text():
print("Hello Qader Welcome To Python Funtions!")
text()

#creating and calling a function (with parameters)

def multiplication(a,b):
print(a * b)
multiplication(5, 9) # multiplication

#creating and calling a function (with parameters)

def addition(a,b):
print(a + b)
addition(15, 15) #addition

#creating and calling a function (with parameters)

def division(a,b):
print(a / b)
division(20, 5) #division

#creating and calling a function (with parameters)

def substraction(a,b):
print(a - b)
substraction(35, 30) # substraction

def greet_user(name):
print(f"Hello{name} Glad to Meet You!")
greet_user("Mohammed Qadar")
greet_user("MohammedQadar")
greet_user("MQadar")
greet_user("QadarM")

-Return statement in Functions:

def add(a,b):
return a + b
result=add(5,5)
print("sum ", result)

-Default parameters in function?

Syntax:

def welcome(name= "Guest"):
print(f"welcome, {name}!")
welcome()
welcome("Qader")

Example:

def welcome(name= "khadar"):
print(f"welcome {name} great to see you!")
welcome()
welcome("qader")

# Billing system example:

def calculate_total(price, tax=0.05):
total= price + (price * tax)
return total
print(calculate_total(100))
print(calculate_total(100, 0.08))

# Keywords and Arguments in Functions?

Syntax:

def student_info(name, age):
print(f"name: {name}, age: {age}")
student_info(age=39, name="Mohammed")

# ATM System Project

def check_balance(balance):
print(f"Your current balance is rupees {balance}")

def withdraw(balance, amount):
if amount > balance:
print("Insufficient balance")
return balance
else:
balance = balance - amount
print(f"Withdraw successful & new balance: rupees {balance}")
return balance

def deposit(balance, amount):
balance = balance + amount
print(f"Deposit successful and new balance is: rupees {balance}")
return balance

def atm():
balance = 10000
print("Welcome to the ATM")

while True:
print("\nChoose option:")
print("1. Check balance")
print("2. Withdraw money")
print("3. Deposit money")
print("4. Exit")
choice = input("Enter your choice (1-4): ")
if choice == "1":
check_balance(balance)
elif choice == "2":
amount = float(input("Enter amount to withdraw: Rupees "))
balance = withdraw(balance, amount)
elif choice == "3":
amount = float(input("Enter amount to deposit: Rupees "))
balance = deposit(balance, amount)
elif choice == "4":
print("Exit, Goodbye")
break
else:
print("Invalid choice")
atm()

# Mini project on calculator:

def add(x, y):
return x + y
def subtraction(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
if y == 0:
return "Cannot divide zero"
return x / y
print("Addition:", add(3, 6))
print("Subtraction:", subtraction(8, 5))
print("Multiplication:", multiply(11, 3))
print("Division:", divide(10, 5))




Thursday, February 26, 2026

AWS Global Infrastructure: Ensuring Availability, Compliance, and Low Latency Across the World

AWS Global Infrastructure: Ensuring Availability, Compliance, and Low Latency Across the World


What is AWS global infrastructure.

AWS global infrastructure consists of multiple geographically isolated Regions. Each Region contains multiple Availability Zones for high availability. For performance optimization, AWS uses Edge Locations and Regional Edge Caches. For ultra-low latency workloads, AWS provides Local Zones and Wavelength Zones. For hybrid deployments, AWS offers Outposts. This layered infrastructure ensures scalability, fault isolation, low latency, and global reach.

AWS Regions

A Region is a geographically distinct area with its own infrastructure.
Each Region contains multiple Availability Zones for redundancy.
Regions are isolated from each other to protect against broad failures.
We choose Regions based on latency, compliance, and data residency needs.
Regions enable multi-Region disaster recovery strategies.
New Regions continue to be announced globally (e.g., Chile, Taiwan).
Regional services vary — not all AWS services launch in every Region.
Regions represent the highest level of AWS infrastructure abstraction.

AWS Availability Zones

An AZ is one or more physically separate data centers within a Region.
AZs are isolated from failures in other AZs.
They are connected by high-speed, low-latency networks.
Applications deployed across AZs are resilient to failures.
Most Regions now have at least three AZs.
Services like RDS Multi-AZ provide automatic failover between AZs.
AZs help ensure high availability of production workloads.
They are the foundation of AWS availability architecture.

AWS Edge Locations

Edge Locations are global points for content caching.
They serve content closer to users to reduce latency.
Primarily used by CloudFront and Global Accelerator.
They improve performance for static and dynamic content.
AWS has hundreds of POPs worldwide for content delivery.
Edge Locations reduce load on origin servers.
They are not full-service compute zones — just caching points.
They make global services feel fast to end users everywhere.

AWS Regional Edge Caches

Regional Edge Caches sit between Edge Locations and origin.
They cache larger objects when Edge Locations can’t hold them.
They help reduce requests going back to origin servers.
This improves global performance for less-frequently accessed content.
They are part of CloudFront’s caching hierarchy.
Regional caches are deployed in strategic intermediate points.
They reduce latency globally for dynamic workloads.
Useful when Edge Locations alone are insufficient for content scale.

AWS Local Zones

Local Zones extend AWS Regions into metro areas.
They deliver compute closer to end users for ultra-low latency.
They connect back to their parent Region.
Ideal for latency-sensitive workloads (gaming, real-time video).
They support compute, storage, and some database services.
Local Zones are not complete Regions — they’re extensions.
Often opt-in in your account before you use them.
They help meet local data gravity and compliance requirements.

AWS Wavelength Zones

Wavelength puts AWS compute inside 5G telco networks.
They deliver ultra-low latency for mobile applications.
They are built in partnership with telecom providers.
Traffic stays inside the 5G network instead of going to a Region.
Ideal for AR/VR, IoT, autonomous systems, real-time processing.
Easy access via AWS APIs, same experience as Regions.
Compute, storage, and networking are available at the edge.
They are especially useful where milliseconds matter.

AWS Outposts

Outposts bring AWS infrastructure on-premises.
They provide local rack infrastructure managed by AWS.
Outposts use the same AWS APIs and tools as in cloud Regions.
Ideal for hybrid cloud or data residency where local compute is needed.
Useful for workloads that must remain on-site for compliance.
They support AWS services locally like EC2, EBS, ECS, EKS.
Outposts hardware is fully supported and updated by AWS.
They extend the cloud’s control plane on customer premises.

✨ Bonus: AWS Dedicated Local Zones 

A Dedicated Local Zone is a Local Zone built for exclusive use by a customer.
Useful where strict data governance is required.
Managed infrastructure for a specific organization or community.
Ideal for public sector or regulated industries.
Helps satisfy stringent sovereignty requirements.
Still connects back to the Region for centralized control.
Combines low latency with strong compliance posture.
A niche (but strong) advanced AWS infrastructure concept to mention.

Wednesday, February 11, 2026

Amazon Redshift Architecture and Its Components

Amazon Redshift Architecture and Its Components


Leader Nodes

It keeps all the important information about tables and how the cluster is set up.
It decides the fastest way to run your query and sends the plan to all compute nodes.
It acts as the middleman between your SQL tools and the compute nodes.
It breaks the work into smaller pieces and sends them to the right slices to process.
It reads your SQL query, understands it, and figures out the best way to run it.
It collects the partial results coming from compute nodes and combines them into the final answer.
It makes sure many users can run queries at the same time without conflicts and keeps data consistent.
It stores all important information about tables, schemas, and cluster configuration.
It spreads the work evenly across compute nodes so no node gets overloaded.
It monitors the health of the cluster and handles node failures or issues.
It acts as the single connection point for all SQL tools and applications.
It breaks your SQL query into smaller tasks that can run in parallel.
It controls how data is distributed across nodes — by key, evenly, or fully copied.
It ensures all compute nodes work together smoothly and stay in sync during query execution.

Compute Nodes

Compute nodes store all the actual user data in the Redshift cluster.
They receive tasks from the leader node and process their assigned portion of the data.
Each compute node has its own CPU, memory, and storage to perform heavy workloads.
They run query operations in parallel and send results back to the leader node.
Compute nodes divide their work across slices for even faster processing.
They handle scanning, filtering, joining, and aggregating data locally.
The performance of the cluster increases as more compute nodes are added.
Compute nodes work independently but stay coordinated through the leader node.
They ensure large datasets can be processed quickly through parallel execution.
All user tables and column data physically reside on compute nodes, not on the leader node.

Node Slices

Each compute node is divided into smaller workers called slices.
Every slice gets its own portion of the node’s CPU, memory, and storage.
Slices work independently and in parallel to process data faster.
When data is loaded, rows are spread across slices based on the distribution key.
Each slice handles only its assigned chunk of data, reducing workload per slice.
More slices mean more parallelism, which improves query performance.
The number of slices depends on the node type (larger nodes = more slices).
Slices perform tasks like scanning, filtering, and joining data locally.
They send their partial results back to the compute node, which forwards them to the leader node.
Slices ensure that Redshift uses every bit of hardware inside a compute node efficiently.


Amazon Redshift Architecture:





What Happens When a User Runs a Simple SELECT Query

The leader node receives the SELECT query from the user.
It parses the SQL to understand what the user wants.
It builds a query tree (a logical structure of the query).
The optimizer checks statistics and finds the fastest way to run the query.
It creates the execution plan (the step‑by‑step blueprint).
The execution engine turns the plan into compiled C++ code.
Compute nodes run the code in parallel, each working on its portion of the data.
The leader node combines the results and returns the final output to the user.


Tuesday, February 10, 2026

The Art of SQL Practice: 12 Dimensions of Real‑World Data Analysis

The Art of SQL Practice: 12 Dimensions of Real‑World Data Analysis


✅ SECTION 1 — Filtering Data (Topics 1–10)

Filtering is the foundation of . Every ETL pipeline, report, and transformation starts with selecting the right rows.

1. Filter rows with simple conditions

What it is

Use WHERE to return only rows that match a condition.

Syntax

SELECT columns FROM table WHERE condition;

Example

Customers from USA:

SELECT * FROM Sales.Customers WHERE Country = 'USA';

Practice

Get all orders where Sales > 500.

2. Filter with AND

What it is

Combine multiple conditions that must all be true.

Example

Orders with high sales AND completed status:

SELECT * FROM Sales.Orders WHERE Sales > 500 AND OrderStatus = 'Completed';

Practice

Find customers from India with Score > 80.

3. Filter with OR

What it is

Return rows where any condition is true.

Example

Orders that are either Pending or Cancelled:

SELECT * FROM Sales.Orders WHERE OrderStatus = 'Pending' OR OrderStatus = 'Cancelled';

Practice

Find customers from USA or Canada.

4. Filter with BETWEEN

What it is

Filter values within a range (inclusive).

Example

Orders placed in May 2023:

SELECT * FROM Sales.Orders WHERE OrderDate BETWEEN '2023-05-01' AND '2023-05-31';

Practice

Find customers created between two dates.

5. Filter with IN

What it is

Match against a list of values.

Example

Orders with specific statuses:

SELECT * FROM Sales.Orders WHERE OrderStatus IN ('Completed', 'Pending');

Practice

Find customers from a list of countries.

6. Filter with LIKE

What it is

Pattern matching for strings.

Example

Customers whose first name starts with “A”:

SELECT * FROM Sales.Customers WHERE FirstName LIKE 'A%';

Practice

Find customers whose email ends with “.com”.

7. Filter NULL values

What it is

Use IS NULL or IS NOT NULL.

Example

Orders missing a ShipDate:

SELECT * FROM Sales.Orders WHERE ShipDate IS NULL;

Practice

Find customers with no phone number.

8. Filter NOT conditions

What it is

Exclude values.

Example

Orders not shipped to USA:

SELECT * FROM Sales.Orders WHERE Country <> 'USA';
(If you add Country to Orders later.)

Practice

Find customers not from India.

9. Filter using expressions

What it is

Use calculations inside WHERE.

Example

Orders where total revenue (Sales × Quantity) > 1000:

SELECT * FROM Sales.Orders WHERE (Sales * Quantity) > 1000;

Practice

Find orders where Quantity × Sales < 500.

10. Combine multiple filters

What it is

Use parentheses to control logic.

Example

Orders that are Completed OR (Pending AND high value):

SELECT * FROM Sales.Orders WHERE OrderStatus = 'Completed' OR (OrderStatus = 'Pending' AND Amount > 500);

Practice

Find customers from USA with Score > 50 OR from India with Score > 80.

⭐ SECTION 2 — JOINS (Topics 11–20)

Joins combine rows from multiple tables based on related columns.

This is the backbone of analytics, reporting, and ETL.

11. INNER JOIN — match rows in both tables

What it is

Returns rows where the join condition matches in both tables.

Syntax

SELECT ... FROM A INNER JOIN B ON A.key = B.key;

Example

List orders with customer names:

SELECT o.OrderID, o.Amount, c.FirstName, c.LastName FROM Sales.Orders o INNER JOIN Sales.Customers c ON o.CustomerID = c.CustomerID;

Practice

Show OrderID, OrderDate, FirstName for all matching orders.

12. LEFT JOIN — keep all customers, even without orders

What it is

Returns all rows from the left table, and matching rows from the right.

Example

Customers with their orders (including those with none):

SELECT c.CustomerID, c.FirstName, o.OrderID, o.Amount FROM Sales.Customers c LEFT JOIN Sales.Orders o ON c.CustomerID = o.CustomerID;

Practice

Find customers who have no orders.

13. RIGHT JOIN — keep all orders, even without customers
(Less common, but useful)

Example

Orders with customer info (even if customer missing):

SELECT o.OrderID, o.Amount, c.FirstName FROM Sales.Orders o RIGHT JOIN Sales.Customers c ON o.CustomerID = c.CustomerID;

Practice

Show all orders and customer names, even if customer is missing.

14. FULL OUTER JOIN — keep everything

What it is

Returns all rows from both tables.

Example

Customers and orders, even unmatched:

SELECT c.CustomerID, o.OrderID, c.FirstName, o.Amount FROM Sales.Customers c FULL OUTER JOIN Sales.Orders o ON c.CustomerID = o.CustomerID;

Practice

Find all customers and orders, including unmatched.

15. JOIN with additional filters

Example

Completed orders with customer names:

SELECT o.OrderID, o.Amount, c.FirstName FROM Sales.Orders o JOIN Sales.Customers c ON o.CustomerID = c.CustomerIDWHERE o.OrderStatus = 'Completed';

Practice

Find all Pending orders with customer names.

16. JOIN using expressions

Example

Orders where customer Score > 80:

SELECT o.OrderID, o.Amount, c.Score

FROM Sales.Orders o

JOIN Sales.Customers c

ON o.CustomerID = c.CustomerID

WHERE c.Score > 80;

Practice

Find orders where Quantity × Sales > 1000.




17. JOIN + GROUP BY

Example

Total sales per customer:







SELECT c.CustomerID, c.FirstName,

SUM(o.Amount) AS TotalSpent

FROM Sales.Customers c

LEFT JOIN Sales.Orders o

ON c.CustomerID = o.CustomerID

GROUP BY c.CustomerID, c.FirstName;

Practice

Count orders per customer.




18. JOIN with multiple tables

Example

Orders with customer and salesperson:







SELECT o.OrderID, c.FirstName, o.SalesPersonID

FROM Sales.Orders o

JOIN Sales.Customers c

ON o.CustomerID = c.CustomerID;

(You can later add a SalesPerson table.)




Practice

Show OrderID, CustomerName, and SalesPersonID.




19. Anti‑join (LEFT JOIN + NULL)

What it is

Find rows in one table with no match in another.




Example

Customers with no orders:







SELECT c.*

FROM Sales.Customers c

LEFT JOIN Sales.Orders o

ON c.CustomerID = o.CustomerID

WHERE o.OrderID IS NULL;

Practice

Find orders with no matching customer.




20. Semi‑join (EXISTS)

What it is

Check if a match exists, but don’t return the joined rows.




Example

Customers who have placed at least one order:







SELECT *

FROM Sales.Customers c

WHERE EXISTS (

SELECT 1

FROM Sales.Orders o

WHERE o.CustomerID = c.CustomerID

);

Practice

Find customers who placed orders after 2024.







SECTION 3 — Advanced joins (Topics 21–30)

We’ll keep using only your real tables:




Sales.Customers




Sales.Orders




21. Customers with orders in a specific month

Idea: Use EXTRACT‑like logic via MONTH() and YEAR() in Server.




Example — customers with orders in June 2023







SELECT DISTINCT c.CustomerID, c.FirstName, c.LastName

FROM Sales.Customers c

JOIN Sales.Orders o

ON c.CustomerID = o.CustomerID

WHERE YEAR(o.OrderDate) = 2023

AND MONTH(o.OrderDate) = 6;

Practice: Get customers who ordered in January 2024.




22. Customers with orders in multiple months

Idea: Group by customer and count distinct months.




Example







SELECT c.CustomerID, c.FirstName, c.LastName,

COUNT(DISTINCT (CONVERT(char(7), o.OrderDate, 120))) AS DistinctMonths

FROM Sales.Customers c

JOIN Sales.Orders o

ON c.CustomerID = o.CustomerID

GROUP BY c.CustomerID, c.FirstName, c.LastName

HAVING COUNT(DISTINCT (CONVERT(char(7), o.OrderDate, 120))) > 1;

Practice: Find customers who ordered in at least 3 different months.




23. Customers whose first order had high Amount

Idea: Use window functions to find the first order per customer.




Example — first order Amount > 200







WITH OrderedOrders AS (

SELECT o.*,

ROW_NUMBER() OVER (

PARTITION BY o.CustomerID

ORDER BY o.OrderDate

) AS rn

FROM Sales.Orders o

)

SELECT c.CustomerID, c.FirstName, c.LastName

FROM Sales.Customers c

JOIN OrderedOrders o

ON c.CustomerID = o.CustomerID

WHERE o.rn = 1

AND o.Amount > 200;

Practice: Find customers whose first order status was Cancelled.




24. Customers whose last order was Cancelled

Idea: Same pattern, but order by date descending.




Example







WITH OrderedOrders AS (

SELECT o.*,

ROW_NUMBER() OVER (

PARTITION BY o.CustomerID

ORDER BY o.OrderDate DESC

) AS rn

FROM Sales.Orders o

)

SELECT c.CustomerID, c.FirstName, c.LastName

FROM Sales.Customers c

JOIN OrderedOrders o

ON c.CustomerID = o.CustomerID

WHERE o.rn = 1

AND o.OrderStatus = 'Cancelled';

Practice: Find customers whose last order was Completed.




25. Customers with more than one PaymentMethod

Idea: Count distinct payment methods per customer.




Example







SELECT c.CustomerID, c.FirstName, c.LastName,

COUNT(DISTINCT o.PaymentMethod) AS DistinctPaymentMethods

FROM Sales.Customers c

JOIN Sales.Orders o

ON c.CustomerID = o.CustomerID

GROUP BY c.CustomerID, c.FirstName, c.LastName

HAVING COUNT(DISTINCT o.PaymentMethod) > 1;

Practice: Find customers who used exactly one payment method.




26. Customers with both Completed and Pending orders

Idea: Use conditional aggregation.




Example







SELECT c.CustomerID, c.FirstName, c.LastName

FROM Sales.Customers c

JOIN Sales.Orders o

ON c.CustomerID = o.CustomerID

GROUP BY c.CustomerID, c.FirstName, c.LastName

HAVING SUM(CASE WHEN o.OrderStatus = 'Completed' THEN 1 ELSE 0 END) > 0

AND SUM(CASE WHEN o.OrderStatus = 'Pending' THEN 1 ELSE 0 END) > 0;

Practice: Find customers who have both Completed and Cancelled orders.




27. Customers whose order Amount increased over time

Idea: Use LAG to compare each order to the previous one.




Example







WITH Lagged AS (

SELECT o.*,

LAG(o.Amount) OVER (

PARTITION BY o.CustomerID

ORDER BY o.OrderDate

) AS PrevAmount

FROM Sales.Orders o

)

SELECT DISTINCT CustomerID

FROM Lagged

WHERE PrevAmount IS NOT NULL

AND Amount > PrevAmount;

Practice: Find customers whose Amount decreased compared to the previous order.




28. Customers whose order Amount decreased over time

Example







WITH Lagged AS (

SELECT o.*,

LAG(o.Amount) OVER (

PARTITION BY o.CustomerID

ORDER BY o.OrderDate

) AS PrevAmount

FROM Sales.Orders o

)

SELECT DISTINCT CustomerID

FROM Lagged

WHERE PrevAmount IS NOT NULL

AND Amount < PrevAmount;

Practice: Find customers whose Amount stayed the same as previous order.




29. Orders updated on the same day they were created

Idea: Compare CreationTime and UpdatedAt dates.




Example







SELECT *

FROM Sales.Orders

WHERE CONVERT(date, CreationTime) = CONVERT(date, UpdatedAt);

Practice: Find orders updated at least 3 days after CreationTime.




30. Customers with orders in 2023 but not in 2024

Idea: Use two sets and anti‑join logic.




Example







WITH Orders2023 AS (

SELECT DISTINCT CustomerID

FROM Sales.Orders

WHERE YEAR(OrderDate) = 2023

),

Orders2024 AS (

SELECT DISTINCT CustomerID

FROM Sales.Orders

WHERE YEAR(OrderDate) = 2024

)

SELECT c.CustomerID, c.FirstName, c.LastName

FROM Sales.Customers c

JOIN Orders2023 y23

ON c.CustomerID = y23.CustomerID

LEFT JOIN Orders2024 y24

ON c.CustomerID = y24.CustomerID

WHERE y24.CustomerID IS NULL;

Practice: Find customers who ordered in 2024 but not in 2023.







✅ SECTION 4 — Set Operators (31–35)

31. UNION

Combine rows from two queries.







SELECT Country FROM Sales.Customers

UNION

SELECT PaymentMethod FROM Sales.Orders;

32. INTERSECT

Common rows.







SELECT CustomerID FROM Sales.Customers

INTERSECT

SELECT CustomerID FROM Sales.Orders;

33. EXCEPT

Rows in first query but not second.







SELECT CustomerID FROM Sales.Customers

EXCEPT

SELECT CustomerID FROM Sales.Orders;

34. UNION ALL

Keeps duplicates.







SELECT Country FROM Sales.Customers

UNION ALL

SELECT Country FROM Sales.Customers;

35. EXCEPT for date ranges




SELECT CustomerID FROM Sales.Orders WHERE YEAR(OrderDate)=2023

EXCEPT

SELECT CustomerID FROM Sales.Orders WHERE YEAR(OrderDate)=2024;

✅ SECTION 5 — Functions (36–45)

36. ROUND




SELECT OrderID, ROUND(Amount,2) FROM Sales.Orders;

37. Math expression




SELECT OrderID, Amount * 1.10 AS WithTax FROM Sales.Orders;

38. CONCAT




SELECT CONCAT(FirstName,' ',LastName) AS FullName FROM Sales.Customers;

39. SUBSTRING




SELECT SUBSTRING(Email, CHARINDEX('@',Email)+1, 100) AS Domain

FROM Sales.Customers;

40. REPLACE




SELECT REPLACE(ShipAddress,'Street','St') FROM Sales.Orders;

41. UPPER/LOWER




SELECT UPPER(FirstName) FROM Sales.Customers;

42. LEN




SELECT Email FROM Sales.Customers WHERE LEN(Email)>15;

43. TRIM




SELECT LTRIM(RTRIM(Phone)) FROM Sales.Customers;

44. ABS




SELECT ABS(Sales - Amount) FROM Sales.Orders;

45. CEILING/FLOOR




SELECT CEILING(Amount), FLOOR(Amount) FROM Sales.Orders;

✅ SECTION 6 — Date Functions (46–55)

46. YEAR/MONTH/DAY




SELECT YEAR(OrderDate), MONTH(OrderDate) FROM Sales.Orders;

47. DATEADD




SELECT DATEADD(DAY,7,OrderDate) FROM Sales.Orders;

48. DATEDIFF




SELECT DATEDIFF(DAY,OrderDate,ShipDate) FROM Sales.Orders;

49. GETDATE




SELECT * FROM Sales.Customers WHERE CreatedAt > DATEADD(DAY,-30,GETDATE());

50. Orders on weekends




SELECT * FROM Sales.Orders WHERE DATEPART(WEEKDAY,OrderDate) IN (1,7);

51. NULLIF




SELECT NULLIF(Amount,0) FROM Sales.Orders;

52. COALESCE




SELECT COALESCE(Phone,'Unknown') FROM Sales.Customers;

53. ISNULL




SELECT ISNULL(Amount,0) FROM Sales.Orders;

54. CAST/CONVERT




SELECT CONVERT(varchar,OrderDate,23) FROM Sales.Orders;

55. DATEFROMPARTS




SELECT DATEFROMPARTS(2024,1,1);

✅ SECTION 7 — CASE (56–65)

56. Categorize Amount




SELECT CASE WHEN Amount>500 THEN 'High' ELSE 'Low' END FROM Sales.Orders;

57. Categorize Score




SELECT CASE WHEN Score>=80 THEN 'Gold' ELSE 'Regular' END FROM Sales.Customers;

58. Categorize OrderStatus




SELECT CASE OrderStatus WHEN 'Completed' THEN 'Done' ELSE 'Pending' END FROM Sales.Orders;

59. Categorize by Country




SELECT CASE WHEN Country='USA' THEN 'North America' ELSE 'Other' END FROM Sales.Customers;

60. Categorize by Quantity




SELECT CASE WHEN Quantity>10 THEN 'Bulk' ELSE 'Normal' END FROM Sales.Orders;

61–65 similar patterns

(You now know the structure.)




✅ SECTION 8 — Aggregates (66–75)

66. COUNT




SELECT COUNT(*) FROM Sales.Customers;

67. SUM




SELECT SUM(Amount) FROM Sales.Orders;

68. AVG




SELECT AVG(Amount) FROM Sales.Orders;

69. MIN/MAX




SELECT MIN(Amount), MAX(Amount) FROM Sales.Orders;

70. GROUP BY Country




SELECT Country, COUNT(*) FROM Sales.Customers GROUP BY Country;

71. Orders per customer




SELECT CustomerID, COUNT(*) FROM Sales.Orders GROUP BY CustomerID;

72. Revenue per customer




SELECT CustomerID, SUM(Amount) FROM Sales.Orders GROUP BY CustomerID;

73. Orders per status




SELECT OrderStatus, COUNT(*) FROM Sales.Orders GROUP BY OrderStatus;

74. Average Quantity




SELECT AVG(Quantity) FROM Sales.Orders;

75. Monthly orders




SELECT YEAR(OrderDate), MONTH(OrderDate), COUNT(*)

FROM Sales.Orders

GROUP BY YEAR(OrderDate), MONTH(OrderDate);

✅ SECTION 9 — Window Functions (76–95)

76. Running total




SELECT OrderID, Amount,

SUM(Amount) OVER (ORDER BY OrderDate) AS RunningTotal

FROM Sales.Orders;

77. Total per customer




SELECT OrderID, CustomerID,

SUM(Amount) OVER (PARTITION BY CustomerID)

FROM Sales.Orders;

78. Avg per customer




SELECT OrderID, AVG(Amount) OVER (PARTITION BY CustomerID)

FROM Sales.Orders;

79. Count per customer




SELECT OrderID, COUNT(*) OVER (PARTITION BY CustomerID)

FROM Sales.Orders;

80. Percent of total




SELECT OrderID, Amount,

Amount * 1.0 / SUM(Amount) OVER ()

FROM Sales.Orders;

81. Max per customer




SELECT OrderID, MAX(Amount) OVER (PARTITION BY CustomerID)

FROM Sales.Orders;

82. Min per customer




SELECT OrderID, MIN(Amount) OVER (PARTITION BY CustomerID)

FROM Sales.Orders;

83. First order amount




SELECT OrderID,

FIRST_VALUE(Amount) OVER (PARTITION BY CustomerID ORDER BY OrderDate)

FROM Sales.Orders;

84. Last order amount




SELECT OrderID,

LAST_VALUE(Amount) OVER (

PARTITION BY CustomerID ORDER BY OrderDate

ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING

)

FROM Sales.Orders;

85. LAG




SELECT OrderID, Amount,

LAG(Amount) OVER (PARTITION BY CustomerID ORDER BY OrderDate)

FROM Sales.Orders;

86. LEAD




SELECT OrderID, Amount,

LEAD(Amount) OVER (PARTITION BY CustomerID ORDER BY OrderDate)

FROM Sales.Orders;

87. ROW_NUMBER




SELECT OrderID,

ROW_NUMBER() OVER (ORDER BY Amount DESC)

FROM Sales.Orders;

88. RANK




SELECT OrderID,

RANK() OVER (ORDER BY Amount DESC)

FROM Sales.Orders;

89. DENSE_RANK




SELECT OrderID,

DENSE_RANK() OVER (ORDER BY Amount DESC)

FROM Sales.Orders;

90–95 similar patterns

(Top N per customer, differences, etc.)




✅ SECTION 10 — Subqueries & CTEs (96–105)

96. Subquery filter




SELECT * FROM Sales.Customers

WHERE CustomerID IN (SELECT CustomerID FROM Sales.Orders WHERE Amount>500);

97. Total spend > 1000




SELECT * FROM Sales.Customers

WHERE CustomerID IN (

SELECT CustomerID FROM Sales.Orders GROUP BY CustomerID HAVING SUM(Amount)>1000

);

98. More than 3 orders




SELECT CustomerID FROM Sales.Orders

GROUP BY CustomerID HAVING COUNT(*)>3;

99. First order cancelled




WITH x AS (

SELECT *, ROW_NUMBER() OVER (PARTITION BY CustomerID ORDER BY OrderDate) rn

FROM Sales.Orders

)

SELECT * FROM x WHERE rn=1 AND OrderStatus='Cancelled';

100. Only ordered in 2023




WITH y AS (

SELECT CustomerID, YEAR(OrderDate) yr FROM Sales.Orders GROUP BY CustomerID,YEAR(OrderDate)

)

SELECT CustomerID FROM y GROUP BY CustomerID HAVING COUNT(*)=1 AND MIN(yr)=2023;

101–105 CTE patterns

(monthly revenue, repeat customers, etc.)




✅ SECTION 11 — Views, CTAS, Temp Tables (106–115)

106. View




CREATE VIEW Sales.CustomerSummary AS

SELECT c.CustomerID, c.FirstName, COUNT(o.OrderID) AS TotalOrders

FROM Sales.Customers c

LEFT JOIN Sales.Orders o ON c.CustomerID=o.CustomerID

GROUP BY c.CustomerID, c.FirstName;

107. High value orders




CREATE VIEW Sales.HighValueOrders AS

SELECT * FROM Sales.Orders WHERE Amount>500;

108. Monthly revenue




CREATE VIEW Sales.MonthlyRevenue AS

SELECT YEAR(OrderDate) yr, MONTH(OrderDate) mn, SUM(Amount) total

FROM Sales.Orders GROUP BY YEAR(OrderDate),MONTH(OrderDate);

109. CTAS




SELECT * INTO Sales.TempHighOrders

FROM Sales.Orders WHERE Amount>500;

110–115 similar patterns

(temp tables, CTAS, etc.)




✅ SECTION 12 — Stored Procedures (116–120)

116. Update order status




CREATE PROCEDURE Sales.UpdateStatus @OrderID int, @Status varchar(50)

AS

UPDATE Sales.Orders SET OrderStatus=@Status WHERE OrderID=@OrderID;

117. Delete cancelled




CREATE PROCEDURE Sales.DeleteCancelled AS

DELETE FROM Sales.Orders WHERE OrderStatus='Cancelled';

118–120 similar patterns

(insert customer, archive orders, etc.)




✅ SECTION 13 — Triggers (121–125)

121. Auto-update UpdatedAt




CREATE TRIGGER trg_UpdateTime ON Sales.Orders

AFTER UPDATE AS

UPDATE o SET UpdatedAt=GETDATE()

FROM Sales.Orders o

JOIN inserted i ON o.OrderID=i.OrderID;

122. Log deletes




CREATE TRIGGER trg_LogDelete ON Sales.Orders

AFTER DELETE AS

INSERT INTO Sales.OrderDeleteLog(OrderID,Amount,DeletedAt)

SELECT OrderID,Amount,GETDATE() FROM deleted;

123–125 similar patterns

(prevent negative, track status changes, etc.)




✅ SECTION 14 — Indexes & Execution Plans (126–135)

126. Index




CREATE INDEX idx_orders_customer ON Sales.Orders(CustomerID);

127. Index on Email




CREATE INDEX idx_customers_email ON Sales.Customers(Email);

128. Composite index




CREATE INDEX idx_orders_customer_date ON Sales.Orders(CustomerID,OrderDate);

129–135

Use:







SET STATISTICS IO ON;

SET STATISTICS TIME ON;

EXPLAIN...

✅ SECTION 15 — Partitioning & Performance (136–150)

Server partitioning example:




136. Create partition function




CREATE PARTITION FUNCTION pfOrders (date)

AS RANGE RIGHT FOR VALUES ('2023-01-01','2024-01-01');

137. Create partition scheme




CREATE PARTITION SCHEME psOrders AS PARTITION pfOrders ALL TO ([PRIMARY]);

138. Create partitioned table




CREATE TABLE Sales.OrdersPartitioned (...)

ON psOrders(OrderDate);

139–150

Performance rewrites:




Replace OR with IN




Use EXISTS instead of IN




Avoid SELECT *




Use covering indexes




Use window functions instead of correlated subqueries




✅ SECTION 16 — AI + (151–155)

151. Convert English →

You already saw many examples.




152. Explain in English

You can ask me anytime.




153. Optimize

Rewrite slow queries using:




indexes




window functions




CTEs




predicate pushdown




154. Generate test data

Use loops or random functions.




155. Convert business question →

Example:




“Top 5 customers by revenue”







SELECT TOP 5 CustomerID, SUM(Amount) AS TotalSpent

FROM Sales.Orders

GROUP BY CustomerID

ORDER BY TotalSpent DESC;

How to Master SQL Using a Single Table: 150+ Real‑World Scenarios

How to Master SQL Using a Single Table: 150+ Real‑World Scenarios

✅ SECTION 1 — Filtering Data (1–10)

You learned how to filter rows using:

Basic WHERE
AND
OR
BETWEEN
IN
LIKE
IS NULL / IS NOT NULL
NOT conditions
Expressions in WHERE
Combined filters with parentheses
All examples used your columns like Country, OrderDate, Amount, Score, etc.

✅ SECTION 2 — Joins (11–20)

You learned:

INNER JOIN
LEFT JOIN
RIGHT JOIN
FULL OUTER JOIN
JOIN with filters
JOIN with expressions
JOIN + GROUP BY
Multi‑table joins
Anti‑join (LEFT JOIN + NULL)
Semi‑join (EXISTS)

All using your real keys: CustomerID, OrderID.

✅ SECTION 3 — Advanced Joins (21–30)

You learned:

Customers with orders in a specific month
Customers ordering in multiple months
First order per customer
Last order per customer
Customers with multiple payment methods
Customers with both Completed & Pending orders
Increasing order amounts
Decreasing order amounts
Orders updated same day
Customers ordering in 2023 but not 2024
All using window functions + joins.

✅ SECTION 4 — Set Operators (31–35)

You learned:

UNION
INTERSECT
EXCEPT
UNION ALL
EXCEPT for date ranges

✅ SECTION 5 — Functions (36–45)

You learned:

ROUND
Math expressions
CONCAT
SUBSTRING
REPLACE
UPPER / LOWER
LEN
TRIM
ABS
CEILING / FLOOR

All applied to your columns like Email, ShipAddress, Amount.

✅ SECTION 6 — Date & NULL Functions (46–55)

You learned:

YEAR / MONTH / DAY
DATEADD
DATEDIFF
GETDATE
Weekend detection
NULLIF
COALESCE
ISNULL
CAST / CONVERT
DATEFROMPARTS
Using your OrderDate, ShipDate, CreatedAt, UpdatedAt.

✅ SECTION 7 — CASE Expressions (56–65)

You learned:

Categorize Amount
Categorize Score
Categorize OrderStatus
Categorize Country
Categorize Quantity

✅ SECTION 8 — Aggregations (66–75)

You learned:

COUNT
SUM
AVG
MIN / MAX
GROUP BY Country
Orders per customer
Revenue per customer
Orders per status
Average Quantity
Monthly orders

✅ SECTION 9 — Window Functions (76–95)

You learned:

Running total
Total per customer
Avg per customer
Count per customer
Percent of total
Max per customer
Min per customer
First order amount
Last order amount
LAG
LEAD
ROW_NUMBER
RANK
DENSE_RANK
Additional window patterns

All using your real columns like Amount, OrderDate.

✅ SECTION 10 — Subqueries & CTEs (96–105)

You learned:

Subquery filters
Total spend > threshold
Customers with > N orders
First order cancelled
Only ordered in 2023
Monthly revenue CTE
Repeat customers
High‑value customers
Increasing order amounts (CTE + LAG)
Recursive date generator

✅ SECTION 11 — Views, CTAS, Temp Tables (106–115)

You learned:

What a VIEW is + example
High value orders view
Monthly revenue view
CTAS (SELECT INTO)
Temp tables
Additional CTAS/temp table patterns

✅ SECTION 12 — Stored Procedures (116–120)

You learned:

Update order status procedure
Delete cancelled orders procedure
Insert customer procedure
Refresh monthly revenue procedure
Archive old orders procedure

✅ SECTION 13 — Triggers (121–125)

You learned:

Auto‑update UpdatedAt
Log deleted orders
Prevent negative Amount
Default values trigger
Track order status changes

Plus:

✔ What a trigger is
✔ Why triggers matter
✔ Practical steps to test triggers

✅ SECTION 14 — Indexes & Execution Plans (126–135)

You learned:

Index on CustomerID
Index on Email
Composite index
Execution plan basics
Execution plan for joins
Execution plan for windows
Execution plan for subqueries
Execution plan for GROUP BY
Execution plan for ORDER BY
Execution plan comparisons

✅ SECTION 15 — Partitioning & Performance (136–150)

You learned:

Partition function
Partition scheme
Partitioned table
Querying partitions
Comparing performance
Rewrite OR → IN
Rewrite subquery → join
DISTINCT vs GROUP BY
EXISTS vs IN
Avoid SELECT *
Use LIMIT/TOP
Predicate pushdown
Covering indexes
Window functions vs correlated subqueries
Reducing scan size

✅ SECTION 16 — AI + (151–155)

You learned:

Convert English →
Explain in English
Optimize using AI
Generate test data
Convert business question →

Thursday, December 11, 2025

Redis Interview Keypoints

Redis Interview Keypoints


Architecture & Execution

✅ 1. Redis executes commands in a single thread “Redis uses an event loop to process all client requests sequentially, ensuring atomicity without locks.”

✅ 2. Redis uses non‑blocking I/O multiplexing “Redis leverages epoll/kqueue/select to handle thousands of concurrent connections efficiently.”

✅ 3. Redis guarantees atomic operations “Because commands are executed sequentially, Redis ensures atomicity without explicit transactions.”

✅ 4. Redis supports multiple data structures “Strings, lists, sets, sorted sets, hashes, streams, bitmaps, and hyperloglogs are natively supported.”

✅ 5. Redis optimizes small collections with encodings “Structures like lists and hashes use ziplist/intset encodings to save memory.”

✅ 6. Redis supports pub/sub messaging “Clients can publish and subscribe to channels for real‑time message distribution.”

✅ 7. Redis supports Lua scripting “Lua scripts run atomically inside Redis, enabling complex operations without race conditions.”

✅ 8. Redis supports transactions with MULTI/EXEC “Commands queued in MULTI are executed atomically when EXEC is called.”

✅ 9. Redis supports pipelines “Clients can batch multiple commands to reduce round‑trip latency.”

✅ 10. Redis supports streams for event data “Streams provide append‑only log structures with consumer groups for processing.”

Persistence

✅ 11. Redis supports RDB snapshots “RDB creates point‑in‑time dumps of the dataset into dump.rdb.”

✅ 12. Redis supports AOF logging “AOF logs every write operation into appendonly.aof for durability.”

✅ 13. Redis supports hybrid persistence “RDB + AOF can be enabled together for balance between speed and durability.”

✅ 14. Redis forks child processes for persistence “On BGSAVE or BGREWRITEAOF, Redis forks a child to handle disk writes.”

✅ 15. Redis supports configurable snapshot intervals “save 900 1 means snapshot every 900 seconds if at least 1 key changed.”

✅ 16. Redis supports appendfsync policies “Options are always, everysec, or no, balancing durability vs performance.”

✅ 17. Redis supports AOF rewrite “BGREWRITEAOF compacts the log by rewriting it in the background.”

✅ 18. Redis supports truncated AOF recovery “aof-load-truncated yes allows Redis to start even if AOF is incomplete.”

✅ 19. Redis supports stop‑writes on persistence error “stop-writes-on-bgsave-error yes prevents data loss if snapshotting fails.”

✅ 20. Redis persistence files are stored in dir “Both RDB and AOF files are written to the configured data directory.”


Replication

✅ 21. Redis supports master‑replica replication “Replicas asynchronously copy data from the master.”

✅ 22. Redis supports partial resynchronization “Replicas can catch up using replication backlog without full resync.”

✅ 23. Redis supports replica promotion “SLAVEOF NO ONE promotes a replica to master.”

✅ 24. Redis supports replica authentication “masterauth config ensures replicas authenticate to the master.”

✅ 25. Redis supports min‑replicas‑to‑write “Writes only succeed if enough replicas acknowledge them.”

✅ 26. Redis supports min‑replicas‑max‑lag “Defines maximum lag allowed before writes are stopped.”

✅ 27. Redis supports diskless replication “repl-diskless-sync yes streams data directly without temporary files.”

✅ 28. Redis supports replication backlog buffer “Backlog stores recent writes for replicas to catch up after disconnects.”

✅ 29. Redis supports chained replication “Replicas can replicate from other replicas, not just the master.”

✅ 30. Redis supports replica read‑only mode “By default, replicas serve read queries but reject writes.”

High Availability (Sentinel & Cluster)

✅ 31. Redis Sentinel monitors masters “Sentinel detects failures and promotes replicas automatically.”

✅ 32. Redis Sentinel reconfigures clients “Clients are updated with new master info after failover.”

✅ 33. Redis Sentinel supports quorum “Failover requires majority agreement among Sentinels.”

✅ 34. Redis Cluster shards data “Cluster divides 16,384 hash slots across masters.”

✅ 35. Redis Cluster supports replicas per master “Each master has replicas for redundancy.”

✅ 36. Redis Cluster supports automatic rebalancing “Slots can be migrated between nodes to balance load.”

✅ 37. Redis Cluster supports resharding “Keys can be moved between slots during scaling.”

✅ 38. Redis Cluster supports gossip protocol “Nodes exchange state info via gossip messages.”

✅ 39. Redis Cluster supports failover “Replicas are promoted if a master fails.”

✅ 40. Redis Cluster requires full slot coverage “By default, cluster stops serving if slots are missing.”

Memory Management

✅ 41. Redis enforces maxmemory limits “maxmemory sets a hard RAM cap for the dataset.”

✅ 42. Redis supports eviction policies “Options include allkeys-lru, volatile-ttl, and noeviction.”

✅ 43. Redis supports maxmemory‑samples “Defines how many keys are sampled for eviction decisions.”

✅ 44. Redis supports memory fragmentation monitoring “INFO memory shows fragmentation ratio for tuning.”

✅ 45. Redis supports lazy freeing “lazyfree-lazy-eviction frees memory asynchronously.”

✅ 46. Redis supports memory allocator tuning “Redis can use jemalloc or libc malloc for memory management.”

✅ 47. Redis supports memory usage command “MEMORY USAGE key shows memory consumed by a key.”

✅ 48. Redis supports memory stats “MEMORY STATS provides allocator and fragmentation details.”

✅ 49. Redis supports memory doctor “MEMORY DOCTOR suggests fixes for memory fragmentation.”

✅ 50. Redis supports eviction notifications “Clients can subscribe to keyspace events for evictions.”



Performance & Monitoring

✅ 51. Redis supports INFO command “Provides runtime stats: memory, clients, persistence, replication, CPU, keyspace.”

✅ 52. Redis supports SLOWLOG “Captures queries slower than threshold for tuning.”

✅ 53. Redis supports latency monitor “Tracks operations exceeding configured latency thresholds.”

✅ 54. Redis supports MONITOR command “Streams all commands in real time for debugging.”

✅ 55. Redis supports CLIENT LIST “Shows connected clients with IP, state, and flags.”

✅ 56. Redis supports CLIENT KILL “Terminates misbehaving or unauthorized client connections.”

✅ 57. Redis supports CONFIG GET/SET “Allows runtime inspection and modification of config parameters.”

✅ 58. Redis supports DEBUG commands “DEBUG SEGFAULT or OBJECT commands help diagnose issues.”

✅ 59. Redis supports command stats “INFO commandstats shows per‑command call counts and latencies.”

✅ 60. Redis supports keyspace stats “INFO keyspace shows keys per DB and TTL distribution.”


Security

✅ 61. Redis supports requirepass “Enforces password authentication for clients.”

✅ 62. Redis supports ACLs (Redis 6+) “ACLs define users, commands, and key patterns allowed.”

✅ 63. Redis supports ACL WHOAMI “Shows which user is currently authenticated.”

✅ 64. Redis supports ACL LIST “Lists all ACL rules configured.”

✅ 65. Redis supports rename‑command “Disables or renames dangerous commands like FLUSHALL.”

✅ 66. Redis supports protected‑mode “Enabled by default, prevents unsafe external access.”

✅ 67. Redis supports TLS encryption “Redis can encrypt client‑server traffic with TLS.”

✅ 68. Redis supports firewall binding “bind restricts Redis to specific IP addresses.”

✅ 69. Redis supports port configuration “Default port is 6379, configurable via port.”

✅ 70. Redis supports AUTH command “Clients authenticate with password or ACL user credentials.”


Advanced Features

✅ 71. Redis supports modules “Modules extend Redis with custom data types and commands.”

✅ 72. Redis supports GEO commands “Stores and queries geospatial data using sorted sets.”

✅ 73. Redis supports BIT operations “Bitmaps allow efficient storage and manipulation of binary data.”

✅ 74. Redis supports HyperLogLog “Provides approximate cardinality estimation with low memory usage.”

✅ 75. Redis supports Bloom filters via modules “Modules like RedisBloom add probabilistic data structures.”

✅ 76. Redis supports JSON via modules “RedisJSON allows storing and querying JSON documents.”

✅ 77. Redis supports graph data via modules “RedisGraph enables graph queries using Cypher syntax.”

✅ 78. Redis supports time series via modules “RedisTimeSeries provides efficient time series storage and queries.”

✅ 79. Redis supports search via modules “RediSearch adds full‑text search and secondary indexing.”

✅ 80. Redis supports AI inference via modules “RedisAI integrates ML models for in‑database inference.”

Operational Practices


✅ 81. Redis supports online configuration changes “CONFIG SET allows parameters to be updated at runtime without restarting the server.”

✅ 82. Redis supports runtime inspection of configs “CONFIG GET retrieves current configuration values for verification.”

✅ 83. Redis supports persistence checks “INFO persistence shows last save time, AOF status, and background save progress.”

✅ 84. Redis supports backup via file copy “Copying dump.rdb or appendonly.aof provides a consistent backup snapshot.”

✅ 85. Redis supports restore by file placement “Placing RDB/AOF files back in the data directory restores the dataset on restart.”

✅ 86. Redis supports keyspace notifications “Clients can subscribe to events like set, expire, or evict for monitoring.”

✅ 87. Redis supports database selection “SELECT <db> switches between logical databases (default is DB 0).”

✅ 88. Redis supports flushing databases “FLUSHDB clears one DB, FLUSHALL clears all DBs — dangerous in production.”

✅ 89. Redis supports migration commands “MIGRATE moves keys between instances atomically with copy or replace options.”

✅ 90. Redis supports renaming keys “RENAME changes a key’s name; RENAMENX only if new name doesn’t exist.”

Advanced Administration

✅ 91. Redis supports cluster resharding tools “redis-cli --cluster reshard moves slots between nodes during scaling.”

✅ 92. Redis supports cluster health checks “redis-cli --cluster check validates slot coverage and node states.”

✅ 93. Redis supports sentinel failover testing “SENTINEL failover <master> forces a manual failover for testing.”

✅ 94. Redis supports sentinel monitoring commands “SENTINEL masters and SENTINEL slaves list monitored nodes.”

✅ 95. Redis supports client pause “CLIENT PAUSE temporarily blocks clients for controlled failover or maintenance.”

✅ 96. Redis supports command renaming for safety “Critical commands can be renamed or disabled to prevent accidental misuse.”

✅ 97. Redis supports eviction statistics “INFO stats shows key eviction counts for monitoring memory pressure.”

✅ 98. Redis supports key expiration checks “TTL key shows remaining time before a key expires.”

✅ 99. Redis supports cluster slot mapping “CLUSTER KEYSLOT key shows which slot a key belongs to.”

✅ 100. Redis supports cluster key migration “CLUSTER GETKEYSINSLOT retrieves keys in a specific slot for migration.”

Redis DBA Daily Commands

Redis DBA Daily Commands

1. Service Management

sudo systemctl start redis → Start the Redis service if it’s stopped.
sudo systemctl stop redis → Stop Redis safely (use before maintenance).
sudo systemctl restart redis → Restart Redis after config changes.
systemctl status redis → Check if Redis is running and view recent logs.

2. Connectivity & Basic Ops

redis-cli → Open the Redis command-line interface.
redis-cli ping → Quick health check; returns PONG if Redis is alive.
redis-cli SET mykey "hello" → Store a key/value pair.
redis-cli GET mykey → Retrieve the value of a key.

3. Monitoring & Health

redis-cli INFO → Full server stats (memory, clients, persistence, replication).
redis-cli INFO memory → Focused memory usage report.
redis-cli CLIENT LIST → Show all connected clients (IP, state, etc.).
redis-cli MONITOR → Stream all commands in real time (use carefully in prod).
redis-cli SLOWLOG get 10 → Show the 10 most recent slow queries.

4. Persistence & Backup

redis-cli SAVE → Force an immediate RDB snapshot (blocking).
redis-cli BGSAVE → Trigger background snapshot (non-blocking).
redis-cli INFO persistence → Check persistence status (last save, AOF enabled).

Backup files:
dump.rdb → RDB snapshot file.
appendonly.aof → AOF log file.

5. Memory & Key Management

redis-cli DBSIZE → Count how many keys are in the database.
redis-cli KEYS '*' → List all keys (avoid in large DBs, can block).
redis-cli DEL mykey → Delete a specific key.
redis-cli EXPIRE mykey 60 → Set a 60‑second TTL on a key.

6. Replication & High Availability

redis-cli INFO replication → Show replication role (master/replica) and status.
redis-cli SLAVEOF NO ONE → Promote a replica to master.
redis-cli SLAVEOF <master_ip> <master_port> → Make this node a replica of another.

7. Cluster Administration (if enabled)

redis-cli -c CLUSTER NODES → List all cluster nodes and their roles.
redis-cli -c CLUSTER INFO → Cluster health and slot coverage.
redis-cli --cluster check <ip:port> → Validate cluster configuration.

8. Security & Access

redis-cli -a <password> → Authenticate with password.
redis-cli ACL LIST → Show all ACL rules (Redis 6+).
redis-cli ACL WHOAMI → Show which user you’re logged in as.

Redis Daily Health‑Check Runbook

1. Service Status
systemctl status redis
Confirms Redis service is running and shows recent logs.

2. Connectivity
redis-cli ping
Quick test; should return PONG if Redis is alive.

3. Memory & Resource Usage
redis-cli INFO memory
Check total memory used, peak memory, fragmentation ratio.
Watch for memory close to system limits.

4. Persistence
redis-cli INFO persistence
Verify RDB/AOF status, last save time, and whether background saves are succeeding.

5. Replication / HA
redis-cli INFO replication
Shows if this node is master or replica.
Check replica lag and connected replicas.

6. Clients
redis-cli CLIENT LIST | wc -l
Count connected clients.
Useful to detect spikes or stuck connections.

7. Slow Queries
redis-cli SLOWLOG get 5
Review the last 5 slow queries.
Helps identify performance bottlenecks.

8. Keyspace Stats
redis-cli INFO keyspace
Shows number of keys per database and how many have TTLs.
Useful for monitoring growth and expiration behavior.

9. General Server Info
redis-cli INFO server
Check Redis version, uptime, and role.
Confirms you’re running the expected build.

10. Optional Cluster Checks (if enabled)
redis-cli -c CLUSTER INFO
redis-cli -c CLUSTER NODES
Verify cluster health, slot coverage, and node states.

✅ Daily Routine Summary

Service status → Is Redis running?
Ping test → Is it responsive?
Memory check → Is usage healthy?
Persistence check → Are RDB/AOF saves working?
Replication check → Are replicas in sync?
Client count → Any unusual spikes?
Slow queries → Any performance issues?
Keyspace stats → Growth and TTL behavior.
Server info → Version, uptime, role.
Cluster info → Slot coverage and node health (if clustered).

Thursday, December 4, 2025

Kubernetes: Complete Feature Summary for Executive Decision‑Makers

Kubernetes: Complete Feature Summary for Executive Decision‑Makers


Kubernetes is a full‑scale platform that modernizes how applications are deployed, scaled, secured, and operated. It delivers value across eight major capability areas, each directly tied to business outcomes.

1. Reliability & High Availability

Self‑healing containers
Automatic failover
Rolling updates & instant rollbacks
Health checks (liveness/readiness probes)
Multi‑node clustering
ReplicaSets for redundancy
Business impact: Keeps applications online, reduces outages, and improves customer experience.

2. Scalability & Performance

Horizontal Pod Autoscaling (HPA)
Vertical Pod Autoscaling (VPA)
Cluster Autoscaler
Built‑in load balancing
Resource quotas & limits
Business impact: Handles traffic spikes automatically and optimizes resource usage.

3. Security & Compliance

Role‑Based Access Control (RBAC)
Network Policies
Secrets encryption
Pod Security Standards
Image scanning & signing
Namespace isolation
Audit logging
Business impact: Strengthens security posture and supports compliance requirements.

4. Automation & DevOps Enablement

CI/CD integration
GitOps workflows
Automated deployments & rollbacks
Declarative configuration
Infrastructure as Code (IaC)
Business impact: Accelerates delivery, reduces manual errors, and standardizes operations.

5. Environment Standardization

Namespaces for dev/test/prod
Consistent container images
ConfigMaps & Secrets for environment configs
Multi‑OS container support (CentOS, Ubuntu, Debian, etc.)
Business impact: Eliminates “works on my machine” issues and improves developer productivity.

6. Cost Optimization

Efficient bin‑packing
Autoscaling to reduce idle resources
Spot instance support
Multi‑cloud flexibility
High container density
Business impact: Lowers infrastructure costs and prevents over‑provisioning.

7. Multi‑Cloud & Hybrid Cloud Flexibility

Runs on AWS, Azure, GCP, on‑prem, or hybrid
No vendor lock‑in
Disaster recovery across regions
Edge computing support
Business impact: Future‑proofs the organization and enables global deployments.

8. Observability & Monitoring

Metrics (Prometheus, Metrics Server)
Logging (ELK, Loki)
Tracing (Jaeger, OpenTelemetry)
Dashboards (Grafana, Lens)
Business impact: Improves visibility, speeds up troubleshooting, and supports data‑driven decisions.

Wednesday, November 26, 2025

Kubernetes Knowledge Transfer Pack

Kubernetes Knowledge Transfer Pack


1. Namespaces
Definition: Logical partitions in a cluster, used to separate environments or teams.
Commands:
kubectl get namespaces
kubectl create namespace dev-team
kubectl delete namespace dev-team

2. Pods
Definition: Smallest deployable unit in Kubernetes, wraps one or more containers.

Commands:
kubectl get pods
kubectl get pods --all-namespaces
kubectl describe pod <pod-name>
kubectl delete pod <pod-name>

3. Containers
Definition: Actual running processes inside pods (Docker/containerd images).

Commands:
kubectl logs <pod-name> -c <container-name>
kubectl exec -it <pod-name> -c <container-name> -- /bin/sh

4. Deployments
Definition: Controller that manages pods, scaling, and rolling updates.

Commands:
kubectl create deployment nginx-deploy --image=nginx
kubectl scale deployment nginx-deploy --replicas=5
kubectl get deployments
kubectl delete deployment nginx-deploy

5. Services
Definition: Provides stable networking to pods.
Types: ClusterIP, NodePort, LoadBalancer.

Commands:
kubectl expose deployment nginx-deploy --port=80 --target-port=80 --type=ClusterIP
kubectl get svc
kubectl delete svc nginx-deploy

6. ConfigMaps
Definition: Store non‑confidential configuration data.

Commands:
kubectl create configmap app-config --from-literal=ENV=prod
kubectl get configmaps
kubectl describe configmap app-config

7. Secrets
Definition: Store sensitive data (passwords, tokens).

Commands:
kubectl create secret generic db-secret --from-literal=DB_PASSWORD=banking123
kubectl get secrets
kubectl describe secret db-secret

8. Volumes & Storage
Definition: Persistent storage for pods.

Commands:
kubectl get pv
kubectl get pvc --all-namespaces

9. StatefulSets
Definition: Manage stateful apps (databases, Kafka).

Commands:
kubectl apply -f redis-statefulset.yaml
kubectl get statefulsets

10. DaemonSets
Definition: Ensures one pod runs on every node (logging, monitoring).

Commands:
kubectl get daemonsets -n kube-system

11. Jobs & CronJobs
Job: Runs pods until completion.
CronJob: Runs jobs on a schedule.

Commands:
kubectl create job pi --image=perl -- perl -Mbignum=bpi -wle 'print bpi(2000)'
kubectl get jobs
kubectl create cronjob hello --image=busybox --schedule="*/1 * * * *" -- echo "Hello World"
kubectl get cronjobs

12. Ingress
Definition: Manages external HTTP/HTTPS access to services.

Commands:
kubectl apply -f ingress.yaml
kubectl get ingress

🏗 Kubernetes Architecture

Control Plane Components

API Server → Entry point for all requests.

etcd → Cluster state database.

Controller Manager → Ensures desired state.

Scheduler → Assigns pods to nodes.

Node Components

Kubelet → Agent ensuring containers run.

Kube-proxy → Networking rules.

Container Runtime → Runs containers (Docker, containerd).

Add‑ons
CoreDNS → DNS service discovery.

CNI Plugin (Flannel/Calico) → Pod networking.

Metrics Server → Resource monitoring.

📊 Monitoring & Health Commands

kubectl get nodes -o wide
kubectl get pods --all-namespaces -w
kubectl get events --all-namespaces --sort-by=.metadata.creationTimestamp
kubectl top nodes
kubectl top pods
systemctl status kubelet
systemctl status containerd

Start and Stop Kubernetes Services

Start and Stop Kubernetes Services


Proper Stop/Start Cycle

1. Stop services:

sudo systemctl stop kubelet
sudo systemctl stop containerd

2. Verify stopped:

systemctl status kubelet
systemctl status containerd

How to Confirm They’re Really Dow

# Check kubelet process
ps -ef | grep kubelet

# Check container runtime process
ps -ef | grep containerd

# List running containers (if using containerd)
sudo crictl ps

# If using Docker runtime
sudo docker ps

3. Start services again:

sudo systemctl start containerd
sudo systemctl start kubelet

4. Verify Recovery

After a minute or two, check again:

kubectl get nodes
kubectl get pods -n kube-system
kubectl get componentstatuses


How to Build Multi‑Environment Pods with CentOS, Ubuntu, Debian, and More

How to Build Multi‑Environment Pods with CentOS, Ubuntu, Debian, and More


Step 1: Create Namespaces

kubectl create namespace mqmdev
kubectl create namespace mqmtest
kubectl create namespace mqmprod

Step 2: Create Pods (example with 7 OS containers)

Save YAML files (mqmdev.yaml, mqmtest.yaml, mqmprod.yaml) with multiple containers inside each pod.

Example for mqmtest:

apiVersion: v1
kind: Pod
metadata:
name: mqmtest-pod
namespace: mqmtest
spec:
containers:
- name: centos-container
image: centos:7
command: ["/bin/bash", "-c", "sleep infinity"]
- name: redhat-container
image: registry.access.redhat.com/ubi8/ubi
command: ["/bin/bash", "-c", "sleep infinity"]
- name: ubuntu-container
image: ubuntu:22.04
command: ["/bin/bash", "-c", "sleep infinity"]
- name: debian-container
image: debian:stable
command: ["/bin/bash", "-c", "sleep infinity"]
- name: fedora-container
image: fedora:latest
command: ["/bin/bash", "-c", "sleep infinity"]
- name: oraclelinux-container
image: oraclelinux:8
command: ["/bin/bash", "-c", "sleep infinity"]
- name: alpine-container
image: alpine:latest
command: ["/bin/sh", "-c", "sleep infinity"]

Apply:

kubectl apply -f mqmdev.yaml
kubectl apply -f mqmtest.yaml
kubectl apply -f mqmprod.yaml

Step 3: Check Pod Status

kubectl get pods -n mqmdev
kubectl get pods -n mqmtest
kubectl get pods -n mqmprod

Step 4: List Container Names Inside a Pod

kubectl get pod mqmtest-pod -n mqmtest -o jsonpath="{.spec.containers[*].name}"

Output example:

centos-container redhat-container ubuntu-container debian-container fedora-container oraclelinux-container alpine-container

Step 5: Connect to a Particular Container

Use kubectl exec with -c <container-name>:

# CentOS
kubectl exec -it mqmtest-pod -n mqmtest -c centos-container -- /bin/bash

# Red Hat UBI
kubectl exec -it mqmtest-pod -n mqmtest -c redhat-container -- /bin/bash

# Ubuntu
kubectl exec -it mqmtest-pod -n mqmtest -c ubuntu-container -- /bin/bash

# Debian
kubectl exec -it mqmtest-pod -n mqmtest -c debian-container -- /bin/bash

# Fedora
kubectl exec -it mqmtest-pod -n mqmtest -c fedora-container -- /bin/bash

# Oracle Linux
kubectl exec -it mqmtest-pod -n mqmtest -c oraclelinux-container -- /bin/bash

# Alpine (use sh instead of bash)
kubectl exec -it mqmtest-pod -n mqmtest -c alpine-container -- /bin/sh

Step 6: Verify OS Inside Container

Once inside, run:
cat /etc/os-release

This confirms which OS environment you’re connected to.

✅ Summary

Create namespaces → mqmdev, mqmtest, mqmprod.
Apply pod YAMLs with 7 containers each.
Check pod status → kubectl get pods -n <namespace>.
List container names → kubectl get pod <pod> -n <namespace> -o jsonpath=....
Connect to container → kubectl exec -it ... -c <container-name> -- /bin/bash.
Verify OS → cat /etc/os-release.

Nodes in Kubernetes: The Unsung Heroes of Container Orchestration

Nodes in Kubernetes: The Unsung Heroes of Container Orchestration


What is a Node in Kubernetes?
A Node is a worker machine in Kubernetes. It can be a physical server or a virtual machine in the cloud. Nodes are where your pods (and therefore your containers) actually run.

Think of it like this:

Cluster = a team of machines.
Node = one machine in that team.
Pod = a unit of work scheduled onto a node.
Container = the actual application process inside the pod.


🔹 Node Components
Each node runs several critical services:

Kubelet → Agent that talks to the control plane and ensures pods are running.
Container Runtime → Runs containers (Docker, containerd, CRI‑O).
Kube‑proxy → Manages networking rules so pods can communicate with each other and with services.

🔹 Types of Nodes

Control Plane Node → Runs cluster management components (API server, etcd, scheduler, controller manager).
Worker Node → Runs user workloads (pods and containers).

🔹 Example: Checking Nodes

When you run:

[root@centosmqm ~]# kubectl get nodes
NAME        STATUS   ROLES           AGE   VERSION
centosmqm   Ready    control-plane   28h   v1.30.14

Explanation of Output:
NAME → centosmqm → the hostname of your node.
STATUS → Ready → the node is healthy and can accept pods.
ROLES → control-plane → this node is acting as the master/control plane, not a worker.
AGE → 28h → the node has been part of the cluster for 28 hours.
VERSION → v1.30.14 → the Kubernetes version running on this node.

👉 In this example, your cluster currently has one node (centosmqm), and it is the control plane node. If you added worker nodes, they would also appear in this list with roles like <none> or worker.

🔹 Commands to Work with Nodes

# List all nodes
kubectl get nodes

# Detailed info about a node
kubectl describe node centosmqm

# Show nodes with more details (IP, OS, version)
kubectl get nodes -o wide

✅ Summary

A Node is the machine (VM or physical) that runs pods.
Nodes can be control plane (managing the cluster) or worker nodes (running workloads).
Your example shows a single control-plane node named centosmqm, which is healthy and running Kubernetes v1.30.14.

Thursday, November 13, 2025

How to Copy an AMI Across AWS Regions: A Step-by-Step Guide

 How to Copy an AMI Across AWS Regions: A Step-by-Step Guide


Step-by-Step Guide: Copying an AMI to a Different AWS Region:

Step 1: Create an AMI from Your EC2 Instance

Go to the EC2 Dashboard in the AWS Console.
Select your instance → click Actions → Image and templates → Create image.
Enter a name and description.
Choose whether to reboot the instance (select NoReboot to avoid downtime).
Click Create image.

Step 2: Wait for the AMI to Become Available

Navigate to AMIs in the EC2 Dashboard.
Monitor the status until it changes to Available.

Step 3: Copy the AMI to Another Region

In the AMIs section, select your AMI.
Click Actions → Copy AMI.
Choose the destination region.
Optionally rename the AMI and configure encryption.
Click Copy AMI.

Step 4: Switch to the Destination Region

Change your region in the AWS Console to the target region.
Go to AMIs and confirm the copied AMI is listed and available.

Step 5: Launch an EC2 Instance from the Copied AMI

Select the copied AMI → click Launch instance.
Configure instance details, storage, and security groups.
Launch the instance.

Friday, November 7, 2025

Creating EC2 Launch Template for Auto Scaling Web Server

Creating EC2 Launch Template for Auto Scaling Web Server


Step 1: Create a Launch Template

Go to EC2 Dashboard → Launch Templates → Create launch template

Fill in:

Name: WebServerTemplate
AMI: Amazon Linux 2 (or your preferred AMI)
Instance Type: t2.micro/t3.micro (Free Tier Eligible)
Key Pair: Select your key
Security Group: Must allow HTTP (port 80)

User Data:

#!/bin/bash
# Update the package index
sudo su
yum update -y

# Install Apache HTTP server
yum install -y httpd

# Install Stress Command
yum install -y stress

# Start the httpd service
systemctl start httpd

# Optional: Create a simple index.html page
echo "<h1>Hello from EC201</h1>" > /var/www/html/index.html

# Enable httpd to start on boot
chkconfig httpd on

✅ Enable Auto Scaling guidance At the bottom of the form, check the box labeled “Provide guidance for Auto Scaling”. This ensures the template is optimized for use with Auto Scaling Groups.

Click Create launch template

Thursday, October 23, 2025

How to Change the Backup Location in pgBackRest for PostgreSQL 15

How to Change the Backup Location in pgBackRest for PostgreSQL 15


This guide walks you through updating pgBackRest to use a new backup directory — in this case, /u01/pgbackrest.

📁 Step 1: Create the New Backup Directory

mkdir -p /u01/pgbackrest
chown postgres:postgres /u01/pgbackrest
chmod 750 /u01/pgbackrest

⚙️ Step 2: Update pgBackRest Configuration

Edit the config file:

vi /etc/pgbackrest.conf

Update the [global] section to use the new path:

ini

[global]
repo1-path=/u01/pgbackrest
repo1-retention-full=2
repo1-retention-diff=4
log-level-console=info
log-level-file=debug
log-path=/var/log/pgbackrest

[pg15]
pg1-path=/u01/postgres/pgdata_15/data
pg1-port=5432
pg1-user=postgres

🔐 Step 3: Set Permissions on Config File

chmod 640 /etc/pgbackrest.conf
chown postgres:postgres /etc/pgbackrest.conf

🧱 Step 4: Recreate the Stanza

Since the backup location changed, you need to recreate the stanza:
sudo -u postgres env PGHOST=/tmp pgbackrest --stanza=pg15 stanza-create

🔍 Step 5: Verify the New Location

Run a check to confirm everything is working:

sudo -u postgres env PGHOST=/tmp pgbackrest --stanza=pg15 check

✅ You should see a message like:

Code
INFO: WAL segment ... successfully archived to '/u01/pgbackrest/archive/pg15/...'

💾 Step 6: Run a Test Backup

sudo -u postgres env PGHOST=/tmp pgbackrest --stanza=pg15 --type=full backup

📊 Step 7: Confirm Backup Storage

Check that backups are stored in the new location:

ls -l /u01/pgbackrest/pg15/backup

🧹 Optional: Clean Up Old Backup Location

If you no longer need the old backups:

bash

rm -rf /var/lib/pgbackrest

⚠️ Only do this if you're sure the new backups are working and complete.

pgBackRest Setup and PostgreSQL 15 Backup Guide

pgBackRest Setup and PostgreSQL 15 Backup Guide


This guide walks you through installing, configuring, backing up, restoring, and automating PostgreSQL 15 backups using pgBackRest.

Installation

# Add PostgreSQL Yum repo

sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Disable built-in PostgreSQL module

sudo dnf -qy module disable postgresql

# Install pgBackRest

sudo dnf install -y pgbackrest --nobest


# Verify installation

which pgbackrest

# Output: /usr/bin/pgbackrest

1. Create Backup Directory

mkdir -p /u01/pgbackrest
chown postgres:postgres /u01/pgbackrest
chmod 750 /u01/pgbackrest

2. Configure pgBackRest

Backup and edit the config file:

cp /etc/pgbackrest.conf /etc/pgbackrest.conf_bkp

vi /etc/pgbackrest.conf

[global]
repo1-path=/u01/pgbackrest
repo1-retention-full=2
repo1-retention-diff=4
log-level-console=info
log-level-file=debug
log-path=/var/log/pgbackrest

[pg15]
pg1-path=/u01/postgres/pgdata_15/data
pg1-port=5432
pg1-user=postgres

3. Set Permissions

chmod 640 /etc/pgbackrest.conf
chown postgres:postgres /etc/pgbackrest.conf

4. Confirm PostgreSQL Is Running

ps aux | grep postgres

Look for:

postgres ... -D /u01/postgres/pgdata_15/data

5. Test PostgreSQL Connection

sudo -u postgres psql -h /tmp -p 5432 -d postgres

6. Create Stanza

sudo -u postgres env PGHOST=/tmp pgbackrest --stanza=pg15 --log-level-console=info stanza-create

7. Configure WAL Archiving

vi /u01/postgres/pgdata_15/data/postgresql.conf
archive_mode = on
archive_command = 'pgbackrest --stanza=pg15 archive-push %p'

Reload PostgreSQL:

sudo -u postgres pg_ctl reload -D /u01/postgres/pgdata_15/data

8. Verify Stanza and Archiving

sudo -u postgres env PGHOST=/tmp pgbackrest --stanza=pg15 --log-level-console=info check

9. Run Full Backup

sudo -u postgres env PGHOST=/tmp pgbackrest --stanza=pg15 --type=full backup

10. View Backup Info

sudo -u postgres pgbackrest --stanza=pg15 info

PostgreSQL Test Database Setup

# Log in

sudo -u postgres psql

# Create Database

CREATE DATABASE test_db;

\c test_db

# Create Table

CREATE TABLE employees (id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, position VARCHAR(50),salary NUMERIC(10, 2));

# Insert Sample Data

INSERT INTO employees (name, position, salary) VALUES
('Ayaan Siddiqui', 'Manager', 75000.00),
('Zara Qureshi', 'Sr. Developer', 60000.00),
('Imran Sheikh', 'Jr. Developer', 50000.00);

# Query Table

SELECT * FROM employees;

# Exit

\q

Backup Types

Full Backup:

sudo -u postgres env PGHOST=/tmp pgbackrest --stanza=pg15 --type=full backup

Differential Backup:

\c test_db

INSERT INTO employees (name, position, salary) VALUES
('Fatima Ansari', 'DBA', 70000.00),
('Yusuf Khan', 'Sr. Developer', 50000.00),
('Nadia Rahman', 'Jr. Developer', 40000.00);

SELECT * FROM employees;

sudo -u postgres env PGHOST=/tmp pgbackrest --stanza=pg15 --type=diff backup

Incremental Backup:

\c test_db

INSERT INTO employees (name, position, salary) VALUES
('Bilal Ahmed', 'DEO', 34000.00),
('Sana Mirza', 'System Admin', 45000.00),
('Tariq Hussain', 'Accountant', 50000.00);

SELECT * FROM employees;

sudo -u postgres env PGHOST=/tmp pgbackrest --stanza=pg15 --type=incr backup

Verify Backups:

sudo -u postgres pgbackrest --stanza=pg15 info

Restore Options:

Option 1: Partial Restore

systemctl stop postgresql
sudo -u postgres env PGHOST=/tmp pgbackrest --stanza=pg15 --delta restore
systemctl start postgresql
systemctl status postgresql

Option 2: Full Clean Restore

systemctl stop postgresql
mv /var/lib/postgresql/15/main /var/lib/postgresql/15/main_backup_$(date +%F)
mkdir /var/lib/postgresql/15/main
chown -R postgres:postgres /var/lib/postgresql/15/main
chmod 700 /var/lib/postgresql/15/main
sudo -u postgres env PGHOST=/tmp pgbackrest --stanza=pg15 restore
systemctl start postgresql
systemctl status postgresql

Verify Restore:

sudo -u postgres psql -c "SELECT datname FROM pg_database;"

tail -f /var/log/pgbackrest/pgbackrest.log

Automate Backups with Cron:

crontab -u postgres -e

Add:

# Full Backup - Sunday 2 AM
0 2 * * 0 pgbackrest --stanza=pg15 --type=full backup

# Incremental Backup - Mon-Sat 2 AM
0 2 * * 1-6 pgbackrest --stanza=pg15 --type=incr backup

Monitor and Test:

Monitor Logs

tail -f /var/log/pgbackrest/pgbackrest.log

journalctl -u postgresql

Test Recovery Plan:

Regularly test backup restoration
Document recovery steps

Troubleshooting:

sudo -u postgres env PGHOST=/tmp pgbackrest --stanza=pg15 check