Skip to content

Instantly share code, notes, and snippets.

View redsfyre's full-sized avatar
:shipit:
There is nothing here -> /dev/null

Yasin İsa YILDIRIM redsfyre

:shipit:
There is nothing here -> /dev/null
View GitHub Profile
@redsfyre
redsfyre / queries.sql
Last active April 22, 2024 06:14
Postgresql troubleshooting shortcuts
-- Get long queries
SELECT
pid,
now() - pg_stat_activity.query_start AS duration,
state,
datname,
query
FROM pg_stat_activity
WHERE (now() - pg_stat_activity.query_start) > interval '5 seconds' and state != 'idle' order by duration desc;
@redsfyre
redsfyre / pg_show_active_locks.sql
Created March 20, 2024 19:29
Postgresql locks view
CREATE OR REPLACE VIEW public.active_locks AS
SELECT t.schemaname,
t.relname,
l.locktype,
l.page,
l.virtualtransaction,
l.pid,
l.mode,
l.granted
FROM pg_locks l
@redsfyre
redsfyre / postgresql_index_stats.sql
Created September 15, 2022 10:47
Postgresql get index scan, index size stats
SELECT
pt.tablename AS TableName
,t.indexname AS IndexName
,to_char(pc.reltuples, '999,999,999,999') AS TotalRows
,pg_size_pretty(pg_relation_size(quote_ident(pt.tablename)::text)) AS TableSize
,pg_size_pretty(pg_relation_size(quote_ident(t.indexrelname)::text)) AS IndexSize
,to_char(t.idx_scan, '999,999,999,999') AS TotalNumberOfScan
,to_char(t.idx_tup_read, '999,999,999,999') AS TotalTupleRead
,to_char(t.idx_tup_fetch, '999,999,999,999') AS TotalTupleFetched
FROM pg_tables AS pt
@redsfyre
redsfyre / custom-opsgenieintegration
Last active September 9, 2022 08:09
An example script for Wazuh - Opsgenie integrations. You need to edit the issue_data variable within the generate_msg function. For example, you should write the name of the team you created on opsgenie in the responder field. Find "XXXX Team" in the code below. Below code tested on Wazuh 4.3.7
#!/bin/bash
# Copyright (C) 2015, Wazuh Inc.
# Created by Wazuh, Inc. <info@wazuh.com>.
# This program is free software; you can redistribute it and/or modify it under the terms of GPLv2
WPYTHON_BIN="framework/python/bin/python3"
SCRIPT_PATH_NAME="$0"
DIR_NAME="$(cd $(dirname ${SCRIPT_PATH_NAME}); pwd -P)"
@redsfyre
redsfyre / oracle-useful-queries.sql
Last active June 30, 2022 05:36
Oracle db useful queries
-- Gets tables with their auto generated sequences
select table_name,data_default from user_tab_cols where identity_column='YES';
-- Gets table and its ID column details, like sequence name if its auto generated sequence
COLUMN table_name FORMAT A50
COLUMN column_name FORMAT A15
COLUMN sequence_name format A15
COLUMN generation_type FORMAT A10
COLUMN identity_options FORMAT A75
@redsfyre
redsfyre / list-table-indexes-on-oracledb.sql
Last active October 3, 2022 07:36
Oracle DB list table indexes and their columns for specific table
select index_name, column_name from user_ind_columns where table_name='&tablename';
-- Enter table name after running this query
-- dba_ind_columns : This is to used if login with user having DBA role
-- all_ind_columns : This is to used if login with user having normal role
-- user_ind_columns : This is to used if login with user having normal role
-- OK nvm, this one is better;
set pagesize 50000 verify off echo off
@redsfyre
redsfyre / sequence_list.sql
Created March 23, 2022 08:05
List postgresql sequences. Actually i dont remember what is this query :D
select sequence_name, (xpath('/row/last_value/text()', xml_count))[1]::text::int as last_value
from (
select sequence_schema,
sequence_name,
query_to_xml(format('select last_value from %I.%I', sequence_schema, sequence_name), false, true, '') as xml_count
from information_schema.sequences
where sequence_schema = 'public'
) new_table order by sequence_name asc;
@redsfyre
redsfyre / k8s-ocp-cli-tricks.md
Last active December 24, 2021 13:10
Kubernetes & Openshift CLI Tricks -- WIP

Kubernetes list all deployments and their specs (requests/limits)

kubectl get deployments -o jsonpath='{range .items[*]}{"NAME:  "}{.metadata.name}{"\nSPEC:  \n  LIMITS  : "}{.spec.template.spec.containers[*].resources.limits}{"\n  REQUESTS: "}{.spec.template.spec.containers[*].resources.requests}{"\n\n"}{end}'

Kubernetes list all cronjobs and their specs (requests/limits)

kubectl get cronjobs -o jsonpath='{range .items[*]}{"NAME:  "}{.metadata.name}{"\nSPEC:  \n  LIMITS  : "}{.spec.jobTemplate.spec.template.spec.containers[*].resources.limits}{"\n  REQUESTS: "}{.spec.jobTemplate.spec.template.spec.containers[*].resources.requests}{"\n\n"}{end}'
@redsfyre
redsfyre / index_dropper.sql
Created November 9, 2021 10:58
Query that drops all indexes in the given table. Note: unique keys are not affected by this operation.
DO
$do$
DECLARE
_sql text;
BEGIN
SELECT 'DROP INDEX ' || string_agg(indexrelid::regclass::text, ', ')
FROM pg_index i
LEFT JOIN pg_depend d ON d.objid = i.indexrelid
AND d.deptype = 'i'
WHERE i.indrelid = 'TABLE_NAME'::regclass -- Replace the TABLE_NAME with your table's name
@redsfyre
redsfyre / copy_id_sequence.sql
Last active November 9, 2021 07:27
While I was creating postgresql table partitions, I realized that I needed to move/copy the old id sequence to the new table. We can do this with the following query
postgres_test_db=# select last_value from old_table_id_seq;
last_value
------------
2084740
(1 row)
postgres_test_db=# select last_value from new_table_id_seq;
last_value
------------
1