Skip to content

Instantly share code, notes, and snippets.

View kilfu0701's full-sized avatar

kilfu0701 kilfu0701

  • Trend Micro
  • Japan & Taiwan
View GitHub Profile
@kilfu0701
kilfu0701 / pg_queries.md
Last active January 25, 2023 04:37
Postgres useful command & queries.

Dump all schema & user's credentials/privileges.

pg_dumpall -U postgres -s > schema_all.sql

Grant Default PRIVILEGES to tables. (also auto apply for new tables.)

ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public \
@kilfu0701
kilfu0701 / zfs_change_drive.md
Created January 19, 2023 05:25
Change/Switch drives in ZFS RADI10. (also for updating broken drive)
  1. check current drivers
sudo zpool status

output:

pool: raid10_pool
state: ONLINE
@kilfu0701
kilfu0701 / zfs_command.sh
Created December 23, 2022 08:17
ZFS related command
## show pool configs
zfs get all zfs10
## print arc summary
arc_summary
## watch arc stats every 2 sec
watch -n 2 grep arc /proc/spl/kstat/zfs/arcstats
## test write speed
@kilfu0701
kilfu0701 / event_trigger_on_table_create.sql
Created December 16, 2022 05:12
[Postgres] Event trigger on table created
CREATE FUNCTION public.on_create_table_funct()
RETURNS event_trigger
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF SECURITY DEFINER
AS $BODY$
DECLARE
sch text;
BEGIN
@kilfu0701
kilfu0701 / send_notification_to_google_chat.sh
Created October 28, 2022 09:17
Send message to Google Chat with bash script.
#/bin/bash
set -e
# set your BOT's API KEY and TOKEN
API_KEY=******************************
API_TOKEN=****************************
## send notification to google chat with card format.
#
# sample:
@kilfu0701
kilfu0701 / postgres_ctid_convert.sql
Created October 21, 2022 05:01
Postgres ctid to bigint converter.
-- https://stackoverflow.com/questions/26279770/how-to-cast-ctid-system-column-into-long-and-vice-versa
-- ctid to long
SELECT ((ctid::text::point)[0]::bigint << 32) | (ctid::text::point)[1]::bigint AS long_ctid FROM table1 LIMIT 1;
long_ctid
-----------------
130043019788289
(1 row)
@kilfu0701
kilfu0701 / nvidia-fan-speed.sh
Created July 5, 2022 07:49
Adjust Nvidia graphic card fan speed on Ubuntu
# start a Xserver
sudo X -config xorg.conf
# set fan speed to 60%
sudo DISPLAY=:0 nvidia-settings -a "[gpu:0]/GPUFanControlState=1" -a "[fan:0]/GPUTargetFanSpeed=60"
@kilfu0701
kilfu0701 / pg_dump_custom.sh
Created April 25, 2022 11:23
Dump Postgres one table script
#!/bin/bash
set -e
set -o pipefail
# https://gist.github.com/kilfu0701/2f545f7f1a8a9d0bd923be8d38028817
function echo_c()
{
WHITE='\033[1;37m'
RED='\033[1;31m'
GREEN='\033[1;32m'
@kilfu0701
kilfu0701 / rm_table_idx.sql
Last active April 5, 2022 12:30
[postgres] delete a table's indexes function.
CREATE OR REPLACE FUNCTION rm_table_idx(tbl_name text)
RETURNS void AS
$$
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
@kilfu0701
kilfu0701 / Dockerfile
Created March 30, 2022 08:30
Dockerfile and docker-compose.yml by SAMBA volumes
FROM python:3.8
USER root
RUN apt-get update
RUN apt-get -y install locales && \
localedef -f UTF-8 -i ja_JP ja_JP.UTF-8
ENV LANG ja_JP.UTF-8
ENV LANGUAGE ja_JP:ja
ENV LC_ALL ja_JP.UTF-8