Tuesday, 25 February 2025

Filled under:

 

Here’s the rephrased version with technical corrections and clarifications:


1. Avoid Using Relaxed listen_addresses Settings

PostgreSQL runs as a server process, allowing users to connect to the database. The key question is: Where are these connections coming from?

The listen_addresses setting in postgresql.conf determines which network interfaces PostgreSQL will bind to and accept connections from.

Why does this matter?
If listen_addresses is set to "*", PostgreSQL will listen on all available network interfaces, accepting incoming connections and then verifying access rules defined in pg_hba.conf.

Why is this a security risk?

Listening on all interfaces increases the risk of unauthorized access. Attackers could flood the server with authentication attempts, and if misconfigured, this could lead to a security breach.

Recommended Best Practices

  • For local connections only:

    • Set listen_addresses = 'localhost'
  • For remote connections (with proper security measures):

    • Set listen_addresses = '<specific IP>' (e.g., listen_addresses = '192.168.1.100' for a private network)
    • Avoid using "*" unless necessary and properly secured with firewalls and authentication.

If your database does not need to accept external connections, disabling listening entirely provides the best security. This ensures PostgreSQL does not even have to reject unauthorized requests.

While pg_hba.conf allows fine-grained access control, limiting network exposure is the first and most effective security measure.


Technical Corrections Made:

  1. Clarified that listen_addresses binds PostgreSQL to network interfaces, not just "addresses."
  2. Corrected the recommendation for remote connections (you should specify a secure IP rather than setting it to "localhost", which only allows local connections).
  3. Emphasized using firewalls and proper authentication for remote connections.

Let me know if you need further refinements!

Posted By Nikhil07:53

Thursday, 13 February 2025

Filled under:

 

Subject: Out of Office – Limited Availability

Hi,

I am currently out of the office and will have limited access to emails.

For assistance, please refer to our Knowledge Base articles or raise a support ticket for prompt resolution.

I will respond to emails as soon as possible upon my return.

Best regards,
[Your Name]

Posted By Nikhil21:46

Wednesday, 12 February 2025

Filled under:

  I know great decisions take time, but I’m starting to wonder if my request has entered a secret VIP queue for extra processing. 

😏 Let me know if there’s a secret handshake I need to speed it up! 

Posted By Nikhil16:55

Saturday, 8 February 2025

Filled under:

 #!/bin/bash


# Configuration

PATRONI_API="http://localhost:8008"

MAX_ALLOWED_LAG=1048576  # 1MB lag threshold


# Function to get LSN of a node

get_lsn() {

    local NODE=$1

    curl -s "${PATRONI_API}/cluster" | jq -r ".members[] | select(.name==\"$NODE\") | .xlog_location"

}


# Check if Patroni API is accessible

if ! curl -s "${PATRONI_API}/cluster" &>/dev/null; then

    echo "Error: Unable to reach Patroni API at ${PATRONI_API}"

    exit 1

fi


# Fetch current cluster status

echo "Fetching Patroni cluster status..."

CLUSTER_INFO=$(curl -s "${PATRONI_API}/cluster")


# Extract leader and replicas

LEADER=$(echo "$CLUSTER_INFO" | jq -r '.leader')

REPLICAS=$(echo "$CLUSTER_INFO" | jq -r '.members[] | select(.role=="replica") | .name')


echo "Current Leader: $LEADER"

echo "Available Replicas:"

echo "$REPLICAS"


# Get current LSN for leader

LEADER_LSN=$(get_lsn "$LEADER")

echo "Leader LSN: $LEADER_LSN"


# Prompt user for the target leader

read -p "Enter the target replica to become the new leader: " TARGET


# Validate input

if ! echo "$REPLICAS" | grep -qw "$TARGET"; then

    echo "Error: Invalid replica name. Exiting."

    exit 1

fi


# Get LSN for target replica

TARGET_LSN=$(get_lsn "$TARGET")

echo "Target Replica LSN: $TARGET_LSN"


# Calculate LSN lag

LSN_LAG=$((LEADER_LSN - TARGET_LSN))

