Tuesday, May 12, 2009

Change default setting of TCP ports allowed in Windows

This happens again so that it maybe a good time to record it here.

If you try to set up TCP connections from ports that are greater than 5000, the local computer responds with the following WSAENOBUFS (10055) error message:

An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full.

The default maximum number of ephemeral TCP ports is 5000,
To increase the maximum number of ephemeral ports, follow these steps:

Start Registry Editor.
Locate the following subkey in the registry, and then click Parameters:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
On the Edit menu, click New, and then add the following registry entry:
Value Name: MaxUserPort
Value Type: DWORD
Value data: 65534
Valid Range: 5000-65534 (decimal)
Default: 0x1388 (5000 decimal)

Description: This parameter controls the maximum port number that is used when a program requests any available user port from the system. Typically , ephemeral (short-lived) ports are allocated between the values of 1024 and 5000 inclusive.

Exit Registry Editor, and then restart the computer.

Note: An additional TCPTimedWaitDelay registry parameter determines how long a closed port waits until the closed port can be reused.

Mysql transaction log restoration

almost all the documents you can find on the Net are telling you to use mysqlbinlog to read the binary logs and pipe the output to mysql client, but this method simply will fail on windows system if the database contains binary data such as blob and binvarchar, due to escaping and piping problem in mysqlbinlog utility. the mysql utility simply can not read the file or output stream created by mysqlbinlog.

here's a workaround though, we can tell mysql to use --execute "source xx" option to parse the log files from mysqlbinlog.

E.g.
C:\> mysqlbinlog binary_log_file --result-file=/tmp/bin.sql
C:\> mysql --user=root --execute "source /tmp/bin.sql"

ref 1: http://bugs.mysql.com/bug.php?id=33048
ref 2: http://www.linuxtopia.org/online_books/database_guides/mysql_5.1_database_reference_guide/windows-vs-unix.html

Basic MS SQLServer backup and restore commands

1. backup
1.1 backup database
BACKUP DATABASE [_db] TO DISK = N'C:\dbBackupTest\MC\db\test' WITH NOINIT , NOUNLOAD , NAME = N'_db backup', NOSKIP , STATS = 10, NOFORMAT
1.2 backup transaction log
BACKUP LOG [db] TO DISK = N'C:\dbBackupTest\MC\db\testlog' WITH NOINIT , NOUNLOAD , NAME = N'_db backup', NOSKIP , STATS = 10, NOFORMAT
--restore
--allow transaction log restore after database restore
RESTORE DATABASE [_db] FROM DISK = N'C:\dbBackupTest\MC\cdsdb\_db_200905090700.BAK' WITH FILE = 1, NOUNLOAD , STATS = 10, NORECOVERY
--allow more transaction log restore after transaction log restore
RESTORE LOG [_db] FROM DISK = N'C:\dbBackupTest\MC\db\_db_tlog_200905091000.TRN' WITH FILE = 1, NOUNLOAD , STATS = 10, NORECOVERY
--last transaction log, put the db operational
RESTORE LOG [_db] FROM DISK = N'C:\dbBackupTest\MC\db\_db_tlog_200905100600.TRN' WITH FILE = 1, NOUNLOAD , STATS = 10, RECOVERY