<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Postgresql on despatches</title><link>https://icle.es/tags/postgresql/</link><description>Recent content in Postgresql on despatches</description><generator>Hugo</generator><language>en</language><lastBuildDate>Fri, 20 Mar 2026 11:06:08 +0000</lastBuildDate><atom:link href="https://icle.es/tags/postgresql/index.xml" rel="self" type="application/rss+xml"/><item><title>Supa Supabase</title><link>https://icle.es/2025/09/23/supa-supabase/</link><pubDate>Tue, 23 Sep 2025 12:09:57 +0100</pubDate><guid>https://icle.es/2025/09/23/supa-supabase/</guid><description>&lt;p>I have always been a fan of &lt;a href="https://icle.es/tags/postgresql">PostgreSQL&lt;/a>. I picked it for
megabus.com and used it when the system grew from a few hundred orders a day to
tens of thousands each day.&lt;/p>
&lt;p>Back in the late noughties, when MySQL was getting popular, people would often
ask me why I was picking Postgres. MySQL was so popular and so fast and it had
cool things like query caching (with postgres did not have). My answer was
simple - postgresql was a &amp;ldquo;real database system.&amp;rdquo; I remember being shocked when
I trying to use transactions and it just ignored it. Postgresql was also really
good at failing gracefully under high load while MySQL had a bad habit of just
stopping processing any requests and becoming unresponsive.&lt;/p></description><content:encoded><![CDATA[<p>I have always been a fan of <a href="https://icle.es/tags/postgresql">PostgreSQL</a>. I picked it for
megabus.com and used it when the system grew from a few hundred orders a day to
tens of thousands each day.</p>
<p>Back in the late noughties, when MySQL was getting popular, people would often
ask me why I was picking Postgres. MySQL was so popular and so fast and it had
cool things like query caching (with postgres did not have). My answer was
simple - postgresql was a &ldquo;real database system.&rdquo; I remember being shocked when
I trying to use transactions and it just ignored it. Postgresql was also really
good at failing gracefully under high load while MySQL had a bad habit of just
stopping processing any requests and becoming unresponsive.</p>
<p>This was more than 15 years ago now so things may have changed with MySQL,
though its acquisition by Oracle was certainly a bad sign.</p>
<p>Years on, and it would seem that people are better informed as to the benefits
of postgresql.</p>
<p>I am currently working on a small game-like social experiment app and it
requires persistent storage. I was intially considering firebase but the costs
put me off. In the world of cloud, I didn&rsquo;t think that spinning up a postgresql
server was really an option - or is it?</p>
<h2 id="supabase">Supabase</h2>
<p>I ran into Supabase as a more cost-effective option and as a bonus it&rsquo;s open
source and based on PostgreSQL. I&rsquo;ll admit that I was skeptical that it would
embody the postgresql philosophy that I knew and loved. I expected another
capitalistic effort at monetising open source.</p>
<p>I was pleasantly surprised. I am in the very early stages of using it, but so
far, I love it. Not a huge fan its love of javascript, but the whole world seems
to be a big fan (I am not - but then I wasn&rsquo;t a fan of MySQL either ;))</p>
<p>I didn&rsquo;t end up going further with it, but the early impression was good enough
that I&rsquo;d reach for it again.</p>
]]></content:encoded></item><item><title>PostgreSQL performing huge updates</title><link>https://icle.es/2011/11/06/postgresql-performing-huge-updates-1106/</link><pubDate>Sun, 06 Nov 2011 12:45:41 +0000</pubDate><guid>https://icle.es/2011/11/06/postgresql-performing-huge-updates-1106/</guid><description>&lt;p>PostgreSQL is a pretty powerful database server and will work with almost any
settings thrown at it. It is really good at making do with what it has and
performing as it is asked.&lt;/p>
&lt;p>We recently found this as we were trying to update every row in a table that had
over eight million entries. We found in the first few tries that the update was
taking over 24 hours to complete which was far too long for an update script.&lt;/p>
&lt;p>Our investigation of this led us to the pgsql_tmp folder and the work_mem
configuration parameter.&lt;/p>
&lt;p>When the query was being executed, we checked the pgsql_tmp folder to see how
was space being utilised in there. We already knew about the pgsql table from
past experience. We had a server running out of disk space and rapidly. We had
narrowed it down into this folder. In cancelling the query referenced by the tmp
files in here, we were able to free up literally gigabytes of disk space...&lt;/p></description><content:encoded><![CDATA[<p>PostgreSQL is a pretty powerful database server and will work with almost any
settings thrown at it. It is really good at making do with what it has and
performing as it is asked.</p>
<p>We recently found this as we were trying to update every row in a table that had
over eight million entries. We found in the first few tries that the update was
taking over 24 hours to complete which was far too long for an update script.</p>
<p>Our investigation of this led us to the pgsql_tmp folder and the work_mem
configuration parameter.</p>
<p>When the query was being executed, we checked the pgsql_tmp folder to see how
was space being utilised in there. We already knew about the pgsql table from
past experience. We had a server running out of disk space and rapidly. We had
narrowed it down into this folder. In cancelling the query referenced by the tmp
files in here, we were able to free up literally gigabytes of disk space...</p>
<p>We had found roughly half a gig of temporary files in here. This led us to
investigate the configuration file.</p>
<p>The one parameter that stuck out was work_mem which was set to a default of 1mb
which I guess might make sense under most circumstances but not in this one.
According to the postgresql documentation</p>
<blockquote>
<p><code>work_mem</code> (<code>integer</code>)</p>
<p>Specifies the amount of memory to be used by internal sort operations and hash
tables before switching to temporary disk files. The value is defaults to one
megabyte (<code>1MB</code>). Note that for a complex query, several sort or hash
operations might be running in parallel; each one will be allowed to use as
much memory as this value specifies before it starts to put data into
temporary files. Also, several running sessions could be doing such operations
concurrently. So the total memory used could be many times the value
of <code>work_mem</code>; it is necessary to keep this fact in mind when choosing the
value. Sort operations are used for <code>ORDER BY</code>, <code>DISTINCT</code>, and merge joins.
Hash tables are used in hash joins, hash-based aggregation, and hash-based
processing of <code>IN</code> subqueries.</p></blockquote>
<p>This would tell us that the total memory usage with work_mem could be several
times the value set here and setting it to half a gig would probably be a
terrible idea for a heavily utilised production server. However, for the
migration process when we need to update over 8,000,000 rows, it might be a good
temporary fix.</p>
<p>After updating the work_mem to 512mb, we found that no more tmp files were
created and the whole thing was done in memory.</p>
<p>When updating so many rows, there area a few other things to consider.</p>
<p>Firstly, autovacuum will likely kick in several times to vacuum the table.
You'll probably want to disable this for the duration of the update statement
and run a vacuum afterwards.</p>
```sql
    --disable auto vacuum
    ALTER TABLE sometable SET (
      autovacuum_enabled = false, toast.autovacuum_enabled = false
    );
```
<p>You can switch autovacuum back on after the update statement has completed</p>
```sql
    --enable auto vacuum
    ALTER TABLE sometable SET (
      autovacuum_enabled = true, toast.autovacuum_enabled = true
    );
```
<p>A few other things you want to take a look at are the</p>
<ul>
<li>fsync parameter (I usually have this set to off anyway since the servers are
pratically fully redundant)</li>
<li>checkpoint_segments: I changed this to roughly 5 times the original value
(check the log to see if it says that its checkpointing too often)</li>
<li>checkpoint_completion_target: I changed this to 0.9</li>
</ul>
<p>With all of these updates, we were able to bring the total time of the update
down to a few hours.</p>]]></content:encoded></item><item><title>Tracking progress of an update statement</title><link>https://icle.es/2011/11/02/tracking-progress-of-an-update-statement-1101/</link><pubDate>Wed, 02 Nov 2011 19:59:02 +0000</pubDate><guid>https://icle.es/2011/11/02/tracking-progress-of-an-update-statement-1101/</guid><description>&lt;p>Sometimes there is a need to execute a long running update statement. This
update statement might be modifying millions of rows as was the case when we
went hunting for a way to track the progress of the update. Hunting around took
us to &lt;a href="http://archives.postgresql.org/pgsql-admin/2002-07/msg00286.php">http://archives.postgresql.org/pgsql-admin/2002-07/msg00286.php&lt;/a> In our
particular case, we are using postgresql but this should work with any database
server that provides sequences. Our original sql was of the form:&lt;/p>
```sql
update only table1 t1
set amount = t2.price
from table2 t2
where t1.id = t2.id;
```
&lt;p>There is of course now way of figuring out how many rows had been updated
already. The first step was to create a sequence&lt;/p>
```sql
CREATE TEMPORARY SEQUENCE seq_progress START 1;
```</description><content:encoded><![CDATA[<p>Sometimes there is a need to execute a long running update statement. This
update statement might be modifying millions of rows as was the case when we
went hunting for a way to track the progress of the update. Hunting around took
us to <a href="http://archives.postgresql.org/pgsql-admin/2002-07/msg00286.php">http://archives.postgresql.org/pgsql-admin/2002-07/msg00286.php</a> In our
particular case, we are using postgresql but this should work with any database
server that provides sequences. Our original sql was of the form:</p>
```sql
update only table1 t1
set amount = t2.price
from table2 t2
where t1.id = t2.id;
```
<p>There is of course now way of figuring out how many rows had been updated
already. The first step was to create a sequence</p>
```sql
CREATE TEMPORARY SEQUENCE seq_progress START 1;
```
<p>We can then use this sequence in the update statement to ensure that each row
updated also increments the sequence</p>
```sql
update only table1 t1
set amount = t2.price
from table2 t2
where nextval('seq_progress') != 0
and t1.id = t2.id;
```
<p>Once the query is running, you can open another connection to the database. To
get an indication of how far it has got, you can just run the following</p>
```sql
select nextval('seq_progress');
```
<p>Bear in mind that this will also increment it by 1 but if you have millions of
rows which is really the only case in which this would be useful, a few
additional increments is hardly going to make a difference.</p>
<p>Good luck and have fun!</p>]]></content:encoded></item><item><title>Database Systems Compared</title><link>https://icle.es/2009/03/10/database-systems-compared/</link><pubDate>Tue, 10 Mar 2009 16:00:21 +0000</pubDate><guid>https://icle.es/2009/03/10/database-systems-compared/</guid><description>&lt;p>My first experiences of a computer started with
&lt;a href="http://en.wikipedia.org/wiki/DBase" title="Dbase on Wikipedia">DBase III+&lt;/a>which is
now &lt;a href="http://www.dbase.com/" title="dBASE">dBASE&lt;/a>, then went on to
&lt;a href="http://en.wikipedia.org/wiki/FoxPro_2" title="Foxpro 2 on Wikipedia">Foxpro&lt;/a>, now
&lt;a href="http://msdn.microsoft.com/en-us/vfoxpro/bb190288.aspx" title="Microsoft Visual Foxpro">Microsoft Visual Foxpro&lt;/a>.&lt;/p>
&lt;p>I have since used:&lt;/p>
&lt;ul>
&lt;li>&lt;a href="http://www.filemaker.co.uk/" title="Filemaker Pro">Filemaker Pro&lt;/a>,&lt;/li>
&lt;li>&lt;a href="http://office.microsoft.com/en-us/access/default.aspx" title="Microsoft Access">Microsoft Access&lt;/a>,&lt;/li>
&lt;li>&lt;a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx" title="Microsoft SQL Server">Microsoft SQL Server&lt;/a>,&lt;/li>
&lt;li>&lt;a href="http://www.mysql.com/" title="MySQL">MySQL&lt;/a>,&lt;/li>
&lt;li>&lt;a href="http://www.postgresql.org/" title="PostgreSQL">PostgreSQL&lt;/a>,&lt;/li>
&lt;li>&lt;a href="http://www.sqlite.org/" title="SQLite">SQLite&lt;/a> and&lt;/li>
&lt;li>&lt;a href="http://hsqldb.org/" title="HSQLDB">HSQLDB&lt;/a>.&lt;/li>
&lt;/ul>
&lt;p>I have not yet used:&lt;/p>
&lt;ul>
&lt;li>&lt;a href="http://www.ibm.com/software/data/db2/" title="IBM DB2">IBM DB2&lt;/a>,&lt;/li>
&lt;li>&lt;a href="http://www.oracle.com/index.html" title="Oracle">Oracle&lt;/a>.&lt;/li>
&lt;/ul>
&lt;p>&lt;a href="http://en.wikipedia.org/wiki/Comparison_of_relational_database_management_systems" title="Compare DB Systems">Wikipedia has a list of database systems&lt;/a>.&lt;/p></description><content:encoded><![CDATA[<p>My first experiences of a computer started with
<a href="http://en.wikipedia.org/wiki/DBase" title="Dbase on Wikipedia">DBase III+</a>which is
now <a href="http://www.dbase.com/" title="dBASE">dBASE</a>, then went on to
<a href="http://en.wikipedia.org/wiki/FoxPro_2" title="Foxpro 2 on Wikipedia">Foxpro</a>, now
<a href="http://msdn.microsoft.com/en-us/vfoxpro/bb190288.aspx" title="Microsoft Visual Foxpro">Microsoft Visual Foxpro</a>.</p>
<p>I have since used:</p>
<ul>
<li><a href="http://www.filemaker.co.uk/" title="Filemaker Pro">Filemaker Pro</a>,</li>
<li><a href="http://office.microsoft.com/en-us/access/default.aspx" title="Microsoft Access">Microsoft Access</a>,</li>
<li><a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx" title="Microsoft SQL Server">Microsoft SQL Server</a>,</li>
<li><a href="http://www.mysql.com/" title="MySQL">MySQL</a>,</li>
<li><a href="http://www.postgresql.org/" title="PostgreSQL">PostgreSQL</a>,</li>
<li><a href="http://www.sqlite.org/" title="SQLite">SQLite</a> and</li>
<li><a href="http://hsqldb.org/" title="HSQLDB">HSQLDB</a>.</li>
</ul>
<p>I have not yet used:</p>
<ul>
<li><a href="http://www.ibm.com/software/data/db2/" title="IBM DB2">IBM DB2</a>,</li>
<li><a href="http://www.oracle.com/index.html" title="Oracle">Oracle</a>.</li>
</ul>
<p><a href="http://en.wikipedia.org/wiki/Comparison_of_relational_database_management_systems" title="Compare DB Systems">Wikipedia has a list of database systems</a>.</p>
<p>Having worked with this range of database systems and having done copious
amounts of research into DB2, Oracle and other DB systems I have not mentioned,
I like answering the age old questions. Which is the best database system?</p>
<p>Ah! if only it was that simple. There is no database system that is appropriate
for any given requirement. But then, if you have been in the technology sector
long enough, you would already know that. It's all about using the right tool
for the job.</p>
<p>I separate these systems into two broad categories and Oracle. There are the
Desktop based database systems:</p>
<ul>
<li>DBase</li>
<li>Foxpro</li>
<li>SQLite</li>
<li>HSQLDB</li>
<li>Filemaker Pro</li>
<li>Microsoft Access</li>
<li>MySQL</li>
</ul>
<p>DBase, FoxPro, Filemaker Pro and Microsoft Access are essentially a GUI frontend
that has a database backing.</p>
<p>Access is the best choice for this purpose under the majority of circumstances.
Filemaker Pro is relevant in some. The usual reason to use DBase or FoxPro is
simply that the developer is used to it. This is not a good enough reason.</p>
<p>I have used DBase III+ for developing an office management suite back in 1994. I
have since used Filemaker Pro to develop a simple contact management database in
1998, Microsoft Access to develop a patient management system for a clinic.</p>
<p>SQLite, HSQLDB and MySQL are database engines that are to be utilised by popping
a frontend on top; sometimes the frontend is Microsoft Access. Microsoft Access
can also be used for its database engine.</p>
<p>Access is usually the worst choice for this except as a stopgap. There are
exceptions to this. One is for a web frontend if the site is not too busy and
its running on a microsoft platform. You don't have to go to the hassle of
installing anything on the server. The drivers will take care of it all.</p>
<p>HSQLDB becomes an obvious choice for a light java based application and SQLite
for any other lightweight applications.</p>
<p>MySQL is substantially more powerful and scales a lot better. I include it in
this section because it is a server grade database system that can also work
well in a desktop environment.</p>
<p>I have used Access for several web based systems and I have used HSQLDB for unit
testing hibernate and for a quick and dirty MP3 library that linked into
<a href="http://musicbrainz.org/" title="Musicbrainz">musicBrainz</a>. I have used SQLite in
passing to be utilised by open source products.</p>
<p>I have used MySQL with an Access frontend as a management suite for a website as
well.</p>
<p>And we have the server based database systems:</p>
<ul>
<li>MySQL</li>
<li>Microsoft SQL Server</li>
<li>IBM DB2</li>
<li>PostgreSQL</li>
</ul>
<p>MySQL was used as the backed database system for the edFringe.com website. This
was the perfect choice since the most important requirement was speed.
Particuarly with the Query Cache and Master Slave replication, MySQL was the
best choice.</p>
<p>SQL Server was used as the backend system for an online course for the Scottish
Enterprise around 1999/2000. While MySQL would have been a good choice this, it
was not of production quality at the time.</p>
<p>We have also used Ms SQL Server for an insurance company since all the
infrastructure was based on Windows and PostgreSQL did not have a viable Windows
version at the time.</p>
<p>We use PostgreSQL for megabus. While speed is absolutely critical, it is a
ticketing system which means that transactionality is absolutely critical.</p>
<p>While MySQL now has transactionality with innodb, it is still nowhere near as
good as the transactionality provided by PostgreSQL through MVCC (Multi-version
Concurrency Control). We could have used Ms SQL Server but the cost savings are
dramatic.</p>
<p>To summarise, each system has a specific use, specific strengths and weaknesses
and which should be used is highly dependent on what it is to be used for. I am
hopeful that the summary of what we have used each of these systems for us
useful in determining which one is best placed to solve any specific problem :-D</p>
<p>We have not yet used Oracle and it was a strong contender for megabus but the
serious heavyweight functionality provided by Oracle comes at a price and it is
not yet a cost effective option.</p>]]></content:encoded></item><item><title>Controversy</title><link>https://icle.es/2009/01/31/controversy/</link><pubDate>Sat, 31 Jan 2009 18:53:02 +0000</pubDate><guid>https://icle.es/2009/01/31/controversy/</guid><description>&lt;p>We have never been shy about voicing our opinions or being controversial. While
discussing some PR requirements recently with a potential agency, the question
was asked about whether we would be willing to be controversial.&lt;/p>
&lt;p>We are not necessarily controversial, just that we hold a view that is usually a
little different from the mainstream views. It could be said that we bring the
alternative to the mainstream.&lt;/p>
&lt;p>But then, so did some world governments, bringing open source software into
their work places, successfully or unsuccessfully in the last few years instead
of Microsoft.&lt;/p>
&lt;p>Someone recently suggested that we were anti-microsoft. I don&amp;rsquo;t think that is
case. Microsoft has its place in a technology infrastructure. It is simply that
its position is usually overrated or misplaced. As far as desktops for
technically shy users are concerned, there is really no alternative but
Microsoft Windows. I can hear the Mac users scream that Macs are also an
alternative. Theoretically, yes but the fact is that they are too expensive for
someone to dabble with it. This is precisely the reason that Microsoft Windows
dominates the desktop market.&lt;/p>
&lt;p>We support and use Linux. In fact, the majority of the desktops in the office
run Linux (Ubuntu as it happens) but people who have a non-technical role use
Windows. They could use Linux but Windows is better suited to their role.&lt;/p></description><content:encoded><![CDATA[<p>We have never been shy about voicing our opinions or being controversial. While
discussing some PR requirements recently with a potential agency, the question
was asked about whether we would be willing to be controversial.</p>
<p>We are not necessarily controversial, just that we hold a view that is usually a
little different from the mainstream views. It could be said that we bring the
alternative to the mainstream.</p>
<p>But then, so did some world governments, bringing open source software into
their work places, successfully or unsuccessfully in the last few years instead
of Microsoft.</p>
<p>Someone recently suggested that we were anti-microsoft. I don&rsquo;t think that is
case. Microsoft has its place in a technology infrastructure. It is simply that
its position is usually overrated or misplaced. As far as desktops for
technically shy users are concerned, there is really no alternative but
Microsoft Windows. I can hear the Mac users scream that Macs are also an
alternative. Theoretically, yes but the fact is that they are too expensive for
someone to dabble with it. This is precisely the reason that Microsoft Windows
dominates the desktop market.</p>
<p>We support and use Linux. In fact, the majority of the desktops in the office
run Linux (Ubuntu as it happens) but people who have a non-technical role use
Windows. They could use Linux but Windows is better suited to their role.</p>
<p>This is not necessarily a cost-saving decision. Sure, we have saved thousands of
pounds by sticking to Linux instead of using Windows but that is a co-incidence
more than anything. In some ways, it is a testament to the skillset of the
people who work at Kraya that they are comfortable with Linux. The mindset of
Linux is in alignment with the mindset of a developer.</p>
<p>I used to develop in Windows and I often found myself fighting with Windows,
whereas with Linux, it just fits. There are several reasons for this. One being
that Linux forces you to understand what you (trying to ) do to a bit more depth
instead of pretending its magically taken care of.</p>
<p>I am not, for one moment implying that developers who use or develop on the
Windows platform is inferior or not as skilled. Simply that my experience was
that the Windows platform made it easier to do things badly and more difficult
to do things well.</p>
<p>Microsoft has done wonders in bringing technology to the masses and making it
more accessible. However, there is still a massive barrier, even for people
specifically in the technology sector to appreciate and use technologies which
require a bit more experience or knowledge to use appropriately.</p>
<p>There are a couple of really good examples. PostgreSQL is a powerful outstanding
database server that can easily compete with Microsoft SQL Server and Oracle.
However, very few people know about it and even fewer use it.</p>
<p>MySQL on the other hand is also an open source database server but is much more
widely used and accepted.</p>
<p>It surprises me when MySQL is used when PostgreSQL is, from a technical
perspective better suited. MySQL is faster than PostgreSQL at the cost of poor
transaction managment (at best). For any system where data integrity is even
remotely important, PostgreSQL is a better choice. However, since there are
better GUI tools for MySQL and since it is easier to get the hang of, it gets
chosen.</p>
<p>This give technology and people in that sector a bad name. Every tool or
software has its place, and should be used in an environment where its strengths
are displayed, not its weaknesses. We have instances where we use multiple
database servers within one project. PostgreSQL for all the data integrity
sensitive areas and MySQL for the speed sensitive areas. Sometimes you want
integrity and speed. In these cases, you have to make a choice based on which is
more important or layer the databases to use the strengths of both.</p>
<p>Metaphorically speaking, MySQL is a hammer, and PostgreSQL is a sledgehammer.
Would you use a sledgehammer to crack a nut, or a hammer to crack a slab of
concrete?</p>
<p>Before someone jumps down my throat, I am not suggesting that PostgreSQL is
better than MySQL or vice versa - just that they both have different goals,
different strengths and weaknesses. They have spent a lot of effort to converge
and strengthen their weaknesses but not matter the amount of convergence, their
core goals are still different that they will never truly be able to remove
their weaknesses without giving up some of their strengths as well. One tool
cannot be both a hammer and a sledgehammer&hellip;</p>]]></content:encoded></item></channel></rss>