Wednesday
22
Feb 2006

Spying on PostgreSQL

(9:58 pm) Tags: [Software, How do I..., Sysadmin]

You have tuned your PostgreSQL database, and you, of course, turned off query logging, but a problem has cropped up. How can you see the activity on your database at any slice of time?

Like me, you have probably turned on command stats to view pg_stat_activity, but that gives you only moment in time. You could use ethereal to capture the Postgres queriy packets, but then what? What if you don’t have X installed? tcpdump you say? What do you do with the dump?

Enter pgqueryspy.

Simply type pgqueryspy 2000 db0 to capture the next 2000 packets to the server named ‘db0′. pgqueryspy then prints out the queries that it intercepts in the packet stream for your consumption on the command line. It even tosses those pesky “BEGIN” and “END” queries for you.

Not too terribly invasive, no load on your database, and you find out NOW what is happening with your database. Code is available here: pgqueryspy.c.

I accept NO RESPONSIBILITY FOR YOUR USE OF THIS CODE. It could toss your database/network/server/grandma out the window. YMMV, caveat emptor, etc, etc.

I am putting this code out here for two reasons:

  1. Like me, Google has not led you to any other solution to sniff packets of Postgres queries without making the database log (which requires a database restart).
  2. As soon as I post this code, someone is going to come along and tell me that I could do it in a single command line, and that my 2 hours building this were for nothing. I say bring it on, prove me wrong. You know why? a) my C skills are non-existent, and b) I wish I knew how to do this on the command line

UPDATE: Forgot to give credit for the help. Thanks to Kris, as well as the libpcap packet capture tutorial.

Popularity: 88%

Comments: (2)
Saturday
7
Jan 2006

Strip predicates from an XPath expression in Java

(11:12 am) Tags: [Software, How do I...]

Fairy simple, and I even tested it for you ;)

private String stripPredicatesFromXPath(String xpath) {
if (xpath == null) {
return xpath;
}
Pattern pattern = Pattern.compile("\\x5B[^\\x5B\\x5D]*\\x5D");
Matcher matcher = pattern.matcher(xpath);
String result = matcher.replaceAll("");
return result;
}

Popularity: 74%

Comments: (0)
Wednesday
4
Jan 2006

Install memcached on Linux (CentOS 4.2)

(12:36 am) Tags: [Software, How do I..., Sysadmin]

curl -O http://www.monkey.org/~provos/libevent-1.1a.tar.gz
tar zxf libevent-1.1a.tar.gz
cd libevent-1.1a
./configure
make
make install
cd ..
mv libevent-1.1a.tar.gz ../installed/
curl -O http://www.danga.com/memcached/dist/memcached-1.1.12.tar.gz
tar zxf memcached-1.1.12.tar.gz
cd memcached-1.1.12
./configure
make
make install
mv memcached-1.1.12.tar.gz ../installed

Then add /usr/local/lib to LD_LIBRARY_PATH in your .bash_profile
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH

Then test:
memcached -m 512 -u nobody -vv

Popularity: 87%

Comments: (5)
Friday
30
Dec 2005

Ignore a file in Subversion (svn ignore)

(11:13 pm) Tags: [Software, How do I...]

svn propset svn:ignore *.pyc dirname

or

svn propedit svn:ignore dirname

Popularity: 92%

Comments: (0)
Monday
26
Dec 2005

CentOS 4.2 steps after install

(9:38 pm) Tags: [Software, How do I..., Sysadmin]

Popularity: 45%

Comments: (2)
Thursday
22
Dec 2005

Upgrading Emacs to OS X 10.4

(12:11 am) Tags: [Software, How do I...]

I gave up on the code compiling ever again (tried for 3 months with latest from CVS), and just download the version from the Apple website here.

Popularity: 34%

Comments: (0)
Saturday
19
Nov 2005

Creating a UTF8 Postgres database

(7:35 pm) Tags: [Software, How do I...]

initdb -D /var/lib/pgsql/data --locale=en_US.utf8 -E UTF8

Popularity: 21%

Comments: (0)
Tuesday
8
Nov 2005

Self-modifying file

(12:30 pm) Tags: [How do I...]

