6 ms·
> Now you can quit Postgres by simply typing quit or exit. Previously you had to use Ctrl + D or \q While this is good to help out beginners a bit, people shou
by jorams 8y ago
> Now you can quit Postgres by simply typing quit or exit. Previously you had to use Ctrl + D or \q
While this is good to help out beginners a bit, people should really learn Ctrl + D. It works practically everywhere and saves tons of time guessing/remembering and even typing the correct incantation for the program you want to exit.
- craigkerstiens 8y agoOriginal author here. Yes, it's great to learn Ctrl + D. But losing out on beginners that aren't familiar in favor of things that are naturally intuitive is a great way to make those who are new to programming and especially databases feel like they're dumb or not capable of it. I still recall the first time I was in vi and I couldn't figure out how to get out of the damn thing, and don't get me started on arrow keys. There are a lot of ways to help others learn things like Ctrl + D, an even better experience might be a 1 second delay with a message informing them of other ways. We could bikeshed all day on which is the more pristine way to exit a program, paint the shed whatever color you want, being intuitive for beginners is never a bad thing.
- Jedd 8y agoYou use the word intuitive a couple of times, and suggest there's a natural way to exit interactive cli programs (and it's not ctrl-d). Yet for me, ctrl-d is my usual first way of trying to exit any shell or cli utility. Whether it's natural or not, I couldn't say. Arguably the nipple is the first and only intuitive interface, everything after that is learned. After many years on my/maria I find the backslash shortcuts very counterintuitive to 'show databases | tables' etc. While I think it's great to have both options present, I don't think the demographic of people who work out they want an rdbms, evaluate and select postgresql, work out how to install server and client components, su to the postgres user, and are then likely to abandon in frustration as they can't determine how to exit the cli, is negligible.
- craigkerstiens 8y agoThe background of what you learned on is key to whats intuitive or natural. If you came up on an unix based system then yes you'd expect this. If you learned databases via MySQL then you'd expect show database to work. Today though many more are coming to development without an academic or linux background. If you install Postgres via Postgres.app there is a chance you're not at all familiar with a commandline. What is intuitive... yes it's relative to your background. I very much hope that the number quit or exit is intuitive for, those that don't come from a linux or academic background, grows of time. This does become a more valuable tool the more beginners there are, and personally from working with a lot of beginners already suspect it's more valuable than many realize.
- tormeh 8y agoMost CLIs can be exited with "quit" or "exit". Many trap Ctrl-C, so those two are the first things I try. Didn't know about Ctrl-D before now, and I've worked as a sysadm.
- Jedd 8y ago> The background of what you learned on is key to whats intuitive or natural. That's pretty much the summary of my post. > If you install Postgres via Postgres.app ... I had to go lookup what postgres.app actually is -- evidently it's an easy way for Mac users to install postgres. I don't have a Mac -- which is also true for most people -- so I can't speak to the average mac user's experience or expectations. As I have (had to repeatedly) say a few times now, I think it's great that multiple options to end the program are available. I'd imagine for Mac users the 'most intuitive' thing would be to find some magic symbol on their keyboard and combine it with the letter Q.
- solarengineer 8y agoMac users either don't stop the service at all, or they use the GUI to do so (if they installed via the postgres.app tool)
- freeopinion 8y ago
- davidw 8y agoI'm reminded of this bit, from https://www.gnu.org/fun/jokes/ed-msg.html https://www.gnu.org/fun/jokes/ed-msg.html Let's look at a typical novice's session with the mighty ed: golem$ ed ? help ? ? ? quit ? exit ? bye ? hello? ? eat flaming death ? ^C ? ^C ? ^D ? --- Note the consistent user interface and error reportage. Ed is generous enough to flag errors, yet prudent enough not to overwhelm the novice with verbosity.
- tormeh 8y agoI think I did something like this with vim when I first encountered it. Now I like the damn thing (but still prefer VS Code).
- user5994461 8y agoThe intuitive way to exit anything is Alt + F4.
- yawboakye 8y ago> But losing out on beginners that aren't familiar in favor of things that are naturally intuitive is a great way to make those who are new to programming and especially databases feel like they're dumb or not capable of it. I disagree with you here, Craig. In my experience I reach for Ctrl + D, Ctrl + C in quick succession to see what succeeds. I've learnt those and it works for most programs that don't trap exits (again, why would you trap exit?). It has saved me from learning how to exit interactive terminals for python, ruby, node, PostgreSQL (psql) without learning their specific instruction. I like that and I'd prefer to have one way of exiting programs that works on all programs on the system than learn what's any programs preferred command.
- SSLy 8y ago>why would you trap exit? flush buffers, gracefully close sockets, print the final \LF to the stdout.
- MaxBarraclough 8y ago> I like that and I'd prefer to have one way of exiting programs that works on all programs on the system than learn what's any programs preferred command. I bet you love Vim ;-P
- eip 8y ago> Ctrl+D > things that are naturally intuitive Pick one
- threeseed 8y agoWhat other apps use Ctrl+D ? I can't think of a single one.
- beardicus 8y agopython and node REPLs both do this.
- 1stranger 8y agoPractically any interactive shell. python or bash for instance. It's everywhere.
- TheDong 8y agoAny command-line that uses readline[0], which in practice is an absolute ton of things. This includes nodejs's repl, irb, ed, gdb, tftp, virsh, gpg --card-edit, and others. It also works for programs that read stdin as if it's a file if you're using a modern readline shell to run them (e.g. cat, tee, etc) [0]: https://en.wikipedia.org/wiki/GNU_Readline https://en.wikipedia.org/wiki/GNU_Readline
- mortehu 8y agoIt has nothing to do with readline, but is a feature of the TTY (i.e. implemented inside the kernel) when in canonical mode. It will work for anything that exits in reaction to read(STDIN_FILENO, ...) returning zero.
- deleted 8y ago[deleted]
- tudelo 8y agoYet, principle of least surprise. What is more surprising, Ctrl+D working or quit/exit not working? Maybe I am an outlier but I would try exit/quit/bye first.
- sdegutis 8y agoI learned about Ctrl + D pretty early on in my software career, probably around 2009 or so, and have been using it 99.99% of the time since then[1]. It's both consistent and easy, so I really can't see any benefit of not using it. [1] The 0.01% of the time was when I was testing out using Windows for software dev. I don't remember but I don't think Ctrl + D works there.
- dvlsg 8y agoI find myself pressing ctrl+c on windows.
- eitally 8y agoctrl+c also works on Crosh (Chrome Shell).
- y4mi 8y agoBut not on Windows cmd I think it worked in powershell however, can't test right now though Also: chromeos is Linux. It's a safe bet they'll support standard signals
- dvlsg 8y agoYou mean in general or specifically for PostgreSQL? Ctrl+c definitely works in cmd in general, which is what my original post was referencing. I use it all the time. Not sure about for PostgreSQL in cmd off the top of my head (posting from my phone). I suspect because I got down voted that it may not work there.
- TheDong 8y ago
- pkulak 8y agoYou're wrong. I think the bike shed should be blue. ;)
- koolba 8y agoNo GP is correct. Control-D sends an EOF (end of file) which indicates there is no more input. This isn’t bike shedding at all as there’s a specific character code to indicate you’ve finished with a program and it’s standardized on all sane pieces of software. Heck it even works with things that aren’t specifically programmed to “exit” as they’ll simply end the stream on receipt.
- viraptor 8y agoThis isn't really about alternatives. Bike shedding could be about exit-vs-quit or similar. Ctrl-d exists a layer above though. In a typical terminal / readline, your process will get an EOF / HUP signal which is treated like a clean-exit in most interactive cases and config-reload in many servers. Just like ctrl-c generates INT and ctrl-z generates STP. This is worth learning.
- colanderman 8y agoDon't forget Ctrl-\. For when you feel like Ctrl-C is too nice. (It sends SIGQUIT.)
- majewsky 8y ago> Just like ctrl-c generates INT and ctrl-z generates STP. It's very different. Ctrl-D does not generate signals. When written into the tty master, it forces the kernel to answer any pending read() syscalls on the tty slave, even if it means returning 0 bytes. Programs then apply the convention of treating a read() that returns 0 bytes as meaning EOF (because that's how it works with all other file types that are not tty slaves).
- t0mbstone 8y agoControl+C is used to kill a process with the signal SIGINT, and can be intercepted by a program so it can clean its self up before exiting, or not exit at all. ... Ctrl+D means end of file. It has no effect if the program isn't reading input from the terminal. Ctrl+C means “interrupt”, i.e., stop what you're doing.
- paulddraper 8y agoOh no! I used to be able to Ctrl+C knowing that it would interrupt any currently running query but never lose my session. If I want to quit the PostgreSQL shell, I'd Ctrl+D like any other shell. What will I do now?
- grzm 8y agoCtrl-D still works. The new sql commands additions.
- paulddraper 8y agoRight, but now I can't Ctrl+C to cancel a query without worrying instead I will exit the shell instead.
- Shish2k 8y agoYou're worried that when you try to hit ctrl-c you might accidentally type "exit"? I'm not sure how else the addition of exit as an alias for ctrl-d would affect your ctrl-c work...
- paulddraper 8y agoNevermind I misread.
- tuukkah 8y agoWhere does it say that Ctrl-C handling has changed?
- peteretep 8y agoWhat does Python do these days? I seem to remember it would catch common cases, but rather than quit, scold you and tell you how you should be doing it the other way, which seemed like the most Western European approach imaginable.
- int_19h 8y agoPython 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> quit Use quit() or Ctrl-Z plus Return to exit >>> exit Use exit() or Ctrl-Z plus Return to exit
- int_19h 8y agoOh, and in true Python fashion, the reason it works is not because the REPL is special-casing "quit". It's because when you evaluate an expression, the REPL prints out its repr. And `quit` is not a function, but rather a callable object with a custom repr: >>> type(quit) <class '_sitebuiltins.Quitter'> >>> repr(quit) 'Use quit() or Ctrl-Z plus Return to exit' and it's implemented like so: class Quitter(object): def __init__(self, name, eof): self.name = name self.eof = eof def __repr__(self): return 'Use %s() or %s to exit' % (self.name, self.eof) def __call__(self, code=None): # Shells like IDLE catch the SystemExit, but listen when their # stdin wrapper is closed. try: sys.stdin.close() except: pass raise SystemExit(code) The same is done for "help", "copyright", "license" and "credits". REPL only does what its name says it does: read, evaluate, print, and loop. So there's no magic. There's only Python.
- ahartmetz 8y agoPython actually taught me to use Ctrl-D everywhere. Even though I was initially annoyed, I now understand the wisdom behind it :P
- int_19h 8y agoExcept it's Ctrl+Z in Python for Windows, because that's the convention for EOF there.
- barrkel 8y agoC-d is a great way to accidentally exit more than one shell with remote latency. I only use it then there's no other choice. Most frequent use case is ad-hoc file transfer via terminal paste to remote end running cat > out.txt.
- lkbm 8y agoI'd propose that "quit" should do two things: 1. Print "You can also quit using Ctrl + D" 2. Quit. But I also believe that only doing step 2 is better than neither. psql should prioritize psql's usability over educating users on Unix standards.