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:
- 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).
- 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%
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%
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%
svn propset svn:ignore *.pyc dirname
or
svn propedit svn:ignore dirname
Popularity: 92%
- yum update
- turn off any services that you won’t use:
/etc/init.d/cups stop
chkconfig --level 2345 cups off
- move sshd to another port (stops most scanning), as well as permit only version 2, and no ‘root’ login (all in /etc/ssh/sshd_config). Restart sshd after the changes
- Turn on the firewall (iptables). Note, that in my default install, it was “disabled”, which means it was running, but had no config in /etc/sysconfig/iptables. Just run system-config-securitylevel, and then restart it
/etc/init.d/iptables restart
- set up your ssh key, as well as your authorized keys:
ssh-keygen -t dsa
vi ~/.ssh/auhtorized_keys2
chmod 600 ~/.ssh/authorized_keys2
Popularity: 45%
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%
initdb -D /var/lib/pgsql/data --locale=en_US.utf8 -E UTF8
Popularity: 21%
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%
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%
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%
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%
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%
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:
- Item 1
- Item 2
- Item 3
- Item 4
And without it:
- I am boring
- Where is the emphasis?
- No one will notice
Popularity: 19%
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%
From the documentation:
<Directory\~ “\.svn”>
Order allow,deny
Deny from all
</Directory>
Popularity: 23%
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%
(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%
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%
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%
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%