From: Tom Lane Date: Tue, 21 Jun 2005 04:02:34 +0000 (+0000) Subject: Cause initdb to create a third standard database "postgres", which X-Git-Tag: REL8_1_0BETA1~500 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6f7fc0badef55b376f408bd318a8065fd2edf266;p=postgresql Cause initdb to create a third standard database "postgres", which unlike template0 and template1 does not have any special status in terms of backend functionality. However, all external utilities such as createuser and createdb now connect to "postgres" instead of template1, and the documentation is changed to encourage people to use "postgres" instead of template1 as a play area. This should fix some longstanding gotchas involving unexpected propagation of database objects by createdb (when you used template1 without understanding the implications), as well as ameliorating the problem that CREATE DATABASE is unhappy if anyone else is connected to template1. Patch by Dave Page, minor editing by Tom Lane. All per recent pghackers discussions. --- diff --git a/contrib/dblink/doc/connection b/contrib/dblink/doc/connection index 251bd93961..c3ce776fbc 100644 --- a/contrib/dblink/doc/connection +++ b/contrib/dblink/doc/connection @@ -28,13 +28,13 @@ Outputs Example usage -select dblink_connect('dbname=template1'); +select dblink_connect('dbname=postgres'); dblink_connect ---------------- OK (1 row) -select dblink_connect('myconn','dbname=template1'); +select dblink_connect('myconn','dbname=postgres'); dblink_connect ---------------- OK diff --git a/contrib/dblink/doc/cursor b/contrib/dblink/doc/cursor index 23a3ce89ba..b989fcb69c 100644 --- a/contrib/dblink/doc/cursor +++ b/contrib/dblink/doc/cursor @@ -44,7 +44,7 @@ Note Example usage -test=# select dblink_connect('dbname=template1'); +test=# select dblink_connect('dbname=postgres'); dblink_connect ---------------- OK @@ -94,7 +94,7 @@ Outputs Example usage -test=# select dblink_connect('dbname=template1'); +test=# select dblink_connect('dbname=postgres'); dblink_connect ---------------- OK @@ -175,7 +175,7 @@ Note Example usage -test=# select dblink_connect('dbname=template1'); +test=# select dblink_connect('dbname=postgres'); dblink_connect ---------------- OK diff --git a/contrib/dblink/doc/misc b/contrib/dblink/doc/misc index 21d241d61b..596c9ecdcf 100644 --- a/contrib/dblink/doc/misc +++ b/contrib/dblink/doc/misc @@ -17,10 +17,10 @@ Outputs Example usage -test=# select dblink_current_query() from (select dblink('dbname=template1','select oid, proname from pg_proc where proname = ''byteacat''') as f1) as t1; +test=# select dblink_current_query() from (select dblink('dbname=postgres','select oid, proname from pg_proc where proname = ''byteacat''') as f1) as t1; dblink_current_query ----------------------------------------------------------------------------------------------------------------------------------------------------- - select dblink_current_query() from (select dblink('dbname=template1','select oid, proname from pg_proc where proname = ''byteacat''') as f1) as t1; + select dblink_current_query() from (select dblink('dbname=postgres','select oid, proname from pg_proc where proname = ''byteacat''') as f1) as t1; (1 row) ================================================================== diff --git a/contrib/dblink/doc/query b/contrib/dblink/doc/query index d232f80dbd..cd58a36142 100644 --- a/contrib/dblink/doc/query +++ b/contrib/dblink/doc/query @@ -37,7 +37,7 @@ Outputs Example usage -select * from dblink('dbname=template1','select proname, prosrc from pg_proc') +select * from dblink('dbname=postgres','select proname, prosrc from pg_proc') as t1(proname name, prosrc text) where proname like 'bytea%'; proname | prosrc ------------+------------ @@ -55,7 +55,7 @@ select * from dblink('dbname=template1','select proname, prosrc from pg_proc') byteaout | byteaout (12 rows) -select dblink_connect('dbname=template1'); +select dblink_connect('dbname=postgres'); dblink_connect ---------------- OK @@ -111,7 +111,7 @@ A more convenient way to use dblink may be to create a view: create view myremote_pg_proc as select * - from dblink('dbname=template1','select proname, prosrc from pg_proc') + from dblink('dbname=postgres','select proname, prosrc from pg_proc') as t1(proname name, prosrc text); Then you can simply write: diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c index 5fd1140f9a..9bea98b507 100644 --- a/contrib/oid2name/oid2name.c +++ b/contrib/oid2name/oid2name.c @@ -518,7 +518,7 @@ main(int argc, char **argv) if (my_opts->dbname == NULL) { - my_opts->dbname = "template1"; + my_opts->dbname = "postgres"; my_opts->nodb = true; } pgconn = sql_conn(my_opts); diff --git a/contrib/reindexdb/reindexdb b/contrib/reindexdb/reindexdb index 7db6a26622..cfe933126b 100644 --- a/contrib/reindexdb/reindexdb +++ b/contrib/reindexdb/reindexdb @@ -1,6 +1,6 @@ #!/bin/sh # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # -# Package : reindexdb Version : $Revision: 1.5 $ +# Package : reindexdb Version : $Revision: 1.6 $ # Date : 05/08/2002 Author : Shaun Thomas # Req : psql, sh, perl, sed Type : Utility # @@ -174,7 +174,7 @@ if [ "$alldb" ]; then # connect to. That's the list we'll be using. It's also why it's # a good idea for this to be run as a super-user. sql='SELECT datname FROM pg_database WHERE datallowconn' - dbname=`$PSQL $PSQLOPT -q -t -A -d template1 -c "$sql"` + dbname=`$PSQL $PSQLOPT -q -t -A -d postgres -c "$sql"` # Ok, if it's not all databases, make sure at least one database is # specified before continuing. diff --git a/contrib/seg/README.seg b/contrib/seg/README.seg index f899b9394d..e738f180e8 100644 --- a/contrib/seg/README.seg +++ b/contrib/seg/README.seg @@ -159,7 +159,7 @@ Any number (rules 5,6) -- creates a zero-length segment (a point, boundaries. For example, it adds an extra digit to the lower boundary if the resulting interval includes a power of ten: - template1=> select '10(+-)1'::seg as seg; + postgres=> select '10(+-)1'::seg as seg; seg --------- 9.0 .. 11 -- should be: 9 .. 11 diff --git a/doc/src/sgml/backup.sgml b/doc/src/sgml/backup.sgml index e4a0d4cb15..cf8244679e 100644 --- a/doc/src/sgml/backup.sgml +++ b/doc/src/sgml/backup.sgml @@ -1,5 +1,5 @@ Backup and Restore @@ -177,11 +177,11 @@ pg_dumpall > outfile The resulting dump can be restored with psql: -psql -f infile template1 +psql -f infile postgres (Actually, you can specify any existing database name to start from, - but if you are reloading in an empty cluster then template1 - is the only available choice.) It is always necessary to have + but if you are reloading in an empty cluster then postgres + should generally be used.) It is always necessary to have database superuser access when restoring a pg_dumpall dump, as that is required to restore the user and group information. @@ -1223,7 +1223,7 @@ restore_command = 'copy /mnt/server/archivedir/%f "%p"' # Windows in parallel, on different ports. Then you can use something like -pg_dumpall -p 5432 | psql -d template1 -p 6543 +pg_dumpall -p 5432 | psql -d postgres -p 6543 to transfer your data. Or use an intermediate file if you want. @@ -1256,7 +1256,7 @@ cd ~/postgresql-&version; gmake install initdb -D /usr/local/pgsql/data postmaster -D /usr/local/pgsql/data -psql -f backup template1 +psql -f backup postgres See about ways to start and stop the diff --git a/doc/src/sgml/charset.sgml b/doc/src/sgml/charset.sgml index 4f8e5c3e86..3383fff14a 100644 --- a/doc/src/sgml/charset.sgml +++ b/doc/src/sgml/charset.sgml @@ -1,4 +1,4 @@ - + Localization</> @@ -647,6 +647,7 @@ $ <userinput>psql -l</userinput> euc_kr | t-ishii | EUC_KR euc_tw | t-ishii | EUC_TW mule_internal | t-ishii | MULE_INTERNAL + postgres | t-ishii | EUC_JP regression | t-ishii | SQL_ASCII template1 | t-ishii | EUC_JP test | t-ishii | EUC_JP diff --git a/doc/src/sgml/client-auth.sgml b/doc/src/sgml/client-auth.sgml index 8439174b02..83611d25ff 100644 --- a/doc/src/sgml/client-auth.sgml +++ b/doc/src/sgml/client-auth.sgml @@ -1,5 +1,5 @@ <!-- -$PostgreSQL: pgsql/doc/src/sgml/client-auth.sgml,v 1.80 2005/06/04 20:42:41 momjian Exp $ +$PostgreSQL: pgsql/doc/src/sgml/client-auth.sgml,v 1.81 2005/06/21 04:02:29 tgl Exp $ --> <chapter id="client-authentication"> @@ -452,17 +452,17 @@ host all all 127.0.0.1/32 trust host all all 127.0.0.1 255.255.255.255 trust # Allow any user from any host with IP address 192.168.93.x to connect -# to database "template1" as the same user name that ident reports for +# to database "postgres" as the same user name that ident reports for # the connection (typically the Unix user name). # # TYPE DATABASE USER CIDR-ADDRESS METHOD -host template1 all 192.168.93.0/24 ident sameuser +host postgres all 192.168.93.0/24 ident sameuser # Allow a user from host 192.168.12.10 to connect to database -# "template1" if the user's password is correctly supplied. +# "postgres" if the user's password is correctly supplied. # # TYPE DATABASE USER CIDR-ADDRESS METHOD -host template1 all 192.168.12.10/32 md5 +host postgres all 192.168.12.10/32 md5 # In the absence of preceding "host" lines, these two lines will # reject all connection from 192.168.54.1 (since that entry will be diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml index 85ae00e8de..b605ea23dd 100644 --- a/doc/src/sgml/installation.sgml +++ b/doc/src/sgml/installation.sgml @@ -1,4 +1,4 @@ -<!-- $PostgreSQL: pgsql/doc/src/sgml/installation.sgml,v 1.235 2005/06/12 15:51:50 tgl Exp $ --> +<!-- $PostgreSQL: pgsql/doc/src/sgml/installation.sgml,v 1.236 2005/06/21 04:02:29 tgl Exp $ --> <chapter id="installation"> <title><![%standalone-include[<productname>PostgreSQL</>]]> @@ -468,7 +468,7 @@ su - postgres </programlisting> Finally, restore your data with <screen> -<userinput>/usr/local/pgsql/bin/psql -d template1 -f <replaceable>outputfile</></userinput> +<userinput>/usr/local/pgsql/bin/psql -d postgres -f <replaceable>outputfile</></userinput> </screen> using the <emphasis>new</> <application>psql</>. </para> diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index fe15c2b1bb..9c1b94e2be 100644 --- a/doc/src/sgml/libpq.sgml +++ b/doc/src/sgml/libpq.sgml @@ -1,5 +1,5 @@ <!-- -$PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.185 2005/06/12 00:00:20 neilc Exp $ +$PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.186 2005/06/21 04:02:29 tgl Exp $ --> <chapter id="libpq"> @@ -4230,14 +4230,14 @@ main(int argc, char **argv) /* * If the user supplies a parameter on the command line, use it as - * the conninfo string; otherwise default to setting dbname=template1 + * the conninfo string; otherwise default to setting dbname=postgres * and using environment variables or defaults for all other connection * parameters. */ if (argc > 1) conninfo = argv[1]; else - conninfo = "dbname = template1"; + conninfo = "dbname = postgres"; /* Make a connection to the database */ conn = PQconnectdb(conninfo); @@ -4376,14 +4376,14 @@ main(int argc, char **argv) /* * If the user supplies a parameter on the command line, use it as - * the conninfo string; otherwise default to setting dbname=template1 + * the conninfo string; otherwise default to setting dbname=postgres * and using environment variables or defaults for all other connection * parameters. */ if (argc > 1) conninfo = argv[1]; else - conninfo = "dbname = template1"; + conninfo = "dbname = postgres"; /* Make a connection to the database */ conn = PQconnectdb(conninfo); @@ -4518,14 +4518,14 @@ main(int argc, char **argv) /* * If the user supplies a parameter on the command line, use it as - * the conninfo string; otherwise default to setting dbname=template1 + * the conninfo string; otherwise default to setting dbname=postgres * and using environment variables or defaults for all other connection * parameters. */ if (argc > 1) conninfo = argv[1]; else - conninfo = "dbname = template1"; + conninfo = "dbname = postgres"; /* Make a connection to the database */ conn = PQconnectdb(conninfo); diff --git a/doc/src/sgml/manage-ag.sgml b/doc/src/sgml/manage-ag.sgml index e95839f050..0ac156cb44 100644 --- a/doc/src/sgml/manage-ag.sgml +++ b/doc/src/sgml/manage-ag.sgml @@ -1,5 +1,5 @@ <!-- -$PostgreSQL: pgsql/doc/src/sgml/manage-ag.sgml,v 2.41 2005/06/13 02:40:04 neilc Exp $ +$PostgreSQL: pgsql/doc/src/sgml/manage-ag.sgml,v 2.42 2005/06/21 04:02:30 tgl Exp $ --> <chapter id="managing-databases"> @@ -113,17 +113,20 @@ CREATE DATABASE <replaceable>name</>; <command>initdb</> command when the data storage area is initialized. (See <xref linkend="creating-cluster">.) This database is called - <literal>template1</>.<indexterm><primary>template1</></> So to - create the first <quote>real</> database you can connect to - <literal>template1</>. + <literal>postgres</>.<indexterm><primary>postgres</></> So to + create the first <quote>ordinary</> database you can connect to + <literal>postgres</>. </para> <para> - The name <literal>template1</literal> is no accident: when a new - database is created, the template database is essentially cloned. + A second database, + <literal>template1</literal>,<indexterm><primary>template1</></> + is also created by + <command>initdb</>. Whenever a new database is created within the + cluster, <literal>template1</literal> is essentially cloned. This means that any changes you make in <literal>template1</> are - propagated to all subsequently created databases. This implies that - you should not use the template database for real work, but when + propagated to all subsequently created databases. Therefore it is + unwise to use <literal>template1</> for real work, but when used judiciously this feature can be convenient. More details appear in <xref linkend="manage-ag-templatedbs">. </para> @@ -137,7 +140,7 @@ CREATE DATABASE <replaceable>name</>; createdb <replaceable class="parameter">dbname</replaceable> </synopsis> - <command>createdb</> does no magic. It connects to the <literal>template1</> + <command>createdb</> does no magic. It connects to the <literal>postgres</> database and issues the <command>CREATE DATABASE</> command, exactly as described above. The <xref linkend="app-createdb"> reference page contains the invocation @@ -268,13 +271,19 @@ createdb -T template0 <replaceable>dbname</> <para> <literal>template1</> and <literal>template0</> do not have any special status beyond the fact that the name <literal>template1</> is the default - source database name for <command>CREATE DATABASE</> and the default - database-to-connect-to for various programs such as <command>createdb</>. + source database name for <command>CREATE DATABASE</>. For example, one could drop <literal>template1</> and recreate it from <literal>template0</> without any ill effects. This course of action might be advisable if one has carelessly added a bunch of junk in <literal>template1</>. </para> + + <para> + The <literal>postgres</> database is also created when a database + cluster is initialized. This database is meant as a default database for + users and applications to connect to. It is simply a copy of + <literal>template1</> and may be dropped and recreated if required. + </para> </note> </sect1> diff --git a/doc/src/sgml/ref/createlang.sgml b/doc/src/sgml/ref/createlang.sgml index 3b84e25041..9829d845b0 100644 --- a/doc/src/sgml/ref/createlang.sgml +++ b/doc/src/sgml/ref/createlang.sgml @@ -1,5 +1,5 @@ <!-- -$PostgreSQL: pgsql/doc/src/sgml/ref/createlang.sgml,v 1.34 2005/05/29 03:32:18 momjian Exp $ +$PostgreSQL: pgsql/doc/src/sgml/ref/createlang.sgml,v 1.35 2005/06/21 04:02:31 tgl Exp $ PostgreSQL documentation --> @@ -223,6 +223,9 @@ PostgreSQL documentation <screen> <prompt>$ </prompt><userinput>createlang pltcl template1</userinput> </screen> + Note that installing the language into <literal>template1</literal> + will cause it to be automatically installed into subsequently-created + databases as well. </para> </refsect1> diff --git a/doc/src/sgml/ref/drop_database.sgml b/doc/src/sgml/ref/drop_database.sgml index 50ab2cde82..6a51ec356f 100644 --- a/doc/src/sgml/ref/drop_database.sgml +++ b/doc/src/sgml/ref/drop_database.sgml @@ -1,5 +1,5 @@ <!-- -$PostgreSQL: pgsql/doc/src/sgml/ref/drop_database.sgml,v 1.19 2003/11/29 19:51:38 pgsql Exp $ +$PostgreSQL: pgsql/doc/src/sgml/ref/drop_database.sgml,v 1.20 2005/06/21 04:02:31 tgl Exp $ PostgreSQL documentation --> @@ -32,7 +32,7 @@ DROP DATABASE <replaceable class="PARAMETER">name</replaceable> catalog entries for the database and deletes the directory containing the data. It can only be executed by the database owner. Also, it cannot be executed while you or anyone else are connected - to the target database. (Connect to <literal>template1</literal> or any + to the target database. (Connect to <literal>postgres</literal> or any other database to issue this command.) </para> diff --git a/doc/src/sgml/ref/initdb.sgml b/doc/src/sgml/ref/initdb.sgml index 7f22b0400f..664a8d8fb5 100644 --- a/doc/src/sgml/ref/initdb.sgml +++ b/doc/src/sgml/ref/initdb.sgml @@ -1,5 +1,5 @@ <!-- -$PostgreSQL: pgsql/doc/src/sgml/ref/initdb.sgml,v 1.34 2005/02/22 02:54:19 momjian Exp $ +$PostgreSQL: pgsql/doc/src/sgml/ref/initdb.sgml,v 1.35 2005/06/21 04:02:31 tgl Exp $ PostgreSQL documentation --> @@ -47,9 +47,12 @@ PostgreSQL documentation which the database data will live, generating the shared catalog tables (tables that belong to the whole cluster rather than to any particular database), and creating the <literal>template1</literal> - database. When you later create a new database, everything in the - <literal>template1</literal> database is copied. It contains catalog - tables containing things like built-in data types. + and <literal>postgres</literal> databases. When you later create a + new database, everything in the <literal>template1</literal> database is + copied. (Therefore, anything installed in <literal>template1</literal> + is automatically copied into each database created later.) + The <literal>postgres</literal> database is a default database meant + for use by users, utilities and third party applications. </para> <para> diff --git a/doc/src/sgml/ref/pg_dumpall.sgml b/doc/src/sgml/ref/pg_dumpall.sgml index 5a15ea439a..857cb1a8a6 100644 --- a/doc/src/sgml/ref/pg_dumpall.sgml +++ b/doc/src/sgml/ref/pg_dumpall.sgml @@ -1,5 +1,5 @@ <!-- -$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.49 2005/05/29 03:32:18 momjian Exp $ +$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.50 2005/06/21 04:02:31 tgl Exp $ PostgreSQL documentation --> @@ -401,7 +401,7 @@ PostgreSQL documentation <para> To reload this database use, for example: <screen> -<prompt>$</prompt> <userinput>psql -f db.out template1</userinput> +<prompt>$</prompt> <userinput>psql -f db.out postgres</userinput> </screen> (It is not important to which database you connect here since the script file created by <application>pg_dumpall</application> will diff --git a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml index 1a2a9935cc..4333445392 100644 --- a/doc/src/sgml/runtime.sgml +++ b/doc/src/sgml/runtime.sgml @@ -1,5 +1,5 @@ <!-- -$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.329 2005/06/17 22:32:42 tgl Exp $ +$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.330 2005/06/21 04:02:30 tgl Exp $ --> <chapter Id="runtime"> @@ -54,8 +54,13 @@ $PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.329 2005/06/17 22:32:42 tgl Exp (<acronym>SQL</acronym> uses the term catalog cluster.) A database cluster is a collection of databases that is managed by a single instance of a running database server. After initialization, a - database cluster will contain a database named - <literal>template1</literal>. As the name suggests, this will be used + database cluster will contain a database named <literal>postgres</literal>, + which is meant as a default database for use by utilities, users and third + party applications. The database server itself does not require the + <literal>postgres</literal> database to exist, but many external utility + programs assume it exists. Another database created within each cluster + during initialization is called + <literal>template1</literal>. As the name suggests, this will be used as a template for subsequently created databases; it should not be used for actual work. (See <xref linkend="managing-databases"> for information about creating new databases within a cluster.) @@ -5319,7 +5324,7 @@ ssh -L 3333:foo.com:5432 joe@foo.com to connect to. In order to connect to the database server using this tunnel, you connect to port 3333 on the local machine: <programlisting> -psql -h localhost -p 3333 template1 +psql -h localhost -p 3333 postgres </programlisting> To the database server it will then look as though you are really user <literal>joe@foo.com</literal> and it will use whatever diff --git a/doc/src/sgml/start.sgml b/doc/src/sgml/start.sgml index 3ae094b37c..c2ce466fe8 100644 --- a/doc/src/sgml/start.sgml +++ b/doc/src/sgml/start.sgml @@ -1,5 +1,5 @@ <!-- -$PostgreSQL: pgsql/doc/src/sgml/start.sgml,v 1.38 2005/01/08 01:44:08 tgl Exp $ +$PostgreSQL: pgsql/doc/src/sgml/start.sgml,v 1.39 2005/06/21 04:02:30 tgl Exp $ --> <chapter id="tutorial-start"> @@ -183,7 +183,7 @@ createdb: command not found <para> Another response could be this: <screen> -createdb: could not connect to database template1: could not connect to server: +createdb: could not connect to database postgres: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"? @@ -196,7 +196,7 @@ No such file or directory <para> Another response could be this: <screen> -createdb: could not connect to database template1: FATAL: user "joe" does not +createdb: could not connect to database postgres: FATAL: user "joe" does not exist </screen> where your own login name is mentioned. This will happen if the diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 40cfb3e658..135c8a73f5 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.159 2005/06/06 20:22:57 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.160 2005/06/21 04:02:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -93,7 +93,7 @@ createdb(const CreatedbStmt *stmt) DefElem *dencoding = NULL; char *dbname = stmt->dbname; char *dbowner = NULL; - char *dbtemplate = NULL; + const char *dbtemplate = NULL; int encoding = -1; #ifndef WIN32 diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 9e42c902f1..dd830f7c03 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -8,14 +8,19 @@ * * To create the database cluster, we create the directory that contains * all its data, create the files that hold the global tables, create - * a few other control files for it, and create two databases: the - * template0 and template1 databases. + * a few other control files for it, and create three databases: the + * template databases "template0" and "template1", and a default user + * database "postgres". * * The template databases are ordinary PostgreSQL databases. template0 * is never supposed to change after initdb, whereas template1 can be * changed to add site-local standard data. Either one can be copied * to produce a new database. * + * For largely-historical reasons, the template1 database is the one built + * by the basic bootstrap process. After it is complete, template0 and + * the default database, postgres, are made just by copying template1. + * * To create template1, we run the postgres (backend) program in bootstrap * mode and feed it data from the postgres.bki library file. After this * initial bootstrap phase, some additional stuff is created by normal @@ -23,12 +28,10 @@ * just embedded into this program (yeah, it's ugly), but larger chunks * are taken from script files. * - * template0 is made just by copying the completed template1. * * Note: * The program has some memory leakage - it isn't worth cleaning it up. * - * * This is a C implementation of the previous shell script for setting up a * PostgreSQL cluster location, and should be highly compatible with it. * author of C translation: Andrew Dunstan mailto:andrew@dunslane.net @@ -39,7 +42,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * Portions taken from FreeBSD. * - * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.84 2005/06/17 22:32:47 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.85 2005/06/21 04:02:32 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -178,6 +181,7 @@ static void set_info_version(void); static void setup_schema(void); static void vacuum_db(void); static void make_template0(void); +static void make_postgres(void); static void trapsig(int signum); static void check_ok(void); static char *escape_quotes(const char *src); @@ -1846,7 +1850,7 @@ make_template0(void) * We use the OID of template0 to determine lastsysoid */ "UPDATE pg_database SET datlastsysoid = " - " (SELECT oid::int4 - 1 FROM pg_database " + " (SELECT oid FROM pg_database " " WHERE datname = 'template0');\n", /* @@ -1882,6 +1886,37 @@ make_template0(void) check_ok(); } +/* + * copy template1 to postgres + */ +static void +make_postgres(void) +{ + PG_CMD_DECL; + char **line; + static char *postgres_setup[] = { + "CREATE DATABASE postgres;\n", + NULL + }; + + fputs(_("copying template1 to postgres ... "), stdout); + fflush(stdout); + + snprintf(cmd, sizeof(cmd), + "\"%s\" %s template1 >%s", + backend_exec, backend_options, + DEVNULL); + + PG_CMD_OPEN; + + for (line = postgres_setup; *line; line++) + PG_CMD_PUTS(*line); + + PG_CMD_CLOSE; + + check_ok(); +} + /* * signal handler in case we are interrupted. @@ -2609,6 +2644,8 @@ main(int argc, char *argv[]) make_template0(); + make_postgres(); + if (authwarning != NULL) fprintf(stderr, "%s", authwarning); diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index 30c95d1321..31547cbbf0 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -4,7 +4,7 @@ * * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.57 2005/05/04 22:35:15 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.58 2005/06/21 04:02:32 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -442,7 +442,7 @@ test_postmaster_connection(void) for (i = 0; i < wait_seconds; i++) { if ((conn = PQsetdbLogin(NULL, portstr, NULL, NULL, - "template1", NULL, NULL)) != NULL && + "postgres", NULL, NULL)) != NULL && (PQstatus(conn) == CONNECTION_OK || (strcmp(PQerrorMessage(conn), PQnoPasswordSupplied) == 0))) diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 07a08c41d8..0ed8b921b8 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.59 2005/04/18 23:47:52 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.60 2005/06/21 04:02:32 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -297,13 +297,13 @@ main(int argc, char *argv[]) } - conn = connectDatabase("template1", pghost, pgport, pguser, force_password); + conn = connectDatabase("postgres", pghost, pgport, pguser, force_password); printf("--\n-- PostgreSQL database cluster dump\n--\n\n"); if (verbose) dumpTimestamp("Started on"); - printf("\\connect \"template1\"\n\n"); + printf("\\connect \"postgres\"\n\n"); if (!data_only) { @@ -880,7 +880,7 @@ runPgDump(const char *dbname) /* * Win32 has to use double-quotes for args, rather than single quotes. * Strangely enough, this is the only place we pass a database name on - * the command line, except template1 that doesn't need quoting. + * the command line, except "postgres" which doesn't need quoting. */ #ifndef WIN32 appendPQExpBuffer(cmd, "%s\"%s\" %s -Fp '", SYSTEMQUOTE, pg_dump_bin, diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index ff8a5c2431..9caecbe449 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2005, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.117 2005/06/14 02:57:41 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.118 2005/06/21 04:02:33 tgl Exp $ */ #include "postgres_fe.h" @@ -195,7 +195,7 @@ main(int argc, char *argv[]) { need_pass = false; pset.db = PQsetdbLogin(options.host, options.port, NULL, NULL, - options.action == ACT_LIST_DB ? "template1" : options.dbname, + options.action == ACT_LIST_DB ? "postgres" : options.dbname, username, password); if (PQstatus(pset.db) == CONNECTION_BAD && diff --git a/src/bin/scripts/clusterdb.c b/src/bin/scripts/clusterdb.c index 4b5bc6f15f..3ab0be575e 100644 --- a/src/bin/scripts/clusterdb.c +++ b/src/bin/scripts/clusterdb.c @@ -4,7 +4,7 @@ * * Portions Copyright (c) 2002-2005, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/scripts/clusterdb.c,v 1.12 2005/01/01 05:43:08 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/clusterdb.c,v 1.13 2005/06/21 04:02:33 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -207,7 +207,7 @@ cluster_all_databases(const char *host, const char *port, PGresult *result; int i; - conn = connectDatabase("template1", host, port, username, password, progname); + conn = connectDatabase("postgres", host, port, username, password, progname); result = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn;", progname, echo); PQfinish(conn); diff --git a/src/bin/scripts/createdb.c b/src/bin/scripts/createdb.c index f85e4e84fe..1585523ab9 100644 --- a/src/bin/scripts/createdb.c +++ b/src/bin/scripts/createdb.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/createdb.c,v 1.14 2004/12/31 22:03:17 pgsql Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/createdb.c,v 1.15 2005/06/21 04:02:33 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -157,7 +157,8 @@ main(int argc, char *argv[]) appendPQExpBuffer(&sql, " TEMPLATE %s", fmtId(template)); appendPQExpBuffer(&sql, ";\n"); - conn = connectDatabase("template1", host, port, username, password, progname); + conn = connectDatabase(strcmp(dbname, "postgres") == 0 ? "template1" : "postgres", + host, port, username, password, progname); if (echo) printf("%s", sql.data); diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.c index 67758e00d7..db85837952 100644 --- a/src/bin/scripts/createuser.c +++ b/src/bin/scripts/createuser.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.16 2004/12/31 22:03:17 pgsql Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.17 2005/06/21 04:02:33 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -209,7 +209,7 @@ main(int argc, char *argv[]) appendPQExpBuffer(&sql, " NOCREATEUSER"); appendPQExpBuffer(&sql, ";\n"); - conn = connectDatabase("template1", host, port, username, password, progname); + conn = connectDatabase("postgres", host, port, username, password, progname); if (echo) printf("%s", sql.data); diff --git a/src/bin/scripts/dropdb.c b/src/bin/scripts/dropdb.c index d58ffcb4ef..944c68dbe3 100644 --- a/src/bin/scripts/dropdb.c +++ b/src/bin/scripts/dropdb.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/dropdb.c,v 1.14 2004/12/31 22:03:17 pgsql Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/dropdb.c,v 1.15 2005/06/21 04:02:33 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -117,7 +117,8 @@ main(int argc, char *argv[]) appendPQExpBuffer(&sql, "DROP DATABASE %s;\n", fmtId(dbname)); - conn = connectDatabase("template1", host, port, username, password, progname); + conn = connectDatabase(strcmp(dbname, "postgres") == 0 ? "template1" : "postgres", + host, port, username, password, progname); if (echo) printf("%s", sql.data); diff --git a/src/bin/scripts/dropuser.c b/src/bin/scripts/dropuser.c index 343cae39b8..32aa83557a 100644 --- a/src/bin/scripts/dropuser.c +++ b/src/bin/scripts/dropuser.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/dropuser.c,v 1.13 2004/12/31 22:03:17 pgsql Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/dropuser.c,v 1.14 2005/06/21 04:02:33 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -116,7 +116,7 @@ main(int argc, char *argv[]) initPQExpBuffer(&sql); appendPQExpBuffer(&sql, "DROP USER %s;\n", fmtId(dropuser)); - conn = connectDatabase("template1", host, port, username, password, progname); + conn = connectDatabase("postgres", host, port, username, password, progname); if (echo) printf("%s", sql.data); diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c index 2015e44242..8998d5da6c 100644 --- a/src/bin/scripts/vacuumdb.c +++ b/src/bin/scripts/vacuumdb.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/vacuumdb.c,v 1.12 2004/12/31 22:03:17 pgsql Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/vacuumdb.c,v 1.13 2005/06/21 04:02:33 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -233,7 +233,7 @@ vacuum_all_databases(bool full, bool verbose, bool analyze, PGresult *result; int i; - conn = connectDatabase("template1", host, port, username, password, progname); + conn = connectDatabase("postgres", host, port, username, password, progname); result = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn;", progname, echo); PQfinish(conn); diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 458cddd134..84e07725cf 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -37,7 +37,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.279 2005/06/20 10:29:37 teodor Exp $ + * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.280 2005/06/21 04:02:33 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 200506201 +#define CATALOG_VERSION_NO 200506202 #endif diff --git a/src/interfaces/ecpg/test/testdynalloc.pgc b/src/interfaces/ecpg/test/testdynalloc.pgc index c0023f8640..a2f67412b7 100644 --- a/src/interfaces/ecpg/test/testdynalloc.pgc +++ b/src/interfaces/ecpg/test/testdynalloc.pgc @@ -13,7 +13,7 @@ int main() if (getenv("SQLOPT")) ECPGdebug(1,stderr); exec sql whenever sqlerror do sqlprint(); - exec sql connect to template1; + exec sql connect to postgres; exec sql allocate descriptor mydesc; exec sql select tablename into descriptor mydesc from pg_tables; diff --git a/src/interfaces/libpq/pg_service.conf.sample b/src/interfaces/libpq/pg_service.conf.sample index e15d79b91e..8a22fda95a 100644 --- a/src/interfaces/libpq/pg_service.conf.sample +++ b/src/interfaces/libpq/pg_service.conf.sample @@ -4,13 +4,13 @@ # A service is a set of named connection parameters. You may specify # multiple services in this file. Each starts with a service name in # brackets. Subsequent lines have connection configuration parameters of -# the pattern "param=value". A sample configuration for template1 is +# the pattern "param=value". A sample configuration for postgres is # included in this file. Lines beginning with '#' are comments. # # Copy this to your sysconf directory (typically /usr/local/pgsql/etc) and # rename it pg_service.conf. # # -#[template1] -#dbname=template1 +#[postgres] +#dbname=postgres #user=postgres diff --git a/src/test/bench/create.sh b/src/test/bench/create.sh index 77c0836830..a865e68f8f 100755 --- a/src/test/bench/create.sh +++ b/src/test/bench/create.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $PostgreSQL: pgsql/src/test/bench/create.sh,v 1.4 2004/09/01 17:25:40 tgl Exp $ +# $PostgreSQL: pgsql/src/test/bench/create.sh,v 1.5 2005/06/21 04:02:34 tgl Exp $ # if [ ! -d $1 ]; then echo " you must specify a valid data directory " >&2 @@ -10,10 +10,10 @@ if [ -d ./obj ]; then fi echo =============== destroying old bench database... ================= -echo "drop database bench" | postgres -D${1} template1 > /dev/null +echo "drop database bench" | postgres -D${1} postgres > /dev/null echo =============== creating new bench database... ================= -echo "create database bench" | postgres -D${1} template1 > /dev/null +echo "create database bench" | postgres -D${1} postgres > /dev/null if [ $? -ne 0 ]; then echo createdb failed exit 1 diff --git a/src/test/examples/testlibpq.c b/src/test/examples/testlibpq.c index b9d396a2dc..3295076481 100644 --- a/src/test/examples/testlibpq.c +++ b/src/test/examples/testlibpq.c @@ -26,14 +26,14 @@ main(int argc, char **argv) /* * If the user supplies a parameter on the command line, use it as the - * conninfo string; otherwise default to setting dbname=template1 and + * conninfo string; otherwise default to setting dbname=postgres and * using environment variables or defaults for all other connection * parameters. */ if (argc > 1) conninfo = argv[1]; else - conninfo = "dbname = template1"; + conninfo = "dbname = postgres"; /* Make a connection to the database */ conn = PQconnectdb(conninfo); diff --git a/src/test/examples/testlibpq2.c b/src/test/examples/testlibpq2.c index 1cb7616f24..9f1e96d8da 100644 --- a/src/test/examples/testlibpq2.c +++ b/src/test/examples/testlibpq2.c @@ -46,14 +46,14 @@ main(int argc, char **argv) /* * If the user supplies a parameter on the command line, use it as the - * conninfo string; otherwise default to setting dbname=template1 and + * conninfo string; otherwise default to setting dbname=postgres and * using environment variables or defaults for all other connection * parameters. */ if (argc > 1) conninfo = argv[1]; else - conninfo = "dbname = template1"; + conninfo = "dbname = postgres"; /* Make a connection to the database */ conn = PQconnectdb(conninfo); diff --git a/src/test/examples/testlibpq3.c b/src/test/examples/testlibpq3.c index 7036d3e81f..49b03066cd 100644 --- a/src/test/examples/testlibpq3.c +++ b/src/test/examples/testlibpq3.c @@ -51,14 +51,14 @@ main(int argc, char **argv) /* * If the user supplies a parameter on the command line, use it as the - * conninfo string; otherwise default to setting dbname=template1 and + * conninfo string; otherwise default to setting dbname=postgres and * using environment variables or defaults for all other connection * parameters. */ if (argc > 1) conninfo = argv[1]; else - conninfo = "dbname = template1"; + conninfo = "dbname = postgres"; /* Make a connection to the database */ conn = PQconnectdb(conninfo); diff --git a/src/test/regress/pg_regress.sh b/src/test/regress/pg_regress.sh index 58534346df..c192edc515 100644 --- a/src/test/regress/pg_regress.sh +++ b/src/test/regress/pg_regress.sh @@ -1,5 +1,5 @@ #! /bin/sh -# $PostgreSQL: pgsql/src/test/regress/pg_regress.sh,v 1.56 2005/06/20 02:26:50 tgl Exp $ +# $PostgreSQL: pgsql/src/test/regress/pg_regress.sh,v 1.57 2005/06/21 04:02:34 tgl Exp $ me=`basename $0` : ${TMPDIR=/tmp} @@ -441,7 +441,7 @@ then # wait forever, however. i=0 max=60 - until "$bindir/psql" -X $psql_options template1 </dev/null 2>/dev/null + until "$bindir/psql" -X $psql_options postgres </dev/null 2>/dev/null do i=`expr $i + 1` if [ $i -ge $max ]