PostgreSQL
PostgreSQL is a powerful, open-source relational database management system (RDBMS) that is widely used for storing and managing large amounts of structured data. It is known for its robustness, scalability, and support for complex queries and transactions.
Installing PostgreSQL
To install PostgreSQL, on:
- Windows: Download the PostgreSQL installer from the official site.
- Mac:
Terminal window # Use Homebrewbrew install postgresql - Linux:
Terminal window # Use the official PostgreSQL installer.sudo apt install postgresql - Docker: Use the official PostgreSQL Docker image.
Setting up a PostgreSQL
To set up a PostgreSQL database, follow these steps:
-
Start the PostgreSQL Service
Start the PostgreSQL service to ensure it’s running on your system:
Terminal window sudo service postgresql start -
Create a Database
create a new database for your chai and city date:
Terminal window createdb chai_and_citythis creates a new database called
chai_and_cityin postgresql. -
Connecting to the Database
Connecting to your newly created database using PostgreSQL command line interface:
Terminal window psql -d chai_and_citythis will prompt you to enter your password. Enter your password. Here -d is a flag that specifies the database you want to connect to.
pgAdmin as GUI
pgAdmin is a graphical interface for managing PostgreSQL databases. Follow these steps to connect and manage your database using pgAdmin:
- Download and Install pgAdmin: Go to the official pgAdmin website and install it for your operating system.
- Connect to your local PostgreSQL Server: Open pgAdmin and create a new server connection. For the host name, use localhost and enter your PostgreSQL username and password.
- Create a Database: Right-click on your server in pgAdmin, select “Create,” and choose “Database.” Name the database chai_and_cities.
- Manage Data Visually: You can now use pgAdmin’s graphical interface to create tables, insert data, and run queries
Summary
In this chapter, we learned how to install PostgreSQL and set up a database. We also learned how to connect to the database using PostgreSQL command line interface and pgAdmin.
Start your journey with ChaiCode
All of our courses are available on chaicode.com. Feel free to check them out.