You should plan on becoming good at all sorts of user interfaces. Each form of user interface has its advantages and disadvantages. Using only one style of UI is as silly as only using one kind of editor or one language. "Specialization is for insects." - Heinlein
- CLI - good for
- low bandwidth environments (talking to cloud servers)
- very fast interactions for users that already know which command to use
- can use scripts and the alias command to create powerful custom commands
- GUI - good for
- exploring functionality & learning
- Seeing structure and organization - how things relate to each other
- Stay local - exhaust your local resources before googling
- Built-in help
pg_ctl --help
psql --help
psql
\q
command
- man pages (Try these in your shell)
man man
man zsh
(orman bash
)man pg_ctl
man psql
- Built-in help
- Practice reading text that is hard to read
- You may have to force yourself to keep reading every line when you feel lost.
- Skim & scan to get an overview, then read for detail
- This skill also helps with reading error messages
- This skill also helps with reading code
- Have a clear idea of what the CLI is supposed to do. (See if you can say a simple statement like "I want to list databases")
- Keep a notebook in a text file with a selection of command strings and what they do
- Your goal is not just to get a quick answer. It's to build your brain muscles to work in this text-heavy, jargon-filled environment.
- Powershell?
- gitbash?
- bash/zsh?
- psql?
- text pager?
Look at the prompt. Are you in zsh? psql? a text pager? The commands you use depend on the program that you are talking to. Try some form of "help" or "?" or "?" to see what's available.
Most of the time, you need to be in a specific folder for best results. It's always better to navigate to the proper folder location in your shell command line and then start up location-dependent GUI tools or running your automation scripts. On the other hand, some tools (like the postgress ones in this course) don't pay attention to their starting location because they connect via special files or network ports.
You can use the ps
command on OSX/Linux and the Services Manager on Windows.
One common problem is forgetting to stop your express server when you want to debug. For the simple architectures we use in class, you should only have one copy of each type of server running at a time.
Similarly, make sure your database server is running.
NOTE we're having trouble getting postgresql running on windows - when it appears to be running in the Services Manager, it doesn't respond reliably. It's better to disable it in the SM and start it from the command line using pg_ctl
.
Which user interface should I use for the command to ...
- ... create a user role?
createuser
orpsql
or dbeaver? - ... create a database?
createdb
orpsql
or dbeaver? - ... run a SQL script?
psql
or dbeaver?
Try them all before forming habits.
I tend to do something similar to this whenever I start working on express/postgres:
- Reboot the machine (Really! Just do it. Every day at least.)
- Log in to your development account (if your normal account is having trouble installing tools, create a fresh account on your laptop)
- Launch a command line shell
- In shell: Navigate to your project folder
- In shell: Launch postgresql database server
- Launch database client (
psql
or dbeaver) & verify server is running - In shell: Launch vscode (
code .
) - Pick a CLI - your shell or a vscode terminal - and stick with it
- Run tests (
npm test
) or server (npm run dev
) from that CLI and only that CLI
You should always have these tools available:
- postgresql database server
- CLI shell in project folder
- Database client (
psql
, dbeaver, or both) - vscode
- Postman
- Is the postgresql server running? (
pg_ctl status
) - Is only one instance of node/express running? (
ps
) - Is my connection spec correct? (use dbeaver to test connection)
- Am I in the right CLI? (look at the prompt characters)