Working with Shelby today, he had written an XSLT that created a SQL script, with embedded search and replace statements (he was calculating parent ids on the fly). So, now we have a SQL script that contains commands to run. So, something like this:

sed -e "`grep SED: test.txt | awk -F" " '{print $2}'`" < test.txt | grep -v SED:

And the file modifies itself. This is why Unix will live forever! GUIs be damned, full command line speed ahead…

Popularity: 20%

Comments: (0)
Friday
9
Sep 2005

Quick NFS HOWTO for Centos

(7:33 pm) Tags: [Software, How do I..., Sysadmin]

On the server

vi /etc/exports
add lines like:
/data1/sessions 192.168.0.0/255.255.0.0(rw) 10.0.0.0/255.0.0.0(rw)

vi /etc/hosts.allow
add lines like:
portmap: 192.168.0.0/255.255.0.0, 10.0.0.0/255.0.0.0

/etc/init.d/nfsd start

On the Client

vi /etc/fstab, adding the following line:
nfshostname:/data1/sessions /mnt nfs rw,hard,intr 0 0

make sure to mkdir /mnt/sessions, or it won’t work. To do it manually, just:
mount nfshostname:/data1/sessions /mnt/sessions

Helpful Links

Popularity: 52%

Comments: (2)
Monday
5
Sep 2005

Adding a domain to named

(12:17 pm) Tags: [How do I..., Sysadmin]

vi /etc/named.conf (adding master zone for newdomain.com)
cp /var/named/example.org.hosts /var/named/newdomain.com.hosts
vi /var/named/newdomain.com.hosts
kill -HUP pid-of-named

Popularity: 31%

Comments: (0)
Monday
22
Aug 2005

Problems getting IMAP working with PHP4?

(8:09 pm) Tags: [Software, How do I..., Sysadmin]

I needed IMAP support in PHP4, so I attempted to compile it in using the instructions here. I kept getting the error:

checking whether IMAP works... no
configure: error: build test failed. Please check the config.log for details.

In my configure.log, I was seeing this:

