Re: initdb createuser commands

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Samuel Williams <space(dot)ship(dot)traveller(at)gmail(dot)com>, Daniel Verite <daniel(at)manitou-mail(dot)org>
Cc: John R Pierce <pierce(at)hogranch(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: initdb createuser commands
Date: 2016-11-01 00:33:17
Message-ID: 5d97109a-d474-0670-a7c2-2fc726b5c749@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 10/31/2016 05:15 PM, Samuel Williams wrote:
> Daniel, your reply is awesome :) I love the historical context and it
> brings much clarity to the discussion!
>
> It's now understandable why the commands were named the way they were.
>
> I'm surprised that distros are making their own commands for
> postgres.. isn't that a bit invasive?

No, actually it is quite handy:

https://wiki.debian.org/PostgreSql

It allows you to handle multiple instances of Postgres easily:

aklaver(at)arkansas:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty

aklaver(at)arkansas:~$ pg_lsclusters

Ver Cluster Port Status Owner Data directory Log file
9.3 main 5432 down postgres /var/lib/postgresql/9.3/main /var/log/postgresql/postgresql-9.3-main.log
9.4 main 5434 online postgres /var/lib/postgresql/9.4/main /var/log/postgresql/postgresql-9.4-main.log

aklaver(at)arkansas:~$ sudo pg_ctlcluster 9.3 main start

aklaver(at)arkansas:~$ pg_lsclusters

Ver Cluster Port Status Owner Data directory Log file
9.3 main 5432 online postgres /var/lib/postgresql/9.3/main /var/log/postgresql/postgresql-9.3-main.log
9.4 main 5434 online postgres /var/lib/postgresql/9.4/main /var/log/postgresql/postgresql-9.4-main.log

>
>
>
> On 1 November 2016 at 06:50, Daniel Verite <daniel(at)manitou-mail(dot)org> wrote:
>> Samuel Williams wrote:
>>
>>> John - that's an interesting example. If it's that easy, why isn't
>>> that the approach given in tutorials and other documentation? What was
>>> the motivation for the createuser command?
>>
>> initdb, createdb and createuser existed even before Postgres
>> adopted SQL, back when it was developed by the University of
>> Berkeley.
>>
>> You can find references to these commands in the doc here:
>> http://db.cs.berkeley.edu/postgres-v4r2/postgres-setup.ps
>> which dates back from 1994.
>> (fun fact: there was no psql yet, the equivalent command was called
>> "monitor". How about that for a name that has seemingly nothing
>> to do with postgres? :)
>>
>> According to these old instructions, commands are installed
>> by default into /usr/local/postgres/bin,
>> so that was their namespace. They were not supposed to be mixed
>> with other non-postgres commands.
>>
>> That's still the case today if you run ./configure and
>> "make install" from the current postgresql sources:
>> these commands end up in /usr/local/pgsql/bin
>> Some installers such as the EDB installers for Windows or Unix
>> typically use a dedicated directory for PostgreSQL, so again its
>> commands don't get mixed with other stuff.
>>
>> As for the Postgresql pre-compiled packages that come with Linux
>> distributions, they need to respect the policy of their distros,
>> meaning that all user-callable commands should be in the default $PATH.
>> That implies that, for instance, postgresql's "createuser" ends up
>> in $PATH along with the system's "adduser", even though they have
>> hardly anything to do with each other, so yes, that's somehow
>> unfortunate.
>> But these decisions are made by packagers and distributions, not
>> by the PostgreSQL developers.
>>
>> Some of these commands are already documented as deprecated,
>> for example "createlang", which I find in Ubuntu 14.04 /usr/bin:
>> $ man createlang
>> [...]
>> Caution
>> createlang is deprecated and may be removed in a future PostgreSQL
>> release. Direct use of the CREATE EXTENSION command is recommended
>> instead.
>>
>> The same could theorically be done to createuser/dropuser or
>> createdb/dropdb, but there's the question of whether this would create
>> more harm that good, because they're much widely used in
>> existing scripts and tutorials.
>>
>> Note that in any case your proposal to use "pg" as an
>> umbrella-command wouldn't fly with these systems because pg is a
>> pager from the Debian's util-linux package.
>>
>> $ which pg
>> /usr/bin/pg
>>
>> $ man pg
>> PG(1) User Commands
>> PG(1)
>>
>> NAME
>> pg - browse pagewise through text files
>>
>> SYNOPSIS
>> pg [-number] [-p string] [-cefnrs] [+line] [+/pattern/] [file...]
>> ...
>>
>> Also, the same Debian/Ubuntu systems don't have initdb or pg_ctl
>> in the default $PATH, as these commands are superseded
>> by different distro-specific pg_* commands . This is also
>> something that should be considered if thinking of unifying
>> the binaries.
>>
>>
>> Best regards,
>> --
>> Daniel Vérité
>> PostgreSQL-powered mailer: http://www.manitou-mail.org
>> Twitter: @DanielVerite
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Patrick B 2016-11-01 01:54:53 Re: Turning slave into a master - PostgreSQL 9.2
Previous Message Samuel Williams 2016-11-01 00:15:07 Re: initdb createuser commands