Sunday, July 28, 2013

Error code 4064 - Cannot Open User Default Database (error 4064) - MSDN - Microsoft

This issue can be solve with the following command

sqlcmd -d master -U sa -P mypassword
and then:
alter login sa with default_database = master

Command prompt to backup and restore

sqlcmd -U username -S servername -Q "BACKUP DATABASE dbname TO DISK='path\filename.bak'"

Streaming Replicaiton in Postgresql

A short information on streaming replication in postgresql 9.2
Requesties
The postgresql servers both master and slave, should be of the same configuration (i.e., the data folder should be in the same location for slave as the master).
Master server changes:
open postgresql.conf master and do the changes
listen_addresses = "*"
wal_level = hot_standby
archive_mode = on
archive_command = "copy %p \\\\192.168.1.1\\wal_archive\\%f"
archive_timeout = 3600
wal_senders = 5
wal_keep_segments = 32

pg_hba.conf
host    all    all    0.0.0.0/0    trust
host    replication   all  0.0.0.0/0   trust

In the slave server, either remove the existing data folder or rename it to data_old, coming back to master issue the following command
pg_basebackup -U postgres -p 5432  -D  "\\192.168.1.1\PostgreSQL\9.2\data"
Windows:
"C:\\Program Files(x86)\PostgreSQL\9.2\bin\pg_basebackup" -U postgres -p 5432 -D "\\192.168.1.1\c$\Program Files(x86)\PostgreSQL\9.2\data"

Use the -w attribute to make your shell script to work uninterrupted for passwords, with the help of pgpass.conf file.

Slave Server Changes
After the files are being copied from  master server, open the postgresql.conf file and comment out all the settings and have only the below change
hot_standby = on

After this prepare a recovery.conf file, open a notepad and add the following code and save it as recover.conf in the data folder of the slave server, where its postgresql.conf file exists
standby_mode = on
primary_conninfo = 'host=192.168.1.0 port = 5432 user = postgres password = sydney11'
trigger_file = 'C:\\trigger_file.trigger'
restore_command = 'copy C:\\wal_archive\\%f %p"

Working
The master will continuously send the wal files to the shared folder of the slave server.
the slave will restore the received wal files using the restore_command from the recovery.conf file
when the master is down create a trigger file, as given in the recovery.conf
the presence of trigger file will alert the slave that the master is down and change the recovery.conf as recovery.done and make it as a master server.

Tamizh numeric system


Keyboard shortcuts

More than 100 Keyboard Shortcuts must read & Share

