Monthly Archives: August 2010
Variable substitution with psql
Updated: Thanks @johto for s/:bar/:foo/. 🙂
A coworker asked about variable substitution with psql using \set
, and so I looked into it a bit further.
You definitely can do things like this:
16:55 sdeckelmann@[local]:5432|postgres=> \set test 'select * from :foo limit 10;'
16:56 sdeckelmann@[local]:5432|postgres=> \set foo 'test'
16:56 sdeckelmann@[local]:5432|postgres=> :test
myint
-------
1
2
3
4
5
6
7
8
9
10
(10 rows)
But, what about something like this:
=> \set test 'select * from :var limit 10;'
=> :test mytable
Unfortunately, this isn’t supported.
The best you could do is something pathological like:
=> \set s 'select * from '
=> \set pr ' limit 10;'
=> :s mytable :pr
=> :s test :pr
myint
-------
1
2
3
4
5
6
7
8
9
10
(10 rows)
Using logger with pg_standby
Piping logs to syslog is pretty useful for automating log rotation and forwarding lots of different logs to a central log server.
To that end, the command-line utility ‘logger’ is nice for piping output from utilities like pg_standby without having to add syslogging code to the utility itself. Another thing is that logger comes by default with modern packages of syslog.
Here’s an easy way to implement this:
restore_command = 'pg_standby -d -s 2 -t /pgdata/trigger /shared/wal_archive/ %f %p %r 2>&1 | logger -p local3.info -t pgstandby'
Weekly tweet digest for 2010-08-29
- Integrated chicks with the crazy white bantum. Celebrating with strawberry crepes. #
- What you say vs. Who you are: http://www.illdoctrine.com/2008/07/how_to_tell_people_they_sound.html #
- Stoked for coffee, sunshine, clouds, tunes. #
- Looking forward to NYC next month: http://nymag.com/arts/art/features/67387/ #
- http://howfuckedismydatabase.com /cc @dbahulk #
- Enjoying epic anti-Java-as-a-first-language rant from @darianapatrick. Been there. #
- Generating 57 volts from a creek, a bucket and some other stuff 😉 http://www.youtube.com/watch?v=Vn1EtGRRkSo #
Online aggregation paper from 1997 and PSU’s database reading group
A couple weeks ago, Mark Wong and I took a field trip over to the Database Reading Group at Portland State University. It’s a group of students and professors that meet weekly throughout the school year to go over research papers. The papers are picked by the participants, and vary in topic from obscure to very practical.
This week’s paper reading was led by Professor Len Shapiro, and titled “Online Aggregation“. The paper is considered a foundational paper about SQL aggregates (like COUNT() or AVERAGE), and was published in 1997 by researchers from UC Berkeley and IBM. It’s also precursor to research into query parallelization and streaming databases. It was also awarded the SIGMOD “Test of Time” award in 2007, and is cited by over 170 other papers in the ACM archive.
The basic idea behind the paper centered around how to improve user experience in reporting results of aggregate queries – asking questions about how to solve three key problems when solving aggregates: blocking, fairness and control (from a user’s perspective). Roughly: Blocking is what happens when some part of the system waits and doesn’t return results to the user as a result of the waiting. Fairness concerns whether certain types of operations prevent certain groups of data from being processed (the example given had to do with GROUP BY and groups being processed one at a time). Control concerns whether or not a user can exert control over the speed of computation applied to a group (example given being a lever that “speeds up” processing of a set).
One insight from the paper is how online aggregates should be treated differently than traditional query processing – which might favor expensive plans involving sorts so that the output is ordered. When you’re dealing with online aggregates, you prefer unordered, or ideally random order, because your intermediate results will be more representative of the ultimate result. I guess that’s probably obvious once you think about it, but the paper provided some concrete examples.
Another interesting thought experiment involving the planner is how you pick plans that favor non-blocking, fairness and user control. Each of those properties is not narrowly defined, and changes based on individual user expectation. Professor Kristen Tufte mentioned that she’d be interested in how the ideas presented in this paper would be applied today, and Professor David Meier brought up that we might most be interested in applications involving managing Hadoop.
Prof Meier also brought up an interesting paper involving alternating nested loop joins during a discussion about optimizing JOIN algorithms for online aggregates. Another cool thing about the paper is that it involved modifications to Postgres! Granted, it was Postgres95, which doesn’t resemble the modern PostgreSQL 9.0 very much. But it was nice to revisit research that used Postgres that’s still relevant today.
twittering on 2010-08-28
- Generating 57 volts from a creek, a bucket and some other stuff 😉 http://www.youtube.com/watch?v=Vn1EtGRRkSo #
twittering on 2010-08-27
- Stoked for coffee, sunshine, clouds, tunes. #
- Looking forward to NYC next month: http://nymag.com/arts/art/features/67387/ #
- http://howfuckedismydatabase.com /cc @dbahulk #
- Enjoying epic anti-Java-as-a-first-language rant from @darianapatrick. Been there. #
twittering on 2010-08-26
- What you say vs. Who you are: http://www.illdoctrine.com/2008/07/how_to_tell_people_they_sound.html #
twittering on 2010-08-23
- Integrated chicks with the crazy white bantum. Celebrating with strawberry crepes. #
Weekly tweet digest for 2010-08-22
- Fact: running makes me more hungry. Now on my third breakfast. #
- Officially tired of being subscribed to bullshit yahoo groups. And also tired of not being able to stop people from adding me to them. #
- Uh oh. Someone's going rogue. #
- hi-5 @mherrick66:meme about pdx software people only interested in "lifestyle companies" & "clocking out at 5" is lame. http://bit.ly/9QAgeQ #
- We work our asses off. Going big isn't the only path to success. #
- Looking forward to hearing about where PL/Parrot is at from @dukeleto this evening. http://calagator.org/events/1250458962 #
- Finally pulling the video off the camera from OSCON and the last @pdxpug meeting. #
- [+] (1, 1, *+* … $^limit) #plperl6 #
- OH: "That's the cheerleader operator." -@gorthx #plperl6 #
- epic @hackathon http://flic.kr/p/8tQzjj #
- epic @pdxhackathon http://flic.kr/p/8tQzjj #