<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>PostgreSQL on Stefan Litsche</title>
		<link>https://biosoft.de/tags/postgresql/</link>
		<description>Recent content in PostgreSQL on Stefan Litsche</description>
		<generator>Hugo</generator>
		<language>en-US</language>
		
		
		
		
			<lastBuildDate>Fri, 02 Jul 2021 10:26:00 +0100</lastBuildDate>
		
			<atom:link href="https://biosoft.de/tags/postgresql/index.xml" rel="self" type="application/rss+xml" />
			<item>
				<title>Sorting in Lakes</title>
				<link>https://biosoft.de/posts/sorting-in-lakes/</link>
				<pubDate>Fri, 02 Jul 2021 10:26:00 +0100</pubDate>
				<guid>https://biosoft.de/posts/sorting-in-lakes/</guid>
				<description>&lt;p&gt;In case we sort rows using SQL we need to distinguish between duplicate values&#xA;of unique rows and duplicate values due to duplicate rows.&lt;/p&gt;&#xA;&lt;p&gt;The nice thing about the &lt;a href=&#34;https://www.postgresql.org/docs/current/functions-window.html&#34;&gt;&lt;code&gt;row_number&lt;/code&gt;&lt;/a&gt; SQL function is that it provides you with&#xA;a unique number (per partition) which is often used as a mean to de-duplicate a&#xA;set.  The &lt;code&gt;rank&lt;/code&gt; function does not provide this property because duplicate&#xA;values share the same rank.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;SELECT a,&#xA;    dense_rank() OVER (ORDER BY a),&#xA;    rank() OVER (ORDER BY a),&#xA;    row_number() OVER (ORDER BY a)&#xA;FROM (VALUES (1),(1),(2)) AS t(a);&#xA;&#xA; a | dense_rank | rank | row_number&#xA;---+------------+------+------------&#xA; 1 |          1 |    1 |          1&#xA; 1 |          1 |    1 |          2&#xA; 2 |          2 |    3 |          3&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The problem occurs if you use it the wrong way.  Recently I spent a some time&#xA;debugging a weird behavior in a report.  The numbers changed during different&#xA;executions on an immutable data set &amp;mdash; which is not what you expect.&lt;/p&gt;</description>
			</item>
			<item>
				<title>An Update on Statistics Target</title>
				<link>https://biosoft.de/posts/analyze-update/</link>
				<pubDate>Sun, 01 Dec 2019 10:30:00 +0100</pubDate>
				<guid>https://biosoft.de/posts/analyze-update/</guid>
				<description>&lt;p&gt;&#xA;In an &lt;a href=&#34;https://biosoft.de/posts/analyze-extreme-distributions-in-postgresql/&#34;&gt;earlier article I analyzed&lt;/a&gt; the influence of the statistics target on the&#xA;result of sampling for extreme distributions.  The representation of extreme&#xA;rare values in the &lt;a href=&#34;https://www.postgresql.org/docs/current/view-pg-stats.html &#34;&gt;most common values&lt;/a&gt; required a drastic increase of the sample&#xA;size.&lt;/p&gt;&#xA;&lt;p&gt;&#xA;My colleage Alex Shulgin initiated a patch which improved the situation for&#xA;null values.  In PostgreSQL 9.6 the &lt;a href=&#34;https://www.postgresql.org/docs/release/9.6.0/&#34;&gt;improvements for &lt;code class=&#34;verbatim&#34;&gt;analyze&lt;/code&gt;&lt;/a&gt; were released.&#xA;More work was done on this issue later to improve the &lt;a href=&#34;https://www.postgresql.org/docs/release/11.0/&#34;&gt;selection of most common&#xA;values&lt;/a&gt; which was released in PostgreSQL 11.&lt;/p&gt;</description>
			</item>
			<item>
				<title>Analyze Extreme Distributions in Postgresql</title>
				<link>https://biosoft.de/posts/analyze-extreme-distributions-in-postgresql/</link>
				<pubDate>Thu, 30 Jul 2015 10:30:00 +0100</pubDate>
				<guid>https://biosoft.de/posts/analyze-extreme-distributions-in-postgresql/</guid>
				<description>&lt;p&gt;&#xA;&lt;img src=&#34;https://biosoft.de/extreme/load-spike.png&#34; alt=&#34;/extreme/load-spike.png&#34; title=&#34;/extreme/load-spike.png&#34; /&gt;&lt;/p&gt;&#xA;&lt;p&gt;&#xA;Recently my team and I observed in our PostgreSQL databases a sporadic increase&#xA;in the execution time of stored procedures (see the graph above). Often it&#xA;happened that an &lt;code&gt;analyze&lt;/code&gt; of the referenced table solved the issue. In our case,&#xA;fluctuations in our execution plan caused statement timeouts. This led to errors&#xA;in our applications.&lt;/p&gt;&#xA;&lt;p&gt;&#xA;We wanted to understand this behavior better. Which circumstances prompted more&#xA;frequent plan fluctuations? How exactly could we influence the system to be more&#xA;reliable? To find answers, we tested how different configurations of PostgreSQL&#xA;influenced the results of the query planner. This post shares the results of our&#xA;tests.&lt;/p&gt;</description>
			</item>
			<item>
				<title>PostgreSQL Background Writer Statistics</title>
				<link>https://biosoft.de/posts/background/</link>
				<pubDate>Tue, 07 Oct 2014 10:30:00 +0100</pubDate>
				<guid>https://biosoft.de/posts/background/</guid>
				<description>&lt;p&gt;The &lt;a href=&#34;http://www.postgresql.org/docs/9.3/static/monitoring-stats.html&#34;&gt;&lt;code&gt;pg_stat_bgwriter&lt;/code&gt;&#xA;view&lt;/a&gt;&#xA;provides some interesting information about the background writer. This&#xA;view provides only one row. If you want to analyze these data, these&#xA;results has to be stored somewhere with a timestamp. The following shall&#xA;show that it allows  an insight into the changes performed in shared&#xA;buffer cache and also hints for tuning several server parameters.&lt;/p&gt;&#xA;&lt;p&gt;If a backend process (a client) requests data it is either found in a&#xA;block in shared buffer cache or the block has to be allocated (read from&#xA;disk). The latter is counted in &lt;code&gt;buffers_alloc&lt;/code&gt; column. The usage count&#xA;of this block is increased. The backend process modifies data in this&#xA;requested page, so this page becomes dirty. With the commit the&#xA;transaction is written to WAL file. At some moment the background writer&#xA;will synchronize the dirty page with the disk and mark this page as&#xA;clean.&lt;/p&gt;</description>
			</item>
			<item>
				<title>Umbennen von Postgres Typen</title>
				<link>https://biosoft.de/posts/rename-postres-type/</link>
				<pubDate>Thu, 08 Nov 2012 16:49:57 +0000</pubDate>
				<guid>https://biosoft.de/posts/rename-postres-type/</guid>
				<description>&lt;p&gt;In PL/pgSQL, eine der Programmiersprachen für die serverseitige Programmierung&#xA;in &lt;a href=&#34;http://www.postgresql.org/&#34;&gt;PostgreSQL&lt;/a&gt;, werden das Interface der Prozedur&#xA;und Body unterschiedlich behandelt.  Der Body wird beim ersten Aufruf in einer&#xA;Session kompiliert, für SQL werden Prepared Statements und ggfs. auch&#xA;Ausführungspläne erstellt und diese im Cache bis zum Ende der Session&#xA;gespeichert.  Innerhalb eines Bedingungsbaums werden so nur die Statements&#xA;vorbereitet, die auch benötigt werden (&lt;a href=&#34;http://www.postgresql.org/docs/current/interactive/plpgsql-implementation.html&#34;&gt;siehe&#xA;Dokumentation&lt;/a&gt;).&lt;/p&gt;&#xA;&lt;p&gt;Typen können in PostgreSQL erstellt und als Parameter oder Variablen&#xA;referenziert werden.  Typen in Parameterdeklarationen werden beim Erstellen der&#xA;Funktion in die OID aufgelöst, Typen in Variablen Deklarationen zu Beginn der&#xA;Session, wenn der Body compiliert wird.&lt;/p&gt;</description>
			</item>
			<item>
				<title>NULL Werte in Order By Klausel</title>
				<link>https://biosoft.de/posts/null-werte-order-by/</link>
				<pubDate>Thu, 21 Jul 2011 16:21:00 +0000</pubDate>
				<guid>https://biosoft.de/posts/null-werte-order-by/</guid>
				<description>&lt;p&gt;Man möchte in einer nach einer Spalte sortieren die &lt;a href=&#34;http://de.wikipedia.org/wiki/Nullwert&#34;&gt;Null&#xA;Werte&lt;/a&gt; enthält.  Aber man braucht ein&#xA;sicheres Verhalten dafür, ob die &lt;code&gt;NULL&lt;/code&gt; Werte am Beginn oder am Ende eingefügt&#xA;werden.  Wie kann man das &lt;em&gt;standard konform&lt;/em&gt; und &lt;em&gt;backend unabhängig&lt;/em&gt; realisieren?&lt;/p&gt;&#xA;&lt;p&gt;Am einfachsten wäre es, wenn es ein zugesichertes Verhalten gibt.  Leider gibt&#xA;es das nicht.  Der Standard gibt nur vor, dass alle Nullmarken gleich behandelt&#xA;werden.  Der ISO Standard SQL/92 sagt dazu (Zitat C.Date, H.Darwin (1998) &lt;a href=&#34;http://www.amazon.de/SQL-Standard-mit-den-Erweiterungen/dp/3827313457&#34;&gt;SQL - Der Standard&lt;/a&gt;. Seite 278):&lt;/p&gt;</description>
			</item>
	</channel>
</rss>