Keyboard Shortcuts (Microsoft Windows)
1. CTRL+C (Copy)
2. CTRL+X (Cut)
3. CTRL+V (Paste)
4. CTRL+Z (Undo)
5. DELETE (Delete)
6. SHIFT+DELETE (Delete the selected item permanently without placing the item in the Recycle Bin)
7. CTRL while dragging an item (Copy the selected item)
8. CTRL+SHIFT while dragging an item (Create a shortcut to the selected item)
9. F2 key (Rename the selected item)
10. CTRL+RIGHT ARROW (Move the insertion point to the beginning of the next word)
11. CTRL+LEFT ARROW (Move the insertion point to the beginning of the previous word)
12. CTRL+DOWN ARROW (Move the insertion point to the beginning of the next paragraph)
13. CTRL+UP ARROW (Move the insertion point to the beginning of the previous paragraph)
14. CTRL+SHIFT with any of the arrow keys (Highlight a block of text)
SHIFT with any of the arrow keys (Select more than one item in a window or on the desktop, or select text in a document)
15. CTRL+A (Select all)
16. F3 key (Search for a file or a folder)
17. ALT+ENTER (View the properties for the selected item)
18. ALT+F4 (Close the active item, or quit the active program)
19. ALT+ENTER (Display the properties of the selected object)
20. ALT+SPACEBAR (Open the shortcut menu for the active window)
21. CTRL+F4 (Close the active document in programs that enable you to have multiple documents opensimultaneously)
22. ALT+TAB (Switch between the open items)
23. ALT+ESC (Cycle through items in the order that they had been opened)
24. F6 key (Cycle through the screen elements in a window or on the desktop)
25. F4 key (Display the Address bar list in My Computer or Windows Explorer)
26. SHIFT+F10 (Display the shortcut menu for the selected item)
27. ALT+SPACEBAR (Display the System menu for the active window)
28. CTRL+ESC (Display the Start menu)
29. ALT+Underlined letter in a menu name (Display the corresponding menu) Underlined letter in a command name on an open menu (Perform the corresponding command)
30. F10 key (Activate the menu bar in the active program)
31. RIGHT ARROW (Open the next menu to the right, or open a submenu)
32. LEFT ARROW (Open the next menu to the left, or close a submenu)
33. F5 key (Update the active window)
34. BACKSPACE (View the folder onelevel up in My Computer or Windows Explorer)
35. ESC (Cancel the current task)
36. SHIFT when you insert a CD-ROMinto the CD-ROM drive (Prevent the CD-ROM from automatically playing)
Dialog Box - Keyboard Shortcuts
1. CTRL+TAB (Move forward through the tabs)
2. CTRL+SHIFT+TAB (Move backward through the tabs)
3. TAB (Move forward through the options)
4. SHIFT+TAB (Move backward through the options)
5. ALT+Underlined letter (Perform the corresponding command or select the corresponding option)
6. ENTER (Perform the command for the active option or button)
7. SPACEBAR (Select or clear the check box if the active option is a check box)
8. Arrow keys (Select a button if the active option is a group of option buttons)
9. F1 key (Display Help)
10. F4 key (Display the items in the active list)
11. BACKSPACE (Open a folder one level up if a folder is selected in the Save As or Open dialog box)

Microsoft Natural Keyboard Shortcuts
1. Windows Logo (Display or hide the Start menu)
2. Windows Logo+BREAK (Display the System Properties dialog box)
3. Windows Logo+D (Display the desktop)
4. Windows Logo+M (Minimize all of the windows)
5. Windows Logo+SHIFT+M (Restorethe minimized windows)
6. Windows Logo+E (Open My Computer)
7. Windows Logo+F (Search for a file or a folder)
8. CTRL+Windows Logo+F (Search for computers)
9. Windows Logo+F1 (Display Windows Help)
10. Windows Logo+ L (Lock the keyboard)
11. Windows Logo+R (Open the Run dialog box)
12. Windows Logo+U (Open Utility Manager)
13. Accessibility Keyboard Shortcuts
14. Right SHIFT for eight seconds (Switch FilterKeys either on or off)
15. Left ALT+left SHIFT+PRINT SCREEN (Switch High Contrast either on or off)
16. Left ALT+left SHIFT+NUM LOCK (Switch the MouseKeys either on or off)
17. SHIFT five times (Switch the StickyKeys either on or off)
18. NUM LOCK for five seconds (Switch the ToggleKeys either on or off)
19. Windows Logo +U (Open Utility Manager)
20. Windows Explorer Keyboard Shortcuts
21. END (Display the bottom of the active window)
22. HOME (Display the top of the active window)
23. NUM LOCK+Asterisk sign (*) (Display all of the subfolders that are under the selected folder)
24. NUM LOCK+Plus sign (+) (Display the contents of the selected folder)
25. NUM LOCK+Minus sign (-) (Collapse the selected folder)
26. LEFT ARROW (Collapse the current selection if it is expanded, or select the parent folder)
27. RIGHT ARROW (Display the current selection if it is collapsed, or select the first subfolder)
Shortcut Keys for Character Map
After you double-click a character on the grid of characters, you can move through the grid by using the keyboard shortcuts:
1. RIGHT ARROW (Move to the rightor to the beginning of the next line)
2. LEFT ARROW (Move to the left orto the end of the previous line)
3. UP ARROW (Move up one row)
4. DOWN ARROW (Move down one row)
5. PAGE UP (Move up one screen at a time)
6. PAGE DOWN (Move down one screen at a time)
7. HOME (Move to the beginning of the line)
8. END (Move to the end of the line)
9. CTRL+HOME (Move to the first character)
10. CTRL+END (Move to the last character)
11. SPACEBAR (Switch between Enlarged and Normal mode when a character is selected)
Microsoft Management Console (MMC)
Main Window Keyboard Shortcuts
1. CTRL+O (Open a saved console)
2. CTRL+N (Open a new console)
3. CTRL+S (Save the open console)
4. CTRL+M (Add or remove a console item)
5. CTRL+W (Open a new window)
6. F5 key (Update the content of all console windows)
7. ALT+SPACEBAR (Display the MMC window menu)
8. ALT+F4 (Close the console)
9. ALT+A (Display the Action menu)
10. ALT+V (Display the View menu)
11. ALT+F (Display the File menu)
12. ALT+O (Display the Favorites menu)