echo "LSN Lag: $LSN_LAG bytes"


# Validate RPO threshold

if (( LSN_LAG > MAX_ALLOWED_LAG )); then

    echo "Error: Replica is lagging by more than $MAX_ALLOWED_LAG bytes. Switchover aborted."

    exit 1

fi


# Initiate switchover

echo "Initiating switchover from $LEADER to $TARGET..."

SWITCHOVER_RESPONSE=$(curl -s -X POST "${PATRONI_API}/switchover" -H "Content-Type: application/json" \

    -d "{\"leader\": \"$LEADER\", \"candidate\": \"$TARGET\"}")


# Check result

if echo "$SWITCHOVER_RESPONSE" | jq -e '.error' &>/dev/null; then

    echo "Switchover failed: $(echo "$SWITCHOVER_RESPONSE" | jq -r '.error')"

    exit 1

fi


echo "Switchover successful! $TARGET is now the new leader."

Posted By Nikhil20:03
Filled under:

 #!/bin/bash


# Configuration

PATRONI_API="http://localhost:8008"


# Check if Patroni API is accessible

if ! curl -s "${PATRONI_API}/cluster" &>/dev/null; then

    echo "Error: Unable to reach Patroni API at ${PATRONI_API}"

    exit 1

fi


# Fetch current cluster status

echo "Fetching Patroni cluster status..."

CLUSTER_INFO=$(curl -s "${PATRONI_API}/cluster")


# Extract leader and replicas

LEADER=$(echo "$CLUSTER_INFO" | jq -r '.leader')

REPLICAS=$(echo "$CLUSTER_INFO" | jq -r '.members[] | select(.role=="replica") | .name')


echo "Current Leader: $LEADER"

echo "Available Replicas:"

echo "$REPLICAS"


# Prompt user for the target leader

read -p "Enter the target replica to become the new leader: " TARGET


# Validate input

if ! echo "$REPLICAS" | grep -qw "$TARGET"; then

    echo "Error: Invalid replica name. Exiting."

    exit 1

fi


# Initiate switchover

echo "Initiating switchover from $LEADER to $TARGET..."

SWITCHOVER_RESPONSE=$(curl -s -X POST "${PATRONI_API}/switchover" -H "Content-Type: application/json" \

    -d "{\"leader\": \"$LEADER\", \"candidate\": \"$TARGET\"}")


# Check result

if echo "$SWITCHOVER_RESPONSE" | jq -e '.error' &>/dev/null; then

    echo "Switchover failed: $(echo "$SWITCHOVER_RESPONSE" | jq -r '.error')"

    exit 1

fi


echo "Switchover successful! $TARGET is now the new leader."

Posted By Nikhil20:01

Wednesday, 5 February 2025

Filled under:

 Your enthusiasm and proactive approach in taking handovers, tackling challenging PostgreSQL tasks, and handling critical incidents have made a significant impact on our team's efficiency and success.

Your clarity in communication during handovers and your passion for knowledge sharing are invaluable assets. It's great to have a colleague who consistently strives for excellence and fosters a collaborative environment.

Thank you for being an exceptional teammate. Looking forward to achieving more milestones together!

Posted By Nikhil05:49
Filled under:

 Your enthusiasm and proactive approach in taking handovers, tackling challenging PostgreSQL tasks, and handling critical incidents have made a significant impact on our team's efficiency and success.

Your clarity in communication during handovers and your passion for knowledge sharing are invaluable assets. It's great to have a colleague who consistently strives for excellence and fosters a collaborative environment.

Thank you for being an exceptional teammate. Looking forward to achieving more milestones together!

Posted By Nikhil05:17
Filled under:

t's truly a pleasure working with you, and I greatly appreciate your consistent cooperation and expertise. Your deep knowledge of Oracle and database management, along with your approachable and proactive nature, ensures that things always go smoothly. Supporting your application has been both seamless and enjoyable.

Thank you for being such a fantastic collaborator! Wishing you a Happy and Prosperous New Year filled with success and happiness. Looking forward to many more successful collaborations in the year ahead.

Posted By Nikhil05:09