brew cask
brew tap homebrew/cask-fonts
brew install font-fira-code
brew install font-Fira-Code-nerd-font
brew install font-hack-nerd-font
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Systemd - How to read live-tail logs of multiple services with journalctl | |
sudo journalctl --follow _SYSTEMD_UNIT=docker.service + _SYSTEMD_UNIT=apache2.service |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3-alpine | |
# install requirements for psycopg2 | |
RUN apk update && apk add -u \ | |
postgresql-dev \ | |
gcc \ | |
python3-dev \ | |
musl-dev | |
RUN pip3 install psycopg2 |
- Create
UNLOGGED
table. This reduces the amount of data written to persistent storage by up to 2x. - Set
WITH (autovacuum_enabled=false)
on the table. This saves CPU time and IO bandwidth on useless vacuuming of the table (since we neverDELETE
orUPDATE
the table). - Insert rows with
COPY FROM STDIN
. This is the fastest possible approach to insert rows into table. - Minimize the number of indexes in the table, since they slow down inserts. Usually an index
on
time timestamp with time zone
is enough. - Add
synchronous_commit = off
topostgresql.conf
. - Use table inheritance for fast removal of old data:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Convert Javascript date to Pg YYYY MM DD HH MI SS | |
function pgFormatDate(date) { | |
/* Via http://stackoverflow.com/questions/3605214/javascript-add-leading-zeroes-to-date */ | |
function zeroPad(d) { | |
return ("0" + d).slice(-2) | |
} | |
var parsed = new Date(date) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with table_stats as ( | |
select psut.relname, | |
psut.n_live_tup, | |
1.0 * psut.idx_scan / greatest(1, psut.seq_scan + psut.idx_scan) as index_use_ratio | |
from pg_stat_user_tables psut | |
order by psut.n_live_tup desc | |
), | |
table_io as ( | |
select psiut.relname, | |
sum(psiut.heap_blks_read) as table_page_read, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pg' | |
db = PG.connect dbname: 'postgres' | |
db.exec("DROP DATABASE IF EXISTS just_fkn_around;") | |
db.exec("CREATE DATABASE just_fkn_around;") | |
db = PG.connect dbname: 'just_fkn_around' | |
define_method(:sql) { |sql| db.exec(sql).to_a } | |
sql <<-SQL | |
-- some data to query |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE EXTENSION tablefunc; | |
CREATE TABLE sales(year int, month int, qty int); | |
INSERT INTO sales VALUES(2007, 1, 1000); | |
INSERT INTO sales VALUES(2007, 2, 1500); | |
INSERT INTO sales VALUES(2007, 7, 500); | |
INSERT INTO sales VALUES(2007, 11, 1500); | |
INSERT INTO sales VALUES(2007, 12, 2000); | |
INSERT INTO sales VALUES(2008, 1, 1000); | |
INSERT INTO sales VALUES(2009, 5, 2500); |
Here's a few things I tried to write output to a python subprocess pipe.
from subprocess import Popen, PIPE
p = Popen('less', stdin=PIPE)
for x in xrange(100):
p.communicate('Line number %d.\n' % x)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Needed PS packages | |
# Install-Package -Name pscx | |
# Install-Package -Name AWSPowerShell | |
# | |
# Scheduling | |
# The script then needs to be scheduled to run every night, I’m using scheduled tasks for this, | |
# creating a task that runs nightly and triggers the powershell script by running | |
# Powershell.exe with the arguments | |
# -ExecutionPolicy Bypass C:\SqlBackup\SqlBackupToS3.ps1. | |
# From <https://www.rhysgodfrey.co.uk/b/blog/posts/backing-up-a-sql-database-to-amazon-s3-using-powershell> |
NewerOlder