Skip to content

Instantly share code, notes, and snippets.

# dump specific postgres schemas from database `mydb`
pg_dump -U postgres -nschema1 -npublic -npg_catalog -npg_toast -ninformation_schema -Fc mydb > mydb.dump
# after restoring above data move the table from the original schema to public schema
DO
$$
DECLARE
row record;
BEGIN
@rjdp
rjdp / default.vcl
Created February 4, 2017 00:02
Varnish 4.x vcl config for django
vcl 4.0;
# Default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
# Happens before we check if we have this in cache already.
@rjdp
rjdp / AWS - EC2 - Change PEM Key
Created January 29, 2017 10:54
AWS - EC2 - Change PEM Key
1. From the AWS EC2 Console go to "Key Pairs" and generate a new key pair (eg: NewKey.pem); Download the generated pem key, and chmod it to 0666
2. Use the new pem key to generate a public key
$ ssh-keygen -y
When prompted, enter the path to NewKey.pem. This will generate NewKey.pub
Tip: Edit NewKey.pub and append the key's name so you can identify it easier in the next steps.
Just append a single space, then a tag/name for the key
@rjdp
rjdp / i3 commands
Last active January 12, 2023 19:36
list of useful i3 commands
reload i3 config - $mod + Shift + r
switch to vertical tiling - $mod + v
switch to horizontal tiling - $mod + h
switch to stack mode - $mod + s
switch to tiling mode - $mode + e
open dmenu(like ubuntu dash) - $mod + d
maximaize window - $mod + w
switch window in current workspace - $mod + <j|k|l|;> or <arrow key>
resize windows - $mod + r then press right/left arrow keys ; Esc to escape resize mode
switch window positon - $mod + shift + <left/right/up/down arrow>
#! /home/blackmonk15/.virtualenv/bm/bin/python
import os, sys, re
from os import listdir
import time
import subprocess
from datetime import datetime
from optparse import OptionParser
BCKP_DIR = "/home/blackmonk15/alldbbckp"
@rjdp
rjdp / backup.sh
Created January 14, 2017 07:30
dump each db postgres
#!/bin/bash
echo "PostgreSQL"
export PGPASSWORD="postgre password here"
DBLIST=`psql -U postgres -d postgres -q -t -c 'SELECT datname from pg_database'`
for d in $DBLIST
do
echo "Dumping $d";
pg_dump -U postgres $d > /path/to/dump/directory/$d.postgres.sql
done
@rjdp
rjdp / tenant_schemas.diff
Created January 6, 2017 22:15
incase using tenant_schemas 1.5.2 with django1.5.x use this diff to patch to tenant_schemas
diff --git a/postgresql_backend/introspection.py b/postgresql_backend/introspection.py
index a856d26..d030edb 100644
--- a/postgresql_backend/introspection.py
+++ b/postgresql_backend/introspection.py
@@ -11,4 +11,5 @@ class DatabaseSchemaIntrospection(DatabaseIntrospection):
WHERE c.relkind IN ('r', 'v', '')
AND n.nspname = '%s'
AND pg_catalog.pg_table_is_visible(c.oid)""" % self.connection.schema_name)
- return [row[0] for row in cursor.fetchall() if row[0] not in self.ignored_tables]
+ #return [row[0] for row in cursor.fetchall() if row[0] not in self.ignored_tables]
@rjdp
rjdp / a.py
Created December 7, 2015 11:54
test
print("hello")