MMC Console Window Keyboard Shortcuts
1. CTRL+P (Print the current page or active pane)
2. ALT+Minus sign (-) (Display the window menu for the active console window)
3. SHIFT+F10 (Display the Action shortcut menu for the selected item)
4. F1 key (Open the Help topic, if any, for the selected item)
5. F5 key (Update the content of all console windows)
6. CTRL+F10 (Maximize the active console window)
7. CTRL+F5 (Restore the active console window)
8. ALT+ENTER (Display the Properties dialog box, if any, for theselected item)
9. F2 key (Rename the selected item)
10. CTRL+F4 (Close the active console window. When a console has only one console window, this shortcut closes the console)
Remote Desktop Connection Navigation
1. CTRL+ALT+END (Open the Microsoft Windows NT Security dialog box)
2. ALT+PAGE UP (Switch between programs from left to right)
3. ALT+PAGE DOWN (Switch between programs from right to left)
4. ALT+INSERT (Cycle through the programs in most recently used order)
5. ALT+HOME (Display the Start menu)
6. CTRL+ALT+BREAK (Switch the client computer between a window and a full screen)
7. ALT+DELETE (Display the Windows menu)
8. CTRL+ALT+Minus sign (-) (Place a snapshot of the active window in the client on the Terminal server clipboard and provide the same functionality as pressing PRINT SCREEN on a local computer.)
9. CTRL+ALT+Plus sign (+) (Place asnapshot of the entire client window area on the Terminal server clipboardand provide the same functionality aspressing ALT+PRINT SCREEN on a local computer.)

Microsoft Internet Explorer Keyboard Shortcuts
1. CTRL+B (Open the Organize Favorites dialog box)
2. CTRL+E (Open the Search bar)
3. CTRL+F (Start the Find utility)
4. CTRL+H (Open the History bar)
5. CTRL+I (Open the Favorites bar)
6. CTRL+L (Open the Open dialog box)
7. CTRL+N (Start another instance of the browser with the same Web address)
8. CTRL+O (Open the Open dialog box,the same as CTRL+L)
9. CTRL+P (Open the Print dialog box)
10. CTRL+R (Update the current Web page)
11. CTRL+W (Close the current window)

Saturday, July 27, 2013

Wamp knowledges

1. Stop directory browsing in wamp apache, goto httpd.conf and edit the following line

"Options Indexes FollowSymLinks" and remove the indexes.                                          


2. If your server is not viewable in another machine, then open httpd.conf file and edit
order deny, allow
deny from all
allow from 127.0.0.1 change this ip address to all.
3. unable to load the modules like php_pgsql.dll, then copy the libpq.dll file from C:\wamp\bin\php\php5.4.3\libpq.dll  to C:\wamp\bin\apache\apache2.4.2\bin

postgresql backup and restore options

the normal backup and restore syntax in cmd prompt is,

pg_dump -U postgres -p 5432 -Fc -d dbname > dumpfile.dump
to restore schema wise use pg_dump -U postgres -p 5432 -Fc -d dbname > dumpfile.dump

The same syntax in windows is,
"C:\\Program Files(x86)\PostgreSQL\8.3\bin\pg_dump.exe" -U postgres -p 5432 -Fc -d dbname > dumpfile.dump

This script can be put in the batch file to create an automated backup process and to make it run unattended prepare a pgpass.conf file with following lines
localhost:5432:*:postgres:dbname

