logo

Art Of Eclipse

« Home » « About » « Github »


Postgresql mini-cheatsheet.

Quick reference for PG command line tools, this post serve as a reference for future use.

Postgresql command line tools:

РDump: /PATH/TO/BIN/pg_dump -U USERNAME DATABASE_NAME > DESTINATION.sql;

– Restore: /PATH/TO/BIN/pg_restore -U USERNAME -no-owner -d DATABASE_NAME < file.sql;
– Connect to PG command line interface : /PATH/TO/BIN/psql --U USERNAME ;
– Exit command line tool: \q

Inside psql command line tool:
– user or connect to database: \connect DATABASE_NAME
– list all databases: \list | \l
– list all tables in the current database: \dt
– describe table structure: \d+ TABLE_NAME
– list all users: \du

svn add/remove newly added files

Sometimes we have an update of codebase many files updates also new files to be added and also removed, to overcome this issue you will need to add them or remove them without adding/removing files already exsits in the repo, the following command line script solve this issue.

add files

svn st | grep ^? | sed 's/? //' | xargs svn add

remove files

svn st | grep ^! | sed 's/! //' | xargs svn rm

edit content in drupal issue with lock message.

Drupal have a good command line interface “CLI” called Drush some time drupal cache behaive in diffrent ways, in one of the projects that I worked on I have a problem with entitycache module, and to solve this issue I had to clear cache everytime I edit and save node, during this I found that I can execute this command “php-eval” :

drush php-eval "entitycache_flush_clear_cache( 'node', nid, TRUE )"

git log and show commits and export theme.

Every wonder how to get a nice formatted log in git here is how to do it with –since and –pretty options :

git log --since='last month' --pretty=format:'%h,%an,%ar,%s'

the above example display the hash of you commit, the author name, commit time “ago format”, and the commit message.

Script to drop all tables form a database.

Just for my reference here is a script that will drop all the tables from the database at once
and don’t forget to replace the username, password and database name ūüėõ

for i in $(mysql -u username -ppassword databasename -e "Show tables;" | grep -v Tables_in | grep -v "+"); do mysql -u username -ppassword databasename -e "drop table $i; "; done;

svn merge and rolling back your changes.

To revert the changes you make to a project/files and reset the changes to a specific revision all what you have to do is the following :

svn merge -rHEAD:oldrev filename
svn commit -m "rolled back to oldrev"

svn diff between tow repositories

To make svn diff include all the unversioned files from your local working copy you have to add these files first. svn diff outputs the same changeset that svn commit would use.

If you know for sure that all unversioned files should be added here’s what you could do.

Prepare a list of unversioned files by taking from the output of svn status all the lines that start with a question mark:

svn status | grep ^? | sed -r 's/^\? +//' > ../unversioned_files_list.txt

You can then pass that list of files to svn add using xargs:

xargs -r -d '\n' svn add < ../unversioned_files_list.txt

And then produce the patch:

svn diff > ../my_patch.patch

If you don't want to keep those files added, use the list of files to unadd them:

xargs -r -d '\n' svn rm --keep-local < ../unversioned_files_list.txt
svn diff --old=https://svn-777.prod.hosting.acquia.com/aljbalkanmr/trunk --new=https://svn-777.prod.hosting.acquia.com/aljbalkanmr/tags/2012-04-10/ > ~/Desktop/balkans_diff.txt

MySQL size functions

Today I want to know my database size and after some research about the database size in mysql I found this script

Get Size of all database tables

SELECT TABLE_SCHEMA AS 'Database', TABLE_NAME AS 'Table',
CONCAT(ROUND(((DATA_LENGTH + INDEX_LENGTH - DATA_FREE) / 1024 / 1024),2)," Mb") AS Size FROM INFORMATION_SCHEMA.TABLES;

replace YOUR_DB_NAME with your database name in following 2 examples:
get size of specific database tables

SELECT TABLE_SCHEMA AS 'Database', TABLE_NAME AS 'Table',
CONCAT(ROUND(((DATA_LENGTH + INDEX_LENGTH - DATA_FREE) / 1024 / 1024),2)," MB") AS Size FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA like '%YOUR_DB_NAME%' ;

to get size of entire DB :

SELECT CONCAT(sum(ROUND(((DATA_LENGTH + INDEX_LENGTH - DATA_FREE) / 1024 / 1024),2))," MB") AS Size FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA like '%YOUR_DB_NAME%' ;

Add directory to system path in linux

Adding a directory to system path variable is easy in linux, just you have to append the directory to the system path
and you can do that by run the following command :

export PATH=/path/to/directory:$PATH

but this one is temporary for you current session, to make directory available in the system path, just edit you .bashrc file in you home folder, and add the above code at the end of the file:

$ vim ~/.bashrc

.......
.......
export PATH=/path/to/directory:$PATH

VBox : unable to find the sources of your current linux kernel ubuntu

after some update for my ubuntu linux, I wasn’t able to make my VBox machines to work, so i tried to run

sudo /etc/init.d/vboxdrv setup

but no use, but after some googling i found this and it’s solved my proble

sudo apt-get install dkms
sudo apt-get install linux-headers-`uname -r|cut -d'-' -f3`-`uname -r|cut -d'-' -f4`

referance : http://www.khattam.info/solved-error-unable-to-find-the-sources-of-your-current-linux-kernel-specify-kern_dir-and-run-make-again-stop-2010-11-26.html