NodeCommunity
6 subscribers
84 photos
1 video
9 files
57 links
Download Telegram
NodeCommunity
https://chartio.com/learn/databases/how-does-indexing-work/ #indexing #database
Advantages

* Speed up SELECT query
* Helps to make a row unique or without duplicates(primary,unique)
* If index is set to fill-text index, then we can search against large string values. for example to find a word from a sentence etc.

Disadvantages

* Indexes take additional disk space.
* indexes slow down INSERT,UPDATE and DELETE, but will speed up UPDATE if the WHERE condition has an indexed field. INSERT, UPDATE and DELETE becomes slower because on each operation the indexes must also be updated.
#js_generators

Iterate over object values and do calculation


function * iter(obj) {
for (let [key, value] of Object.entries(obj)) {
if (Object(value) !== value) yield [obj, key, value];
else yield * iter(value);
}
}

// demo
const myObject = {
base: {
serving: {
size: 100
}
},
fat: {
acids: {
monoUnsaturatedFattyAcids: 12,
polyUnsaturatedFattyAcids: 'hello',
saturatedFattyAcids: [1, 2]
},
}
};

for (let [obj, key, value] of iter(myObject)) {
if (typeof value === "number") obj[key] *= 0.5; // multiply by 0.5
}
// The object has been mutated accordingly
console.log(myObject);
How to solve npm i error thike this on dokcer?

Here we go:

https://robinwinslow.uk/fix-docker-networking-dns

#docker #npm
Forwarded from hahacker_news
Manning.Elasticsearch.in.Action.pdf
20.3 MB
πŸ“šElasticsearch in Action (2023)
βœοΈΠΠ²Ρ‚ΠΎΡ€: Madhusudhan Konda
Forwarded from hahacker_news
Apress.Deploy.Container.Applications.Using.Kubernetes.pdf
16.1 MB
πŸ“šDeploy Container Applications Using Kubernetes: With Integration and Implementations with Aws Eks and Gcp Gke (2023)
βœοΈΠΠ²Ρ‚ΠΎΡ€: Shiva Subramanian
#postgres #docker #dump #backup

Backup postgres database running on docker.
docker exec -t <container_name_or_id> pg_dump -U <username> <db_name> > dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql


using gzip - If you want a smaller file size
docker exec -t <container_name_or_id> pg_dump -U <username> <db_name> | gzip > dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql.gz


Restore your databases
cat your_dump.sql | docker exec -i <container_name_or_id> psql -U <username> -d <db_name>
#postgres #cron #crontab #docker #dump #backup

Cron job to backaup postgres database running on docker which saves only last 3 file and save logs

- create a new file named backup_postgres.sh
- add the following content to the script

#!/bin/bash

# Script variables
DATE=$(date +%Y-%m-%d"_"%H:%M:%S)


# Docker container name or ID
CONTAINER=
<container_name_or_id>

# Database user
USER=
<db_user>

# Database name
DB_NAME=
<db_name>

# Path to your backup folder
BACKUP_DIR="/path/to/your/backup/folder"


# Backup filename
BACKUP_FILE="$BACKUP_DIR/$DB_NAME-$DATE.sql"


# Log filename
LOG_FILE="$
BACKUP_DIR/backup_log.log"

# Maximum number of backup files to keep
MAX_BACKUPS=
<number_of_backups_you_want_to_keep>

# Function to log messages
log_message() {
echo "$(date +%Y-%m-%d"_"%H:%M:%S) - $1" >> $LOG_FILE
}

# Start backup process
log_message "Starting backup for database: $DB_NAME"

# Run pg_dump inside Docker container and save the output to a file
if docker exec -t $CONTAINER pg_dump -U $USER $DB_NAME > $BACKUP_FILE; then
log_message "Backup successful: $BACKUP_FILE"
else
log_message "Error: Backup failed for $DB_NAME"
exit 1
fi

# Create an array with files sorted by modification time, oldest first
# shellcheck disable=SC2207
BACKUP_FILES=($(ls -ltr $BACKUP_DIR/*.sql | awk '{print $9}'))

# Get the number of existing backup files
NUM_BACKUPS=${#BACKUP_FILES[@]}

# Check if the number of backups exceeded the maximum allowed
if [ $NUM_BACKUPS -gt $MAX_BACKUPS ]; then
# Calculate how many files to delete
let "FILES_TO_DELETE = $NUM_BACKUPS - $MAX_BACKUPS"

# Delete the oldest files
for ((i=0; i<$FILES_TO_DELETE; i++)); do
echo "Deleting old backup: ${BACKUP_FILES[$i]}"
rm -f "${BACKUP_FILES[$i]}"
done
fi

log_message "Backup process completed"


- save and close the file.
- make your script executable:
chmod +x backup_postgres.sh

- edit Your Crontab to Schedule the Backup
crontab -e

- add a line to schedule your script. The format for a crontab entry is:
* * * * * command to execute
β”‚ β”‚ β”‚ β”‚ β”‚
β”‚ β”‚ β”‚ β”‚ β”‚
β”‚ β”‚ β”‚ β”‚ └───── day of week (0 - 7) (Sunday=0 or 7)
β”‚ β”‚ β”‚ └────────── month (1 - 12)
β”‚ β”‚ └─────────────── day of month (1 - 31)
β”‚ └──────────────────── hour (0 - 23)
└───────────────────────── min (0 - 59)


- for example, to run the backup daily at 3:00 AM:
0 3 * * * /path/to/your/script/backup_postgres.sh

- save and exit the editor. The cron job is now scheduled.
- ensure the cron service is running on your system:
sudo service cron status

- If it's not running, start it:
sudo service cron start

- to restart
sudo service cron restart