<?xml version="1.0" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">

<channel>
<title>Bruce Momjian: Postgres Blog</title>
<description>Bruce Momjian: Postgres Blog</description>
<link>http://momjian.us/main/blogs/pgblog.html</link>
<language>en-us</language>
<pubDate>Thu, 02 Feb 2012 10:45:01 EST</pubDate>
<lastBuildDate>Thu, 02 Feb 2012 10:45:01 EST</lastBuildDate>
<managingEditor>bruce@momjian.us (Bruce Momjian)</managingEditor>
<webMaster>bruce@momjian.us (Bruce Momjian)</webMaster>


<atom:link href="http://momjian.us/main/rss/pgblog.xml" rel="self" type="application/rss+xml" />

<item>
<title>
Let's See work_mem
</title>
<pubDate>Thursday,, 02 February 2012 10:45:01 -0500</pubDate>
<description>
&lt;p&gt;Having shown memory allocation (and deallocation) in my previous &lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://momjian.us/main/blogs/pgblog/2012.html#February_1_2012&quot;&gt;blog
post&lt;/a&gt;, I would like to show
&lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://www.postgresql.org/docs/9.1/static/runtime-config-resource.html#RUNTIME-CONFIG-RESOURCE-MEMORY&quot;&gt;&lt;em&gt;work_mem&lt;/em&gt;&lt;/a&gt; in action.
&lt;/p&gt;
&lt;p&gt;First, I ran the following database session using a &lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://momjian.us/main/blogs/pgblog/2012.html#January_20_2012&quot;&gt;~6k RPM drive&lt;/a&gt;:
&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://momjian.us/main/blogs/pgblog/2012.html#February_2_2012&quot;&gt;Continue Reading &amp;raquo;&lt;/a&gt;&lt;/p&gt;
</description>
<link>http://momjian.us/main/blogs/pgblog/2012.html#February_2_2012</link>
<guid>http://momjian.us/main/blogs/pgblog/2012.html#February_2_2012</guid>
</item>

