{"id":16367,"date":"2021-05-20T09:59:46","date_gmt":"2021-05-20T07:59:46","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/"},"modified":"2021-05-20T09:59:46","modified_gmt":"2021-05-20T07:59:46","slug":"why-is-the-default-postgres-database-slightly-larger-than-template1","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/","title":{"rendered":"Why is the default postgres database slightly larger than template1?"},"content":{"rendered":"<p>You probably know that a fresh initialized PostgreSQL cluster comes with three databases by default: template0, template1, and postgres. If you want to know why they are there, and what their purpose is, <a href=\"https:\/\/www.dbi-services.com\/blog\/what-the-hell-are-these-template0-and-template1-databases-in-postgresql\/\" target=\"_blank\" rel=\"noopener\">check this post<\/a>. In this post we&#8217;ll look at something you may never have noticed: Why is the postgres database, even after a fresh <a href=\"https:\/\/www.postgresql.org\/docs\/current\/app-initdb.html\" target=\"_blank\" rel=\"noopener\">initdb<\/a>, slightly larger than template1 and template0?<\/p>\n<p><!--more--><\/p>\n<p>Let&#8217;s start from scratch and initialize a new cluster:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1; highlight: [1]\">\npostgres@debian10pg:\/home\/postgres\/ [pg14] initdb -D \/var\/tmp\/dummy\nThe files belonging to this database system will be owned by user \"postgres\".\nThis user must also own the server process.\n\nThe database cluster will be initialized with locale \"en_US.UTF-8\".\nThe default database encoding has accordingly been set to \"UTF8\".\nThe default text search configuration will be set to \"english\".\n\nData page checksums are disabled.\n\ncreating directory \/var\/tmp\/dummy ... ok\ncreating subdirectories ... ok\nselecting dynamic shared memory implementation ... posix\nselecting default max_connections ... 100\nselecting default shared_buffers ... 128MB\nselecting default time zone ... Europe\/Zurich\ncreating configuration files ... ok\nrunning bootstrap script ... ok\nperforming post-bootstrap initialization ... ok\nsyncing data to disk ... ok\n\ninitdb: warning: enabling \"trust\" authentication for local connections\nYou can change this by editing pg_hba.conf or using the option -A, or\n--auth-local and --auth-host, the next time you run initdb.\n\nSuccess. You can now start the database server using:\n\n    pg_ctl -D \/var\/tmp\/dummy -l logfile start\n<\/pre>\n<p>Once we start start that up and ask for the size of the databases, you&#8217;ll notice the difference:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1; highlight: [1,2,12]\">\npostgres@debian10pg:\/home\/postgres\/ [pg14] export PGPORT=8888\npostgres@debian10pg:\/home\/postgres\/ [pg14] pg_ctl -D \/var\/tmp\/dummy start\nwaiting for server to start....2021-05-20 11:04:49.527 CEST [2708] LOG:  starting PostgreSQL 14devel on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit\n2021-05-20 11:04:49.528 CEST [2708] LOG:  listening on IPv6 address \"::1\", port 8888\n2021-05-20 11:04:49.528 CEST [2708] LOG:  listening on IPv4 address \"127.0.0.1\", port 8888\n2021-05-20 11:04:49.541 CEST [2708] LOG:  listening on Unix socket \"\/tmp\/.s.PGSQL.8888\"\n2021-05-20 11:04:49.557 CEST [2709] LOG:  database system was shut down at 2021-05-20 11:03:23 CEST\n2021-05-20 11:04:49.566 CEST [2708] LOG:  database system is ready to accept connections\n done\nserver started\n\npostgres@debian10pg:\/home\/postgres\/ [pg14] psql -c \"l+\"\n                                                                    List of databases\n   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   |  Size   | Tablespace |                Description                 \n-----------+----------+----------+-------------+-------------+-----------------------+---------+------------+--------------------------------------------\n postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |                       | 8265 kB | pg_default | default administrative connection database\n template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +| 8113 kB | pg_default | unmodifiable empty database\n           |          |          |             |             | postgres=CTc\/postgres |         |            | \n template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +| 8113 kB | pg_default | default template for new databases\n           |          |          |             |             | postgres=CTc\/postgres |         |            | \n(3 rows)\n<\/pre>\n<p>The results may differ in your environment, depending on what version of PostgreSQL you are using. This is 14devel, but it doesn&#8217;t really matter: You will see that the &#8220;postgres&#8221; database is a bit larger than the other two. But how can this be? The first database which is created by initdb, is template1. The other two are just copies of it. But then they should all have the same size, shouldn&#8217;t they?<\/p>\n<p>To understand what&#8217;s going on here, we first need to know how the database size is calculated, when you use the &#8220;l+&#8221; shortcut. This is easy to check:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1; highlight: [1,2,11]\">\npostgres=# set ECHO_HIDDEN on\npostgres=# l+\n********* QUERY **********\nSELECT d.datname as \"Name\",\n       pg_catalog.pg_get_userbyid(d.datdba) as \"Owner\",\n       pg_catalog.pg_encoding_to_char(d.encoding) as \"Encoding\",\n       d.datcollate as \"Collate\",\n       d.datctype as \"Ctype\",\n       pg_catalog.array_to_string(d.datacl, E'n') AS \"Access privileges\",\n       CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n            THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n            ELSE 'No Access'\n       END as \"Size\",\n       t.spcname as \"Tablespace\",\n       pg_catalog.shobj_description(d.oid, 'pg_database') as \"Description\"\nFROM pg_catalog.pg_database d\n  JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\nORDER BY 1;\n**************************\n\n                                                                    List of databases\n   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   |  Size   | Tablespace |                Description                 \n-----------+----------+----------+-------------+-------------+-----------------------+---------+------------+--------------------------------------------\n postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |                       | 8265 kB | pg_default | default administrative connection database\n template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +| 8113 kB | pg_default | unmodifiable empty database\n           |          |          |             |             | postgres=CTc\/postgres |         |            | \n template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +| 8113 kB | pg_default | default template for new databases\n           |          |          |             |             | postgres=CTc\/postgres |         |            | \n(3 rows)\n<\/pre>\n<p>The statement that is used in the background uses the <a href=\"https:\/\/www.postgresql.org\/docs\/current\/functions-admin.html\" target=\"_blank\" rel=\"noopener\">pg_database_size<\/a> administrative function to calculate the size for each database. But what is pg_database_size actually doing? Time to check the source. pg_database_size is defined in &#8220;src\/backend\/utils\/adt\/dbsize.c&#8221;:<\/p>\n<pre class=\"brush: c; gutter: true; first-line: 1\">\nDatum\npg_database_size_oid(PG_FUNCTION_ARGS)\n{\n        Oid                     dbOid = PG_GETARG_OID(0);\n        int64           size;\n\n        size = calculate_database_size(dbOid);\n\n        if (size == 0)\n                PG_RETURN_NULL();\n\n        PG_RETURN_INT64(size);\n}\n<\/pre>\n<p>This in fact calls &#8220;calculate_database_size&#8221;, which is defined in the same file. If you check this one you&#8217;ll see this:<\/p>\n<pre class=\"brush: c; gutter: true; first-line: 1\">\n...\n        \/* Shared storage in pg_global is not counted *\/\n\n        \/* Include pg_default storage *\/\n        snprintf(pathname, sizeof(pathname), \"base\/%u\", dbOid);\n        totalsize = db_dir_size(pathname);\n\n        \/* Scan the non-default tablespaces *\/\n        snprintf(dirpath, MAXPGPATH, \"pg_tblspc\");\n        dirdesc = AllocateDir(dirpath);\n...\n<\/pre>\n<p>All it does is to calculate the size of the directory in db_dir_size (and any tablespaces if there are any):<\/p>\n<pre class=\"brush: c; gutter: true; first-line: 1\">\n\/* Return physical size of directory contents, or 0 if dir doesn't exist *\/\nstatic int64\ndb_dir_size(const char *path)\n...\n        while ((direntry = ReadDir(dirdesc, path)) != NULL)\n        {\n<\/pre>\n<p>It is looping over all the files and then sums up the size of the files it finds there. Nothing is excluded as you can easily verify:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1; highlight: [1,2,9,10,15,26]\">\npostgres@debian10pg:\/home\/postgres\/ [pg14] cd \/var\/tmp\/dummy\/base\/\npostgres@debian10pg:\/var\/tmp\/dummy\/base\/ [pg14] oid2name \nAll databases:\n    Oid  Database Name  Tablespace\n----------------------------------\n  13974       postgres  pg_default\n  13973      template0  pg_default\n      1      template1  pg_default\npostgres@debian10pg:\/var\/tmp\/dummy\/base\/ [pg14] cd 13974\npostgres@debian10pg:\/var\/tmp\/dummy\/base\/13974\/ [pg14] dd if=\/dev\/zero of=dummy bs=1M count=100\n100+0 records in\n100+0 records out\n104857600 bytes (105 MB, 100 MiB) copied, 0.0924525 s, 1.1 GB\/s\n\npostgres@debian10pg:\/var\/tmp\/dummy\/base\/13974\/ [pg14] psql -c \"l+\"\n                                                                    List of databases\n   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   |  Size   | Tablespace |                Description                 \n-----------+----------+----------+-------------+-------------+-----------------------+---------+------------+--------------------------------------------\n postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |                       | 108 MB  | pg_default | default administrative connection database\n template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +| 8113 kB | pg_default | unmodifiable empty database\n           |          |          |             |             | postgres=CTc\/postgres |         |            | \n template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +| 8113 kB | pg_default | default template for new databases\n           |          |          |             |             | postgres=CTc\/postgres |         |            | \n(3 rows)\n\npostgres@debian10pg:\/var\/tmp\/dummy\/base\/13974\/ [pg14] rm dummy \n<\/pre>\n<p>All I did here, is to create a file a bit larger than 100MB in the directory of the &#8220;postgres&#8221; database, and asked for the database size once more. As you can see above, the size of this file is counted.<\/p>\n<p>What information can we get out of this? The difference between the &#8220;postgres&#8221; and the &#8220;template0&#8221; and &#8220;template1&#8221; databases must come from the files on disk. Let&#8217;s look at the directories:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\npostgres@debian10pg:\/home\/postgres\/ [pg14] du -s \/var\/tmp\/dummy\/base\/13974\/\n8280    \/var\/tmp\/dummy\/base\/13974\/   ## postgres\npostgres@debian10pg:\/home\/postgres\/ [pg14] du -s \/var\/tmp\/dummy\/base\/1\/\n8124    \/var\/tmp\/dummy\/base\/1\/       ## template1\n<\/pre>\n<p>Same picture here: &#8220;postgres&#8221; is larger than &#8220;template1&#8221; but what is the difference. Actually the difference can easily be spotted:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1; highlight: [4]\">\npostgres@debian10pg:\/home\/postgres\/ [pg14] ls -ltr \/var\/tmp\/dummy\/base\/13974\/ | tail -3    # postgres\n-rw------- 1 postgres postgres   8192 May 20 11:03 1247_vm\n-rw------- 1 postgres postgres 114688 May 20 11:03 1247\n-rw------- 1 postgres postgres 156486 May 20 11:06 pg_internal.init\npostgres@debian10pg:\/home\/postgres\/ [pg14] ls -ltr \/var\/tmp\/dummy\/base\/1\/ | tail -3        # template1\n-rw------- 1 postgres postgres  24576 May 20 11:03 13792_fsm\n-rw------- 1 postgres postgres  65536 May 20 11:03 13792\n-rw------- 1 postgres postgres 106496 May 20 11:03 1259\n<\/pre>\n<p>To verify that this file really is the reason: Stop the instance, delete the file and compare again:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1; highlight: [6,8]\">\npostgres@debian10pg:\/home\/postgres\/ [pg14] pg_ctl -D \/var\/tmp\/dummy\/ stop\nwaiting for server to shut down.... done\nserver stopped\npostgres@debian10pg:\/home\/postgres\/ [pg14] rm \/var\/tmp\/dummy\/base\/13974\/pg_internal.init\npostgres@debian10pg:\/home\/postgres\/ [pg14] du -s \/var\/tmp\/dummy\/base\/13974\/\n8124    \/var\/tmp\/dummy\/base\/13974\/\npostgres@debian10pg:\/home\/postgres\/ [pg14] du -s \/var\/tmp\/dummy\/base\/1\/\n8124    \/var\/tmp\/dummy\/base\/1\/\n<\/pre>\n<p>Exactly the same now. Once you start the instance again, the file will be re-created:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1; highlight: [1,2,6,17,20]\">\npostgres@debian10pg:\/home\/postgres\/ [pg14] pg_ctl -D \/var\/tmp\/dummy\/ start\npostgres@debian10pg:\/home\/postgres\/ [pg14] ls -ltr \/var\/tmp\/dummy\/base\/13974\/ | tail -3\n-rw------- 1 postgres postgres 770048 May 20 11:03 1255\n-rw------- 1 postgres postgres   8192 May 20 11:03 1247_vm\n-rw------- 1 postgres postgres 114688 May 20 11:03 1247\npostgres@debian10pg:\/home\/postgres\/ [pg14] psql -c \"l+\"\n                                                                    List of databases\n   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   |  Size   | Tablespace |                Description                 \n-----------+----------+----------+-------------+-------------+-----------------------+---------+------------+--------------------------------------------\n postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |                       | 8265 kB | pg_default | default administrative connection database\n template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +| 8113 kB | pg_default | unmodifiable empty database\n           |          |          |             |             | postgres=CTc\/postgres |         |            | \n template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +| 8113 kB | pg_default | default template for new databases\n           |          |          |             |             | postgres=CTc\/postgres |         |            | \n(3 rows)\n\npostgres@debian10pg:\/home\/postgres\/ [pg14] ls -ltr \/var\/tmp\/dummy\/base\/13974\/ | tail -3\n-rw------- 1 postgres postgres   8192 May 20 11:03 1247_vm\n-rw------- 1 postgres postgres 114688 May 20 11:03 1247\n-rw------- 1 postgres postgres 156486 May 20 11:45 pg_internal.init\n<\/pre>\n<p>Last question for today: What is that file for? The answer is, once more, in the source code (src\/include\/utils\/relcache.h):<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\n\/*\n * Name of relcache init file(s), used to speed up backend startup\n *\/\n#define RELCACHE_INIT_FILENAME  \"pg_internal.init\"\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You probably know that a fresh initialized PostgreSQL cluster comes with three databases by default: template0, template1, and postgres. If you want to know why they are there, and what their purpose is, check this post. In this post we&#8217;ll look at something you may never have noticed: Why is the postgres database, even after [&hellip;]<\/p>\n","protected":false},"author":29,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229],"tags":[77],"type_dbi":[],"class_list":["post-16367","post","type-post","status-publish","format-standard","hentry","category-database-administration-monitoring","tag-postgresql"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Why is the default postgres database slightly larger than template1? - dbi Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Why is the default postgres database slightly larger than template1?\" \/>\n<meta property=\"og:description\" content=\"You probably know that a fresh initialized PostgreSQL cluster comes with three databases by default: template0, template1, and postgres. If you want to know why they are there, and what their purpose is, check this post. In this post we&#8217;ll look at something you may never have noticed: Why is the postgres database, even after [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-05-20T07:59:46+00:00\" \/>\n<meta name=\"author\" content=\"Daniel Westermann\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@westermanndanie\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Daniel Westermann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/\"},\"author\":{\"name\":\"Daniel Westermann\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66\"},\"headline\":\"Why is the default postgres database slightly larger than template1?\",\"datePublished\":\"2021-05-20T07:59:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/\"},\"wordCount\":476,\"commentCount\":0,\"keywords\":[\"PostgreSQL\"],\"articleSection\":[\"Database Administration &amp; Monitoring\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/\",\"name\":\"Why is the default postgres database slightly larger than template1? - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2021-05-20T07:59:46+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Why is the default postgres database slightly larger than template1?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66\",\"name\":\"Daniel Westermann\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g\",\"caption\":\"Daniel Westermann\"},\"description\":\"Daniel Westermann is Principal Consultant and Technology Leader Open Infrastructure at dbi services. He has more than 15 years of experience in management, engineering and optimization of databases and infrastructures, especially on Oracle and PostgreSQL. Since the beginning of his career, he has specialized in Oracle Technologies and is Oracle Certified Professional 12c and Oracle Certified Expert RAC\/GridInfra. Over time, Daniel has become increasingly interested in open source technologies, becoming \u201cTechnology Leader Open Infrastructure\u201d and PostgreSQL expert. \u00a0Based on community or EnterpriseDB tools, he develops and installs complex high available solutions with PostgreSQL. He is also a certified PostgreSQL Plus 9.0 Professional and a Postgres Advanced Server 9.4 Professional. He is a regular speaker at PostgreSQL conferences in Switzerland and Europe. Today Daniel is also supporting our customers on AWS services such as AWS RDS, database migrations into the cloud, EC2 and automated infrastructure management with AWS SSM (System Manager). He is a certified AWS Solutions Architect Professional. Prior to dbi services, Daniel was Management System Engineer at LC SYSTEMS-Engineering AG in Basel. Before that, he worked as Oracle Developper &amp;\u00a0Project Manager at Delta Energy Solutions AG in Basel (today Powel AG). Daniel holds a diploma in Business Informatics (DHBW, Germany). His branch-related experience mainly covers the pharma industry, the financial sector, energy, lottery and telecommunications.\",\"sameAs\":[\"https:\/\/x.com\/westermanndanie\"],\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/daniel-westermann\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Why is the default postgres database slightly larger than template1? - dbi Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/","og_locale":"en_US","og_type":"article","og_title":"Why is the default postgres database slightly larger than template1?","og_description":"You probably know that a fresh initialized PostgreSQL cluster comes with three databases by default: template0, template1, and postgres. If you want to know why they are there, and what their purpose is, check this post. In this post we&#8217;ll look at something you may never have noticed: Why is the postgres database, even after [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/","og_site_name":"dbi Blog","article_published_time":"2021-05-20T07:59:46+00:00","author":"Daniel Westermann","twitter_card":"summary_large_image","twitter_creator":"@westermanndanie","twitter_misc":{"Written by":"Daniel Westermann","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/"},"author":{"name":"Daniel Westermann","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66"},"headline":"Why is the default postgres database slightly larger than template1?","datePublished":"2021-05-20T07:59:46+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/"},"wordCount":476,"commentCount":0,"keywords":["PostgreSQL"],"articleSection":["Database Administration &amp; Monitoring"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/","url":"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/","name":"Why is the default postgres database slightly larger than template1? - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2021-05-20T07:59:46+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/why-is-the-default-postgres-database-slightly-larger-than-template1\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Why is the default postgres database slightly larger than template1?"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66","name":"Daniel Westermann","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g","caption":"Daniel Westermann"},"description":"Daniel Westermann is Principal Consultant and Technology Leader Open Infrastructure at dbi services. He has more than 15 years of experience in management, engineering and optimization of databases and infrastructures, especially on Oracle and PostgreSQL. Since the beginning of his career, he has specialized in Oracle Technologies and is Oracle Certified Professional 12c and Oracle Certified Expert RAC\/GridInfra. Over time, Daniel has become increasingly interested in open source technologies, becoming \u201cTechnology Leader Open Infrastructure\u201d and PostgreSQL expert. \u00a0Based on community or EnterpriseDB tools, he develops and installs complex high available solutions with PostgreSQL. He is also a certified PostgreSQL Plus 9.0 Professional and a Postgres Advanced Server 9.4 Professional. He is a regular speaker at PostgreSQL conferences in Switzerland and Europe. Today Daniel is also supporting our customers on AWS services such as AWS RDS, database migrations into the cloud, EC2 and automated infrastructure management with AWS SSM (System Manager). He is a certified AWS Solutions Architect Professional. Prior to dbi services, Daniel was Management System Engineer at LC SYSTEMS-Engineering AG in Basel. Before that, he worked as Oracle Developper &amp;\u00a0Project Manager at Delta Energy Solutions AG in Basel (today Powel AG). Daniel holds a diploma in Business Informatics (DHBW, Germany). His branch-related experience mainly covers the pharma industry, the financial sector, energy, lottery and telecommunications.","sameAs":["https:\/\/x.com\/westermanndanie"],"url":"https:\/\/www.dbi-services.com\/blog\/author\/daniel-westermann\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/16367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=16367"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/16367\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=16367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=16367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=16367"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=16367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}