Tag Archives: command

git: general commands

git init // initialize new repository
git remote add origin ssh://username@domain.tld/path/to/git/project.git
git add . //add all files in this folder to repository
git commit -a -m 'commit description' // make commit
git checkout -b new // create new branch
git checkout master // use master branch
git push // send changes to repository
git pull // take changes from repository
git reset --hard COMMIT // reset to COMMIT
git reset --hard HEAD // reset to last commit
git reset --hard HEAD-1 // reset to one from last
git merge new // if you in another branch will merge change in new for current branch
git reflog // list of last commits
git log // git logs
git show COMMIT // list of change in commit
git clone ssh://username@domain.tld/path/to/git/repository

PostgreSQL: useful commands

show count of active connections

select datname, count(*) from pg_stat_activity group by datname;

show size of db

SELECT pg_size_pretty(pg_database_size('DATABASE_NAME'));

show size of all dbs

SELECT pg_size_pretty(sum(pg_database_size(datname))) from pg_database;

show table size

SELECT relname, pg_total_relation_size(oid) / (1024 * 1024) as sizeM
from pg_class
order by 2 desc
limit 100

show tables size, also it calculates sizes of segmented tables and doesn't show segments in result.

select s.schemaname, s.relname,pg_size_pretty(sm) from (select oid, sum(sm) as sm from (select oid,pg_total_relation_size(oid) as sm from pg_class where relkind='r' and oid not in (select inhrelid from pg_inherits) union (select c.oid,sum(pg_total_relation_size(i.inhrelid)) as sm from pg_class c, pg_inherits i where c.oid=i.inhparent group by c.oid)) t group by oid) tt, pg_stat_user_tables s where s.relid=tt.oid order by sm desc;

show current requests and they duration time

SELECT datname, NOW() - query_start AS duration, procpid, current_query FROM pg_stat_activity ORDER BY duration DESC;

show list of blocks

SELECT l.mode, d.datname, c.relname, l.granted, l.transactionid FROM pg_locks AS l
LEFT JOIN pg_database AS d ON l.database= d.oid
LEFT JOIN pg_class AS c ON l.relation = c.oid;