<item>
<title>
Postgres Memory Surprises
</title>
<pubDate>Wednesday,, 01 February 2012 12:00:00 -0500</pubDate>
<description>
&lt;p&gt;In my previous &lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://momjian.us/main/blogs/pgblog/2012.html#January_30_2012&quot;&gt;blog entry&lt;/a&gt;, I analyzed how various
tools (&lt;em&gt;ps&lt;/em&gt; and &lt;em&gt;smem&lt;/em&gt;) report memory usage.  In summary:
&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;em&gt;ps&lt;/em&gt; columns &lt;em&gt;TRS&lt;/em&gt;, &lt;em&gt;DRS&lt;/em&gt;, and &lt;em&gt;VSZ&lt;/em&gt; report virtual address space allocated, not actual RAM allocated.
  &lt;/li&gt;&lt;li&gt;&lt;em&gt;smem&lt;/em&gt;'s &lt;em&gt;USS&lt;/em&gt; reports a process's private (unshared) memory allocated.
  &lt;/li&gt;&lt;li&gt;&lt;em&gt;smem&lt;/em&gt;'s &lt;em&gt;PSS&lt;/em&gt; is a sum of process's private memory allocated and a proportional amount of shared memory (both System V shared
memory, like Postgres's shared_buffers, and shared libraries).
  &lt;/li&gt;&lt;li&gt;&lt;em&gt;RSS&lt;/em&gt; shows actual RAM allocated, private and shared.
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;With these issues understood, let's look at a running Postgres cluster:
&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://momjian.us/main/blogs/pgblog/2012.html#February_1_2012&quot;&gt;Continue Reading &amp;raquo;&lt;/a&gt;&lt;/p&gt;
</description>
<link>http://momjian.us/main/blogs/pgblog/2012.html#February_1_2012</link>
<guid>http://momjian.us/main/blogs/pgblog/2012.html#February_1_2012</guid>
</item>

<item>
<title>
Revisiting Memory Reporting
</title>
<pubDate>Monday,, 30 January 2012 12:00:00 -0500</pubDate>
<description>
&lt;p&gt;Memory is very important to databases &amp;mdash; much more so than for typical applications
(&lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://momjian.us/main/presentations/overview.html#hw_selection&quot;&gt;presentation&lt;/a&gt;).  Unfortunately, because memory allocation is so
complex, it is often hard to figure out how physical RAM is being used.  There are several reasons for the complexity:
&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Virtual Memory:&lt;/strong&gt; CPUs in virtual memory mode don't access RAM directly, but rather through
&lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://en.wikipedia.org/wiki/Page_table&quot;&gt;page tables&lt;/a&gt;.
  &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Segmentation:&lt;/strong&gt; Memory is allocated in specific &lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://en.wikipedia.org/wiki/Segmentation_%28memory%29&quot;&gt;segments&lt;/a&gt;:
&lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://en.wikipedia.org/wiki/Text_segment&quot;&gt;text(code)&lt;/a&gt;, &lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://en.wikipedia.org/wiki/Data_segment&quot;&gt;data&lt;/a&gt;, and stack.
  &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Sharing:&lt;/strong&gt;  physical RAM is often shared by multiple processes, either in read-only mode (program instructions), shared mode (read/write
of share memory), or &lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://en.wikipedia.org/wiki/Copy-on-write&quot;&gt;copy-on-write&lt;/a&gt; (create a new copy on write; used by
&lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://en.wikipedia.org/wiki/Fork_%28operating_system%29&quot;&gt;fork&lt;/a&gt;).
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Robert Haas's excellent &lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://rhaas.blogspot.com/2012/01/linux-memory-reporting.html&quot;&gt;blog post&lt;/a&gt; highlighted much uncertainty about
how to analyze memory usage for specific processes, especially Postgres.  I commented on his blog, as did others, and now have a much
clearer idea of how to study memory usage.  A &lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://utcc.utoronto.ca/~cks/space/blog/linux/LinuxMemoryStats&quot;&gt;blog post&lt;/a&gt; by Chris
Siebenmann directly addresses some of my and Robert's questions, and suggests &lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://www.selenic.com/smem/&quot;&gt;smem&lt;/a&gt; as a way to analyze
memory, especially the sharing of memory.  It was interesting to learn that smem was designed specifically to address the problems Robert
outlined (&lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://lwn.net/Articles/230975/&quot;&gt;2007&lt;/a&gt;, &lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://lwn.net/Articles/329458/&quot;&gt;2009&lt;/a&gt;).
&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://momjian.us/main/blogs/pgblog/2012.html#January_30_2012&quot;&gt;Continue Reading &amp;raquo;&lt;/a&gt;&lt;/p&gt;
</description>
<link>http://momjian.us/main/blogs/pgblog/2012.html#January_30_2012</link>
<guid>http://momjian.us/main/blogs/pgblog/2012.html#January_30_2012</guid>
</item>

<item>
<title>
NoSQL Databases as the New Scripting Language
</title>
<pubDate>Friday,, 27 January 2012 12:00:00 -0500</pubDate>
<description>
&lt;p&gt;This &lt;a style=&quot;text-decoration: underline&quot; class=&quot;major&quot; href=&quot;http://www.youtube.com/watch?v=56TTOqMOkoY&quot;&gt;video presentation&lt;/a&gt; by Dwight Merriman (MongoDB) at OSCON Data 2011 explores the
role of NoSQL databases.  He makes some very interesting points:
&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;NoSQL was created to allow &lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://momjian.us/main/blogs/pgblog/2012.html#January_26_2012&quot;&gt;horizontal, read-write scaling&lt;/a&gt;
  &lt;/li&gt;&lt;li&gt;NoSQL uses a dynamic schema
  &lt;/li&gt;&lt;li&gt;NoSQL is similar to dynamically-typed languages, e.g. Perl, PHP
  &lt;/li&gt;&lt;li&gt;NoSQL has serious limitations compared to relational data storage, e.g. reporting
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;What I found most interesting about his presentation was the comparison to dynamically-typed languages.  When dynamically-typed scripting
languages started to become popular years ago, there was a sense that they were only for trivial applications, compared to compiled
language that were for serious work.  As CPUs became faster, scripting languages were increasingly used for production applications,
particularly web applications that are modified frequently.  There might be a similar pattern now in the (improper?) dismissal of NoSQL
for serious applications.  
&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://momjian.us/main/blogs/pgblog/2012.html#January_27_2012&quot;&gt;Continue Reading &amp;raquo;&lt;/a&gt;&lt;/p&gt;
</description>
<link>http://momjian.us/main/blogs/pgblog/2012.html#January_27_2012</link>
<guid>http://momjian.us/main/blogs/pgblog/2012.html#January_27_2012</guid>
</item>

<item>
<title>
Scalability What?
</title>
<pubDate>Thursday,, 26 January 2012 12:00:00 -0500</pubDate>
<description>
&lt;p&gt;The term &quot;scalability&quot; gets injected into database conversations often, but scalability discussions often end without a clear consensus. 
I believe this is because &quot;scalability&quot;, like &quot;replication&quot;, actually means different things to different people.  
&lt;/p&gt;
&lt;p&gt;There are two dimensions to database scalability;  the first dimension specifies if additional servers are involved:
&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;vertical:&lt;/strong&gt;  The hardware capabilities of a single database server are increased to increase throughput
  &lt;/li&gt;&lt;li&gt;&lt;strong&gt;horizontal:&lt;/strong&gt;  The number of a database servers is increased to increase throughput
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;a href=&quot;http://momjian.us/main/blogs/pgblog/2012.html#January_26_2012&quot;&gt;Continue Reading &amp;raquo;&lt;/a&gt;&lt;/p&gt;
</description>
<link>http://momjian.us/main/blogs/pgblog/2012.html#January_26_2012</link>
<guid>http://momjian.us/main/blogs/pgblog/2012.html#January_26_2012</guid>
</item>

<item>
<title>
Increasing Database Reliability
</title>
<pubDate>Wednesday,, 25 January 2012 12:00:00 -0500</pubDate>
<description>
&lt;p&gt;While database software can be the cause of outages, for Postgres, it is often not the software but the hardware that causes failures
&amp;mdash; and storage is often the failing component.  Magnetic disk is one of the few moving parts on a computer, and hence prone to
breakage, and solid-state drives (&lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://en.wikipedia.org/wiki/Solid-state_drive&quot;&gt;SSDs&lt;/a&gt;) have a finite write limit.
&lt;/p&gt;
&lt;p&gt;While waiting for storage to start making loud noises or fail is an option, a better option is to use some type of monitoring that warns
of storage failure before it occurs, e.g. enter &lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://en.wikipedia.org/wiki/S.M.A.R.T.&quot;&gt;SMART&lt;/a&gt;.  SMART is a system developed by
storage vendors that allows the operating system to query diagnostics on the drive and warn of unusual storage behavior before failure
occurs.  While read/write failures are reported by the kernel, SMART parameters often warn of danger before failure occurs.  Below is the
SMART output from a Western Digital (WDC) &lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://www.amazon.com/Western-Digital-Caviar-Desktop-WD20EARX/dp/B004VFJ9MK&quot;&gt;WD20EARX&lt;/a&gt;
magnetic disk drive:
&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://momjian.us/main/blogs/pgblog/2012.html#January_25_2012&quot;&gt;Continue Reading &amp;raquo;&lt;/a&gt;&lt;/p&gt;
</description>
<link>http://momjian.us/main/blogs/pgblog/2012.html#January_25_2012</link>
<guid>http://momjian.us/main/blogs/pgblog/2012.html#January_25_2012</guid>
</item>

<item>
<title>
The Most Important Postgres CPU Instruction
</title>
<pubDate>Tuesday,, 24 January 2012 12:00:00 -0500</pubDate>
<description>
&lt;p&gt;Postgres consists of roughly 1.1 million lines of C code, which is compiled into an executable with millions of CPU instructions.  Of the
many CPU machine-language instructions in the Postgres server executable, which one is the most important?  That might seem like an odd
question, and one that is hard to answer, but I think I know the answer.
&lt;/p&gt;
&lt;p&gt;You might wonder, &quot;If Postgres is written in C, how would we find the most important machine-language instruction?&quot;  Well, there is a
trick to that.  Postgres is not completely written in C.  There is a very small file (1000 lines) with C code that adds specific
assembly-language CPU instructions into the executable.  This file is called
&lt;a style=&quot;text-decoration: underline&quot; class=&quot;major&quot; href=&quot;http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/include/storage/s_lock.h;hb=HEAD&quot;&gt;s_lock.h&lt;/a&gt;.  It is an include file
that is referenced in various parts of the server code that allows very fast locking operations.  The C language doesn't supply
fast-locking infrastructure, so Postgres is required to supply its own locking instructions for all twelve supported CPU architectures.
(Operating system kernels do supply locking instructions, but they are much too slow to be used for Postgres.)
&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://momjian.us/main/blogs/pgblog/2012.html#January_24_2012&quot;&gt;Continue Reading &amp;raquo;&lt;/a&gt;&lt;/p&gt;
</description>
<link>http://momjian.us/main/blogs/pgblog/2012.html#January_24_2012</link>
<guid>http://momjian.us/main/blogs/pgblog/2012.html#January_24_2012</guid>
</item>

<item>
<title>
More Lessons From My Server Migration
</title>
<pubDate>Monday,, 23 January 2012 12:00:00 -0500</pubDate>
<description>
&lt;p&gt;The &lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://momjian.us/main/blogs/pgblog/2012.html#January_20_2012&quot;&gt;new server&lt;/a&gt; is 2-10 times faster than my old 2003 server, but that
10x speedup is only possible for applications that:
&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Do lots of random I/O, thanks to the SSDs.  Postgres already supports tablespace-specific
&lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://www.postgresql.org/docs/9.1/static/runtime-config-query.html#RUNTIME-CONFIG-QUERY-CONSTANTS&quot;&gt;random_page_cost&lt;/a&gt; settings, but it
would be interesting to see if there are cases that can be optimized for low random pages costs.  This is probably not an immediate
requirement because the in-memory algorithms already assume a low random page cost.
  &lt;/li&gt;&lt;li&gt;Can be highly parallelized.  See my previous &lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://momjian.us/main/blogs/pgblog/2011.html#December_5_2011&quot;&gt;blog entry&lt;/a&gt; regarding
parallelism.  The 16 virtual cores in this server certainly offer more parallelism opportunities than my old two-core system.
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Other observations:
&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;It takes serious money to do the job right, roughly USD $4k &amp;mdash; hopefully increased productivity and reliability will pay back
this investment.
  &lt;/li&gt;&lt;li&gt;I actually started the upgrade two years ago by adjusting my scripts to be more portable;  this made the migration go much smoother. 
The same method can be used for migrations to Postgres by rewriting SQL queries to be more portable before the migration.  Reliable
hardware is often the best way to ensure Postgres reliability.
  &lt;/li&gt;&lt;li&gt;My hot-swappable SATA-2 drive bays allow for a flexible hard-drive-based backup solution (no more magnetic tapes).  File system
snapshots allow similar backups for Postgres tablespaces, but it would be good if this were more flexible.  It would also be cool if you
could move a drive containing Postgres tablespaces from one server to another (perhaps after freezing the rows).
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;a href=&quot;http://momjian.us/main/blogs/pgblog/2012.html#January_23_2012&quot;&gt;Continue Reading &amp;raquo;&lt;/a&gt;&lt;/p&gt;
</description>
<link>http://momjian.us/main/blogs/pgblog/2012.html#January_23_2012</link>
<guid>http://momjian.us/main/blogs/pgblog/2012.html#January_23_2012</guid>
</item>

<item>
<title>
New Server
</title>
<pubDate>Friday,, 20 January 2012 12:00:00 -0500</pubDate>
<description>
&lt;p&gt;A few weeks ago, I finally replaced my eight-year-old home server.  The age of my server, and its operating system,
(&lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://en.wikipedia.org/wiki/BSD/OS&quot;&gt;BSD/OS&lt;/a&gt;, last officially updated in &lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://www.bsdnewsletter.com/2002/12/News61.html&quot;&gt;2002&lt;/a&gt;)
were a frequent source of amusement among Postgres community members.  The
&lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://www.avadirect.com/tower-server-configurator.asp?PRID=13634&quot;&gt;new server&lt;/a&gt; is:
&lt;/p&gt;
&lt;p&gt;&lt;blockquote&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;
Super Micro 7046A-T 4U Tower Workstation
2 x Intel Xeon E5620 2.4GHz Quad-Core Processors
Crucial 24GB Dual-Rank PC3-10600 DDR3 SDRAM
Intel 160GB 320 Series SSD Drive
4 x Western Digital Caviar Green 2TB Hard Drives
&lt;/span&gt;
&lt;/blockquote&gt;
&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://momjian.us/main/blogs/pgblog/2012.html#January_20_2012&quot;&gt;Continue Reading &amp;raquo;&lt;/a&gt;&lt;/p&gt;
</description>
<link>http://momjian.us/main/blogs/pgblog/2012.html#January_20_2012</link>
<guid>http://momjian.us/main/blogs/pgblog/2012.html#January_20_2012</guid>
</item>

<item>
<title>
TOAST Queries
</title>
<pubDate>Thursday,, 19 January 2012 12:00:00 -0500</pubDate>
<description>
&lt;p&gt;As a followup to my previous &lt;a style=&quot;text-decoration: none&quot; class=&quot;txt2html&quot; href=&quot;http://momjian.us/main/blogs/pgblog/2012.html#January_17_2012&quot;&gt;blog entry&lt;/a&gt;, I want to show queries that
allow users to analyze TOAST tables.  First, we find the TOAST details about the &lt;em&gt;test&lt;/em&gt; heap table:
&lt;/p&gt;
&lt;p&gt;&lt;blockquote&gt;
&lt;/p&gt;&lt;pre class='quote_explicit'&gt;
SELECT oid, relname, reltoastrelid, reltoastidxid FROM pg_class where relname = 'test';
  oid  | relname | reltoastrelid | reltoastidxid
-------+---------+---------------+---------------
 17172 | test    |         &lt;strong&gt;17175&lt;/strong&gt; |             0
&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;http://momjian.us/main/blogs/pgblog/2012.html#January_19_2012&quot;&gt;Continue Reading &amp;raquo;&lt;/a&gt;&lt;/p&gt;
</description>
<link>http://momjian.us/main/blogs/pgblog/2012.html#January_19_2012</link>
<guid>http://momjian.us/main/blogs/pgblog/2012.html#January_19_2012</guid>
</item>


</channel>

</rss>