configure:43918: undefined reference to `auth_gssapi_valid'
collect2: ld returned 1 exit status

The problem was that I was trying to use imap2004e. When I found and download imap2001c as an rpm, and installed it, everything went fine. Just logging this for future frustrated sysadmins without a solution.

Popularity: 24%

Comments: (0)
Monday
8
Aug 2005

Change MySQL server variables at runtime

(8:47 am) Tags: [How do I..., Sysadmin]

I was in the need this morning to set some MySQL variables without taking the database server down. This is possible, if you can find the right piece of documentation to tell you how. The proper documentation would be this: 4.3.4 Using Options to Set Program Variables.

Note that not all options can be set. The list of allowed variables to be set this way is listed here: 5.3.3.1 Dynamic System Variables.

Popularity: 25%

Comments: (0)
Monday
28
Mar 2005

Bold an ordered list item?

(6:57 pm) Tags: [How do I...]

Alex tells me that this is the current best way to bold ordered list items (the actual list item numbers, not the data in the list item):

<ol>
<li><span>list item</span></li>
<li><span>list item</span></li>
<li><span>list item</span></li>
</ol>

And the css:

ol {font-weight: bold;}
ol span {font-weight: normal;}

And here is an example:

  1. Item 1
  2. Item 2
  3. Item 3
  4. Item 4

And without it:

  1. I am boring
  2. Where is the emphasis?
  3. No one will notice

Popularity: 19%

Comments: (1)
Tuesday
22
Feb 2005

Call a WSDL/SOAP Service from PHP using NuSOAP

(4:50 pm) Tags: [Software, How do I...]

Ever find yourself needing to make a quick call to some WSDL service out there? Do it with PHP next time, and find out how easy it is!

Just download the latest copy of NuSOAP, and type up a PHP file something like:

< ?php

// include the SOAP classes
require_once(’nusoap.php’);

$client = new soapclient(’http://example.com/url/to/some/valid.wsdl’, True);

$err = $client->getError();
if ($err) {
// Display the error
echo ‘client construction error: ‘ . $err ;
} else {
$answer = $client->call(’someSOAPMethod’,
array(
‘param1′=>’foo’
,’param2′=>’bar’));

$err = $client->getError();
if ($err) {
// Display the error
echo ‘Call error: ‘ . $err;
print_r($client->response);
print_r($client->getDebug());
} else {
print_r($answer);
}
}
?>

It couldn’t be easier. NuSOAP reads and parses the WSDL, configures your method call and params with the correct schema types, and makes the call. The response comes back as an associative array. This is how WS-* should be :)

Popularity: 31%

Comments: (4)
Thursday
13
Jan 2005

Refuse access to .svn directories in Apache 2?

(10:12 pm) Tags: [Site, How do I..., Sysadmin]

From the documentation:

<Directory\~ “\.svn”>
Order allow,deny
Deny from all
</Directory>

Popularity: 23%

Comments: (0)

Move a Subversion repository from one machine to another

(6:05 pm) Tags: [Site, How do I..., Sysadmin]

Even if the machines are on different operating systems, this is dead easy. On the source machine, simply ‘dump’ the repository:

svnadmin dump /path/to/repo > reponame.dump
tar zcf reponame.tgz reponame.dump
scp reponame.tgz hostname:/path/to/new/repo

Then login to the new machine, and set up the new repo:

cd /path/to/new
svnadmin create reponame
tar zxf reponame.tgz
svnadmin load reponame < reponame.dump

That’s all there is to it. Then you can of course delete the dump files, the .tgz files, and even the source repo if you are brave.

Popularity: 87%

Comments: (23)

How to SSLify a site in Apache 2

(5:49 pm) Tags: [Site, How do I..., Sysadmin]

(Adapted to my needs from the original at http://www.apache-ssl.org/#FAQ)

First, you create the cert:

cd /www/conf
vi www.example.com.conf
openssl req -new > www.example.com.csr
mv privkey.pem www.example.com.privkey.pem
openssl rsa -in www.example.com.privkey.pem -out www.example.com.key
openssl x509 -in www.example.com.csr -out www.example.com.cert -req -signkey www.example.com.key -days 10000

Then, you edit the site config, adding the following lines:

SSLEngine on
SSLCertificateFile /www/conf/www.example.com.cert
SSLCertificateKeyFile /www/conf/www.example.com.key

Then, you restart apache, while crossing your fingers:

sudo /usr/local/apache2/bin/apachectl restart

Popularity: 23%

Comments: (0)
Tuesday
11
Jan 2005

Query logging in MySQL on Windows

(10:40 pm) Tags: [Software, How do I...]

So, you’re running MySQL on Windows, and would really like to see a log of all of the queries the server is processing? Simple, just find your my.ini file, open it in a text editor, and add the following line in the [mysqld] section:

[mysqld]
log=hostname.log

Then restart the mysql service, and every query will be logged in a file called hostname.log in the MySql\data directory.

For you unix types, starting the mysqld daemon with the ‘–log’ parameter will create the file ‘hostname.log’ in the $MYSQL_HOME/data directory.

Popularity: 19%

Comments: (2)
Friday
15
Oct 2004

Start a WebSphere 5 application from the command line?

(5:33 pm) Tags: [How do I...]

Using the wsadmin tool is easy, if you know which documentation to dig through :)

Here is the documentation.

I distilled it down to a one liner, for those that like that sort of thing:

$AdminControl invoke [$AdminControl queryNames cell=cell1,node=node1,type=ApplicationManager,process=server1,*] startApplication theAppName

Simple, once you know where to look, and actually succeed in finding it. I have found that IBM’s documentation usually contains what you need, you just can’t find it.

Popularity: 18%

Comments: (1)
Sunday
27
Jun 2004

Install mysql-python 1.0.0 on Mac OS X 10.3.4

(12:31 am) Tags: [Software, How do I...]

Step 1. Download mysql-python 1.0.0 from sourceforge and expand.
Step 2. Modify the setup.py script to remove library dirs that don’t exist and to change ‘crypt’ to ‘crypto’. Follow the directions in the readme otherwise.
Step 3. Profit! :)

Popularity: 19%

Comments: (0)