where postgres is the service username, you can change it to the user with which you are going to run the command. The command for uninterrupted execution is
"C:\\Program Files(x86)\PostgreSQL\8.3\bin\pg_dump.exe" -U postgres -p 5432 -w -Fc -d dbname > dumpfile.dump.  so this will check with the pgpass file and and execute uninterrupted.
The pgpass.conf file can be found in
su - postgres     //this will land in the home directory set for postgres user vi .pgpass.conf    //enter all users entries   chmod 0600 .pgpass.conf    // change the ownership to 0600 to avoid error like    
-bash-3.2$ psql   
WARNING: password file "/opt/PostgreSQL/9.2//.pgpass" has group or world access; permissions should be u=rw (0600) or less 

In windows this can be found at "C:\Users\welcome\AppData\Roamin\postgresql" or %appdata%\postgresql


To restore use the following command as
pg_restore -U postgres -p 5432 -w -d dbname backupfile.dump
to restore schema only, use pg_restore -U postgres -p 5432 -w -s -d dbname backupfile.dump
to restore tablewise, use pg_restore -U postgres -p 5432 -w -s -t tablename -d dbname backupfile.dump
to restore data only, replace the -s option with -a attribute.

Make your schemas in postgresql localized

Depend on your requirement, database can be designed with many schemas. But to make it localized, that is when you want to fetch data or use the tables, it should be visible to the code, without the need to search it with schema, with any application you use, for eg., pgadmin, phppgadmin or any other application which you may develop. To achieve this, use the search_path attributes in postgresql.

syntax:
search_path = '"$user",public'

To implement it at user level, try the following syntax:
ALTER USER username SET search_path = schema1,schema2,schema3,etc;  

Sunday, May 26, 2013

apache - stop directory browsing

If you are using apache as your web server, then you would notice that if you type localhost/ in your browser and you fill find the directory listing of your web directory. To stop directory browsing, that is when you type localhost/ in your browse, it redirects to the localhost folder that is the www folder of your server, which will allow everyone to see all the contents of you www directory. To acheive this, just open the httpd.conf file from apache's directory, and find the line,

options indexes followsymlinks

In the above line remove the indexes. This i have tested with wamp server.

Ldap authentication with wamp, php in windows


// using ldap bind$ldaprdn  'uname';     // ldap rdn or dn$ldappass 'password';  // associated password

// connect to ldap server
$ldapconn ldap_connect("ldap.example.com")
    or die(
"Could not connect to LDAP server.");

if (
$ldapconn) {

    
// binding to ldap server
    
$ldapbind ldap_bind($ldapconn$ldaprdn$ldappass);

    
// verify binding
    
if ($ldapbind) {
        echo 
"LDAP bind successful...";
    } else {
        echo 
"LDAP bind failed...";
    }

}

?>

to make this code, work check if your ldap is in fine condition and users are enabled to log in  with the ADS username and password. This can be checked by going to the ADS, service, right click the user and go to properties, in that select the logon tab, and check if he is valid to log in the computer.


Thursday, April 4, 2013

Additions with timestamp in postgresql

To add to the hours, minutes, seconds, day, month or year of a timestamp, the function i used in my project is :
select (timestamp '2013-01-01 08:56:15' +(interval '1 hour'));
this can be used in a stored procedure or function that we can make it use for our own projects as we need.
In functions just use variables which are predefined with its datatype, like
hour_count interval;
date_to_add timestamp;
date_result timestamp;
date_to_add := '2013-01-01 08:56:15'
hour_count : = '1 hour';
date_result := (date_to_add + hour_count);

when we use it with predefined variables no need to cast it as it is in the select statement.

Tuesday, April 2, 2013

Gant/Revoke in Postgres

The "grant all privileges on all tables to postgres;",  is never applicable for postgresql version 8.3 and the above syntax works for only versions after 9.0.

For versions below this, we need to do it separately for each tables. To achieve this, what i did is to have a select query that can prepare the grant or revoke statement for all tables at a once and then output it to some text file and then execute this file.

work out this..
select 'REVOKE ALL ON public.' || table_name || ' FROM  username ' from information_schema.tables WHERE table_type='BASE TABLE' AND table_schema='public';