Wednesday, February 27, 2013

DB2 command reference

Invoke interpreter:
shell> db2

List available databases:
db2_shell> list database directory

List DB2 shell history:
db2_shell> history
# or
db2_shell> h

Edit and Execute command from DB2 shell history:
# command_num is from the above history command
db2_shell> edit command_num
# or
db2_shell> e command_num

Connect to database from within the db2 interpreter (CLP):
db2_shell> connect to databasename

Connect to database from UNIX shell:
# lasts for duration of current shell session.
db2 connect to database_name

Run SQL command from UNIX shell:
# first connect to database via UNIX shell (above)
# then run the following
db2 -vf scriptname.sql

List tables in database:
db2_shell> list tables

List indexes on a table:
SELECT indschema,INDNAME from syscat.indexes where tabname = 'MYTABLE' and tabschema = 'MYSCHEMA'

Analyze table:
runstats on table schema.tablename

List connections to database:
unix> db2 list applications
# or
db2_shell> list applications
# for detail information
unix> db2 list applications show detail

Get current user:

Disconnect all connections:
force applications all
db2 terminate # this might work

Drop database:
drop database databasename

Create database:
create database databasename

Create the explain tables:
connect to databasename
db2 -vtf /opt/ibm/db2/V9.7/misc/EXPLAIN.DDL

Stop DB2:

Start DB2: 

Allow TCP connections (probably unsafe):
update database manager configuration using svcename 3700
get database manager configuration    # verify change
db2set DB2COMM=tcpip
sudo /sbin/iptables -A INPUT -p tcp --dport 7300 -j ACCEPT
sudo /sbin/service iptables save
sudo /sbin/service iptables restart

Update config params:
update db cfg for database_name using logfilsiz 8000
 # or
update database configuration for database_name using logprimary 9 logfilsiz 8000
force applications all


Thursday, February 14, 2013

NewRelic quick Django setup

pip install newrelic
newrelic-admin generate-config LICENSE-KEY newrelic.ini
# add your key to generated config

NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-program python run_gunicorn


NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-program python runserver

Monday, February 11, 2013

Postgres Access

In pg_hba.conf, set the following: 

To allow all remote users to log into a postgres database:

In pg_hba.conf, set the following: 
# remote hosts    Database    User      From any IP       Using PG md5 auth
host                      all                 all            md5

In the postgres.conf, set the following:
listen_addresses = '*'

To allow local UNIX users with the same name as PG users to auth automatically:
local                     all                 all           trust

Friday, February 08, 2013


Login to Redis:

Login to Remote Redis:
redis-cli -h
auth mypassword

Switch database:
select 1  # where one is the database name

List keys in database:
redis> keys *

Persist everything to disk right away:

Get the location of the redis data dump dir:
config get dir
1) "dir"
2) "/var/lib/redis/"

Backup the Redis database datafile:
cp /var/lib/redis/dump.rdb /my/backup/location/

Drop all data in db: