stats_start_collector: This is always on so it is not necessary to configure in PostgreSQL 8.3
stats_command_string: This is now called track_activities.
stats_block_level: This is now combined with stats_row_level and renamed to track_counts
stats_row_level: This is now combined with stats_block_level and renamed to track_counts
stats_reset_on_server_start: This is no longer necessary and is not a configuration option anymore
So now the only additions you will need to make to collect all of the stats you need will be track_counts and track_activities.
Example Configuration Addition:
track_activities = on
track_counts = on
To test that you are collecting the stats run the following command:
select * from pg_stat_all_tables;
Monday, March 2, 2009
Configuration file changes when moving to postgresql 8.3
Found this blog entry, which helped me when updating a postgresql.conf file to run under PostgreSQL 8.3. Summary of the changes:
Friday, February 13, 2009
Printing exceptions in Ruby
Steve wrote a post about the simplest way to print an exception's message and backtrace in ruby.
The snippet he provides is the following:
The $! variable contains the last exception and $@ contains the last exception's backtrace as a string.
Some people (including me, before reading his post) do the following:
I'm glad I stumbled upon Steve's post. Learning about the little idioms of a language helps you to write more succinct and clear code.
The snippet he provides is the following:
# catch most exceptions (anything that derives from StandardError)
begin
...
rescue
puts $!, $@
end
# catch all exceptions (anything that derives from Exception)
begin
...
rescue Exception
puts $!, $@
end
end
The $! variable contains the last exception and $@ contains the last exception's backtrace as a string.
Some people (including me, before reading his post) do the following:
begin
...
rescue Exception => ex
puts ex.message
puts ex.backtrace.join("\n")
end
I'm glad I stumbled upon Steve's post. Learning about the little idioms of a language helps you to write more succinct and clear code.
Wednesday, February 4, 2009
git: prune to remove old remote tracking branches
I was trying to delete "somebranch" from a git repository today but got this error message, which baffled me for a bit:
Doing a 'git branch -a' showed a "origin/somebranch" remote branch. Why can't I delete it? Then I realized that the branch might have been deleted on the remote repository and I haven't updated my remote tracking branches yet. Doing a "git pull" won't remove remote tracking branches for branches that have been deleted. To do that for a remote named "origin", you'll need to use this command:
$ git push origin :somebranch
error: unable to push to unqualified destination: somebranch
The destination refspec neither matches an existing ref on the remote nor
begins with refs/, and we are unable to guess a prefix based on the source ref.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'git@my_server:my_repo.git'
Doing a 'git branch -a' showed a "origin/somebranch" remote branch. Why can't I delete it? Then I realized that the branch might have been deleted on the remote repository and I haven't updated my remote tracking branches yet. Doing a "git pull" won't remove remote tracking branches for branches that have been deleted. To do that for a remote named "origin", you'll need to use this command:
$ git remote prune origin
Tuesday, February 3, 2009
pv (Pipe Viewer) - a unix utility for monitoring the progress of data through a pipe
Just learned about Pipe Viewer from this blog post:
Here is the example that Peteris provides. For long-running commands, it gives you a progress indicator so you won't be left wondering, "Should I go get lunch, or wait for the gzip to be finished?"
Pipe viewer is a terminal-based tool for monitoring the progress of data through a pipeline. It can be inserted into any normal pipeline between two processes to give a visual indication of how quickly data is passing through, how long it has taken, how near to completion it is, and an estimate of how long it will be until completion.
Here is the example that Peteris provides. For long-running commands, it gives you a progress indicator so you won't be left wondering, "Should I go get lunch, or wait for the gzip to be finished?"
$ pv access.log | gzip > access.log.gz
611MB 0:00:11 [58.3MB/s] [=> ] 15% ETA 0:00:59
Sunday, February 1, 2009
If you installed any of the Ubuntu flavors (Ubuntu - default with the Gnome environment, Xubuntu - a flavor that uses the Xfce desktop environment, or Kubuntu - a flavor that uses the KDE desktop environment), you can switch between them without their respective install CD's by installing the right set of packages.
I recently ran into this because I used wubi to install Kubuntu, but found that KDE was a bit "busy" for my liking. (I have a short attention span, having more things on the desktop ended up being distracting for me.)
To install Ubuntu desktop:
To install Xubuntu desktop:
To install Kubuntu desktop:
If you're settled with switching from one environment to the other and would like to remove all the packages from the one that you no longer use (for example, xubuntu-desktop), do the following:
I recently ran into this because I used wubi to install Kubuntu, but found that KDE was a bit "busy" for my liking. (I have a short attention span, having more things on the desktop ended up being distracting for me.)
To install Ubuntu desktop:
sudo apt-get install ubuntu-desktop
To install Xubuntu desktop:
sudo apt-get install xubuntu-desktop
To install Kubuntu desktop:
sudo apt-get install kubuntu-desktop
If you're settled with switching from one environment to the other and would like to remove all the packages from the one that you no longer use (for example, xubuntu-desktop), do the following:
sudo apt-get remove xubuntu-desktop
sudo apt-get autoremove
Tuesday, January 13, 2009
Overloading the ActiveRecord Setter
Sometimes, you want to do some extra work when you set an attribute on your ActiveRecord model instance.
You can't just do the following, because you'll just end up recursively calling the very setter that you're defining:
...and you can't do the following because you'll only modify a copy of the attributes hash of the model instance, which will not be written through to the database when the model instance is saved. ( check out ActiveRecord::Base::attributes in active_record/base.rb):
You can't just do the following, because you'll just end up recursively calling the very setter that you're defining:
class Square < ActiveRecord::Base
def side=(value)
area = value * value
side = value
end
end
...and you can't do the following because you'll only modify a copy of the attributes hash of the model instance, which will not be written through to the database when the model instance is saved. ( check out ActiveRecord::Base::attributes in active_record/base.rb):
class Square < ActiveRecord::Base
def side=(value)
self.attributes['side'] = value
self.area = value * value
end
end
After looking through the source for ActiveRecord::Base and some testing, I've found a method that's worked for me and appears to be the preferred way of doing it:
class Square < ActiveRecord::Base
def side=(value)
self.area = value * value
# This would still work because we're calling the default setter for area
write_attribute('side', value)
end
end
Alternatively, you could do "self['side'] = value" instead of write_attribute. The index assignment operatore actually does the same thing.
Thursday, November 20, 2008
Ruby load path
There are three ways to refer to the variable that stores the load paths that Ruby checks for libraries when you use 'require' or 'load.'
$:
$-I
$LOAD_PATH
Subscribe to:
Posts (Atom)