Skip to content

Instantly share code, notes, and snippets.

@phaneesh
phaneesh / README.md
Created April 16, 2025 04:47
PostgreSQL maintenance

Features

  • Runs VACUUM ANALYZE on all tables or selected tables
  • Optional VACUUM FULL for more aggressive space reclamation
  • Optional REINDEX to rebuild all indexes
  • Includes table size reporting before and after optimization
  • Supports filtering tables (include/exclude lists)
  • Provides detailed progress and timing information

How to Use the Script

  • First, install the required dependency:
@phaneesh
phaneesh / postgres_backup.sh
Last active April 15, 2025 14:58
PostgreSql Daily Backup & Restore
#!/bin/bash
#
# PostgreSQL Daily Backup Script
# This script creates daily backups of PostgreSQL databases with rotation
#
# Configuration variables
BACKUP_DIR="/var/backups/postgresql"
DB_USER="postgres"
DB_PASSWORD="" # For security, consider using a .pgpass file instead
@phaneesh
phaneesh / jenkins-deletejobs.groovy
Created December 24, 2024 04:51
jenkins-delete-jobs.groovy
import jenkins.model.*
String[] toBeDeletedJobs = []
def matchedJobs = Jenkins.instance.items.findAll { job ->
toBeDeletedJobs.contains(job.name)
}
matchedJobs.each { job ->
println job.name
https://github.com/Thomas-George-T/Movies-Analytics-in-Spark-and-Scala
Change execution engine = Tez, spark ( set Tez/Spark client jars into HADOOP_CLASSPATH)
Partitioning - PARTITIONED BY clause is used to divide the table into buckets.
Buckting - CLUSTERED BY clause is used to divide the table into buckets.
Map-Side join, Bucket-Map-Side join, Sorted Bucket-Map-Side join
Usage of suitable file format = ORC(Optimized Row Columnar) file formate
Indexing
Vectorization along with ORC
CBO
@phaneesh
phaneesh / jenkins-get-git-url.groovy
Last active August 2, 2022 12:18
Jenkins git repository URL for all jobs in a view
import jenkins.model.*
Jenkins.instance.getView('<view name>').items.each {
try {
println(it.fullName +"," + it.getScm().getUserRemoteConfigs()[0].getUrl())
} catch(Exception e) {
println("Error getting git url for: " +it)
}
}
@phaneesh
phaneesh / rundeck-cleanup.sh
Last active August 28, 2020 06:03
Clear rundeck logs and job execution history
#!/bin/bash
RUNDECK_DB_HOST=''
RUNDECK_DB_USER=''
RUNDECK_DB_PASSWORD=''
RUNDECK_DB_NAME=''
cd /var/log/rundeck/
find . -type f \( -name "*.api.log.*" -o -name "*.executions.log.*" -o -name "rundeck.log.*" -o -name "*.service.log.*" -o -name "*.jobs.log.*" -o -name "*.audit.log.*" \) -mtime +3 -exec rm {} \;
cd /var/lib/rundeck/logs/rundeck/
find . -type f \( -name "*.rdlog" -o -name "*.json" -o -name "*.xml" \) -mtime +10 -exec rm {} \;
find . -type d -empty -delete
@phaneesh
phaneesh / jenkins-old-builds-cleanup.groovy
Last active March 10, 2020 05:38
Cleanup Old Jenkins builds
import jenkins.model.Jenkins
import hudson.model.Job
MAX_BUILDS = 3
for (job in Jenkins.instance.items) {
if(job.name.toLowerCase().endsWith("develop") || job.name.toLowerCase().endsWith("stage")) {
println "Deleting old builds: " +job.name
def recent = job.builds.limit(MAX_BUILDS)
for (build in job.builds) {
@phaneesh
phaneesh / jenkins-workspace-cleanup.groovy
Last active March 10, 2020 03:59
Cleanup Jenkins Workspaces (All Projects)
import jenkins.model.*
Jenkins.instance.getAllItems(AbstractProject.class)
.each {
try {
println("Wiping workspace for "+it.fullName)
it.doDoWipeOutWorkspace()
} catch(Exception e) {
println("Error wiping workspace for "+it.fullName)
}
}
@phaneesh
phaneesh / jenkins-get-invalid-branch-list.groovy
Created July 29, 2019 06:37
Get Branch invalid/non-standard configuration from Jenkins
import hudson.model.*
import hudson.maven.MavenModuleSet
import hudson.tasks.*
import hudson.plugins.git.GitSCM
//List valid branches that can be built
def validBranches = ["develop","master"]
Hudson.instance.items.each {
if(it.getScm() instanceof GitSCM) {
Set branchNames = []
it.getScm().getBranches().each { b ->
@phaneesh
phaneesh / set-build-history.groovy
Created July 26, 2019 15:27
Jenkins - Set Build History Retention
import hudson.model.*
import hudson.maven.MavenModuleSet
import hudson.tasks.*
Hudson.instance.items.each {
if(it instanceof MavenModuleSet) {
if(it.getBuildDiscarder() != null && it.getBuildDiscarder() instanceof LogRotator) {
def l = new LogRotator(365,-1,-1,-1)
it.setBuildDIscarder(l)
}