wtorek, 16 października 2012

Software raid

Today I connected SDD hard drive to my new server. Because it contains 4 memory drives I decided to use software raid to use it as one huge free space.
root@alucard:/home/shamrock# mdadm --create /dev/md0 \ -f -v -l 0 -n 4 /dev/dm-1 /dev/dm-2 /dev/dm-3 /dev/dm-4 mdadm: chunk size defaults to 512K mdadm: /dev/sdb appears to be part of a raid array: level=raid0 devices=0 ctime=Thu Jan 1 00:00:00 1970 mdadm: partition table exists on /dev/sdb but will be lost or meaningless after creating array mdadm: /dev/sdc appears to be part of a raid array: level=raid0 devices=0 ctime=Thu Jan 1 00:00:00 1970 mdadm: partition table exists on /dev/sdc but will be lost or meaningless after creating array mdadm: /dev/sdd appears to be part of a raid array: level=raid0 devices=0 ctime=Thu Jan 1 00:00:00 1970 mdadm: partition table exists on /dev/sdd but will be lost or meaningless after creating array mdadm: /dev/sde appears to be part of a raid array: level=raid0 devices=0 ctime=Thu Jan 1 00:00:00 1970 mdadm: partition table exists on /dev/sde but will be lost or meaningless after creating array Continue creating array? y mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started. root@alucard:/home/shamrock# mkfs.xfs /dev/md0 log stripe unit (524288 bytes) is too large (maximum is 256KiB) log stripe unit adjusted to 32KiB meta-data=/dev/md0 isize=256 agcount=32, agsize=9157376 blks = sectsz=512 attr=2, projid32bit=0 data = bsize=4096 blocks=293036032, imaxpct=5 = sunit=128 swidth=512 blks naming =version 2 bsize=4096 ascii-ci=0 log =internal log bsize=4096 blocks=143088, version=2 = sectsz=512 sunit=8 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 root@alucard:/home/shamrock# df -h Filesystem Size Used Avail Use% Mounted on rootfs 12G 2.6G 9.5G 22% / udev 95G 132K 95G 1% /dev tmpfs 19G 2.3M 19G 1% /run /dev/mapper/lvm0-dom0 12G 2.6G 9.5G 22% / tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 38G 10M 38G 1% /tmp tmpfs 38G 4.0K 38G 1% /run/shm /dev/mapper/lvm0-base 2.6T 2.4T 238G 91% /base /dev/md0 1.1T 34M 1.1T 1% /media/md0

środa, 13 czerwca 2012

How to obtain postgresql database size

If you want to find the size of a dataase , the simples method is use query : 

SELECT pg_database_size(‘databasename’);


postgres=# SELECT pg_database_size('aad');
 pg_database_size
------------------
       4582268508
(1 row)



For more human readable format please use:

SELECT pg_size_pretty(pg_database_size(‘databasename’));


postgres=# SELECT pg_size_pretty(pg_database_size('aad'));
 pg_size_pretty
----------------
 4370 MB
(1 row)

To get the size of all databases with alphabetical order:
 
SELECT datname,pg_size_pretty(pg_database_size(pg_database.datname)) FROM  pg_database ORDER BY datname;


postgres=# SELECT datname,pg_size_pretty(pg_database_size(pg_database.datname)) FROM  pg_database ORDER BY datname;
      datname      | pg_size_pretty
-------------------+----------------
 aad              | 4370 MB
 bae     | 4797 MB
 maad    | 534 MB
 pjvi            | 11 MB
 template0         | 4248 kB
 template1         | 4248 kB
 (6 rows)

poniedziałek, 14 maja 2012

Move table to another tablespace in Postgresql

dbtest# \t
dbtest# \o dbtest_tablespace.txt
dbtest# select 'alter table '||tablename||' set tablespace temporary_tablespace;' from pg_tables where tablename like 'example%';
dbtest# select 'alter index '||indexname||'  set tablespace temporary_tablespace;' from pg_indexes where tablename like 'example%';
dbtest# \i dbtest_tablespace.txt

środa, 2 maja 2012

FusionIO kernel linux 3.2 patch

Recently I've got problems with fusionIO and linux new kernel because fusionIO doesn't support new kernels (> 2.6). Below is patch for kernel 3.2 ( I think it should work on 3.x too). FusionIO kernel patch

czwartek, 19 kwietnia 2012

Log coloring with bash

Below is link to short script I've made to see different logs with highlight different patterns.
How to use it ?


shamrock@alucard:~/dev/shell$ ./cgrep.sh
Usage : ./cgrep.sh <-g|--grep,-l|--less,-m|--more,-t|--tail> file [line|pattern]
-g, --grep - use grep with highlight
-l, --less - use less with highlight
-m, --more - use more with highlight
-t, --tail - use tail with highlight
line - highlights whole line
pattern - highlights whole pattern
Available colours: black,red,green,yellow,blue,magenta,cyan,white
Available bold colours: blackb,redb,greenb,yellowb,blueb,magentab,cyanb,whiteb

It is possible to use sed different patterns inside quotation marks i.e.:

cgrep sample.log pattern redb "Process target" blueb [Cc]urrent magentab "[0-9]\{3,10\}"


How doe it work in practice?


shamrock@alucard:~/dev/shell$ cat test
Lorem ipsum
Test lorem ipsum
test test lorem ipsum
shamrock@alucard:~/dev/shell$ ./cgrep.sh --grep test redb [Ll]orem

Lorem ipsum
Test
lorem ipsum
test test
lorem ipsum


cgrep.sh

piątek, 10 lutego 2012

Recover mysql/postgresql root password

To recover MySQL password you simply need to 

1) shutdown mysql database if it's possible or just kill with TERM 
In Linux :

# service mysqld shutdown
For killing process
# kill -TERM `ps axxwww | grep mysqld`

2) Run database with "skip grants" option


# /bin/sh /usr/bin/mysqld_safe --defaults-file=/etc/my.cnf \
--pid-file=/var/run/mysqld/mysqld.pid --skip-grant-tables

3) Log in into database and change password
# mysql 
mysql> use mysql;
mysql> update user set password=PASSWORD("newpassword") where user="root";
mysql> quit;
 
4) Restart database and log in with new password
 
To recover Postgresql password
 
1) Edit postgresql config file pg_hba.conf  and change line from :
 local   all postgres  peer
to 
local all postgres trust
 
2) Restart postgresql server :
# service postgresql restart 

3) Log in into database and change password
# psql -U postgres
postgres=# use template1
postgres-# alter user postgres with password 'secret';
postgres-# \q

4) Restart postgresql server

niedziela, 8 stycznia 2012

Vim tips

Converting TAB to SPACE

:set et
:ret!
or convert all SPACE to TAB
:set et!
:ret! 
 
Joining lines based on pattern:
 
global join:
 :g/pattern/j 

single join:
 :/pattern/j 

Some useful things to .vimrc

set cursorline                  " highlight current line
hi cursorline guibg=#333333     " highlight bg color of current line
"hi tab guibg=#000333     " highlight bg color of current line
hi CursorColumn guibg=#333333   " highlight cursor

syntax on