Databases: PostgreSQL

Getting Started
Intro: Commands For Creating Your First Database
- Install PostgreSQL
brew install postgresql
- Start PostgreSQL server
brew services start postgresql
- Create a new database
createdb my_database
- Connect to the database
psql my_database
- Enter with Postgres shell:
psql -d my_database
Our First Workflow: What is Postgres
Postgres is a open-source relational database management system (RDBMS) that uses SQL as its query language. What we did above was first installing Postgres, then starting the Postgres server, create a new database, and finally connecting to the database using the psql command-line tool.
The first question that comes to mind is: what is a database? A database is a structured collection of data that is stored and accessed electronically. It allows us to store, retrieve, and manage data efficiently.
Next is, what is a Postgres server? A Postgres server is a software application that manages databases and handles client requests. It lives on a port (default is 5432) and listens for incoming connections from clients. When a client connects to the server, it can send SQL commands to interact with the database. Its essentially the backend that handles all the database operations, such as storing data, executing queries, and managing transactions. The database itself is just a collection of files on disk that the Postgres server manages. When we create a new database, we are essentially creating a new set of files that the Postgres server will manage. So we can't touch the database without the Postgres server, because the server is what allows us to interact with the database through SQL commands. So thus, we need to start the Postgres server before we can create a new database or connect to it.