New 'pg' consolidated metacommand patch

From: Mark Dilger <mark(dot)dilger(at)enterprisedb(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: New 'pg' consolidated metacommand patch
Date: 2020-05-26 23:19:37
Message-ID: AFA2DAE0-133E-4F2D-B608-E7540DF194CB@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hackers,

Attached is a patch for a `pg' command that consolidates various PostgreSQL functionality into a single command, along the lines of how `git' commands are run from a single 'git' executable. In other words,

`pg upgrade` # instead of `pg_upgrade`
`pg resetwal` # instead of `pg_resetwal`

This has been discussed before on the -hackers list, but I don't recall seeing a patch. I'm submitting this patch mostly as a way of moving the conversation along, fully expecting the community to want some (or all) of what I wrote to be changed.

I'd also appreciate +1 and -1 votes on the overall idea, in case this entire feature, regardless of implementation, is simply something the community does not want.

Once again, this is mostly intended as a starting point for discussion.

The patch moves some commands from BINDIR to LIBEXECDIR where `pg' expects to find them. For commands named pg_foo, the executable is still named pg_foo and the sources are still located in src/bin/pg_foo/, but the command can now be run as `pg foo`, `pg foo --version`, `pg foo FOO SPECIFIC ARGS`, etc.

The command pgbench (no underscore) maps to 'pg bench'.

Commands without a "pg" prefix stay the same, so "createdb" => "pg createdb", etc.

The 'psql' and 'postgres' executables (and the 'postmaster' link) have been left in BINDIR, as has 'ecpg'. The 'pg' executable has been added to BINDIR.

All other executables have been moved to LIBEXECDIR where they retain their old names and can still be run directly from the command line. If we committed this patch for v14, I think it makes sense that packagers could put the LIBEXECDIR in the PATH so that 3rd-party scripts which call pg_ctl, initdb, etc. continue to work. For that reason, I did not change the names of the executables, merely their location. During conversations with Robert off-list, we discussed renaming the executables to things like 'pg-ctl' (hyphen rather than underscore), mostly because that's the more modern way of doing it and follows what 'git' does. To avoid breaking scripts that execute these commands by the old name, this patch doesn't go that far. It also leaves the usage() functions alone such that when they report their own progname in the usage text, they do so under the old name. This would need to change at some point, but I'm unclear on whether that would be for v14 or if it would be delayed.

The binaries 'createuser' and 'dropuser' might be better named 'createrole' and 'droprole'. I don't currently have aliases in this patch, but it might make sense to allow 'pg createrole' as a synonym for 'pg createuser' and 'pg droprole' as a synonym for 'pg dropuser'. I have not pursued that yet, largely because as soon as you go that route, it starts making sense to have things like 'pg drop user', 'pg cluster db' and so forth, with the extra spaces. How far would people want me to go in this direction?

Prior to this patch, postgres binaries that need to execute other postgres binaries determine the BINDIR using find_my_exec and trimming off their own executable name. They can then assume the other binary is in that same directory. After this patch, binaries need to find the common prefix ROOTDIR = commonprefix(BINDIR,LIBEXECDIR) and then assume the other binary is either in ROOTDIR/binsuffix or ROOTDIR/libexecsuffix. This may cause problems on windows if BINDIR and LIBEXECDIR are configured on different drives, as there won't be a common prefix of C:\my\pg\bin and D:\my\pg\libexec. I'm hoping somebody with more Windows savvy expresses an opinion about how to handle this.

The handling of the old libexec directory in pg_upgrade is not as robust as it could be. I'll look to improve that for a subsequent version of the patch, assuming the overall idea of the patch seems acceptable.

I've updated some of the doc/sgml/* files, but don't want to spend too much time changing documentation until we have some consensus that the patch is moving in the right direction.

Attachment Content-Type Size
v1-0001-Implementing-new-pg-consolidated-metacommand.patch application/octet-stream 142.8 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2020-05-26 23:52:56 Re: Default gucs for EXPLAIN
Previous Message Andy Fan 2020-05-26 23:12:52 Re: Make the qual cost on index Filter slightly higher than qual cost on index Cond.