Re: initdb createuser commands - Mailing list pgsql-general

From Adrian Klaver
Subject Re: initdb createuser commands
Date
Msg-id 5d97109a-d474-0670-a7c2-2fc726b5c749@aklaver.com
Whole thread Raw
In response to Re: initdb createuser commands  (Samuel Williams <space.ship.traveller@gmail.com>)
List 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@arkansas:~$ lsb_release -a
                                     
No LSB modules are available.
                                     
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:        14.04
Codename:       trusty


aklaver@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@arkansas:~$ sudo pg_ctlcluster 9.3 main start

aklaver@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@manitou-mail.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.klaver@aklaver.com


pgsql-general by date:

Previous
From: Samuel Williams
Date:
Subject: Re: initdb createuser commands
Next
From: Patrick B
Date:
Subject: Re: Turning slave into a master - PostgreSQL 9.2