This article is based on my experience using these commands and my general understanding, there undoubtedly is more that can be accomplished with each, so please keep that in mind as you proceed through this wildly fun postgres post.
Any time I reach for the
pg_ctl command it is for administrating my postgres server. An example would be starting and stopping the server. The most common commands I’ve used:
Start postgres server:
Stop postgres server:
Check the status of the postgres server:
Restart the postgres server:
psql command is used for accessing a database server. The documentation describes it as “terminal based front-end to PostgreSQL”. There are different options you can use with this command to specify things like user and hostname. Below we cover some of the different options:
Connect to a database under root access:
You can also specify a specific user to connect to the database with:
psql -d database_name -U user_name -W
Or connect to a server on a different host:
psql -h host -d database_name -U user_name -W
Did this post make your day a little brighter? Why not take a swim in this other postgres article about postgres with Homebrew or learn how to access table metadata if that’s more your cup of liquid iv.